jbig2dec
Ralph Giles <[email protected]> Wed, 07 Aug 2002 05:50:35 -0700
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jbig2dec/jbig2dec
In directory usw-pr-cvs1:/tmp/cvs-serv9522
Modified Files:
jbig2_image_png.c
Log Message:
Use callbacks for writing png data out to a file. This is necessary when
dynamically linking to libpng on win32 when different run-times are used
for each library. Patch from Russell Lang.
Index: jbig2_image_png.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_image_png.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jbig2_image_png.c 6 Aug 2002 11:31:53 -0000 1.8
+++ jbig2_image_png.c 7 Aug 2002 12:50:33 -0000 1.9
@@ -26,6 +26,26 @@
/* take an image structure and write it out in png format */
+static void
+jbig2_png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
+{
+ png_size_t check;
+
+ check = fwrite(data, 1, length, (png_FILE_p)png_ptr->io_ptr);
+ if (check != length) {
+ png_error(png_ptr, "Write Error");
+ }
+}
+
+static void
+jbig2_png_flush(png_structp png_ptr)
+{
+ png_FILE_p io_ptr;
+ io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
+ if (io_ptr != NULL)
+ fflush(io_ptr);
+}
+
int jbig2_image_write_png_file(Jbig2Image *image, char *filename)
{
FILE *out;
@@ -73,11 +93,13 @@
return 4;
}
- /* note that this doesn't work linking dynamically to libpng on win32
+ /* png_init_io() doesn't work linking dynamically to libpng on win32
one has to either link statically or use callbacks because of runtime
variations */
- png_init_io(png, out);
-
+ /* png_init_io(png, out); */
+ png_set_write_fn(png, (png_voidp)out, jbig2_png_write_data,
+ jbig2_png_flush);
+
/* now we fill out the info structure with our format data */
png_set_IHDR(png, info, image->width, image->height,
1, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,