X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfbits.c;h=5106df5faad8135637b16a43ad4d9a8b64ebba23;hb=387eb848e7ef7a878ced45d4193529787628dff0;hp=05b21fb671222d62264fa4985f40fd84aac2824d;hpb=feacd0e752b03cb7e953483f4251956a362fec7c;p=swftools.git diff --git a/lib/modules/swfbits.c b/lib/modules/swfbits.c index 05b21fb..5106df5 100644 --- a/lib/modules/swfbits.c +++ b/lib/modules/swfbits.c @@ -1,152 +1,151 @@ -/* swfbits.c - - Bitmap functions (needs libjpeg) - - Extension module for the rfxswf library. - Part of the swftools package. - - Copyright (c) 2000, 2001 Rainer Böhme - - This file is distributed under the GPL, see file COPYING for details - -*/ - -#ifdef _JPEGLIB_INCLUDED_ -#define OUTBUFFER_SIZE 32768 - -typedef struct _JPEGDESTMGR -{ struct jpeg_destination_mgr mgr; - LPTAG t; - JOCTET * buffer; - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; -} JPEGDESTMGR, * LPJPEGDESTMGR; - -// Destination manager callbacks - -void swf_init_destination(j_compress_ptr cinfo) -{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; - dmgr->buffer = (JOCTET*)malloc(OUTBUFFER_SIZE); - dmgr->mgr.next_output_byte = dmgr->buffer; - dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE; -} - -boolean swf_empty_output_buffer(j_compress_ptr cinfo) -{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; - SetBlock(dmgr->t, - (U8*)dmgr->buffer, - OUTBUFFER_SIZE-dmgr->mgr.free_in_buffer); - dmgr->mgr.next_output_byte = dmgr->buffer; - dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE; -} - -void swf_term_destination(j_compress_ptr cinfo) -{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; - swf_empty_output_buffer(cinfo); - free(dmgr->buffer); - dmgr->mgr.free_in_buffer = 0; -} - -LPJPEGBITS SetJPEGBitsStart(LPTAG t,int width,int height,int quality) -{ - LPJPEGDESTMGR jpeg; - - // redirect compression lib output to local SWF Tag structure - - jpeg = (LPJPEGDESTMGR)malloc(sizeof(JPEGDESTMGR)); - if (!jpeg) return NULL; - - memset(jpeg,0x00,sizeof(JPEGDESTMGR)); - jpeg->cinfo.err = jpeg_std_error(&jpeg->jerr); - - jpeg_create_compress(&jpeg->cinfo); - - jpeg->mgr.init_destination = swf_init_destination; - jpeg->mgr.empty_output_buffer = swf_empty_output_buffer; - jpeg->mgr.term_destination = swf_term_destination; - - jpeg->t = t; - - jpeg->cinfo.dest = (struct jpeg_destination_mgr *)jpeg; - - // init compression - - jpeg->cinfo.image_width = width; - jpeg->cinfo.image_height = height; - jpeg->cinfo.input_components = 3; - jpeg->cinfo.in_color_space = JCS_RGB; - - jpeg_set_defaults(&jpeg->cinfo); - jpeg_set_quality(&jpeg->cinfo,quality,TRUE); - - // write tables to SWF - - jpeg_write_tables(&jpeg->cinfo); - - // compess image to SWF - - jpeg_suppress_tables(&jpeg->cinfo, TRUE); - jpeg_start_compress(&jpeg->cinfo, FALSE); - - return (LPJPEGBITS)jpeg; -} - -int SetJPEGBitsLines(LPJPEGBITS jpegbits,U8 ** data,int n) -{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits; - if (!jpeg) return -1; - jpeg_write_scanlines(&jpeg->cinfo,data,n); - return 0; -} - -int SetJPEGBitsLine(LPJPEGBITS jpegbits,U8 * data) -{ return SetJPEGBitsLines(jpegbits,&data,1); -} - -int SetJPEGBitsFinish(LPJPEGBITS jpegbits) -{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits; - if (!jpeg) return -1; - jpeg_finish_compress(&jpeg->cinfo); - free(jpeg); - return 0; -} - -int SetJPEGBits(LPTAG t,char * fname,int quality) -{ struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - LPJPEGBITS out; - FILE * f; - U8 * scanline; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - - if ((f=fopen(fname,"rb"))==NULL) return -1; - - - jpeg_stdio_src(&cinfo,f); - jpeg_read_header(&cinfo, TRUE); - jpeg_start_decompress(&cinfo); - - out = SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality); - scanline = (U8*)malloc(4*cinfo.output_width); - - if (scanline) - { int y; - U8 * js = scanline; - for (y=0;y + + This file is distributed under the GPL, see file COPYING for details + +*/ + +#ifdef _JPEGLIB_INCLUDED_ +#define OUTBUFFER_SIZE 0x8000 + +typedef struct _JPEGDESTMGR +{ struct jpeg_destination_mgr mgr; + LPTAG t; + JOCTET * buffer; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; +} JPEGDESTMGR, * LPJPEGDESTMGR; + +// Destination manager callbacks + +void swf_init_destination(j_compress_ptr cinfo) +{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; + dmgr->buffer = (JOCTET*)malloc(OUTBUFFER_SIZE); + dmgr->mgr.next_output_byte = dmgr->buffer; + dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE; +} + +boolean swf_empty_output_buffer(j_compress_ptr cinfo) +{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; + SetBlock(dmgr->t,(U8*)dmgr->buffer,OUTBUFFER_SIZE); + dmgr->mgr.next_output_byte = dmgr->buffer; + dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE; + return TRUE; +} + +void swf_term_destination(j_compress_ptr cinfo) +{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest; + SetBlock(dmgr->t,(U8*)dmgr->buffer,OUTBUFFER_SIZE-dmgr->mgr.free_in_buffer); + free(dmgr->buffer); + dmgr->mgr.free_in_buffer = 0; +} + +LPJPEGBITS SetJPEGBitsStart(LPTAG t,int width,int height,int quality) +{ + LPJPEGDESTMGR jpeg; + + // redirect compression lib output to local SWF Tag structure + + jpeg = (LPJPEGDESTMGR)malloc(sizeof(JPEGDESTMGR)); + if (!jpeg) return NULL; + + memset(jpeg,0x00,sizeof(JPEGDESTMGR)); + jpeg->cinfo.err = jpeg_std_error(&jpeg->jerr); + + jpeg_create_compress(&jpeg->cinfo); + + jpeg->mgr.init_destination = swf_init_destination; + jpeg->mgr.empty_output_buffer = swf_empty_output_buffer; + jpeg->mgr.term_destination = swf_term_destination; + + jpeg->t = t; + + jpeg->cinfo.dest = (struct jpeg_destination_mgr *)jpeg; + + // init compression + + jpeg->cinfo.image_width = width; + jpeg->cinfo.image_height = height; + jpeg->cinfo.input_components = 3; + jpeg->cinfo.in_color_space = JCS_RGB; + + jpeg_set_defaults(&jpeg->cinfo); + jpeg_set_quality(&jpeg->cinfo,quality,TRUE); + + // write tables to SWF + + jpeg_write_tables(&jpeg->cinfo); + + // compess image to SWF + + jpeg_suppress_tables(&jpeg->cinfo, TRUE); + jpeg_start_compress(&jpeg->cinfo, FALSE); + + return (LPJPEGBITS)jpeg; +} + +int SetJPEGBitsLines(LPJPEGBITS jpegbits,U8 ** data,int n) +{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits; + if (!jpeg) return -1; + jpeg_write_scanlines(&jpeg->cinfo,data,n); + return 0; +} + +int SetJPEGBitsLine(LPJPEGBITS jpegbits,U8 * data) +{ return SetJPEGBitsLines(jpegbits,&data,1); +} + +int SetJPEGBitsFinish(LPJPEGBITS jpegbits) +{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits; + if (!jpeg) return -1; + jpeg_finish_compress(&jpeg->cinfo); + free(jpeg); + return 0; +} + +int SetJPEGBits(LPTAG t,char * fname,int quality) +{ struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + LPJPEGBITS out; + FILE * f; + U8 * scanline; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + + if ((f=fopen(fname,"rb"))==NULL) return -1; + + + jpeg_stdio_src(&cinfo,f); + jpeg_read_header(&cinfo, TRUE); + jpeg_start_decompress(&cinfo); + + out = SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality); + scanline = (U8*)malloc(4*cinfo.output_width); + + if (scanline) + { int y; + U8 * js = scanline; + for (y=0;y