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
5 -Copyright (c) 1996-2008 Han The Thanh, <thanh@pdftex.org>
6 +Copyright 1996-2011 Han The Thanh, <thanh@pdftex.org>
8 This file is part of pdfTeX.
11 GNU General Public License for more details.
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/>.
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 $";
25 -static int transparent_page_group = -1;
26 +static int transparent_page_group = 0;
28 void read_png_info(integer img)
31 FILE *png_file = xfopen(img_name(img), FOPEN_RBIN_MODE);
33 if ((png_ptr(img) = png_create_read_struct(PNG_LIBPNG_VER_STRING,
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));
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));
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);
61 - png_set_gamma(png_ptr(img), (fixedgamma / 1000.0),
62 - (1000.0 / fixedimagegamma));
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)) {
75 png_get_x_pixels_per_meter(png_ptr(img), png_info(img)));
78 png_get_y_pixels_per_meter(png_ptr(img), png_info(img)));
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;
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)));
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
100 - if (transparent_page_group < 1) {
101 + if (transparent_page_group == 0) {
102 transparent_page_group = pdfnewobjnum();
104 - if (pdfpagegroupval < 1) {
105 + if (pdfpagegroupval == 0) {
106 pdfpagegroupval = transparent_page_group;
108 img_group_ref(img) = pdfpagegroupval;
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++
117 #define write_rgb_pixel_16(r) \
118 @@ -128,62 +100,67 @@
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); \
126 - k = png_info(img)->rowbytes; \
127 + k = png_get_rowbytes(png_ptr(img), png_info(img)); \
129 - l = (k > pdfbufsize)? pdfbufsize : k; \
131 - for (j = 0; j < l; j++) { \
136 + l = (k > pdfbufsize)? pdfbufsize : k; \
138 + for (j = 0; j < l; j++) { \
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++) { \
149 - k = png_info(img)->rowbytes; \
151 - l = (k > pdfbufsize)? pdfbufsize : k; \
153 - for (j = 0; j < l; j++) { \
158 + k = png_get_rowbytes(png_ptr(img), png_info(img)); \
160 + l = (k > pdfbufsize)? pdfbufsize : k; \
162 + for (j = 0; j < l; j++) { \
171 -void write_png_palette(integer img)
172 +static void write_png_palette(integer img)
175 png_bytep row, r, *rows;
176 integer palette_objnum = 0;
177 + png_colorp palette;
180 + png_get_PLTE(png_ptr(img), png_info(img), &palette, &num_palette);
183 palette_objnum = objptr;
184 if (img_colorspace_ref(img) != 0) {
185 pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
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);
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));
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)
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));
214 @@ -192,17 +169,17 @@
215 if (palette_objnum > 0) {
216 pdfbegindict(palette_objnum, 0);
218 - for (i = 0; (unsigned) i < png_info(img)->num_palette; i++) {
219 + for (i = 0; (unsigned) i < num_palette; i++) {
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;
232 -void write_png_gray(integer img)
233 +static void write_png_gray(integer img)
236 png_bytep row, r, *rows;
237 @@ -212,17 +189,18 @@
238 pdf_puts("/DeviceGray\n");
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));
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)
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));
266 -void write_png_gray_alpha(integer img)
267 +static void write_png_gray_alpha(integer img)
270 png_bytep row, r, *rows;
271 @@ -249,26 +227,28 @@
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);
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));
288 write_noninterlaced(write_gray_pixel_8(r));
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)
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));
308 write_interlaced(write_gray_pixel_8(row));
309 @@ -279,12 +259,12 @@
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");
329 -void write_png_rgb(integer img)
330 +static void write_png_rgb(integer img)
333 png_bytep row, r, *rows;
334 @@ -310,17 +290,18 @@
335 pdf_puts("/DeviceRGB\n");
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));
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)
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));
363 -void write_png_rgb_alpha(integer img)
364 +static void write_png_rgb_alpha(integer img)
367 png_bytep row, r, *rows;
368 @@ -345,26 +326,28 @@
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);
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));
385 write_noninterlaced(write_rgb_pixel_8(r));
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)
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));
405 write_interlaced(write_rgb_pixel_8(row));
406 @@ -375,12 +358,12 @@
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");
423 #define SPNG_CHUNK_IDAT 0x49444154
424 #define SPNG_CHUNK_IEND 0x49454E44
426 -void copy_png(integer img)
427 +static void copy_png(integer img)
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 */
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 */
445 if (fseek(fp, 8, SEEK_SET) != 0)
446 @@ -489,52 +473,109 @@
449 static boolean last_png_needs_page_group;
450 +static boolean transparent_page_group_was_written = false;
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)
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");
464 + pdf_puts("<</Type/Group /S/Transparency /CS/DeviceRGB /I true>>\n");
470 void write_png(integer img)
473 - double gamma, checked_gamma;
474 + boolean png_copy = true;
475 + double gamma = 0.0;
476 + png_fixed_point int_file_gamma = 0;
478 + /* for libpng < 1.5.0 */
479 +#define PNG_FP_1 100000
482 integer palette_objnum = 0;
483 + png_colorp palette;
485 last_png_needs_page_group = false;
487 + png_get_PLTE(png_ptr(img), png_info(img), &palette, &num_palette);
489 if (fixedpdfminorversion < 5)
490 fixedimagehicolor = 0;
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));
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));
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));
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);
521 if (fixedimageapplygamma) {
522 - if (png_get_gAMA(png_ptr(img), png_info(img), &gamma)) {
523 - checked_gamma = (fixedgamma / 1000.0) * gamma;
525 - checked_gamma = (fixedgamma / 1000.0) * (1000.0 / fixedimagegamma);
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);
530 + png_set_gamma(png_ptr(img), fixedgamma / 1000.0,
531 + 1000.0 / fixedimagegamma);
534 - /* the switching between |png_info| and |png_ptr| queries has been trial and error.
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)
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));
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)
566 if (img_colorspace_ref(img) != 0) {
567 pdf_printf("%i 0 R\n", (int) img_colorspace_ref(img));
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:
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);
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);
585 - for (i = 0; i < png_info(img)->num_palette; i++) {
586 + for (i = 0; i < num_palette; i++) {
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;
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:");
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");
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);
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)));
664 -static boolean transparent_page_group_was_written = false;
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)
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");
678 - pdf_puts("<</Type/Group /S/Transparency /CS/DeviceRGB /I true>>\n");
682 + write_additional_png_objects();
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
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
698 switch (img_type(img)) {
700 - return png_info(img)->bit_depth;
701 + return png_get_bit_depth(png_ptr(img), png_info(img));
703 return jpg_ptr(img)->bits_per_component;
704 case IMAGE_TYPE_JBIG2:
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);
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
717 pdftex_fail("unknown type of image");
720 - if (img_type(img) == IMAGE_TYPE_PDF) {
721 - write_additional_epdf_objects();
723 - if (img_type(img) == IMAGE_TYPE_PNG) {
724 - write_additional_png_objects();
727 cur_file_name = NULL;