]> git.pld-linux.org Git - packages/texlive.git/blob - texlive-libpng15.patch
- removed duplicated tex/latex/xkeyval from latex (packaged in -tex-xkeyval, depends...
[packages/texlive.git] / texlive-libpng15.patch
1 --- texlive-20080816-source/texk/web2c/pdftexdir/writepng.c.org 2012-02-08 08:36:18.131142166 +0100
2 +++ texlive-20080816-source/texk/web2c/pdftexdir/writepng.c     2012-02-08 08:43:47.718175693 +0100
3 @@ -1,5 +1,5 @@
4  /*
5 -Copyright (c) 1996-2008 Han The Thanh, <thanh@pdftex.org>
6 +Copyright 1996-2011 Han The Thanh, <thanh@pdftex.org>
7  
8  This file is part of pdfTeX.
9  
10 @@ -14,21 +14,16 @@
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License along
14 -with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
15 -Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 +with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18  
19  #include "ptexlib.h"
20  #include "image.h"
21  
22 -static const char _svn_version[] =
23 -    "$Id: writepng.c 7945 2008-05-08 14:25:16Z martin $ $URL: http://scm.foundry.supelec.fr/svn/pdftex/branches/stable/source/src/texk/web2c/pdftexdir/writepng.c $";
24 -
25 -static int transparent_page_group = -1;
26 +static int transparent_page_group = 0;
27  
28  void read_png_info(integer img)
29  {
30 -    double gamma;
31      FILE *png_file = xfopen(img_name(img), FOPEN_RBIN_MODE);
32  
33      if ((png_ptr(img) = png_create_read_struct(PNG_LIBPNG_VER_STRING,
34 @@ -36,37 +31,14 @@
35          pdftex_fail("libpng: png_create_read_struct() failed");
36      if ((png_info(img) = png_create_info_struct(png_ptr(img))) == NULL)
37          pdftex_fail("libpng: png_create_info_struct() failed");
38 -    if (setjmp(png_ptr(img)->jmpbuf))
39 +    if (setjmp(png_jmpbuf(png_ptr(img))))
40          pdftex_fail("libpng: internal error");
41      png_init_io(png_ptr(img), png_file);
42      png_read_info(png_ptr(img), png_info(img));
43 -    /* simple transparency support */
44 -    if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_tRNS)) {
45 -        png_set_tRNS_to_alpha(png_ptr(img));
46 -    }
47 -    /* alpha channel support  */
48 -    if (fixedpdfminorversion < 4
49 -        && png_ptr(img)->color_type | PNG_COLOR_MASK_ALPHA)
50 -        png_set_strip_alpha(png_ptr(img));
51 -    /* 16bit depth support */
52 -    if (fixedpdfminorversion < 5)
53 -        fixedimagehicolor = 0;
54 -    if (png_info(img)->bit_depth == 16 && !fixedimagehicolor)
55 -        png_set_strip_16(png_ptr(img));
56 -    /* gamma support */
57 -    if (fixedimageapplygamma) {
58 -        if (png_get_gAMA(png_ptr(img), png_info(img), &gamma))
59 -            png_set_gamma(png_ptr(img), (fixedgamma / 1000.0), gamma);
60 -        else
61 -            png_set_gamma(png_ptr(img), (fixedgamma / 1000.0),
62 -                          (1000.0 / fixedimagegamma));
63 -    }
64 -    /* reset structure */
65 -    png_read_update_info(png_ptr(img), png_info(img));
66      /* resolution support */
67 -    img_width(img) = png_info(img)->width;
68 -    img_height(img) = png_info(img)->height;
69 -    if (png_info(img)->valid & PNG_INFO_pHYs) {
70 +    img_width(img) = png_get_image_width(png_ptr(img), png_info(img));
71 +    img_height(img) = png_get_image_height(png_ptr(img), png_info(img));
72 +    if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_pHYs)) {
73          img_xres(img) =
74              round(0.0254 *
75                    png_get_x_pixels_per_meter(png_ptr(img), png_info(img)));
76 @@ -74,7 +46,7 @@
77              round(0.0254 *
78                    png_get_y_pixels_per_meter(png_ptr(img), png_info(img)));
79      }
80 -    switch (png_info(img)->color_type) {
81 +    switch (png_get_color_type(png_ptr(img), png_info(img))) {
82      case PNG_COLOR_TYPE_PALETTE:
83          img_color(img) = IMAGE_COLOR_C | IMAGE_COLOR_I;
84          break;
85 @@ -88,18 +60,18 @@
86          break;
87      default:
88          pdftex_fail("unsupported type of color_type <%i>",
89 -                    png_info(img)->color_type);
90 +                    png_get_color_type(png_ptr(img), png_info(img)));
91      }
92      if (fixedpdfminorversion >= 4
93 -        && (png_info(img)->color_type == PNG_COLOR_TYPE_GRAY_ALPHA
94 -            || png_info(img)->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) {
95 +        && (png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_GRAY_ALPHA
96 +            || png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_RGB_ALPHA)) {
97          /* png with alpha channel in device colours; we have to add a Page
98           * Group to make Adobe happy, so we have to create a dummy group object
99           */
100 -        if (transparent_page_group < 1) {
101 +        if (transparent_page_group == 0) {
102              transparent_page_group = pdfnewobjnum();
103          }
104 -        if (pdfpagegroupval < 1) {
105 +        if (pdfpagegroupval == 0) {
106              pdfpagegroupval = transparent_page_group;
107          }
108          img_group_ref(img) = pdfpagegroupval;
109 @@ -113,7 +85,7 @@
110  
111  #define write_gray_pixel_8(r)                   \
112      if (j % 2 == 0)  pdfbuf[pdfptr++]   = *r++; \
113 -    else            smask[smask_ptr++] = *r++
114 +    else             smask[smask_ptr++] = *r++
115  
116  
117  #define write_rgb_pixel_16(r)                                 \
118 @@ -128,62 +100,67 @@
119  
120  
121  #define write_noninterlaced(outmac)                    \
122 -  for (i = 0; i < (int)png_info(img)->height; i++) {   \
123 +  for (i = 0; i < (int)png_get_image_height(png_ptr(img), png_info(img)); i++) {   \
124      png_read_row(png_ptr(img), row, NULL);             \
125      r = row;                                           \
126 -    k = png_info(img)->rowbytes;                       \
127 +    k = png_get_rowbytes(png_ptr(img), png_info(img)); \
128      while(k > 0) {                                     \
129 -       l = (k > pdfbufsize)? pdfbufsize : k;          \
130 -               pdfroom(l);                            \
131 -               for (j = 0; j < l; j++) {              \
132 -                 outmac;                              \
133 -               }                                      \
134 -               k -= l;                                \
135 -           }                                          \
136 +        l = (k > pdfbufsize)? pdfbufsize : k;          \
137 +                pdfroom(l);                            \
138 +                for (j = 0; j < l; j++) {              \
139 +                  outmac;                              \
140 +                }                                      \
141 +                k -= l;                                \
142 +            }                                          \
143          }
144  
145  #define write_interlaced(outmac)                       \
146 -  for (i = 0; i < (int)png_info(img)->height; i++) {   \
147 +  for (i = 0; i < (int)png_get_image_height(png_ptr(img), png_info(img)); i++) {   \
148              row = rows[i];                             \
149 -           k = png_info(img)->rowbytes;               \
150 -           while(k > 0) {                             \
151 -               l = (k > pdfbufsize)? pdfbufsize : k;  \
152 -               pdfroom(l);                            \
153 -               for (j = 0; j < l; j++) {              \
154 -                 outmac;                              \
155 -               }                                      \
156 -               k -= l;                                \
157 -           }                                          \
158 +            k = png_get_rowbytes(png_ptr(img), png_info(img));  \
159 +            while(k > 0) {                             \
160 +                l = (k > pdfbufsize)? pdfbufsize : k;  \
161 +                pdfroom(l);                            \
162 +                for (j = 0; j < l; j++) {              \
163 +                  outmac;                              \
164 +                }                                      \
165 +                k -= l;                                \
166 +            }                                          \
167              xfree(rows[i]);                            \
168          }
169  
170  
171 -void write_png_palette(integer img)
172 +static void write_png_palette(integer img)
173  {
174      int i, j, k, l;
175      png_bytep row, r, *rows;
176      integer palette_objnum = 0;
177 +    png_colorp palette;
178 +    int num_palette;
179 +
180 +    png_get_PLTE(png_ptr(img), png_info(img), &palette, &num_palette);
181 +
182      pdfcreateobj(0, 0);
183      palette_objnum = objptr;
184      if (img_colorspace_ref(img) != 0) {
185          pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
186      } else {
187          pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
188 -                   (int) (png_info(img)->num_palette - 1),
189 -                   (int) palette_objnum);
190 +                   num_palette -1, (int) palette_objnum);
191      }
192      pdfbeginstream();
193 -    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
194 -        row = xtalloc(png_info(img)->rowbytes, png_byte);
195 +    if (png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE) {
196 +        row = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
197          write_noninterlaced(write_simple_pixel(r));
198          xfree(row);
199      } else {
200 -        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
201 +        if (png_get_image_height(png_ptr(img), png_info(img))
202 +            * png_get_rowbytes(png_ptr(img), png_info(img)) >= 10240000L)
203              pdftex_warn
204                  ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
205 -        rows = xtalloc(png_info(img)->height, png_bytep);
206 -        for (i = 0; (unsigned) i < png_info(img)->height; i++)
207 -            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
208 +        rows = xtalloc(png_get_image_height(png_ptr(img), png_info(img)), png_bytep);
209 +        for (i = 0; (unsigned) i < png_get_image_height(png_ptr(img), png_info(img)); i++)
210 +            rows[i] = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
211          png_read_image(png_ptr(img), rows);
212          write_interlaced(write_simple_pixel(row));
213          xfree(rows);
214 @@ -192,17 +169,17 @@
215      if (palette_objnum > 0) {
216          pdfbegindict(palette_objnum, 0);
217          pdfbeginstream();
218 -        for (i = 0; (unsigned) i < png_info(img)->num_palette; i++) {
219 +        for (i = 0; (unsigned) i < num_palette; i++) {
220              pdfroom(3);
221 -            pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
222 -            pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
223 -            pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
224 +            pdfbuf[pdfptr++] = palette[i].red;
225 +            pdfbuf[pdfptr++] = palette[i].green;
226 +            pdfbuf[pdfptr++] = palette[i].blue;
227          }
228          pdfendstream();
229      }
230  }
231  
232 -void write_png_gray(integer img)
233 +static void write_png_gray(integer img)
234  {
235      int i, j, k, l;
236      png_bytep row, r, *rows;
237 @@ -212,17 +189,18 @@
238          pdf_puts("/DeviceGray\n");
239      }
240      pdfbeginstream();
241 -    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
242 -        row = xtalloc(png_info(img)->rowbytes, png_byte);
243 +    if (png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE) {
244 +        row = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
245          write_noninterlaced(write_simple_pixel(r));
246          xfree(row);
247      } else {
248 -        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
249 +        if (png_get_image_height(png_ptr(img), png_info(img))
250 +            * png_get_rowbytes(png_ptr(img), png_info(img)) >= 10240000L)
251              pdftex_warn
252                  ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
253 -        rows = xtalloc(png_info(img)->height, png_bytep);
254 -        for (i = 0; (unsigned) i < png_info(img)->height; i++)
255 -            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
256 +        rows = xtalloc(png_get_image_height(png_ptr(img), png_info(img)), png_bytep);
257 +        for (i = 0; (unsigned) i < png_get_image_height(png_ptr(img), png_info(img)); i++)
258 +            rows[i] = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
259          png_read_image(png_ptr(img), rows);
260          write_interlaced(write_simple_pixel(row));
261          xfree(rows);
262 @@ -232,7 +210,7 @@
263  
264  
265  
266 -void write_png_gray_alpha(integer img)
267 +static void write_png_gray_alpha(integer img)
268  {
269      int i, j, k, l;
270      png_bytep row, r, *rows;
271 @@ -249,26 +227,28 @@
272      pdfcreateobj(0, 0);
273      smask_objnum = objptr;
274      pdf_printf("/SMask %i 0 R\n", (int) smask_objnum);
275 -    smask_size = (png_info(img)->rowbytes / 2) * png_info(img)->height;
276 +    smask_size = (png_get_rowbytes(png_ptr(img), png_info(img)) / 2)
277 +                 * png_get_image_height(png_ptr(img), png_info(img));
278      smask = xtalloc(smask_size, png_byte);
279      pdfbeginstream();
280 -    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
281 -        row = xtalloc(png_info(img)->rowbytes, png_byte);
282 -        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
283 +    if (png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE) {
284 +        row = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
285 +        if ((png_get_bit_depth(png_ptr(img), png_info(img)) == 16) && fixedimagehicolor) {
286              write_noninterlaced(write_gray_pixel_16(r));
287          } else {
288              write_noninterlaced(write_gray_pixel_8(r));
289          }
290          xfree(row);
291      } else {
292 -        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
293 +        if (png_get_image_height(png_ptr(img), png_info(img))
294 +            * png_get_rowbytes(png_ptr(img), png_info(img)) >= 10240000L)
295              pdftex_warn
296                  ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
297 -        rows = xtalloc(png_info(img)->height, png_bytep);
298 -        for (i = 0; (unsigned) i < png_info(img)->height; i++)
299 -            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
300 +        rows = xtalloc(png_get_image_height(png_ptr(img), png_info(img)), png_bytep);
301 +        for (i = 0; (unsigned) i < png_get_image_height(png_ptr(img), png_info(img)); i++)
302 +            rows[i] = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
303          png_read_image(png_ptr(img), rows);
304 -        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
305 +        if ((png_get_bit_depth(png_ptr(img), png_info(img)) == 16) && fixedimagehicolor) {
306              write_interlaced(write_gray_pixel_16(row));
307          } else {
308              write_interlaced(write_gray_pixel_8(row));
309 @@ -279,12 +259,12 @@
310      pdfflush();
311      /* now write the Smask object */
312      if (smask_objnum > 0) {
313 -        bitdepth = (int) png_info(img)->bit_depth;
314 +        bitdepth = (int) png_get_bit_depth(png_ptr(img), png_info(img));
315          pdfbegindict(smask_objnum, 0);
316          pdf_puts("/Type /XObject\n/Subtype /Image\n");
317          pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
318 -                   (int) png_info(img)->width,
319 -                   (int) png_info(img)->height,
320 +                   (int) png_get_image_width(png_ptr(img), png_info(img)),
321 +                   (int) png_get_image_height(png_ptr(img), png_info(img)),
322                     (bitdepth == 16 ? 8 : bitdepth));
323          pdf_puts("/ColorSpace /DeviceGray\n");
324          pdfbeginstream();
325 @@ -300,7 +280,7 @@
326      }
327  }
328  
329 -void write_png_rgb(integer img)
330 +static void write_png_rgb(integer img)
331  {
332      int i, j, k, l;
333      png_bytep row, r, *rows;
334 @@ -310,17 +290,18 @@
335          pdf_puts("/DeviceRGB\n");
336      }
337      pdfbeginstream();
338 -    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
339 -        row = xtalloc(png_info(img)->rowbytes, png_byte);
340 +    if (png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE) {
341 +        row = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
342          write_noninterlaced(write_simple_pixel(r));
343          xfree(row);
344      } else {
345 -        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
346 +        if (png_get_image_height(png_ptr(img), png_info(img))
347 +            * png_get_rowbytes(png_ptr(img), png_info(img)) >= 10240000L)
348              pdftex_warn
349                  ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
350 -        rows = xtalloc(png_info(img)->height, png_bytep);
351 -        for (i = 0; (unsigned) i < png_info(img)->height; i++)
352 -            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
353 +        rows = xtalloc(png_get_image_height(png_ptr(img), png_info(img)), png_bytep);
354 +        for (i = 0; (unsigned) i < png_get_image_height(png_ptr(img), png_info(img)); i++)
355 +            rows[i] = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
356          png_read_image(png_ptr(img), rows);
357          write_interlaced(write_simple_pixel(row));
358          xfree(rows);
359 @@ -328,7 +309,7 @@
360      pdfendstream();
361  }
362  
363 -void write_png_rgb_alpha(integer img)
364 +static void write_png_rgb_alpha(integer img)
365  {
366      int i, j, k, l;
367      png_bytep row, r, *rows;
368 @@ -345,26 +326,28 @@
369      pdfcreateobj(0, 0);
370      smask_objnum = objptr;
371      pdf_printf("/SMask %i 0 R\n", (int) smask_objnum);
372 -    smask_size = (png_info(img)->rowbytes / 2) * png_info(img)->height;
373 +    smask_size = (png_get_rowbytes(png_ptr(img), png_info(img)) / 2)
374 +                 * png_get_image_height(png_ptr(img), png_info(img));
375      smask = xtalloc(smask_size, png_byte);
376      pdfbeginstream();
377 -    if (png_info(img)->interlace_type == PNG_INTERLACE_NONE) {
378 -        row = xtalloc(png_info(img)->rowbytes, png_byte);
379 -        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
380 +    if (png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE) {
381 +        row = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
382 +        if ((png_get_bit_depth(png_ptr(img), png_info(img)) == 16) && fixedimagehicolor) {
383              write_noninterlaced(write_rgb_pixel_16(r));
384          } else {
385              write_noninterlaced(write_rgb_pixel_8(r));
386          }
387          xfree(row);
388      } else {
389 -        if (png_info(img)->height * png_info(img)->rowbytes >= 10240000L)
390 +        if (png_get_image_height(png_ptr(img), png_info(img))
391 +            * png_get_rowbytes(png_ptr(img), png_info(img)) >= 10240000L)
392              pdftex_warn
393                  ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)");
394 -        rows = xtalloc(png_info(img)->height, png_bytep);
395 -        for (i = 0; (unsigned) i < png_info(img)->height; i++)
396 -            rows[i] = xtalloc(png_info(img)->rowbytes, png_byte);
397 +        rows = xtalloc(png_get_image_height(png_ptr(img), png_info(img)), png_bytep);
398 +        for (i = 0; (unsigned) i < png_get_image_height(png_ptr(img), png_info(img)); i++)
399 +            rows[i] = xtalloc(png_get_rowbytes(png_ptr(img), png_info(img)), png_byte);
400          png_read_image(png_ptr(img), rows);
401 -        if ((png_info(img)->bit_depth == 16) && fixedimagehicolor) {
402 +        if ((png_get_bit_depth(png_ptr(img), png_info(img)) == 16) && fixedimagehicolor) {
403              write_interlaced(write_rgb_pixel_16(row));
404          } else {
405              write_interlaced(write_rgb_pixel_8(row));
406 @@ -375,12 +358,12 @@
407      pdfflush();
408      /* now write the Smask object */
409      if (smask_objnum > 0) {
410 -        bitdepth = (int) png_info(img)->bit_depth;
411 +        bitdepth = (int) png_get_bit_depth(png_ptr(img), png_info(img));
412          pdfbegindict(smask_objnum, 0);
413          pdf_puts("/Type /XObject\n/Subtype /Image\n");
414          pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
415 -                   (int) png_info(img)->width,
416 -                   (int) png_info(img)->height,
417 +                   (int) png_get_image_width(png_ptr(img), png_info(img)),
418 +                   (int) png_get_image_height(png_ptr(img), png_info(img)),
419                     (bitdepth == 16 ? 8 : bitdepth));
420          pdf_puts("/ColorSpace /DeviceGray\n");
421          pdfbeginstream();
422 @@ -421,9 +404,9 @@
423  #define SPNG_CHUNK_IDAT 0x49444154
424  #define SPNG_CHUNK_IEND 0x49454E44
425  
426 -void copy_png(integer img)
427 +static void copy_png(integer img)
428  {
429 -    FILE *fp = (FILE *) png_ptr(img)->io_ptr;
430 +    FILE *fp = (FILE *) png_get_io_ptr(png_ptr(img));
431      int i, len, type, streamlength = 0;
432      boolean endflag = false;
433      int idat = 0;               /* flag to check continuous IDAT chunks sequence */
434 @@ -451,8 +434,9 @@
435                 "/Columns %d"
436                 "/BitsPerComponent %i"
437                 "/Predictor 10>>\n>>\nstream\n", streamlength,
438 -               png_info(img)->color_type == 2 ? 3 : 1,
439 -               (int) png_info(img)->width, (int) png_info(img)->bit_depth);
440 +               png_get_color_type(png_ptr(img), png_info(img)) == 2 ? 3 : 1,
441 +               (int) png_get_image_width(png_ptr(img), png_info(img)),
442 +               (int) png_get_bit_depth(png_ptr(img), png_info(img)));
443      /* 2nd pass to copy data */
444      endflag = false;
445      if (fseek(fp, 8, SEEK_SET) != 0)
446 @@ -489,52 +473,109 @@
447  }
448  
449  static boolean last_png_needs_page_group;
450 +static boolean transparent_page_group_was_written = false;
451 +
452 +/* Called after the xobject generated by write_png has been finished; used to
453 + * write out additional objects */
454 +static void write_additional_png_objects(void)
455 +{
456 +    if (last_png_needs_page_group) {
457 +        if (!transparent_page_group_was_written && transparent_page_group > 0) {
458 +            // create new group object
459 +            transparent_page_group_was_written = true;
460 +            pdfbeginobj(transparent_page_group, 2);
461 +            if (getpdfcompresslevel() == 0) {
462 +                pdf_puts("%PTEX Group needed for transparent pngs\n");
463 +            }
464 +            pdf_puts("<</Type/Group /S/Transparency /CS/DeviceRGB /I true>>\n");
465 +            pdfendobj();
466 +        }
467 +    }
468 +}
469  
470  void write_png(integer img)
471  {
472  
473 -    double gamma, checked_gamma;
474 +    boolean png_copy = true;
475 +    double gamma = 0.0;
476 +    png_fixed_point int_file_gamma = 0;
477 +#ifndef PNG_FP_1
478 +   /* for libpng < 1.5.0 */
479 +#define PNG_FP_1    100000
480 +#endif
481      int i;
482      integer palette_objnum = 0;
483 +    png_colorp palette;
484 +    int num_palette;
485      last_png_needs_page_group = false;
486 +
487 +    png_get_PLTE(png_ptr(img), png_info(img), &palette, &num_palette);
488 +
489      if (fixedpdfminorversion < 5)
490          fixedimagehicolor = 0;
491  
492      pdf_puts("/Type /XObject\n/Subtype /Image\n");
493 -    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
494 -               (int) png_info(img)->width,
495 -               (int) png_info(img)->height, (int) png_info(img)->bit_depth);
496 -    pdf_puts("/ColorSpace ");
497 -    checked_gamma = 1.0;
498 +    /* simple transparency support */
499 +    if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_tRNS)) {
500 +        png_set_tRNS_to_alpha(png_ptr(img));
501 +        png_copy = false;
502 +    }
503 +    /* alpha channel support */
504 +    if (fixedpdfminorversion < 4
505 +        && png_get_color_type(png_ptr(img), png_info(img)) | PNG_COLOR_MASK_ALPHA) {
506 +        png_set_strip_alpha(png_ptr(img));
507 +        png_copy = false;
508 +    }
509 +    /* 16 bit depth support */
510 +    if (fixedpdfminorversion < 5)
511 +        fixedimagehicolor = 0;
512 +    if ((png_get_bit_depth(png_ptr(img), png_info(img)) == 16) && (fixedimagehicolor == 0)) {
513 +        png_set_strip_16(png_ptr(img));
514 +        png_copy = false;
515 +    }
516 +    /* gamma support */
517 +    if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_gAMA)) {
518 +        png_get_gAMA(png_ptr(img), png_info(img), &gamma);
519 +        png_get_gAMA_fixed(png_ptr(img), png_info(img), &int_file_gamma);
520 +    }
521      if (fixedimageapplygamma) {
522 -        if (png_get_gAMA(png_ptr(img), png_info(img), &gamma)) {
523 -            checked_gamma = (fixedgamma / 1000.0) * gamma;
524 -        } else {
525 -            checked_gamma = (fixedgamma / 1000.0) * (1000.0 / fixedimagegamma);
526 -        }
527 +        if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_gAMA))
528 +            png_set_gamma(png_ptr(img), fixedgamma / 1000.0, gamma);
529 +        else
530 +            png_set_gamma(png_ptr(img), fixedgamma / 1000.0,
531 +                          1000.0 / fixedimagegamma);
532 +        png_copy = false;
533      }
534 -    /* the switching between |png_info| and |png_ptr| queries has been trial and error.
535 -     */
536 -    if (fixedpdfminorversion > 1
537 -        && png_info(img)->interlace_type == PNG_INTERLACE_NONE
538 -        && (png_ptr(img)->transformations == PNG_TRANSFORM_IDENTITY
539 -            || png_ptr(img)->transformations == 0x2000)
540 -        /* gamma */
541 -        && !(png_ptr(img)->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
542 -             png_ptr(img)->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
543 -        && (fixedimagehicolor || (png_ptr(img)->bit_depth <= 8))
544 -        && (checked_gamma <= 1.01 && checked_gamma > 0.99)
545 +    /* reset structure */
546 +    (void) png_set_interlace_handling(png_ptr(img));
547 +    png_read_update_info(png_ptr(img), png_info(img));
548 +
549 +    pdf_printf("/Width %i\n/Height %i\n/BitsPerComponent %i\n",
550 +               (int) png_get_image_width(png_ptr(img), png_info(img)),
551 +               (int) png_get_image_height(png_ptr(img), png_info(img)),
552 +               (int) png_get_bit_depth(png_ptr(img), png_info(img)));
553 +    pdf_puts("/ColorSpace ");
554 +    if (png_copy && fixedpdfminorversion > 1
555 +        && png_get_interlace_type(png_ptr(img), png_info(img)) == PNG_INTERLACE_NONE
556 +        && (png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_GRAY
557 +            || png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_RGB)
558 +        && !fixedimageapplygamma
559 +        && (!png_get_valid(png_ptr(img), png_info(img), PNG_INFO_gAMA)
560 +            || int_file_gamma == PNG_FP_1)
561 +        && !png_get_valid(png_ptr(img), png_info(img),
562 +                          PNG_INFO_cHRM | PNG_INFO_iCCP | PNG_INFO_sBIT | PNG_INFO_sRGB
563 +                          | PNG_INFO_bKGD | PNG_INFO_hIST | PNG_INFO_tRNS | PNG_INFO_sPLT)
564          ) {
565 +        /* Copy PNG */
566          if (img_colorspace_ref(img) != 0) {
567              pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
568          } else {
569 -            switch (png_info(img)->color_type) {
570 +            switch (png_get_color_type(png_ptr(img), png_info(img))) {
571              case PNG_COLOR_TYPE_PALETTE:
572                  pdfcreateobj(0, 0);
573                  palette_objnum = objptr;
574                  pdf_printf("[/Indexed /DeviceRGB %i %i 0 R]\n",
575 -                           (int) (png_info(img)->num_palette - 1),
576 -                           (int) palette_objnum);
577 +                           num_palette - 1, (int) palette_objnum);
578                  break;
579              case PNG_COLOR_TYPE_GRAY:
580                  pdf_puts("/DeviceGray\n");
581 @@ -548,37 +589,49 @@
582          if (palette_objnum > 0) {
583              pdfbegindict(palette_objnum, 0);
584              pdfbeginstream();
585 -            for (i = 0; i < png_info(img)->num_palette; i++) {
586 +            for (i = 0; i < num_palette; i++) {
587                  pdfroom(3);
588 -                pdfbuf[pdfptr++] = png_info(img)->palette[i].red;
589 -                pdfbuf[pdfptr++] = png_info(img)->palette[i].green;
590 -                pdfbuf[pdfptr++] = png_info(img)->palette[i].blue;
591 +                pdfbuf[pdfptr++] = palette[i].red;
592 +                pdfbuf[pdfptr++] = palette[i].green;
593 +                pdfbuf[pdfptr++] = palette[i].blue;
594              }
595              pdfendstream();
596          }
597      } else {
598          if (0) {
599 -            tex_printf(" PNG copy skipped because: ");
600 -            if (fixedimageapplygamma &&
601 -                (checked_gamma > 1.01 || checked_gamma < 0.99))
602 -                tex_printf("gamma delta=%lf ", checked_gamma);
603 -            if (png_ptr(img)->transformations != PNG_TRANSFORM_IDENTITY)
604 -                tex_printf("transform=%lu",
605 -                           (long) png_ptr(img)->transformations);
606 -            if ((png_info(img)->color_type != PNG_COLOR_TYPE_GRAY)
607 -                && (png_info(img)->color_type != PNG_COLOR_TYPE_RGB)
608 -                && (png_info(img)->color_type != PNG_COLOR_TYPE_PALETTE))
609 -                tex_printf("colortype ");
610 +            tex_printf(" *** PNG copy skipped because:");
611 +            if (!png_copy)
612 +                tex_printf(" !png_copy");
613              if (fixedpdfminorversion <= 1)
614 -                tex_printf("version=%d ", (int) fixedpdfminorversion);
615 -            if (png_info(img)->interlace_type != PNG_INTERLACE_NONE)
616 -                tex_printf("interlaced ");
617 -            if (png_info(img)->bit_depth > 8)
618 -                tex_printf("bitdepth=%d ", png_info(img)->bit_depth);
619 +                tex_printf(" minorversion=%d", (int) fixedpdfminorversion);
620 +            if (png_get_interlace_type(png_ptr(img), png_info(img)) != PNG_INTERLACE_NONE)
621 +                tex_printf(" interlaced");
622 +            if (!((png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_GRAY)
623 +                  || (png_get_color_type(png_ptr(img), png_info(img)) == PNG_COLOR_TYPE_RGB)))
624 +                tex_printf(" colortype");
625 +            if (fixedimageapplygamma)
626 +                tex_printf(" apply gamma");
627 +            if (!(!png_get_valid(png_ptr(img), png_info(img), PNG_INFO_gAMA)
628 +                  || int_file_gamma == PNG_FP_1))
629 +                tex_printf(" gamma");
630 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_cHRM))
631 +                tex_printf(" cHRM");
632 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_iCCP))
633 +                tex_printf(" iCCP");
634 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_sBIT))
635 +                tex_printf(" sBIT");
636 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_sRGB))
637 +                tex_printf(" sRGB");
638 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_bKGD))
639 +                tex_printf(" bKGD");
640 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_hIST))
641 +                tex_printf(" hIST");
642              if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_tRNS))
643 -                tex_printf("simple transparancy ");
644 +                tex_printf(" tRNS");
645 +            if (png_get_valid(png_ptr(img), png_info(img), PNG_INFO_sPLT))
646 +                tex_printf(" sPLT");
647          }
648 -        switch (png_info(img)->color_type) {
649 +        switch (png_get_color_type(png_ptr(img), png_info(img))) {
650          case PNG_COLOR_TYPE_PALETTE:
651              write_png_palette(img);
652              break;
653 @@ -604,28 +657,9 @@
654              break;
655          default:
656              pdftex_fail("unsupported type of color_type <%i>",
657 -                        png_info(img)->color_type);
658 +                        png_get_color_type(png_ptr(img), png_info(img)));
659          }
660      }
661      pdfflush();
662 -}
663 -
664 -static boolean transparent_page_group_was_written = false;
665 -
666 -/* Called after the xobject generated by write_png has been finished; used to
667 - * write out additional objects */
668 -void write_additional_png_objects(void)
669 -{
670 -    if (last_png_needs_page_group) {
671 -        if (!transparent_page_group_was_written && transparent_page_group > 1) {
672 -            // create new group object
673 -            transparent_page_group_was_written = true;
674 -            pdfbeginobj(transparent_page_group, 2);
675 -            if (getpdfcompresslevel() == 0) {
676 -                pdf_puts("%PTEX Group needed for transparent pngs\n");
677 -            }
678 -            pdf_puts("<</Type/Group /S/Transparency /CS/DeviceRGB /I true>>\n");
679 -            pdfendobj();
680 -        }
681 -    }
682 +    write_additional_png_objects();
683  }
684 --- texlive-20080816-source/texk/web2c/pdftexdir/image.h~       2008-03-23 17:38:33.000000000 +0100
685 +++ texlive-20080816-source/texk/web2c/pdftexdir/image.h        2012-02-08 08:48:24.077931893 +0100
686 @@ -111,7 +111,6 @@
687  extern void epdf_delete(void);
688  extern void read_png_info(integer);
689  extern void write_png(integer);
690 -extern void write_additional_png_objects(void);
691  extern void read_jpg_info(integer);
692  extern void write_jpg(integer);
693  extern void read_jbig2_info(integer);
694 --- texlive-20080816-source/texk/web2c/pdftexdir/writeimg.c.org 2008-07-15 22:56:20.000000000 +0200
695 +++ texlive-20080816-source/texk/web2c/pdftexdir/writeimg.c     2012-02-08 08:56:29.195301939 +0100
696 @@ -134,7 +134,7 @@
697  {
698      switch (img_type(img)) {
699      case IMAGE_TYPE_PNG:
700 -        return png_info(img)->bit_depth;
701 +        return png_get_bit_depth(png_ptr(img), png_info(img));
702      case IMAGE_TYPE_JPG:
703          return jpg_ptr(img)->bits_per_component;
704      case IMAGE_TYPE_JBIG2:
705 @@ -393,7 +393,7 @@
706          epdf_delete();
707          break;
708      case IMAGE_TYPE_PNG:
709 -        xfclose((FILE *) png_ptr(img)->io_ptr, cur_file_name);
710 +        xfclose((FILE *) png_get_io_ptr(png_ptr(img)), cur_file_name);
711          png_destroy_read_struct(&(png_ptr(img)), &(png_info(img)), NULL);
712          break;
713      case IMAGE_TYPE_JPG:
714 --- texlive-20080816-source/texk/web2c/pdftexdir/writeimg.c~    2012-02-08 08:56:29.000000000 +0100
715 +++ texlive-20080816-source/texk/web2c/pdftexdir/writeimg.c     2012-02-08 09:31:11.542239751 +0100
716 @@ -373,13 +373,6 @@
717          pdftex_fail("unknown type of image");
718      }
719      tex_printf(">");
720 -    if (img_type(img) == IMAGE_TYPE_PDF) {
721 -        write_additional_epdf_objects();
722 -    } else {
723 -        if (img_type(img) == IMAGE_TYPE_PNG) {
724 -            write_additional_png_objects();
725 -        }
726 -    }
727      cur_file_name = NULL;
728  }
729  
This page took 0.357429 seconds and 3 git commands to generate.