View Issue Details

IDProjectCategoryView StatusLast Update
0000418luatexfeature requestpublic2010-12-13 14:43
ReporterTaco Assigned Tooneiros  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Fixed in Version0.65.0 
Summary0000418: prepare for libpng 1.4
DescriptionSee attached patched for pdftex from PEB.
TagsNo tags attached.

Relationships

related to 0000529 closedoneiros Adapt to libpng 1.4.x 

Activities

Taco

2010-06-17 06:12

administrator  

png-pdf.diff (19,970 bytes)   
diff -ur TeXlive-trunk/Build/source/texk/web2c/pdftexdir/ChangeLog Work/New/tex-live-2010-06-10/texk/web2c/pdftexdir/ChangeLog
--- TeXlive-trunk/Build/source/texk/web2c/pdftexdir/ChangeLog	2010-06-10 15:18:47.000000000 +0200
+++ Work/New/tex-live-2010-06-10/texk/web2c/pdftexdir/ChangeLog	2010-06-16 14:14:55.377279306 +0200
@@ -1,3 +1,10 @@
+2010-06-16  Peter Breitenlohner  <peb@mppmu.mpg.de>
+
+	Prepare for libpng-1.4.x.
+	* writepng.c: Define and use macros to access bit_depth and the
+	other fields of the png_info and png_ptr structs.  There remain
+	a few direct references due to png_info/png_ptr ambiguities.
+
 2010-06-10  Peter Breitenlohner  <peb@mppmu.mpg.de>
 
 	* am/pdftex.am (pdftex_cppflags): Add $(AM_CPPFLAGS).
diff -ur TeXlive-trunk/Build/source/texk/web2c/pdftexdir/writepng.c Work/New/tex-live-2010-06-10/texk/web2c/pdftexdir/writepng.c
--- TeXlive-trunk/Build/source/texk/web2c/pdftexdir/writepng.c	2010-04-16 12:39:02.000000000 +0200
+++ Work/New/tex-live-2010-06-10/texk/web2c/pdftexdir/writepng.c	2010-06-16 14:17:13.843157575 +0200
@@ -21,6 +21,18 @@
 #include "ptexlib.h"
 #include "image.h"
 
+#define png_bit_depth(N)	png_info(N)->bit_depth
+#define png_color_type(N)	png_info(N)->color_type
+#define png_height(N)		png_info(N)->height
+#define png_interlace_type(N)	png_info(N)->interlace_type
+#define png_io_ptr(N)		png_ptr(N)->io_ptr
+#define png_num_palette(N)	png_info(N)->num_palette
+#define png_palette(N)		png_info(N)->palette
+#define png_rowbytes(N)		png_info(N)->rowbytes
+#define png_transformations(N)	png_ptr(N)->transformations
+#define png_valid(N)		png_info(N)->valid
+#define png_width(N)		png_info(N)->width
+
 static int transparent_page_group = -1;
 
 void read_png_info(integer img)
@@ -48,7 +60,7 @@
     /* 16bit depth support */
     if (fixedpdfminorversion < 5)
         fixedimagehicolor = 0;
