X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fjpeg.c;h=f9cdf414a16be5a67d23c7e1e0045a846f6e3561;hp=dee4dfa6383b51add209c4c6211d9f296a22ab93;hb=bdad407fb79c2f7be9f3603694ebdeadc645b52d;hpb=f37e8f18c9aabe6b7298ef037df26a02bfc4f361 diff --git a/lib/jpeg.c b/lib/jpeg.c index dee4dfa..f9cdf41 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; @@ -313,13 +352,13 @@ int jpeg_load(const char*filename, unsigned char**dest, int*_width, int*_height) int width = *_width = cinfo.output_width; int height = *_height = cinfo.output_height; - *dest = malloc(width*height*4); + *dest = (unsigned char*)malloc(width*height*4); int y; for (y=0;y