diff options
Diffstat (limited to 'converter/other/pngtopnm.c')
-rw-r--r-- | converter/other/pngtopnm.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/converter/other/pngtopnm.c b/converter/other/pngtopnm.c index 3bbc942f..47e26437 100644 --- a/converter/other/pngtopnm.c +++ b/converter/other/pngtopnm.c @@ -1,6 +1,6 @@ /* ** pngtopnm.c - -** read a Portable Network Graphics file and produce a portable anymap +** read a Portable Network Graphics file and produce a PNM. ** ** Copyright (C) 1995,1998 by Alexander Lehmann <alex@hal.rhein-main.de> ** and Willem van Schaik <willem@schaik.com> @@ -222,6 +222,15 @@ pngx_destroy(struct pngx * const pngxP) { +static bool +pngx_chunkIsPresent(struct pngx * const pngxP, + uint32_t const chunkType) { + + return png_get_valid(pngxP->png_ptr, pngxP->info_ptr, chunkType); +} + + + static void verifyFileIsPng(FILE * const ifP, size_t * const consumedByteCtP) { @@ -598,6 +607,23 @@ dumpPngInfo(struct pngx * const pngxP) { +static const png_color_16 * +transColor(struct pngx * const pngxP) { + + png_bytep trans; + int numTrans; + png_color_16 * transColor; + + assert(chunkIsPresent(PNG_INFO_tRNS)); + + png_get_tRNS(pngxP->png_ptr, pngxP->info_ptr, + &trans, &numTrans, &transColor); + + return transColor; +} + + + static bool isTransparentColor(pngcolor const color, struct pngx * const pngxP, @@ -610,9 +636,8 @@ isTransparentColor(pngcolor const color, -----------------------------------------------------------------------------*/ bool retval; - if (pngxP->info_ptr->valid & PNG_INFO_tRNS) { - const png_color_16 * const transColorP = - &pngxP->info_ptr->trans_values; + if (pngx_chunkIsPresent(PNG_INFO_tRNS)) { + const png_color_16 * const transColorP = transColor(pngxP); /* It seems odd that libpng lets you get gamma-corrected pixel values, but not gamma-corrected transparency or background |