From: kramm Date: Sun, 27 Feb 2005 07:33:57 +0000 (+0000) Subject: added function swf_AddImage(). X-Git-Tag: release-0-7-0~184 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=62464bfc865c26edcdaec364ec9743018cadfd5a added function swf_AddImage(). --- diff --git a/lib/modules/swfbits.c b/lib/modules/swfbits.c index 8852237..57350da 100644 --- a/lib/modules/swfbits.c +++ b/lib/modules/swfbits.c @@ -849,6 +849,44 @@ int swf_SetJPEGBits3(TAG * tag, U16 width, U16 height, RGBA * bitmap, int qualit rfx_free(data); return 0; } + +TAG* swf_AddImage(TAG*tag, int bitid, RGBA*mem, int width, int height, int quality) +{ + TAG *tag1 = 0, *tag2 = 0; + int has_alpha = swf_ImageHasAlpha(mem,width,height); + + /* try lossless image */ + tag1 = swf_InsertTag(0, /*ST_DEFINEBITSLOSSLESS1/2*/0); + swf_SetU16(tag1, bitid); + swf_SetLosslessImage(tag1, mem, width, height); + + /* try jpeg image */ + if(has_alpha) { + tag2 = swf_InsertTag(0, ST_DEFINEBITSJPEG3); + swf_SetU16(tag2, bitid); + swf_SetJPEGBits3(tag2, width, height, mem, quality); + } else { + tag2 = swf_InsertTag(0, ST_DEFINEBITSJPEG2); + swf_SetU16(tag2, bitid); + swf_SetJPEGBits2(tag2, width, height, mem, quality); + } + + if(tag1 && tag1->len < tag2->len) { + /* use the zlib version- it's smaller */ + tag1->prev = tag; + if(tag) tag->next = tag1; + tag = tag1; + swf_DeleteTag(tag2); + } else { + /* use the jpeg version- it's smaller */ + tag2->prev = tag; + if(tag) tag->next = tag2; + tag = tag2; + swf_DeleteTag(tag1); + } + return tag; +} + #endif RGBA *swf_ExtractImage(TAG * tag, int *dwidth, int *dheight) diff --git a/lib/rfxswf.h b/lib/rfxswf.h index 1266d48..b05d3e6 100644 --- a/lib/rfxswf.h +++ b/lib/rfxswf.h @@ -739,6 +739,7 @@ RGBA* swf_DefineLosslessBitsTagToImage(TAG*tag, int*width, int*height); RGBA* swf_ExtractImage(TAG*tag, int*dwidth, int*dheight); RGBA* swf_ImageScale(RGBA*data, int width, int height, int newwidth, int newheight); +TAG* swf_AddImage(TAG*tag, int bitid, RGBA*mem, int width, int height, int quality); // swfsound.c void swf_SetSoundStreamHead(TAG*tag, int avgnumsamples);