@@ -, +, @@ -- Stuart Longland (redhatter@gentoo.org) --- netpbm-10.51.00/converter/other/pamrgbatopng.c.orig 2011-07-19 00:58:57.212999572 +1000 +++ netpbm-10.51.00/converter/other/pamrgbatopng.c.orig 2011-07-19 00:59:05.573000371 +1000 @@ -101,10 +101,12 @@ if (!infoP) pm_error("Could not allocate PNG info structure"); else { - infoP->width = pamP->width; - infoP->height = pamP->height; - infoP->bit_depth = 8; - infoP->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + png_set_IHDR(pngP, infoP, + pamP->width, pamP->height, 8, + PNG_COLOR_TYPE_RGB_ALPHA, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); png_init_io(pngP, ofP); --- netpbm-10.51.00/converter/other/pngtxt.c.orig 2011-07-18 23:35:56.686000302 +1000 +++ netpbm-10.51.00/converter/other/pngtxt.c.orig 2011-07-18 23:47:37.493000403 +1000 @@ -240,12 +240,13 @@ void -pnmpng_read_text (png_info * const info_ptr, +pnmpng_read_text (struct pngx* const pngxP, FILE * const tfp, bool const ztxt, bool const verbose) { const char * textline; + struct png_text_struct* text; unsigned int lineLength; unsigned int commentIdx; bool noCommentsYet; @@ -257,8 +258,8 @@ allocatedComments = 256; /* initial value */ - MALLOCARRAY(info_ptr->text, allocatedComments); - if (info_ptr->text == NULL) + MALLOCARRAY(text, allocatedComments); + if (text == NULL) pm_error("unable to allocate memory for comment array"); commentIdx = 0; @@ -273,7 +274,7 @@ if (lineLength == 0) { /* skip this empty line */ } else { - handleArrayAllocation(&info_ptr->text, &allocatedComments, + handleArrayAllocation(&text, &allocatedComments, commentIdx); if ((textline[0] != ' ') && (textline[0] != '\t')) { /* Line doesn't start with white space, which @@ -285,7 +286,7 @@ ++commentIdx; noCommentsYet = FALSE; - startComment(&info_ptr->text[commentIdx], + startComment(&text[commentIdx], textline, lineLength, ztxt); } else { /* Line starts with whitespace, which means it is @@ -295,7 +296,7 @@ pm_error("Invalid comment file format: " "first line is a continuation line! " "(It starts with whitespace)"); - continueComment(&info_ptr->text[commentIdx], + continueComment(&text[commentIdx], textline, lineLength); } } @@ -303,12 +304,13 @@ } } if (noCommentsYet) - info_ptr->num_text = 0; + png_set_text(pngxP->png_ptr, pngxP->info_ptr, NULL, 0); else - info_ptr->num_text = commentIdx + 1; - + png_set_text(pngxP->png_ptr, pngxP->info_ptr, text, commentIdx + 1); + /* TODO: does this leak memory if noCommentsYet is true? */ if (verbose) - pm_message("%d comments placed in text chunk", info_ptr->num_text); + pm_message("%d comments placed in text chunk", + noCommentsYet ? 0 : commentIdx+1); } --- netpbm-10.51.00/converter/other/pnmtopng.c.orig 2011-07-18 22:25:20.358000284 +1000 +++ netpbm-10.51.00/converter/other/pnmtopng.c.orig 2011-07-18 23:35:42.038000349 +1000 @@ -58,7 +58,8 @@ #include #include /* strcat() */ #include -#include /* includes zlib.h and setjmp.h */ +#include /* includes setjmp.h */ +#include #include "pm_c_util.h" #include "pnm.h" @@ -2180,7 +2181,7 @@ gray * const alpha_mask, colorhash_table const cht, coloralphahash_table const caht, - png_info * const info_ptr, + struct pngx * const pngxP, xelval const png_maxval, unsigned int const depth) { @@ -2192,20 +2193,22 @@ 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) { + png_byte color_type = png_get_color_type(pngxP->png_ptr, + pngxP->info_ptr); + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == 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 (color_type == 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 (color_type == PNG_COLOR_TYPE_RGB || + color_type == PNG_COLOR_TYPE_RGB_ALPHA) { if (depth == 16) *pp++ = PPM_GETR(p_png) >> 8; *pp++ = PPM_GETR(p_png) & 0xff; @@ -2218,7 +2221,7 @@ } else pm_error("INTERNAL ERROR: undefined color_type"); - if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) { + if (color_type & PNG_COLOR_MASK_ALPHA) { int const png_alphaval = (int) alpha_mask[col] * (float) png_maxval / maxval + 0.5; if (depth == 16) @@ -2274,7 +2277,7 @@ makePngLine(line, xelrow, cols, maxval, alpha, alpha ? alpha_mask[row] : NULL, - cht, caht, pngxP->info_ptr, png_maxval, depth); + cht, caht, pngxP, png_maxval, depth); png_write_row(pngxP->png_ptr, line); } @@ -2293,7 +2296,7 @@ unsigned int const rows, xelval const maxval, int const format, - png_info * const info_ptr, + struct pngx* const pngxP, bool const verbose) { if (histRequested) { @@ -2324,8 +2327,7 @@ histogram[i] = chv[chvIndex].value; } - info_ptr->valid |= PNG_INFO_hIST; - info_ptr->hist = histogram; + png_set_hIST(pngxP->png_ptr, pngxP->info_ptr, histogram); if (verbose) pm_message("histogram created in PNG stream"); } @@ -2336,41 +2338,44 @@ -static void +static png_byte setColorType(struct pngx * const pngxP, bool const colorMapped, int const pnmType, bool const alpha) { + png_byte color_type = 0; + if (colorMapped) - pngxP->info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; + color_type = PNG_COLOR_TYPE_PALETTE; else if (pnmType == PPM_TYPE) - pngxP->info_ptr->color_type = PNG_COLOR_TYPE_RGB; + color_type = PNG_COLOR_TYPE_RGB; else - pngxP->info_ptr->color_type = PNG_COLOR_TYPE_GRAY; + color_type = PNG_COLOR_TYPE_GRAY; - if (alpha && pngxP->info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) - pngxP->info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; + if (alpha && color_type != PNG_COLOR_TYPE_PALETTE) + color_type |= PNG_COLOR_MASK_ALPHA; + return color_type; } static void doGamaChunk(struct cmdlineInfo const cmdline, - png_info * const info_ptr) { + struct pngx * const pngxP) { if (cmdline.gammaSpec) { /* gAMA chunk */ - info_ptr->valid |= PNG_INFO_gAMA; - info_ptr->gamma = cmdline.gamma; + png_set_gAMA(pngxP->png_ptr, pngxP->info_ptr, cmdline.gamma); } } - +/* TODO: needs porting */ +#if 0 static void doChrmChunk(struct cmdlineInfo const cmdline, - png_info * const info_ptr) { + struct pngx * const pngxP) { if (cmdline.rgbSpec) { /* cHRM chunk */ @@ -2386,20 +2391,19 @@ info_ptr->y_blue = cmdline.rgb.by; } } +#endif static void doPhysChunk(struct cmdlineInfo const cmdline, - png_info * const info_ptr) { + struct pngx * const pngxP) { 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(pngxP->png_ptr, pngxP->info_ptr, + cmdline.size.x, cmdline.size.y, + cmdline.size.unit); } } @@ -2408,13 +2412,14 @@ static void doTimeChunk(struct cmdlineInfo const cmdline, - png_info * const info_ptr) { + struct pngx * const pngxP) { if (cmdline.modtimeSpec) { /* tIME chunk */ - info_ptr->valid |= PNG_INFO_tIME; + png_timep ptime; - png_convert_from_time_t(&info_ptr->mod_time, cmdline.modtime); + png_convert_from_time_t(ptime, cmdline.modtime); + png_set_tIME(pngxP->png_ptr, pngxP->info_ptr, ptime); } } @@ -2450,8 +2455,8 @@ pixel const transColor, xelval const maxval, xelval const pngMaxval) { - - switch (pngxP->info_ptr->color_type) { + png_byte color_type = png_get_color_type(pngxP->png_ptr, pngxP->info_ptr); + switch (color_type) { case PNG_COLOR_TYPE_PALETTE: if (transPaletteSize > 0) { png_set_tRNS(pngxP->png_ptr, pngxP->info_ptr, @@ -2483,7 +2488,7 @@ static void doBkgdChunk(bool const bkgdRequested, - png_info * const info_ptr, + struct pngx* const pngxP, unsigned int const backgroundIndex, pixel const backColor, xelval const maxval, @@ -2491,33 +2496,28 @@ bool const verbose) { if (bkgdRequested) { - info_ptr->valid |= PNG_INFO_bKGD; - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - info_ptr->background.index = backgroundIndex; - } else { - info_ptr->background = - xelToPngColor_16(backColor, maxval, pngMaxval); - if (verbose) - pm_message("Writing bKGD chunk with background color " - " {gray, red, green, blue} = {%d, %d, %d, %d}", - info_ptr->background.gray, - info_ptr->background.red, - info_ptr->background.green, - info_ptr->background.blue ); - } + png_color_16 bg = xelToPngColor_16(backColor, maxval, pngMaxval); + png_set_bKGD(pngxP->png_ptr, pngxP->info_ptr, &bg); + if (verbose) + pm_message("Writing bKGD chunk with background color " + " {gray, red, green, blue} = {%d, %d, %d, %d}", + bg.gray, + bg.red, + bg.green, + bg.blue ); } } static void -doSbitChunk(png_info * const pngInfoP, +doSbitChunk(struct pngx* const pngxP, xelval const pngMaxval, xelval const maxval, bool const alpha, xelval const alphaMaxval) { - - if (pngInfoP->color_type != PNG_COLOR_TYPE_PALETTE && + png_byte color_type = png_get_color_type(pngxP->png_ptr, pngxP->info_ptr); + if (color_type != PNG_COLOR_TYPE_PALETTE && (pngMaxval > maxval || (alpha && pngMaxval > alphaMaxval))) { /* We're writing in a bit depth that doesn't match the maxval @@ -2535,28 +2535,28 @@ PNG doesn't allow it, we don't attempt to create such an sBIT chunk. */ - - pngInfoP->valid |= PNG_INFO_sBIT; + png_color_8 sig_bit; { 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; + if (color_type & PNG_COLOR_MASK_COLOR) { + sig_bit.red = sbitval; + sig_bit.green = sbitval; + sig_bit.blue = sbitval; } else - pngInfoP->sig_bit.gray = sbitval; + sig_bit.gray = sbitval; if (verbose) pm_message("Writing sBIT chunk with bits = %d", sbitval); } - if (pngInfoP->color_type & PNG_COLOR_MASK_ALPHA) { - pngInfoP->sig_bit.alpha = + if (color_type & PNG_COLOR_MASK_ALPHA) { + sig_bit.alpha = pm_maxvaltobits(MIN(alphaMaxval, pngMaxval)); if (verbose) - pm_message(" alpha bits = %d", pngInfoP->sig_bit.alpha); + pm_message(" alpha bits = %d", sig_bit.alpha); } + png_set_sBIT(pngxP->png_ptr, pngxP->info_ptr, &sig_bit); } } @@ -2755,50 +2755,48 @@ pm_error ("setjmp returns error condition (2)"); } - pngxP->info_ptr->width = cols; - pngxP->info_ptr->height = rows; - pngxP->info_ptr->bit_depth = depth; - - setColorType(pngxP, colorMapped, pnm_type, alpha); - - pngxP->info_ptr->interlace_type = cmdline.interlace; - - doGamaChunk(cmdline, pngxP->info_ptr); - - doChrmChunk(cmdline, pngxP->info_ptr); - - doPhysChunk(cmdline, pngxP->info_ptr); + png_byte color_type = setColorType(pngxP, colorMapped, pnm_type, alpha); + png_set_IHDR(pngxP->png_ptr, pngxP->info_ptr, + cols, rows, depth, color_type, + cmdline.interlace, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + + doGamaChunk(cmdline, pngxP); + /* TODO: port doChrmChunk */ +#if 0 + doChrmChunk(cmdline, pngxP); +#endif + doPhysChunk(cmdline, pngxP); - if (pngxP->info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { + if (color_type == PNG_COLOR_TYPE_PALETTE) { /* creating PNG palette (Not counting the transparency palette) */ createPngPalette(palette_pnm, palette_size, maxval, trans_pnm, trans_size, alpha_maxval, palette, trans); - pngxP->info_ptr->valid |= PNG_INFO_PLTE; - pngxP->info_ptr->palette = palette; - pngxP->info_ptr->num_palette = palette_size; + png_set_PLTE(pngxP->png_ptr, pngxP->info_ptr, palette, palette_size); doHistChunk(cmdline.hist, palette_pnm, ifP, rasterPos, cols, rows, maxval, format, - pngxP->info_ptr, cmdline.verbose); + pngxP, cmdline.verbose); } doTrnsChunk(pngxP, trans, trans_size, transparent, transcolor, maxval, png_maxval); - doBkgdChunk(!!cmdline.background, pngxP->info_ptr, + doBkgdChunk(!!cmdline.background, pngxP, background_index, backcolor, maxval, png_maxval, cmdline.verbose); - doSbitChunk(pngxP->info_ptr, png_maxval, maxval, alpha, alpha_maxval); + doSbitChunk(pngxP, png_maxval, maxval, alpha, alpha_maxval); /* tEXT and zTXT chunks */ if (cmdline.text || cmdline.ztxt) pnmpng_read_text(pngxP->info_ptr, tfP, !!cmdline.ztxt, cmdline.verbose); - doTimeChunk(cmdline, pngxP->info_ptr); + doTimeChunk(cmdline, pngxP); if (cmdline.filterSet != 0) png_set_filter(pngxP->png_ptr, 0, cmdline.filterSet); @@ -2809,7 +2807,8 @@ /* write the png-info struct */ png_write_info(pngxP->png_ptr, pngxP->info_ptr); - +#if 0 + /* should no longer be necessary */ if (cmdline.text || cmdline.ztxt) /* prevent from being written twice with png_write_end */ pngxP->info_ptr->num_text = 0; @@ -2817,7 +2816,7 @@ if (cmdline.modtime) /* prevent from being written twice with png_write_end */ pngxP->info_ptr->valid &= ~PNG_INFO_tIME; - +#endif /* let libpng take care of, e.g., bit-depth conversions */ png_set_packing(pngxP->png_ptr);