-    if (png_info(img)->bit_depth == 16 && !fixedimagehicolor)
+    if (png_bit_depth(img) == 16 && !fixedimagehicolor)
         png_set_strip_16(png_ptr(img));
     /* gamma support */
     if (fixedimageapplygamma) {
@@ -61,9 +73,9 @@
     /* reset structure */
     png_read_update_info(png_ptr(img), png_info(img));
     /* resolution support */
-    img_width(img) = png_info(img)->width;
-    img_height(img) = png_info(img)->height;
-    if (png_info(img)->valid & PNG_INFO_pHYs) {
+    img_width(img) = png_width(img);
+    img_height(img) = png_height(img);
+    if (png_valid(img) & PNG_INFO_pHYs) {
         img_xres(img) =
             round(0.0254 *
                   png_get_x_pixels_per_meter(png_ptr(img), png_info(img)));
@@ -71,7 +83,7 @@
             round(0.0254 *
                   png_get_y_pixels_per_meter(png_ptr(img), png_info(img)));
     }
-    switch (png_info(img)->color_type) {
+    switch (png_color_type(img)) {
     case PNG_COLOR_TYPE_PALETTE:
         img_color(img) = IMAGE_COLOR_C | IMAGE_COLOR_I;
         break;
@@ -85,11 +97,11 @@
         break;
     default:
         pdftex_fail("unsupported type of color_type <%i>",
-                    png_info(img)->color_type);
+                    png_color_type(img));
     }
     if (fixedpdfminorversion >= 4
-        && (png_info(img)->color_type == PNG_COLOR_TYPE_GRAY_ALPHA
-            || png_info(img)->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) {
+        && (png_color_type(img) == PNG_COLOR_TYPE_GRAY_ALPHA
+            || png_color_type(img) == PNG_COLOR_TYPE_RGB_ALPHA)) {
         /* png with alpha channel in device colours; we have to add a Page
          * Group to make Adobe happy, so we have to create a dummy group object
          */
@@ -125,10 +137,10 @@
 
 
 #define write_noninterlaced(outmac)                    \
-  for (i = 0; i < (int)png_info(img)->height; i++) {   \
+  for (i = 0; i < (int)png_height(img); i++) {   \
     png_read_row(png_ptr(img), row, NULL);             \
     r = row;                                           \
-    k = png_info(img)->rowbytes;                       \
+    k = png_rowbytes(img);                       \
     while(k > 0) {                                     \
         l = (k > pdfbufsize)? pdfbufsize : k;          \
                 pdfroom(l);                            \
@@ -140,9 +152,9 @@
         }
 
 #define write_interlaced(outmac)                       \
-  for (i = 0; i < (int)png_info(img)->height; i++) {   \
+  for (i = 0; i < (int)png_height(img); i++) {   \
             row = rows[i];                             \
-            k = png_info(img)->rowbytes;               \
+            k = png_rowbytes(img);               \
             while(k > 0) {                             \
                 l = (k > pdfbufsize)? pdfbufsize : k;  \
                 pdfroom(l);                            \
@@ -166,21 +178,21 @@
         pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
     } else {
         pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
-                   (int) (png_info(img)->num_palette - 1),
+                   (int) (png_num_palette(img) - 1),
                    (int) palette_objnum);
     }
     pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
+    if (png_interlace_type(img) == PNG_INTERLACE_NONE) {
+        row = xtalloc(png_rowbytes(img), png_byte);
         write_noninterlaced(write_simple_pixel(r));
         xfree(row);
     } else {
-        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
+        if (png_height(img) * png_rowbytes(img) >= 10240000L)
             pdftex_warn
                 ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; (unsigned) i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
+        rows = xtalloc(png_height(img), png_bytep);
+        for (i = 0; (unsigned) i < png_height(img); i++)
+            rows[i] = xtalloc(png_rowbytes(img), png_byte);
         png_read_image(png_ptr(img), rows);
         write_interlaced(write_simple_pixel(row));
         xfree(rows);
@@ -189,11 +201,11 @@
     if (palette_objnum > 0) {
         pdfbegindict(palette_objnum, 0);
         pdfbeginstream();
-        for (i = 0; (unsigned) i < png_info(img)->num_palette; i++) {
+        for (i = 0; (unsigned) i < png_num_palette(img); i++) {
             pdfroom(3);
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
-            pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
+            pdfbuf[pdfptr++] = png_palette(img)[i].red;
+            pdfbuf[pdfptr++] = png_palette(img)[i].green;
+            pdfbuf[pdfptr++] = png_palette(img)[i].blue;
         }
         pdfendstream();
     }
@@ -209,17 +221,17 @@
         pdf_puts("/DeviceGray\n");
     }
     pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
+    if (png_interlace_type(img) == PNG_INTERLACE_NONE) {
+        row = xtalloc(png_rowbytes(img), png_byte);
         write_noninterlaced(write_simple_pixel(r));
         xfree(row);
     } else {
-        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
+        if (png_height(img) * png_rowbytes(img) >= 10240000L)
             pdftex_warn
                 ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; (unsigned) i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
+        rows = xtalloc(png_height(img), png_bytep);
+        for (i = 0; (unsigned) i < png_height(img); i++)
+            rows[i] = xtalloc(png_rowbytes(img), png_byte);
         png_read_image(png_ptr(img), rows);
         write_interlaced(write_simple_pixel(row));
         xfree(rows);
@@ -246,26 +258,26 @@
     pdfcreateobj(0, 0);
     smask_objnum = objptr;
     pdf_printf("/SMask %i 0 R\n", (int) smask_objnum);
-    smask_size = (png_info(img)->rowbytes / 2) * png_info(img)->height;
+    smask_size = (png_rowbytes(img) / 2) * png_height(img);
     smask = xtalloc(smask_size, png_byte);
     pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
-        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
+    if (png_interlace_type(img) == PNG_INTERLACE_NONE) {
+        row = xtalloc(png_rowbytes(img), png_byte);
+        if ((png_bit_depth(img) == 16) && fixedimagehicolor) {
             write_noninterlaced(write_gray_pixel_16(r));
         } else {
             write_noninterlaced(write_gray_pixel_8(r));
         }
         xfree(row);
     } else {
-        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
+        if (png_height(img) * png_rowbytes(img) >= 10240000L)
             pdftex_warn
                 ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; (unsigned) i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
+        rows = xtalloc(png_height(img), png_bytep);
+        for (i = 0; (unsigned) i < png_height(img); i++)
+            rows[i] = xtalloc(png_rowbytes(img), png_byte);
         png_read_image(png_ptr(img), rows);
-        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
+        if ((png_bit_depth(img) == 16) && fixedimagehicolor) {
             write_interlaced(write_gray_pixel_16(row));
         } else {
             write_interlaced(write_gray_pixel_8(row));
@@ -276,12 +288,12 @@
     pdfflush();
     /* now write the Smask object */
     if (smask_objnum > 0) {
-        bitdepth = (int) png_info(img)->bit_depth;
+        bitdepth = (int) png_bit_depth(img);
         pdfbegindict(smask_objnum, 0);
         pdf_puts("/Type /XObject\n/Subtype /Image\n");
         pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
-                   (int) png_info(img)->width,
-                   (int) png_info(img)->height,
+                   (int) png_width(img),
+                   (int) png_height(img),
                    (bitdepth == 16 ? 8 : bitdepth));
         pdf_puts("/ColorSpace /DeviceGray\n");
         pdfbeginstream();
@@ -307,17 +319,17 @@
         pdf_puts("/DeviceRGB\n");
     }
     pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
+    if (png_interlace_type(img) == PNG_INTERLACE_NONE) {
+        row = xtalloc(png_rowbytes(img), png_byte);
         write_noninterlaced(write_simple_pixel(r));
         xfree(row);
     } else {
-        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
+        if (png_height(img) * png_rowbytes(img) >= 10240000L)
             pdftex_warn
                 ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; (unsigned) i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
+        rows = xtalloc(png_height(img), png_bytep);
+        for (i = 0; (unsigned) i < png_height(img); i++)
+            rows[i] = xtalloc(png_rowbytes(img), png_byte);
         png_read_image(png_ptr(img), rows);
         write_interlaced(write_simple_pixel(row));
         xfree(rows);
@@ -342,26 +354,26 @@
     pdfcreateobj(0, 0);
     smask_objnum = objptr;
     pdf_printf("/SMask %i 0 R\n", (int) smask_objnum);
-    smask_size = (png_info(img)->rowbytes / 2) * png_info(img)->height;
+    smask_size = (png_rowbytes(img) / 2) * png_height(img);
     smask = xtalloc(smask_size, png_byte);
     pdfbeginstream();
-    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
-        row = xtalloc(png_info(img)->rowbytes, png_byte);
-        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
+    if (png_interlace_type(img) == PNG_INTERLACE_NONE) {
+        row = xtalloc(png_rowbytes(img), png_byte);
+        if ((png_bit_depth(img) == 16) && fixedimagehicolor) {
             write_noninterlaced(write_rgb_pixel_16(r));
         } else {
             write_noninterlaced(write_rgb_pixel_8(r));
         }
         xfree(row);
     } else {
-        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
+        if (png_height(img) * png_rowbytes(img) >= 10240000L)
             pdftex_warn
                 ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
-        rows = xtalloc(png_info(img)->height, png_bytep);
-        for (i = 0; (unsigned) i < png_info(img)->height; i++)
-            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
+        rows = xtalloc(png_height(img), png_bytep);
+        for (i = 0; (unsigned) i < png_height(img); i++)
+            rows[i] = xtalloc(png_rowbytes(img), png_byte);
         png_read_image(png_ptr(img), rows);
-        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
+        if ((png_bit_depth(img) == 16) && fixedimagehicolor) {
             write_interlaced(write_rgb_pixel_16(row));
         } else {
             write_interlaced(write_rgb_pixel_8(row));
@@ -372,12 +384,12 @@
     pdfflush();
     /* now write the Smask object */
     if (smask_objnum > 0) {
-        bitdepth = (int) png_info(img)->bit_depth;
+        bitdepth = (int) png_bit_depth(img);
         pdfbegindict(smask_objnum, 0);
         pdf_puts("/Type /XObject\n/Subtype /Image\n");
         pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
-                   (int) png_info(img)->width,
-                   (int) png_info(img)->height,
+                   (int) png_width(img),
+                   (int) png_height(img),
                    (bitdepth == 16 ? 8 : bitdepth));
         pdf_puts("/ColorSpace /DeviceGray\n");
         pdfbeginstream();
@@ -420,7 +432,7 @@
 
 static void copy_png(integer img)
 {
-    FILE *fp = (FILE *) png_ptr(img)->io_ptr;
+    FILE *fp = (FILE *) png_io_ptr(img);
     int i, len, type, streamlength = 0;
     boolean endflag = false;
     int idat = 0;               /* flag to check continuous IDAT chunks sequence */
@@ -448,8 +460,8 @@
                "/Columns %d"
                "/BitsPerComponent %i"
                "/Predictor 10>>\n>>\nstream\n", streamlength,
-               png_info(img)->color_type == 2 ? 3 : 1,
-               (int) png_info(img)->width, (int) png_info(img)->bit_depth);
+               png_color_type(img) == 2 ? 3 : 1,
+               (int) png_width(img), (int) png_bit_depth(img));
     /* 2nd pass to copy data */
     endflag = false;
     if (fseek(fp, 8, SEEK_SET) != 0)
@@ -518,8 +530,8 @@
 
     pdf_puts("/Type /XObject\n/Subtype /Image\n");
     pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
-               (int) png_info(img)->width,
-               (int) png_info(img)->height, (int) png_info(img)->bit_depth);
+               (int) png_width(img),
+               (int) png_height(img), (int) png_bit_depth(img));
     pdf_puts("/ColorSpace ");
     checked_gamma = 1.0;
     if (fixedimageapplygamma) {
@@ -532,9 +544,9 @@
     /* the switching between |png_info| and |png_ptr| queries has been trial and error.
      */
     if (fixedpdfminorversion > 1
-        && png_info(img)->interlace_type == PNG_INTERLACE_NONE
-        && (png_ptr(img)->transformations == PNG_TRANSFORM_IDENTITY
-            || png_ptr(img)->transformations == 0x2000)
+        && png_interlace_type(img) == PNG_INTERLACE_NONE
+        && (png_transformations(img) == PNG_TRANSFORM_IDENTITY
+            || png_transformations(img) == 0x2000)
         /* gamma */
         && !(png_ptr(img)->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
              png_ptr(img)->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
@@ -544,12 +556,12 @@
         if (img_colorspace_ref(img) != 0) {
             pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
         } else {
-            switch (png_info(img)->color_type) {
+            switch (png_color_type(img)) {
             case PNG_COLOR_TYPE_PALETTE:
                 pdfcreateobj(0, 0);
                 palette_objnum = objptr;
                 pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
-                           (int) (png_info(img)->num_palette - 1),
+                           (int) (png_num_palette(img) - 1),
                            (int) palette_objnum);
                 break;
             case PNG_COLOR_TYPE_GRAY:
@@ -564,11 +576,11 @@
         if (palette_objnum > 0) {
             pdfbegindict(palette_objnum, 0);
             pdfbeginstream();
-            for (i = 0; i < png_info(img)->num_palette; i++) {
+            for (i = 0; i < png_num_palette(img); i++) {
                 pdfroom(3);
-                pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
-                pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
-                pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
+                pdfbuf[pdfptr++] = png_palette(img)[i].red;
+                pdfbuf[pdfptr++] = png_palette(img)[i].green;
+                pdfbuf[pdfptr++] = png_palette(img)[i].blue;
             }
             pdfendstream();
         }
@@ -578,23 +590,23 @@
             if (fixedimageapplygamma &&
                 (checked_gamma > 1.01 || checked_gamma < 0.99))
                 tex_printf("gamma delta=%lf ", checked_gamma);
-            if (png_ptr(img)->transformations != PNG_TRANSFORM_IDENTITY)
+            if (png_transformations(img) != PNG_TRANSFORM_IDENTITY)
                 tex_printf("transform=%lu",
-                           (long) png_ptr(img)->transformations);
-            if ((png_info(img)->color_type != PNG_COLOR_TYPE_GRAY)
-                && (png_info(img)->color_type != PNG_COLOR_TYPE_RGB)
-                && (png_info(img)->color_type != PNG_COLOR_TYPE_PALETTE))
+                           (long) png_transformations(img));
+            if ((png_color_type(img) != PNG_COLOR_TYPE_GRAY)
+                && (png_color_type(img) != PNG_COLOR_TYPE_RGB)
+                && (png_color_type(img) != PNG_COLOR_TYPE_PALETTE))
                 tex_printf("colortype ");
             if (fixedpdfminorversion <= 1)
                 tex_printf("version=%d ", (int) fixedpdfminorversion);
-            if (png_info(img)->interlace_type != PNG_INTERLACE_NONE)
+            if (png_interlace_type(img) != PNG_INTERLACE_NONE)
                 tex_printf("interlaced ");
-            if (png_info(img)->bit_depth > 8)
-                tex_printf("bitdepth=%d ", png_info(img)->bit_depth);
+            if (png_bit_depth(img) > 8)
+                tex_printf("bitdepth=%d ", png_bit_depth(img));
             if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_tRNS))
                 tex_printf("simple transparancy ");
         }
-        switch (png_info(img)->color_type) {
+        switch (png_color_type(img)) {
         case PNG_COLOR_TYPE_PALETTE:
             write_png_palette(img);
             break;
@@ -620,7 +632,7 @@
             break;
         default:
             pdftex_fail("unsupported type of color_type <%i>",
-                        png_info(img)->color_type);
+                        png_color_type(img));
         }
     }
     pdfflush();
png-pdf.diff (19,970 bytes)   

oneiros

2010-11-29 17:41

developer   ~0000700

Should be fixed in r4017

Issue History

Date Modified Username Field Change
2010-06-17 06:12 Taco New Issue
2010-06-17 06:12 Taco Status new => assigned
2010-06-17 06:12 Taco Assigned To => Taco
2010-06-17 06:12 Taco File Added: png-pdf.diff
2010-11-29 17:40 oneiros Assigned To Taco => oneiros
2010-11-29 17:41 oneiros Note Added: 0000700
2010-11-30 12:19 oneiros Relationship added related to 0000529
2010-12-01 12:36 Taco Status assigned => resolved
2010-12-01 12:36 Taco Resolution open => fixed
2010-12-13 14:43 Taco Fixed in Version => 0.65.0
2010-12-13 14:43 Taco Status resolved => closed