X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfbits.c;h=c8cb96b04267e9856ada51cba5a097ee448db214;hb=735edd1d444cb6c62c655b96b2d37c2da8bda5dd;hp=cef0c2741580355c80f64e97ac5a2388063bb4db;hpb=d193d733dfa41679452284e4e60e7237ac721cba;p=swftools.git diff --git a/lib/modules/swfbits.c b/lib/modules/swfbits.c index cef0c27..c8cb96b 100644 --- a/lib/modules/swfbits.c +++ b/lib/modules/swfbits.c @@ -13,7 +13,7 @@ #define OUTBUFFER_SIZE 0x8000 -#ifdef _JPEGLIB_INCLUDED_ +#ifdef HAVE_JPEGLIB typedef struct _JPEGDESTMGR { struct jpeg_destination_mgr mgr; @@ -138,7 +138,10 @@ int swf_SetJPEGBits(TAG * t,char * fname,int quality) cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); - if ((f=fopen(fname,"rb"))==NULL) return -1; + if ((f=fopen(fname,"rb"))==NULL) { + fprintf(stderr, "rfxswf: file open error\n"); + return -1; + } jpeg_stdio_src(&cinfo,f); jpeg_read_header(&cinfo, TRUE); @@ -216,7 +219,7 @@ int swf_SetJPEGBits(TAG * t,char * fname,int quality) return 0; } -#endif // _JPEGLIB_INCLUDED_ +#endif // HAVE_JPEGLIB // Lossless compression texture based on zlib @@ -248,6 +251,7 @@ int RFXSWF_deflate_wraper(TAG * t,z_stream * zs,U8 * data,boolean finish) return 0; } + int swf_SetLosslessBits(TAG * t,U16 width,U16 height,void * bitmap,U8 bitmap_flags) { int res = 0; int bps; @@ -263,6 +267,7 @@ int swf_SetLosslessBits(TAG * t,U16 width,U16 height,void * bitmap,U8 bitmap_fla bps = width*4; break; default: + fprintf(stderr, "rfxswf: unknown bitmap type %d\n", bitmap_flags); return -1; } @@ -288,7 +293,6 @@ int swf_SetLosslessBits(TAG * t,U16 width,U16 height,void * bitmap,U8 bitmap_fla deflateEnd(&zs); - } else res = -3; // zlib error free(data); } else res = -2; // memory error @@ -309,7 +313,10 @@ int swf_SetLosslessBitsIndexed(TAG * t,U16 width,U16 height,U8 * bitmap,RGBA * p ncolors = 256; } - if ((ncolors<2)||(ncolors>256)||(!t)) return -1; // parameter error + if ((ncolors<2)||(ncolors>256)||(!t)) { + fprintf(stderr, "rfxswf: unsupported number of colors: %d\n", ncolors); + return -1; // parameter error + } swf_SetU8(t,BMF_8BIT); swf_SetU16(t,width); @@ -394,6 +401,90 @@ int swf_SetLosslessBitsGrayscale(TAG * t,U16 width,U16 height,U8 * bitmap) #endif // HAVE_ZLIB -#undef OUTBUFFER_SIZE +#if defined(HAVE_ZLIB) && defined(HAVE_JPEGLIB) +int swf_SetJPEGBits3(TAG * tag,U16 width,U16 height,RGBA* bitmap, int quality) +{ + JPEGBITS* jpeg; + int y; + int pos; + int res = 0; + U8 * data; + z_stream zs; + + pos = tag->len; + swf_SetU32(tag, 0); //placeholder + jpeg = swf_SetJPEGBitsStart(tag,width,height,quality); + for (y=0;ydata[pos], tag->len - pos - 4); + + data=malloc(OUTBUFFER_SIZE); + memset(&zs,0x00,sizeof(z_stream)); + + if (deflateInit(&zs,Z_DEFAULT_COMPRESSION)!=Z_OK) { + fprintf(stderr, "rfxswf: zlib compression failed"); + return -3; + } + + zs.next_out = data; + zs.avail_out = OUTBUFFER_SIZE; + + for (y=0;y