X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmodules%2Fswfbits.c;h=4643551695a7c0348d8e1c75ba1e19bcf1f6f900;hb=fc815311aa1bd67877b404493838dfd85a86f596;hp=0749e0b1bc4c7672b64f4e10896de1dd67762691;hpb=8d7fb28616f751a5b645f7b2330c61116e24ca8d;p=swftools.git diff --git a/lib/modules/swfbits.c b/lib/modules/swfbits.c index 0749e0b..4643551 100644 --- a/lib/modules/swfbits.c +++ b/lib/modules/swfbits.c @@ -326,7 +326,7 @@ void swf_SetJPEGBits2(TAG * tag, U16 width, U16 height, RGBA * bitmap, int quali } #endif -void swf_GetJPEGSize(char *fname, int *width, int *height) +void swf_GetJPEGSize(const char *fname, int *width, int *height) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -347,7 +347,7 @@ void swf_GetJPEGSize(char *fname, int *width, int *height) fclose(fi); } -int swf_SetJPEGBits(TAG * t, char *fname, int quality) +int swf_SetJPEGBits(TAG * t, const char *fname, int quality) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -561,7 +561,8 @@ static void tag_init_source(struct jpeg_decompress_struct *cinfo) static boolean tag_fill_input_buffer(struct jpeg_decompress_struct *cinfo) { TAG *tag = (TAG *) cinfo->client_data; - if (tag->data[tag->pos + 0] == 0xff && + if (tag->pos + 4 <= tag->len && + tag->data[tag->pos + 0] == 0xff && tag->data[tag->pos + 1] == 0xd9 && tag->data[tag->pos + 2] == 0xff && tag->data[tag->pos + 3] == 0xd8) { @@ -1181,10 +1182,17 @@ TAG* swf_AddImage(TAG*tag, int bitid, RGBA*mem, int width, int height, int quali int has_alpha = swf_ImageHasAlpha(mem,width,height); /* try lossless image */ + +#ifdef NO_LOSSLESS + tag1 = swf_InsertTag(0, /*ST_DEFINEBITSLOSSLESS1/2*/0); + tag1->len = 0x7fffffff; +#else tag1 = swf_InsertTag(0, /*ST_DEFINEBITSLOSSLESS1/2*/0); swf_SetU16(tag1, bitid); swf_SetLosslessImage(tag1, mem, width, height); +#endif +#if defined(HAVE_JPEGLIB) /* try jpeg image */ if(has_alpha) { tag2 = swf_InsertTag(0, ST_DEFINEBITSJPEG3); @@ -1195,8 +1203,9 @@ TAG* swf_AddImage(TAG*tag, int bitid, RGBA*mem, int width, int height, int quali swf_SetU16(tag2, bitid); swf_SetJPEGBits2(tag2, width, height, mem, quality); } +#endif - if(quality>100 || (tag1 && tag1->len < tag2->len)) { + if(quality>100 || !tag2 || (tag1 && tag1->len < tag2->len)) { /* use the zlib version- it's smaller */ tag1->prev = tag; if(tag) tag->next = tag1; @@ -1380,6 +1389,97 @@ static void decodeMonochromeImage(RGBA*data, int width, int height, RGBA*colors) } } +static void blurImage(RGBA*src, int width, int height, int r) +{ + int e = 2; // r times e is the sampling interval + double*gauss = (double*)malloc(r*e*sizeof(double)); + double sum=0; + int x; + for(x=0;x> 16; + d[x].g = g >> 16; + d[x].b = b >> 16; + d[x].a = a >> 16; + } + for(x=width-range;x> 16; + d[yy].g = g >> 16; + d[yy].b = b >> 16; + d[yy].a = a >> 16; + yy += width; + } + for(y=0;y4) { + /* high-resolution monochrome images are usually dithered, so + low-pass filter them first to get rid of any moire patterns */ + blurImage(data, width, height, r+1); + } } tmpline = (rgba_int_t*)malloc(width*sizeof(rgba_int_t));