[tex-k] web2c vs. png-1.5

Thomas Klausner tk at giga.or.at
Mon Jan 31 19:21:51 CET 2011


On Mon, Jan 31, 2011 at 06:13:54PM +0100, Taco Hoekwater wrote:
> On 01/31/11 17:33, Martin Schröder wrote:
> > We have already adapted to 1.4 (with some warnings left).
> 
> Martin, can you look into this? I currently have no time to
> sort this out.

Here's a patch against current SVN 4051 of writepng.w which makes it
compatible with png-1.5.

As I wrote to the web2c mailing list:

png-1.5 hides structure members from public view. For this reason,
some code doesn't compile any more.

The attached patches fix the problem.

I wasn't sure how to fix the png_transformations part of the patch; I
asked the png people and was told by a png developer, John Bowler,
that the check as-is doesn't make sense. His full reply is available
at http://sourceforge.net/mailarchive/message.php?msg_id=26908171

So I think the patch should be fine as-is. It seems to still be needed
in the current development trunk, AFAICT. Please apply it or something
similar.


Cheers,
 Thomas
-------------- next part --------------
--- writepng.w	2011-01-31 19:17:59.000000000 +0100
+++ writepng.w.new	2011-01-31 19:19:13.000000000 +0100
@@ -66,7 +67,7 @@
     if ((info_p = png_create_info_struct(png_p)) == NULL)
         pdftex_fail("libpng: png_create_info_struct() failed");
     img_png_info_ptr(idict) = info_p;
-    if (setjmp(png_p->jmpbuf))
+    if (setjmp(png_jmpbuf(png_p)))
         pdftex_fail("libpng: internal error");
     png_init_io(png_p, img_file(idict));
     png_read_info(png_p, info_p);
@@ -95,7 +96,7 @@
     /* resolution support */
     img_xsize(idict) = (int) png_get_image_width (png_p, info_p);
     img_ysize(idict) = (int) png_get_image_height (png_p, info_p);
-    if (info_p->valid & PNG_INFO_pHYs) {
+    if (png_get_valid(png_p, info_p, PNG_INFO_pHYs)) {
         img_xres(idict) =
             round(0.0254 * (double) png_get_x_pixels_per_meter(png_p, info_p));
         img_yres(idict) =
@@ -178,12 +179,17 @@
     png_infop info_p = img_png_info_ptr(idict);
     png_bytep row, r, *rows;
     int palette_objnum = 0;
+    png_colorp palette;
+    int num_palette;
+
+    png_get_PLTE(png_p, info_p, &palette, &num_palette);
+
     if (img_colorspace(idict) != 0) {
         pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
     } else {
         palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
         pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
-                   (int) (info_p->num_palette - 1), (int) palette_objnum);
+                   num_palette - 1, (int) palette_objnum);
     }
     pdf_begin_stream(pdf);
     if (png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE) {
@@ -205,11 +211,11 @@
     if (palette_objnum > 0) {
         pdf_begin_dict(pdf, palette_objnum, 0);
         pdf_begin_stream(pdf);
-        for (i = 0; (unsigned) i < info_p->num_palette; i++) {
+        for (i = 0; (unsigned) i < num_palette; i++) {
             pdf_room(pdf, 3);
-            pdf_quick_out(pdf, info_p->palette[i].red);
-            pdf_quick_out(pdf, info_p->palette[i].green);
-            pdf_quick_out(pdf, info_p->palette[i].blue);
+            pdf_quick_out(pdf, palette[i].red);
+            pdf_quick_out(pdf, palette[i].green);
+            pdf_quick_out(pdf, palette[i].blue);
         }
         pdf_end_stream(pdf);
     }
@@ -568,12 +574,15 @@
      */
     if (pdf->minor_version > 1 
            && png_get_interlace_type (png_p, info_p) == PNG_INTERLACE_NONE 
-           && (png_p->transformations == 0 || png_p->transformations == 0x2000)     /* gamma */
         &&!(png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_GRAY_ALPHA ||
             png_get_color_type (png_p, info_p) == PNG_COLOR_TYPE_RGB_ALPHA)
         && ((pdf->image_hicolor != 0) || (png_get_bit_depth (png_p, info_p) <= 8))
         && (checked_gamma <= 1.01 && checked_gamma > 0.99)
         ) {
+        png_colorp palette;
+        int num_palette;
+
+        png_get_PLTE(png_p, info_p, &palette, &num_palette);
         if (img_colorspace(idict) != 0) {
             pdf_printf(pdf, "%i 0 R\n", (int) img_colorspace(idict));
         } else {
@@ -581,8 +590,7 @@
             case PNG_COLOR_TYPE_PALETTE:
                 palette_objnum = pdf_create_obj(pdf, obj_type_others, 0);
                 pdf_printf(pdf, "[/Indexed /DeviceRGB %i %i 0 R]\n",
-                           (int) (info_p->num_palette - 1),
-                           (int) palette_objnum);
+                           num_palette - 1, (int) palette_objnum);
                 break;
             case PNG_COLOR_TYPE_GRAY:
                 pdf_puts(pdf, "/DeviceGray\n");
@@ -597,11 +605,11 @@
         if (palette_objnum > 0) {
             pdf_begin_dict(pdf, palette_objnum, 0);
             pdf_begin_stream(pdf);
-            for (i = 0; (unsigned) i < info_p->num_palette; i++) {
+            for (i = 0; (unsigned) i < num_palette; i++) {
                 pdf_room(pdf, 3);
-                pdf_quick_out(pdf, info_p->palette[i].red);
-                pdf_quick_out(pdf, info_p->palette[i].green);
-                pdf_quick_out(pdf, info_p->palette[i].blue);
+                pdf_quick_out(pdf, palette[i].red);
+                pdf_quick_out(pdf, palette[i].green);
+                pdf_quick_out(pdf, palette[i].blue);
             }
             pdf_end_stream(pdf);
         }
@@ -611,8 +619,6 @@
             if ((pdf->image_apply_gamma != 0) &&
                 (checked_gamma > 1.01 || checked_gamma < 0.99))
                 tex_printf("gamma delta=%lf ", checked_gamma);
-            if (png_p->transformations != PNG_TRANSFORM_IDENTITY)
-                tex_printf("transform=%lu", (long) png_p->transformations);
             if ((png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_GRAY)
                 && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_RGB)
                 && (png_get_color_type (png_p, info_p) != PNG_COLOR_TYPE_PALETTE))


More information about the tex-k mailing list