aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosmin Truta <ctruta@gmail.com>2024-01-09 00:33:39 +0200
committerCosmin Truta <ctruta@gmail.com>2024-01-09 00:33:39 +0200
commit6beae586d64f414510c04723bee475b4234bdd80 (patch)
tree905887ac57bb820aac2a1198b7a8dc13849ef00a
parentbdbbcaa4578f804734ddc6678fb24378cc18ebcf (diff)
downloadlibpng-6beae586d64f414510c04723bee475b4234bdd80.tar.gz
pngminus: Expect all image transformations to be available in libpng
The pngminus programs use several PNG image transformations: `png_set_expand`, `png_set_expand_1_2_4_to_8`, etc. (in png2pnm.c); `png_set_packing`, `png_set_invert_mono`, etc. (in pnm2png.c). The availability of all of these transformations in libpng is now required at compile time. On the topic of transformations, apply an unrelated fix to the use of `png_set_gamma`.
-rw-r--r--contrib/pngminus/png2pnm.c11
-rw-r--r--contrib/pngminus/pnm2png.c14
2 files changed, 7 insertions, 18 deletions
diff --git a/contrib/pngminus/png2pnm.c b/contrib/pngminus/png2pnm.c
index de58dfdc3..bb159e213 100644
--- a/contrib/pngminus/png2pnm.c
+++ b/contrib/pngminus/png2pnm.c
@@ -224,7 +224,7 @@ BOOL png2pnm_internal (png_struct *png_ptr, png_info *info_ptr,
/* set up (if applicable) the expansion of grayscale images to bit-depth 8 */
png_set_expand_gray_1_2_4_to_8 (png_ptr);
-#ifdef NJET /* FIXME */
+#ifdef NJET
/* downgrade 16-bit images to 8-bit */
if (bit_depth == 16)
png_set_strip_16 (png_ptr);
@@ -232,9 +232,12 @@ BOOL png2pnm_internal (png_struct *png_ptr, png_info *info_ptr,
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
- /* only if file has a file gamma, we do a correction */
- if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
- png_set_gamma (png_ptr, (double) 2.2, file_gamma);
+ /* if the PNG image has a gAMA chunk then gamma-correct the output image */
+ {
+ double file_gamma;
+ if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
+ png_set_gamma (png_ptr, (double) 2.2, file_gamma);
+ }
#endif
/* read the image file, with all of the above image transforms applied */
diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c
index 5558023be..b89b73266 100644
--- a/contrib/pngminus/pnm2png.c
+++ b/contrib/pngminus/pnm2png.c
@@ -222,9 +222,7 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
png_uint_32 alpha_width = 0, alpha_height = 0;
int alpha_depth = 0, alpha_present = 0;
BOOL alpha_raw = FALSE;
-#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
BOOL packed_bitmap = FALSE;
-#endif
/* read header of PNM file */
@@ -247,16 +245,10 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
if ((magic_token[1] == '1') || (magic_token[1] == '4'))
{
-#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
raw = (magic_token[1] == '4');
bit_depth = 1;
color_type = PNG_COLOR_TYPE_GRAY;
packed_bitmap = TRUE;
-#else
- fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and\n");
- fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n");
- return FALSE;
-#endif
}
else if ((magic_token[1] == '2') || (magic_token[1] == '5'))
{
@@ -356,14 +348,12 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
alpha_present = (channels - 1) % 2;
-#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
if (packed_bitmap)
{
/* row data is as many bytes as can fit width x channels x bit_depth */
row_bytes = (width * channels * bit_depth + 7) / 8;
}
else
-#endif
{
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
@@ -396,7 +386,6 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
for (row = 0; row < height; row++)
{
pix_ptr = row_pointers[row];
-#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
if (packed_bitmap)
{
for (i = 0; i < row_bytes; i++)
@@ -406,7 +395,6 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
}
}
else
-#endif
{
for (col = 0; col < width; col++)
{
@@ -466,13 +454,11 @@ BOOL pnm2png_internal (png_struct *png_ptr, png_info *info_ptr,
(!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
if (packed_bitmap == TRUE)
{
png_set_packing (png_ptr);
png_set_invert_mono (png_ptr);
}
-#endif
/* write the file header information */
png_write_info (png_ptr, info_ptr);