diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-02-01 09:11:14 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-02-01 09:11:14 +0000 |
commit | b737f5c4afa72f4fa6f99934ba1b165246227f03 (patch) | |
tree | 3227bf06b36179f801bbfa6533c4db7b38a8a8d2 | |
parent | 298fbf7e62048af6cb5a2cdd6773f17b515b3a4a (diff) |
temporary fix for luatex and png-1.5
git-svn-id: svn://tug.org/texlive/trunk@21250 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/web2c/luatexdir/image/writepng.w | 183 |
1 files changed, 96 insertions, 87 deletions
diff --git a/Build/source/texk/web2c/luatexdir/image/writepng.w b/Build/source/texk/web2c/luatexdir/image/writepng.w index 084e9324a6d..fbe80259a63 100644 --- a/Build/source/texk/web2c/luatexdir/image/writepng.w +++ b/Build/source/texk/web2c/luatexdir/image/writepng.w @@ -67,7 +67,7 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) 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); @@ -76,12 +76,12 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) png_set_tRNS_to_alpha(png_p); } /* alpha channel support */ - if (pdf->minor_version < 4 && png_p->color_type | PNG_COLOR_MASK_ALPHA) + if (pdf->minor_version < 4 && png_get_color_type(png_p, info_p) | PNG_COLOR_MASK_ALPHA) png_set_strip_alpha(png_p); /* 16bit depth support */ if (pdf->minor_version < 5) pdf->image_hicolor = 0; - if ((info_p->bit_depth == 16) && (pdf->image_hicolor == 0)) + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor == 0)) png_set_strip_16(png_p); /* gamma support */ if (pdf->image_apply_gamma) { @@ -94,15 +94,15 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) /* reset structure */ png_read_update_info(png_p, info_p); /* resolution support */ - img_xsize(idict) = (int) info_p->width; - img_ysize(idict) = (int) info_p->height; - if (info_p->valid & PNG_INFO_pHYs) { + 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 (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) = round(0.0254 * (double) png_get_y_pixels_per_meter(png_p, info_p)); } - switch (info_p->color_type) { + switch (png_get_color_type(png_p, info_p)) { case PNG_COLOR_TYPE_PALETTE: img_procset(idict) |= PROCSET_IMAGE_C | PROCSET_IMAGE_I; break; @@ -115,9 +115,9 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) img_procset(idict) |= PROCSET_IMAGE_C; break; default: - pdftex_fail("unsupported type of color_type <%i>", info_p->color_type); + pdftex_fail("unsupported type of color_type <%i>", png_get_color_type(png_p, info_p)); } - img_colordepth(idict) = info_p->bit_depth; + img_colordepth(idict) = png_get_bit_depth(png_p, info_p); if (readtype == IMG_CLOSEINBETWEEN) close_and_cleanup_png(idict); } @@ -142,10 +142,10 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) #define write_simple_pixel(r) pdf_quick_out(pdf,*r++) #define write_noninterlaced(outmac) \ - for (i = 0; i < (int)info_p->height; i++) { \ + for (i = 0; i < (int)png_get_image_height (png_p, info_p); i++) { \ png_read_row(png_p, row, NULL); \ r = row; \ - k = (int)info_p->rowbytes; \ + k = (int)png_get_rowbytes(png_p, info_p); \ while(k > 0) { \ l = (k > pdf->buf_size)? pdf->buf_size : k; \ pdf_room(pdf,l); \ @@ -157,9 +157,9 @@ void read_png_info(PDF pdf, image_dict * idict, img_readtype_e readtype) } #define write_interlaced(outmac) \ - for (i = 0; i < (int)info_p->height; i++) { \ + for (i = 0; i < (int)png_get_image_height (png_p, info_p); i++) { \ row = rows[i]; \ - k = (int)info_p->rowbytes; \ + k = (int)png_get_rowbytes(png_p, info_p); \ while(k > 0) { \ l = (k > pdf->buf_size)?pdf->buf_size: k;\ pdf_room(pdf,l); \ @@ -179,26 +179,31 @@ static void write_png_palette(PDF pdf, image_dict * idict) 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 { pdf_create_obj(pdf, obj_type_others, 0); palette_objnum = pdf->obj_ptr; 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 (info_p->interlace_type == PNG_INTERLACE_NONE) { - row = xtalloc(info_p->rowbytes, png_byte); + if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { + row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); write_noninterlaced(write_simple_pixel(r)); xfree(row); } else { - if (info_p->height * info_p->rowbytes >= 10240000L) + if (png_get_image_height (png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) pdftex_warn ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); - rows = xtalloc(info_p->height, png_bytep); - for (i = 0; (unsigned) i < info_p->height; i++) - rows[i] = xtalloc(info_p->rowbytes, png_byte); + rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep); + for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++) + rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); png_read_image(png_p, rows); write_interlaced(write_simple_pixel(row)); xfree(rows); @@ -207,11 +212,11 @@ static void write_png_palette(PDF pdf, image_dict * idict) 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); } @@ -230,17 +235,17 @@ static void write_png_gray(PDF pdf, image_dict * idict) pdf_puts(pdf, "/DeviceGray\n"); } pdf_begin_stream(pdf); - if (info_p->interlace_type == PNG_INTERLACE_NONE) { - row = xtalloc(info_p->rowbytes, png_byte); + if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { + row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); write_noninterlaced(write_simple_pixel(r)); xfree(row); } else { - if (info_p->height * info_p->rowbytes >= 10240000L) + if (png_get_image_height (png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) pdftex_warn ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); - rows = xtalloc(info_p->height, png_bytep); - for (i = 0; (unsigned) i < info_p->height; i++) - rows[i] = xtalloc(info_p->rowbytes, png_byte); + rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep); + for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++) + rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); png_read_image(png_p, rows); write_interlaced(write_simple_pixel(row)); xfree(rows); @@ -268,26 +273,26 @@ static void write_png_gray_alpha(PDF pdf, image_dict * idict) pdf_create_obj(pdf, obj_type_others, 0); smask_objnum = pdf->obj_ptr; pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum); - smask_size = (int) ((info_p->rowbytes / 2) * info_p->height); + smask_size = (int) ((png_get_rowbytes(png_p, info_p) / 2) * png_get_image_height (png_p, info_p)); smask = xtalloc((unsigned) smask_size, png_byte); pdf_begin_stream(pdf); - if (info_p->interlace_type == PNG_INTERLACE_NONE) { - row = xtalloc(info_p->rowbytes, png_byte); - if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) { + if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { + row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_noninterlaced(write_gray_pixel_16(r)); } else { write_noninterlaced(write_gray_pixel_8(r)); } xfree(row); } else { - if (info_p->height * info_p->rowbytes >= 10240000L) + if (png_get_image_height (png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) pdftex_warn ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); - rows = xtalloc(info_p->height, png_bytep); - for (i = 0; (unsigned) i < info_p->height; i++) - rows[i] = xtalloc(info_p->rowbytes, png_byte); + rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep); + for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++) + rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); png_read_image(png_p, rows); - if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_interlaced(write_gray_pixel_16(row)); } else { write_interlaced(write_gray_pixel_8(row)); @@ -297,14 +302,15 @@ static void write_png_gray_alpha(PDF pdf, image_dict * idict) pdf_end_stream(pdf); pdf_flush(pdf); /* now write the Smask object */ - bitdepth = (int) info_p->bit_depth; + bitdepth = (int) png_get_bit_depth(png_p, info_p); pdf_begin_dict(pdf, smask_objnum, 0); pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n"); if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) pdf_printf(pdf, "%s\n", img_attr(idict)); pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n", - (int) info_p->width, - (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth)); + (int) png_get_image_width (png_p, info_p), + (int) png_get_image_height (png_p, info_p), + (bitdepth == 16 ? 8 : bitdepth)); pdf_puts(pdf, "/ColorSpace /DeviceGray\n"); pdf_begin_stream(pdf); for (i = 0; i < smask_size; i++) { @@ -331,17 +337,17 @@ static void write_png_rgb(PDF pdf, image_dict * idict) pdf_puts(pdf, "/DeviceRGB\n"); } pdf_begin_stream(pdf); - if (info_p->interlace_type == PNG_INTERLACE_NONE) { - row = xtalloc(info_p->rowbytes, png_byte); + if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { + row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); write_noninterlaced(write_simple_pixel(r)); xfree(row); } else { - if (info_p->height * info_p->rowbytes >= 10240000L) + if (png_get_image_height (png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) pdftex_warn ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); - rows = xtalloc(info_p->height, png_bytep); - for (i = 0; (unsigned) i < info_p->height; i++) - rows[i] = xtalloc(info_p->rowbytes, png_byte); + rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep); + for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++) + rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); png_read_image(png_p, rows); write_interlaced(write_simple_pixel(row)); xfree(rows); @@ -369,26 +375,26 @@ static void write_png_rgb_alpha(PDF pdf, image_dict * idict) pdf_create_obj(pdf, obj_type_others, 0); smask_objnum = pdf->obj_ptr; pdf_printf(pdf, "/SMask %i 0 R\n", (int) smask_objnum); - smask_size = (int) ((info_p->rowbytes / 2) * info_p->height); + smask_size = (int) ((png_get_rowbytes(png_p, info_p) / 2) * png_get_image_height (png_p, info_p)); smask = xtalloc((unsigned) smask_size, png_byte); pdf_begin_stream(pdf); - if (info_p->interlace_type == PNG_INTERLACE_NONE) { - row = xtalloc(info_p->rowbytes, png_byte); - if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) { + if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE) { + row = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_noninterlaced(write_rgb_pixel_16(r)); } else { write_noninterlaced(write_rgb_pixel_8(r)); } xfree(row); } else { - if (info_p->height * info_p->rowbytes >= 10240000L) + if (png_get_image_height (png_p, info_p) * png_get_rowbytes(png_p, info_p) >= 10240000L) pdftex_warn ("large interlaced PNG might cause out of memory (use non-interlaced PNG to fix this)"); - rows = xtalloc(info_p->height, png_bytep); - for (i = 0; (unsigned) i < info_p->height; i++) - rows[i] = xtalloc(info_p->rowbytes, png_byte); + rows = xtalloc(png_get_image_height (png_p, info_p), png_bytep); + for (i = 0; (unsigned) i < png_get_image_height (png_p, info_p); i++) + rows[i] = xtalloc(png_get_rowbytes(png_p, info_p), png_byte); png_read_image(png_p, rows); - if ((info_p->bit_depth == 16) && (pdf->image_hicolor != 0)) { + if ((png_get_bit_depth(png_p, info_p) == 16) && (pdf->image_hicolor != 0)) { write_interlaced(write_rgb_pixel_16(row)); } else { write_interlaced(write_rgb_pixel_8(row)); @@ -399,14 +405,15 @@ static void write_png_rgb_alpha(PDF pdf, image_dict * idict) pdf_flush(pdf); /* now write the Smask object */ if (smask_objnum > 0) { - bitdepth = (int) info_p->bit_depth; + bitdepth = (int) png_get_bit_depth(png_p, info_p); pdf_begin_dict(pdf, smask_objnum, 0); pdf_puts(pdf, "/Type /XObject\n/Subtype /Image\n"); if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) pdf_printf(pdf, "%s\n", img_attr(idict)); pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n", - (int) info_p->width, - (int) info_p->height, (bitdepth == 16 ? 8 : bitdepth)); + (int) png_get_image_width (png_p, info_p), + (int) png_get_image_height (png_p, info_p), + (bitdepth == 16 ? 8 : bitdepth)); pdf_puts(pdf, "/ColorSpace /DeviceGray\n"); pdf_begin_stream(pdf); for (i = 0; i < smask_size; i++) { @@ -454,7 +461,7 @@ static void copy_png(PDF pdf, image_dict * idict) assert(idict != NULL); png_p = img_png_png_ptr(idict); info_p = img_png_info_ptr(idict); - fp = (FILE *) png_p->io_ptr; + fp = (FILE *) png_get_io_ptr(png_p); /* 1st pass to find overall stream /Length */ if (fseek(fp, 8, SEEK_SET) != 0) pdftex_fail("writepng: fseek in PNG file failed"); @@ -479,8 +486,9 @@ static void copy_png(PDF pdf, image_dict * idict) "/Columns %d" "/BitsPerComponent %i" "/Predictor 10>>\n>>\nstream\n", streamlength, - info_p->color_type == 2 ? 3 : 1, - (int) info_p->width, info_p->bit_depth); + png_get_color_type(png_p, info_p) == 2 ? 3 : 1, + (int) png_get_image_width (png_p, info_p), + png_get_bit_depth(png_p, info_p)); /* 2nd pass to copy data */ endflag = false; if (fseek(fp, 8, SEEK_SET) != 0) @@ -553,8 +561,9 @@ void write_png(PDF pdf, image_dict * idict) if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) pdf_printf(pdf, "%s\n", img_attr(idict)); pdf_printf(pdf, "/Width %i\n/Height %i\n/BitsPerComponent %i\n", - (int) info_p->width, - (int) info_p->height, (int) info_p->bit_depth); + (int) png_get_image_width (png_p, info_p), + (int) png_get_image_height (png_p, info_p), + (int) png_get_bit_depth(png_p, info_p)); pdf_puts(pdf, "/ColorSpace "); checked_gamma = 1.0; if (pdf->image_apply_gamma) { @@ -566,23 +575,25 @@ void write_png(PDF pdf, image_dict * idict) } /* the switching between |info_p| and |png_p| queries has been trial and error. */ - if (pdf->minor_version > 1 && info_p->interlace_type == PNG_INTERLACE_NONE && - (png_p->transformations == 0 || png_p->transformations == 0x2000) /* gamma */ - &&!(png_p->color_type == PNG_COLOR_TYPE_GRAY_ALPHA || - png_p->color_type == PNG_COLOR_TYPE_RGB_ALPHA) - && ((pdf->image_hicolor != 0) || (png_p->bit_depth <= 8)) + if (pdf->minor_version > 1 && png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE + &&!(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 { - switch (info_p->color_type) { + switch (png_get_color_type(png_p, info_p)) { case PNG_COLOR_TYPE_PALETTE: pdf_create_obj(pdf, obj_type_others, 0); palette_objnum = pdf->obj_ptr; 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 +608,11 @@ void write_png(PDF pdf, image_dict * idict) 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,22 +622,20 @@ void write_png(PDF pdf, image_dict * idict) 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 ((info_p->color_type != PNG_COLOR_TYPE_GRAY) - && (info_p->color_type != PNG_COLOR_TYPE_RGB) - && (info_p->color_type != PNG_COLOR_TYPE_PALETTE)) + 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)) tex_printf("colortype "); if (pdf->minor_version <= 1) tex_printf("version=%d ", pdf->minor_version); - if (info_p->interlace_type != PNG_INTERLACE_NONE) + if (png_get_interlace_type(png_p, info_p) != PNG_INTERLACE_NONE) tex_printf("interlaced "); - if (info_p->bit_depth > 8) - tex_printf("bitdepth=%d ", info_p->bit_depth); + if (png_get_bit_depth(png_p, info_p) > 8) + tex_printf("bitdepth=%d ", png_get_bit_depth(png_p, info_p)); if (png_get_valid(png_p, info_p, PNG_INFO_tRNS)) tex_printf("simple transparancy "); } - switch (info_p->color_type) { + switch (png_get_color_type(png_p, info_p)) { case PNG_COLOR_TYPE_PALETTE: write_png_palette(pdf, idict); break; @@ -652,7 +661,7 @@ void write_png(PDF pdf, image_dict * idict) break; default: pdftex_fail("unsupported type of color_type <%i>", - info_p->color_type); + png_get_color_type(png_p, info_p)); } } pdf_flush(pdf); |