merged rainers jpeg patch, and converted newlines to Unix style.
authorkramm <kramm>
Mon, 22 Oct 2001 15:53:49 +0000 (15:53 +0000)
committerkramm <kramm>
Mon, 22 Oct 2001 15:53:49 +0000 (15:53 +0000)
lib/modules/swfbits.c

index 05b21fb..5106df5 100644 (file)
-/* swfbits.c\r
-\r
-   Bitmap functions (needs libjpeg) \r
-\r
-   Extension module for the rfxswf library.\r
-   Part of the swftools package.\r
-\r
-   Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>\r
\r
-   This file is distributed under the GPL, see file COPYING for details \r
-\r
-*/\r
-\r
-#ifdef _JPEGLIB_INCLUDED_\r
-#define OUTBUFFER_SIZE 32768\r
-\r
-typedef struct _JPEGDESTMGR\r
-{ struct jpeg_destination_mgr mgr;\r
-  LPTAG  t;\r
-  JOCTET * buffer;\r
-  struct jpeg_compress_struct cinfo;\r
-  struct jpeg_error_mgr jerr;\r
-} JPEGDESTMGR, * LPJPEGDESTMGR;\r
-\r
-// Destination manager callbacks\r
-\r
-void swf_init_destination(j_compress_ptr cinfo) \r
-{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest;\r
-  dmgr->buffer = (JOCTET*)malloc(OUTBUFFER_SIZE);\r
-  dmgr->mgr.next_output_byte = dmgr->buffer;\r
-  dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE;\r
-}\r
-\r
-boolean swf_empty_output_buffer(j_compress_ptr cinfo)\r
-{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest;\r
-  SetBlock(dmgr->t,\r
-           (U8*)dmgr->buffer,\r
-           OUTBUFFER_SIZE-dmgr->mgr.free_in_buffer);\r
-  dmgr->mgr.next_output_byte = dmgr->buffer;\r
-  dmgr->mgr.free_in_buffer = OUTBUFFER_SIZE;\r
-}\r
-\r
-void swf_term_destination(j_compress_ptr cinfo) \r
-{ LPJPEGDESTMGR dmgr = (LPJPEGDESTMGR)cinfo->dest;\r
-  swf_empty_output_buffer(cinfo);\r
-  free(dmgr->buffer);\r
-  dmgr->mgr.free_in_buffer = 0;\r
-}\r
-\r
-LPJPEGBITS SetJPEGBitsStart(LPTAG t,int width,int height,int quality)\r
-{\r
-  LPJPEGDESTMGR jpeg;\r
-        \r
-  // redirect compression lib output to local SWF Tag structure\r
-  \r
-  jpeg = (LPJPEGDESTMGR)malloc(sizeof(JPEGDESTMGR));\r
-  if (!jpeg) return NULL;\r
-  \r
-  memset(jpeg,0x00,sizeof(JPEGDESTMGR));\r
-  jpeg->cinfo.err = jpeg_std_error(&jpeg->jerr);\r
-\r
-  jpeg_create_compress(&jpeg->cinfo);\r
-\r
-  jpeg->mgr.init_destination =  swf_init_destination;\r
-  jpeg->mgr.empty_output_buffer =       swf_empty_output_buffer;\r
-  jpeg->mgr.term_destination =  swf_term_destination;\r
-      \r
-  jpeg->t = t;\r
-\r
-  jpeg->cinfo.dest = (struct jpeg_destination_mgr *)jpeg;\r
-\r
-  // init compression\r
-  \r
-  jpeg->cinfo.image_width  = width;\r
-  jpeg->cinfo.image_height = height;\r
-  jpeg->cinfo.input_components = 3;\r
-  jpeg->cinfo.in_color_space = JCS_RGB;\r
-\r
-  jpeg_set_defaults(&jpeg->cinfo);\r
-  jpeg_set_quality(&jpeg->cinfo,quality,TRUE);\r
-\r
-  // write tables to SWF\r
-  \r
-  jpeg_write_tables(&jpeg->cinfo);\r
-\r
-  // compess image to SWF\r
-   \r
-  jpeg_suppress_tables(&jpeg->cinfo, TRUE);\r
-  jpeg_start_compress(&jpeg->cinfo, FALSE);\r
-\r
-  return (LPJPEGBITS)jpeg;\r
-}\r
-\r
-int SetJPEGBitsLines(LPJPEGBITS jpegbits,U8 ** data,int n)\r
-{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits;\r
-  if (!jpeg) return -1;\r
-  jpeg_write_scanlines(&jpeg->cinfo,data,n);\r
-  return 0;\r
-}\r
-\r
-int SetJPEGBitsLine(LPJPEGBITS jpegbits,U8 * data)\r
-{ return SetJPEGBitsLines(jpegbits,&data,1);\r
-}\r
-\r
-int SetJPEGBitsFinish(LPJPEGBITS jpegbits)\r
-{ LPJPEGDESTMGR jpeg = (LPJPEGDESTMGR)jpegbits;\r
-  if (!jpeg) return -1;\r
-  jpeg_finish_compress(&jpeg->cinfo);\r
-  free(jpeg);\r
-  return 0;\r
-}\r
-\r
-int SetJPEGBits(LPTAG t,char * fname,int quality)\r
-{ struct jpeg_decompress_struct cinfo;\r
-  struct jpeg_error_mgr jerr;\r
-  LPJPEGBITS out;\r
-  FILE * f;\r
-  U8 * scanline;\r
-  \r
-  cinfo.err = jpeg_std_error(&jerr);\r
-  jpeg_create_decompress(&cinfo); \r
-\r
-  if ((f=fopen(fname,"rb"))==NULL) return -1;\r
-  \r
-\r
-  jpeg_stdio_src(&cinfo,f);\r
-  jpeg_read_header(&cinfo, TRUE);\r
-  jpeg_start_decompress(&cinfo);\r
-\r
-  out = SetJPEGBitsStart(t,cinfo.output_width,cinfo.output_height,quality);\r
-  scanline = (U8*)malloc(4*cinfo.output_width);\r
-  \r
-  if (scanline)\r
-  { int y;\r
-    U8 * js = scanline;\r
-    for (y=0;y<cinfo.output_height;y++)\r
-    { jpeg_read_scanlines(&cinfo,&js,1);\r
-      SetJPEGBitsLines(out,(U8**)&js,1);\r
-    }\r
-  }\r
-\r
-  SetJPEGBitsFinish(out);\r
-  jpeg_finish_decompress(&cinfo);\r
-  fclose(f);\r
-  \r
-  return 0;\r
-}\r
-\r
-#undef OUTBUFFER_SIZE\r
-#endif\r
-\r
-// insert zlib/PNG functions here\r
+/* swfbits.c
+
+   Bitmap functions (needs libjpeg) 
+
+   Extension module for the rfxswf library.
+   Part of the swftools package.
+
+   Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
+   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<cinfo.output_height;y++)
+    { jpeg_read_scanlines(&cinfo,&js,1);
+      SetJPEGBitsLines(out,(U8**)&js,1);
+    }
+  }
+
+  SetJPEGBitsFinish(out);
+  jpeg_finish_decompress(&cinfo);
+  fclose(f);
+  
+  return 0;
+}
+
+#undef OUTBUFFER_SIZE
+#endif
+
+// insert zlib/PNG functions here