pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [HEADS UP] png update to 1.5 branch
On Fri, Jan 14, 2011 at 03:39:54PM +0900, OBATA Akio wrote:
> graphics/netpbm is broken.
> need to include <zlib.h> and convert to use png_get_color_type() API, or
> something...?
As usual, netpbm is annoying by accessing internal data structures.
I've started fixing it (attached) but there is more todo (and probably
one bug in there, see TODO). I'll work more on it later, except if
someone wants to take over... :)
General status update:
Other known-broken packages are SDL_image, luatex, web2c, ghostscript,
kdelibs4; possibly emacs<22 and wxGTK<2.8, but the patches for emacs
and wxGTK28 should work. I'll take a break now and continue fixing
later.
Thomas
$NetBSD: patch-ac,v 1.19 2010/06/13 22:44:39 wiz Exp $
Fix build with png-1.5.
--- converter/other/pnmtopng.c.orig 2010-07-10 01:38:01.000000000 +0000
+++ converter/other/pnmtopng.c
@@ -61,7 +61,8 @@
#include <assert.h>
#include <string.h> /* strcat() */
#include <limits.h>
-#include <png.h> /* includes zlib.h and setjmp.h */
+#include <png.h> /* includes setjmp.h */
+#include <zlib.h>
#include "pnm.h"
#include "pngtxt.h"
#include "shhopt.h"
@@ -69,11 +70,6 @@
#include "nstring.h"
#include "version.h"
-#if PNG_LIBPNG_VER >= 10400
-#error Your PNG library (<png.h>) is incompatible with this Netpbm source code.
-#error You need either an older PNG library (older than 1.4)
-#error newer Netpbm source code (at least 10.48)
-#endif
struct zlibCompression {
@@ -2079,6 +2075,7 @@ makePngLine(png_byte * const l
gray * const alpha_mask,
colorhash_table const cht,
coloralphahash_table const caht,
+ png_struct * const png_ptr,
png_info * const info_ptr,
xelval const png_maxval,
unsigned int const depth) {
@@ -2091,20 +2088,20 @@ makePngLine(png_byte * const l
xel p_png;
xel const p = xelrow[col];
PPM_DEPTH(p_png, p, maxval, png_maxval);
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) ==
PNG_COLOR_TYPE_GRAY_ALPHA) {
if (depth == 16)
*pp++ = PNM_GET1(p_png) >> 8;
*pp++ = PNM_GET1(p_png) & 0xff;
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ } else if (png_get_color_type(png_ptr, info_ptr) ==
PNG_COLOR_TYPE_PALETTE) {
unsigned int paletteIndex;
if (alpha)
paletteIndex = lookupColorAlpha(caht, &p, &alpha_mask[col]);
else
paletteIndex = ppm_lookupcolor(cht, &p);
*pp++ = paletteIndex;
- } else if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ } else if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB
||
+ png_get_color_type(png_ptr, info_ptr) ==
PNG_COLOR_TYPE_RGB_ALPHA) {
if (depth == 16)
*pp++ = PPM_GETR(p_png) >> 8;
*pp++ = PPM_GETR(p_png) & 0xff;
@@ -2117,7 +2114,7 @@ makePngLine(png_byte * const l
} else
pm_error("INTERNAL ERROR: undefined color_type");
- if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) {
+ if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) {
int const png_alphaval = (int)
alpha_mask[col] * (float) png_maxval / maxval + 0.5;
if (depth == 16)
@@ -2174,7 +2171,7 @@ writeRaster(png_struct * const p
makePngLine(line, xelrow, cols, maxval,
alpha, alpha ? alpha_mask[row] : NULL,
- cht, caht, info_ptr, png_maxval, depth);
+ cht, caht, png_ptr, info_ptr, png_maxval, depth);
png_write_row(png_ptr, line);
}
@@ -2186,12 +2183,12 @@ writeRaster(png_struct * const p
static void
doGamaChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.gammaSpec) {
/* gAMA chunk */
- info_ptr->valid |= PNG_INFO_gAMA;
- info_ptr->gamma = cmdline.gamma;
+ png_set_gAMA(png_ptr, info_ptr, cmdline.gamma);
}
}
@@ -2199,20 +2196,15 @@ doGamaChunk(struct cmdlineInfo const cmd
static void
doChrmChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.rgbSpec) {
/* cHRM chunk */
- info_ptr->valid |= PNG_INFO_cHRM;
-
- info_ptr->x_white = cmdline.rgb.wx;
- info_ptr->y_white = cmdline.rgb.wy;
- info_ptr->x_red = cmdline.rgb.rx;
- info_ptr->y_red = cmdline.rgb.ry;
- info_ptr->x_green = cmdline.rgb.gx;
- info_ptr->y_green = cmdline.rgb.gy;
- info_ptr->x_blue = cmdline.rgb.bx;
- info_ptr->y_blue = cmdline.rgb.by;
+
+ png_set_cHRM (png_ptr, info_ptr, cmdline.rgb.wx, cmdline.rgb.wy,
+ cmdline.rgb.rx, cmdline.rgb.ry, cmdline.rgb.gx,
+ cmdline.rgb.gy, cmdline.rgb.bx, cmdline.rgb.by);
}
}
@@ -2220,15 +2212,12 @@ doChrmChunk(struct cmdlineInfo const cmd
static void
doPhysChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.sizeSpec) {
/* pHYS chunk */
- info_ptr->valid |= PNG_INFO_pHYs;
-
- info_ptr->x_pixels_per_unit = cmdline.size.x;
- info_ptr->y_pixels_per_unit = cmdline.size.y;
- info_ptr->phys_unit_type = cmdline.size.unit;
+ png_set_pHYs(png_ptr, info_ptr, cmdline.size.x, cmdline.size.y,
cmdline.size.unit);
}
}
@@ -2237,26 +2226,28 @@ doPhysChunk(struct cmdlineInfo const cmd
static void
doTimeChunk(struct cmdlineInfo const cmdline,
+ png_struct * const png_ptr,
png_info * const info_ptr) {
if (cmdline.modtimeSpec) {
/* tIME chunk */
- info_ptr->valid |= PNG_INFO_tIME;
-
- png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime);
+ png_timep ptime;
+ png_convert_from_time_t(ptime, cmdline.modtime);
+ png_set_tIME(png_ptr, info_ptr, ptime);
}
}
static void
-doSbitChunk(png_info * const pngInfoP,
+doSbitChunk(png_struct * const pngP,
+ png_info * const pngInfoP,
xelval const pngMaxval,
xelval const maxval,
bool const alpha,
xelval const alphaMaxval) {
- if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE &&
+ if (png_get_color_type(pngP, pngInfoP) != PNG_COLOR_TYPE_PALETTE &&
(pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) {
/* We're writing in a bit depth that doesn't match the maxval
@@ -2275,26 +2266,16 @@ doSbitChunk(png_info * const pngInfoP,
sBIT chunk.
*/
- pngInfoP->valid |= PNG_INFO_sBIT;
-
- {
- int const sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
-
- if (pngInfoP->color_type & PNG_COLOR_MASK_COLOR) {
- pngInfoP->sig_bit.red = sbitval;
- pngInfoP->sig_bit.green = sbitval;
- pngInfoP->sig_bit.blue = sbitval;
- } else
- pngInfoP->sig_bit.gray = sbitval;
+ /* TODO: fixme */
+ png_color_8p sbitval = pm_maxvaltobits(MIN(maxval, pngMaxval));
+ png_set_sBIT(pngP, pngInfoP, &sbitval);
+ if (verbose)
+ pm_message("Writing sBIT chunk with bits = %d", sbitval);
+
+ if (png_get_color_type(pngP, pngInfoP) & PNG_COLOR_MASK_ALPHA) {
if (verbose)
- pm_message("Writing sBIT chunk with bits = %d", sbitval);
- }
- if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) {
- pngInfoP->sig_bit.alpha =
- pm_maxvaltobits(MIN(alphaMaxval, pngMaxval));
- if (verbose)
- pm_message(" alpha bits = %d", pngInfoP->sig_bit.alpha);
+ pm_message(" alpha bits = %d", sbitval);
}
}
}
@@ -2577,29 +2558,33 @@ convertpnm(struct cmdlineInfo const cmdl
}
png_init_io (png_ptr, stdout);
- info_ptr->width = cols;
- info_ptr->height = rows;
- info_ptr->bit_depth = depth;
+ png_set_IHDR(png_ptr, info_ptr, cols, rows, depth, PNG_COLOR_TYPE_PALETTE,
0, 0, 0);
if (colorMapped)
- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
- else if (pnm_type == PPM_TYPE)
- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
- else
- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
-
- if (alpha && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
- info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+ png_set_color_type(png_ptr, info_ptr, PNG_COLOR_TYPE_PALETTE);
+ else if (pnm_type == PPM_TYPE) {
+ if (alpha)
+ png_set_color_type(png_ptr, info_ptr, PNG_COLOR_TYPE_RGB_ALPHA);
+ else
+ png_set_color_type(png_ptr, info_ptr, PNG_COLOR_TYPE_RGB);
+ } else {
+ if (alpha)
+ png_set_color_type(png_ptr, info_ptr, PNG_COLOR_TYPE_GRAY_ALPHA);
+ else
+ png_set_color_type(png_ptr, info_ptr, PNG_COLOR_TYPE_GRAY);
+ }
- info_ptr->interlace_type = cmdline.interlace;
+ /* TODO: correct? */
+ if (cmdline.interlace)
+ png_set_interlace_handling(png_ptr);
- doGamaChunk(cmdline, info_ptr);
+ doGamaChunk(cmdline, png_ptr, info_ptr);
- doChrmChunk(cmdline, info_ptr);
+ doChrmChunk(cmdline, png_ptr, info_ptr);
- doPhysChunk(cmdline, info_ptr);
+ doPhysChunk(cmdline, png_ptr, info_ptr);
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
/* creating PNG palette (PLTE and tRNS chunks) */
@@ -2611,7 +2596,7 @@ convertpnm(struct cmdlineInfo const cmdl
info_ptr->num_palette = palette_size;
if (trans_size > 0) {
info_ptr->valid |= PNG_INFO_tRNS;
- info_ptr->trans = trans;
+ info_ptr->trans_alpha = trans;
info_ptr->num_trans = trans_size; /* omit opaque values */
}
/* creating hIST chunk */
@@ -2644,11 +2629,11 @@ convertpnm(struct cmdlineInfo const cmdl
pm_message("histogram created");
}
} else { /* color_type != PNG_COLOR_TYPE_PALETTE */
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
- info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
if (transparent > 0) {
info_ptr->valid |= PNG_INFO_tRNS;
- info_ptr->trans_values =
+ info_ptr->trans_color =
xelToPngColor_16(transcolor, maxval, png_maxval);
}
} else {
@@ -2660,10 +2645,10 @@ convertpnm(struct cmdlineInfo const cmdl
if (info_ptr->valid && PNG_INFO_tRNS)
pm_message("Transparent color {gray, red, green, blue} = "
"{%d, %d, %d, %d}",
- info_ptr->trans_values.gray,
- info_ptr->trans_values.red,
- info_ptr->trans_values.green,
- info_ptr->trans_values.blue);
+ info_ptr->trans_color.gray,
+ info_ptr->trans_color.red,
+ info_ptr->trans_color.green,
+ info_ptr->trans_color.blue);
else
pm_message("No transparent color");
}
@@ -2672,7 +2657,7 @@ convertpnm(struct cmdlineInfo const cmdl
/* bKGD chunk */
if (cmdline.background) {
info_ptr->valid |= PNG_INFO_bKGD;
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
info_ptr->background.index = background_index;
} else {
info_ptr->background =
@@ -2687,13 +2672,13 @@ convertpnm(struct cmdlineInfo const cmdl
}
}
- doSbitChunk(info_ptr, png_maxval, maxval, alpha, alpha_maxval);
+ doSbitChunk(png_ptr, info_ptr, png_maxval, maxval, alpha, alpha_maxval);
/* tEXT and zTXT chunks */
if (cmdline.text || cmdline.ztxt)
pnmpng_read_text(info_ptr, tfp, !!cmdline.ztxt, cmdline.verbose);
- doTimeChunk(cmdline, info_ptr);
+ doTimeChunk(cmdline, png_ptr, info_ptr);
if (cmdline.filterSet != 0)
png_set_filter(png_ptr, 0, cmdline.filterSet);
Home |
Main Index |
Thread Index |
Old Index