X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fjpeg.c;h=1c5e91c9da15fe671e74e9cbc020199b0c3b5d8f;hb=bbcffe11621c032e06b92eeb17c49c2875ade3b5;hp=66882b0182b1f88a198e03b7f439bbe6ede64f2a;hpb=2ce26d808e6296ef01e50b1cbf7417cdca523a08;p=swftools.git diff --git a/lib/jpeg.c b/lib/jpeg.c index 66882b0..1c5e91c 100644 --- a/lib/jpeg.c +++ b/lib/jpeg.c @@ -124,6 +124,45 @@ int jpeg_save(unsigned char*data, int width, int height, int quality, const char return 1; } +int jpeg_save_gray(unsigned char*data, int width, int height, int quality, const char*filename) +{ + struct jpeg_destination_mgr mgr; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + + if(filename) fi = fopen(filename, "wb"); + else fi = 0; + + memset(&cinfo, 0, sizeof(cinfo)); + memset(&jerr, 0, sizeof(jerr)); + memset(&mgr, 0, sizeof(mgr)); + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + + mgr.init_destination = file_init_destination; + mgr.empty_output_buffer = file_empty_output_buffer; + mgr.term_destination = file_term_destination; + cinfo.dest = &mgr; + cinfo.image_width = width; + cinfo.image_height = height; + cinfo.input_components = 1; + cinfo.in_color_space = JCS_GRAYSCALE; + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo,quality,TRUE); + jpeg_start_compress(&cinfo, FALSE); + int t; + for(t=0;tsrc; - printf("skip %d +%d\n", size - mgr->bytes_in_buffer, num_bytes); + printf("skip %d +%ld\n", size - mgr->bytes_in_buffer, num_bytes); if(num_bytes<=0) return; mgr->next_input_byte += num_bytes; @@ -362,9 +401,33 @@ int jpeg_load(const char*filename, unsigned char**dest, int*_width, int*_height) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); + fclose(fi); return 1; } +void jpeg_get_size(const char *filename, int *width, int *height) +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + FILE *fi; + *width = 0; + *height = 0; + cinfo.err = jpeg_std_error(&jerr); + cinfo.image_width = 0; + cinfo.image_height = 0; + jpeg_create_decompress(&cinfo); + if ((fi = fopen(filename, "rb")) == NULL) { + fprintf(stderr, "couldn't open %s\n", filename); + return; + } + jpeg_stdio_src(&cinfo, fi); + jpeg_read_header(&cinfo, TRUE); + *width = cinfo.image_width; + *height = cinfo.image_height; + jpeg_destroy_decompress(&cinfo); + fclose(fi); +} + #else int jpeg_save(unsigned char*data, int width, int height, int quality, const char*filename) @@ -392,5 +455,11 @@ int jpeg_load(const char*filename, unsigned char**dest, int*_width, int*_height) fprintf(stderr, "jpeg_load: No JPEG support compiled in\n"); return 0; } +void jpeg_get_size(const char *fname, int *width, int *height) +{ + *width = 0; + *height = 0; + fprintf(stderr, "jpeg_get_size: No JPEG support compiled in\n"); +} #endif