summaryrefslogtreecommitdiff
path: root/plugins/AdvaImg/src/LibPNG/pngread.c
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2014-12-13 20:28:24 +0000
committerKirill Volinsky <mataes2007@gmail.com>2014-12-13 20:28:24 +0000
commitd2d798d0f11abcbf141db69869e76e8d123ec1eb (patch)
treecee8645964030b4b80231952885911f724850d12 /plugins/AdvaImg/src/LibPNG/pngread.c
parenta400ebf572dcad9b43d1b641b1742814f8b5e8a5 (diff)
FreeImage updated to 3.16
git-svn-id: http://svn.miranda-ng.org/main/trunk@11379 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AdvaImg/src/LibPNG/pngread.c')
-rw-r--r--plugins/AdvaImg/src/LibPNG/pngread.c460
1 files changed, 239 insertions, 221 deletions
diff --git a/plugins/AdvaImg/src/LibPNG/pngread.c b/plugins/AdvaImg/src/LibPNG/pngread.c
index 51ff8f3434..4b80ef2d46 100644
--- a/plugins/AdvaImg/src/LibPNG/pngread.c
+++ b/plugins/AdvaImg/src/LibPNG/pngread.c
@@ -1,8 +1,8 @@
/* pngread.c - read a PNG file
*
- * Last changed in libpng 1.6.1 [March 28, 2013]
- * Copyright (c) 1998-2013 Glenn Randers-Pehrson
+ * Last changed in libpng 1.6.10 [March 6, 2014]
+ * Copyright (c) 1998-2014 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -158,9 +158,6 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
else if (chunk_name == png_IDAT)
{
-#ifdef PNG_READ_APNG_SUPPORTED
- png_have_info(png_ptr, info_ptr);
-#endif
png_ptr->idat_size = length;
break;
}
@@ -250,17 +247,6 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_handle_iTXt(png_ptr, info_ptr, length);
#endif
-#ifdef PNG_READ_APNG_SUPPORTED
- else if (chunk_name == png_acTL)
- png_handle_acTL(png_ptr, info_ptr, length);
-
- else if (chunk_name == png_fcTL)
- png_handle_fcTL(png_ptr, info_ptr, length);
-
- else if (chunk_name == png_fdAT)
- png_handle_fdAT(png_ptr, info_ptr, length);
-#endif
-
else
png_handle_unknown(png_ptr, info_ptr, length,
PNG_HANDLE_CHUNK_AS_DEFAULT);
@@ -268,72 +254,6 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
}
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
-#ifdef PNG_READ_APNG_SUPPORTED
-void PNGAPI
-png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
-{
- png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
-
- png_debug(0, "Reading frame head");
-
- if (!(png_ptr->mode & PNG_HAVE_acTL))
- png_error(png_ptr, "attempt to png_read_frame_head() but "
- "no acTL present");
-
- /* do nothing for the main IDAT */
- if (png_ptr->num_frames_read == 0)
- return;
-
- png_read_reset(png_ptr);
- png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
- png_ptr->mode &= ~PNG_HAVE_fcTL;
-
- have_chunk_after_DAT = 0;
- for (;;)
- {
- png_uint_32 length = png_read_chunk_header(png_ptr);
-
- if (png_ptr->chunk_name == png_IDAT)
- {
- /* discard trailing IDATs for the first frame */
- if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
- png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
- png_crc_finish(png_ptr, length);
- }
-
- else if (png_ptr->chunk_name == png_fcTL)
- {
- png_handle_fcTL(png_ptr, info_ptr, length);
- have_chunk_after_DAT = 1;
- }
-
- else if (png_ptr->chunk_name == png_fdAT)
- {
- png_ensure_sequence_number(png_ptr, length);
-
- /* discard trailing fdATs for frames other than the first */
- if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
- png_crc_finish(png_ptr, length - 4);
- else if(png_ptr->mode & PNG_HAVE_fcTL)
- {
- png_ptr->idat_size = length - 4;
- png_ptr->mode |= PNG_HAVE_IDAT;
-
- break;
- }
- else
- png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
- }
- else
- {
- png_warning(png_ptr, "Skipped (ignored) a chunk "
- "between APNG chunks");
- png_crc_finish(png_ptr, length);
- }
- }
-}
-#endif /* PNG_READ_APNG_SUPPORTED */
-
/* Optional call to update the users info_ptr structure */
void PNGAPI
png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
@@ -385,6 +305,72 @@ png_start_read_image(png_structrp png_ptr)
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
+#ifdef PNG_MNG_FEATURES_SUPPORTED
+/* Undoes intrapixel differencing,
+ * NOTE: this is apparently only supported in the 'sequential' reader.
+ */
+static void
+png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
+{
+ png_debug(1, "in png_do_read_intrapixel");
+
+ if (
+ (row_info->color_type & PNG_COLOR_MASK_COLOR))
+ {
+ int bytes_per_pixel;
+ png_uint_32 row_width = row_info->width;
+
+ if (row_info->bit_depth == 8)
+ {
+ png_bytep rp;
+ png_uint_32 i;
+
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB)
+ bytes_per_pixel = 3;
+
+ else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ bytes_per_pixel = 4;
+
+ else
+ return;
+
+ for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
+ {
+ *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
+ *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
+ }
+ }
+ else if (row_info->bit_depth == 16)
+ {
+ png_bytep rp;
+ png_uint_32 i;
+
+ if (row_info->color_type == PNG_COLOR_TYPE_RGB)
+ bytes_per_pixel = 6;
+
+ else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ bytes_per_pixel = 8;
+
+ else
+ return;
+
+ for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
+ {
+ png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
+ png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
+ png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
+ png_uint_32 red = (s0 + s1 + 65536) & 0xffff;
+ png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
+ *(rp ) = (png_byte)((red >> 8) & 0xff);
+ *(rp + 1) = (png_byte)(red & 0xff);
+ *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
+ *(rp + 5) = (png_byte)(blue & 0xff);
+ }
+ }
+ }
+}
+#endif /* PNG_MNG_FEATURES_SUPPORTED */
+
void PNGAPI
png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
{
@@ -569,7 +555,6 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)
}
#endif
-
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
if (png_ptr->transformations)
png_do_read_transformations(png_ptr, &row_info);
@@ -796,11 +781,14 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
png_uint_32 length = png_read_chunk_header(png_ptr);
png_uint_32 chunk_name = png_ptr->chunk_name;
- if (chunk_name == png_IHDR)
+ if (chunk_name == png_IEND)
+ png_handle_IEND(png_ptr, info_ptr, length);
+
+ else if (chunk_name == png_IHDR)
png_handle_IHDR(png_ptr, info_ptr, length);
- else if (chunk_name == png_IEND)
- png_handle_IEND(png_ptr, info_ptr, length);
+ else if (info_ptr == NULL)
+ png_crc_finish(png_ptr, length);
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
@@ -1016,8 +1004,6 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
int transforms,
voidp params)
{
- int row;
-
if (png_ptr == NULL || info_ptr == NULL)
return;
@@ -1029,126 +1015,149 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
png_error(png_ptr, "Image is too high to process with png_read_png()");
/* -------------- image transformations start here ------------------- */
+ /* libpng 1.6.10: add code to cause a png_app_error if a selected TRANSFORM
+ * is not implemented. This will only happen in de-configured (non-default)
+ * libpng builds. The results can be unexpected - png_read_png may return
+ * short or mal-formed rows because the transform is skipped.
+ */
-#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
/* Tell libpng to strip 16-bit/color files down to 8 bits per color.
*/
if (transforms & PNG_TRANSFORM_SCALE_16)
- {
/* Added at libpng-1.5.4. "strip_16" produces the same result that it
* did in earlier versions, while "scale_16" is now more accurate.
*/
+#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png_ptr);
- }
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_SCALE_16 not supported");
#endif
-#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
/* If both SCALE and STRIP are required pngrtran will effectively cancel the
* latter by doing SCALE first. This is ok and allows apps not to check for
* which is supported to get the right answer.
*/
if (transforms & PNG_TRANSFORM_STRIP_16)
+#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
png_set_strip_16(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_16 not supported");
#endif
-#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
/* Strip alpha bytes from the input data without combining with
* the background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
+#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
png_set_strip_alpha(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_ALPHA not supported");
#endif
-#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
+#ifdef PNG_READ_PACK_SUPPORTED
png_set_packing(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
#endif
-#ifdef PNG_READ_PACKSWAP_SUPPORTED
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing).
*/
if (transforms & PNG_TRANSFORM_PACKSWAP)
+#ifdef PNG_READ_PACKSWAP_SUPPORTED
png_set_packswap(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
#endif
-#ifdef PNG_READ_EXPAND_SUPPORTED
/* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
- if ((png_ptr->bit_depth < 8) ||
- (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
- (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
- png_set_expand(png_ptr);
+#ifdef PNG_READ_EXPAND_SUPPORTED
+ png_set_expand(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND not supported");
#endif
/* We don't handle background color or gamma transformation or quantizing.
*/
-#ifdef PNG_READ_INVERT_SUPPORTED
/* Invert monochrome files to have 0 as white and 1 as black
*/
if (transforms & PNG_TRANSFORM_INVERT_MONO)
+#ifdef PNG_READ_INVERT_SUPPORTED
png_set_invert_mono(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
#endif
-#ifdef PNG_READ_SHIFT_SUPPORTED
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
- if ((transforms & PNG_TRANSFORM_SHIFT)
- && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
- {
- png_color_8p sig_bit;
-
- png_get_sBIT(png_ptr, info_ptr, &sig_bit);
- png_set_shift(png_ptr, sig_bit);
- }
+ if (transforms & PNG_TRANSFORM_SHIFT)
+#ifdef PNG_READ_SHIFT_SUPPORTED
+ if (info_ptr->valid & PNG_INFO_sBIT)
+ png_set_shift(png_ptr, &info_ptr->sig_bit);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
#endif
-#ifdef PNG_READ_BGR_SUPPORTED
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
+#ifdef PNG_READ_BGR_SUPPORTED
png_set_bgr(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
#endif
-#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
+#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
png_set_swap_alpha(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
#endif
-#ifdef PNG_READ_SWAP_SUPPORTED
/* Swap bytes of 16-bit files to least significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
+#ifdef PNG_READ_SWAP_SUPPORTED
png_set_swap(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
#endif
/* Added at libpng-1.2.41 */
-#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
/* Invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
+#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
png_set_invert_alpha(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
#endif
/* Added at libpng-1.2.41 */
-#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
/* Expand grayscale image to RGB */
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
+#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
png_set_gray_to_rgb(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_GRAY_TO_RGB not supported");
#endif
/* Added at libpng-1.5.4 */
-#ifdef PNG_READ_EXPAND_16_SUPPORTED
if (transforms & PNG_TRANSFORM_EXPAND_16)
+#ifdef PNG_READ_EXPAND_16_SUPPORTED
png_set_expand_16(png_ptr);
+#else
+ png_app_error(png_ptr, "PNG_TRANSFORM_EXPAND_16 not supported");
#endif
/* We don't handle adding filler bytes */
@@ -1171,16 +1180,17 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
{
png_uint_32 iptr;
- info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
- info_ptr->height * (sizeof (png_bytep)));
+ info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr,
+ info_ptr->height * (sizeof (png_bytep))));
+
for (iptr=0; iptr<info_ptr->height; iptr++)
info_ptr->row_pointers[iptr] = NULL;
info_ptr->free_me |= PNG_FREE_ROWS;
- for (row = 0; row < (int)info_ptr->height; row++)
- info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
- png_get_rowbytes(png_ptr, info_ptr));
+ for (iptr = 0; iptr < info_ptr->height; iptr++)
+ info_ptr->row_pointers[iptr] = png_voidcast(png_bytep,
+ png_malloc(png_ptr, info_ptr->rowbytes));
}
png_read_image(png_ptr, info_ptr->row_pointers);
@@ -1189,9 +1199,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
- PNG_UNUSED(transforms) /* Quiet compiler warnings */
PNG_UNUSED(params)
-
}
#endif /* PNG_INFO_IMAGE_SUPPORTED */
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
@@ -1205,12 +1213,11 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr,
/* Arguments to png_image_finish_read: */
/* Encoding of PNG data (used by the color-map code) */
-/* TODO: change these, dang, ANSI-C reserves the 'E' namespace. */
-# define E_NOTSET 0 /* File encoding not yet known */
-# define E_sRGB 1 /* 8-bit encoded to sRGB gamma */
-# define E_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
-# define E_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
-# define E_LINEAR8 4 /* 8-bit linear: only from a file value */
+# define P_NOTSET 0 /* File encoding not yet known */
+# define P_sRGB 1 /* 8-bit encoded to sRGB gamma */
+# define P_LINEAR 2 /* 16-bit linear: not encoded, NOT pre-multiplied! */
+# define P_FILE 3 /* 8-bit encoded to file gamma, not sRGB or linear */
+# define P_LINEAR8 4 /* 8-bit linear: only from a file value */
/* Color-map processing: after libpng has run on the PNG image further
* processing may be needed to conver the data to color-map indicies.
@@ -1241,7 +1248,7 @@ typedef struct
png_voidp first_row;
ptrdiff_t row_bytes; /* step between rows */
int file_encoding; /* E_ values above */
- png_fixed_point gamma_to_linear; /* For E_FILE, reciprocal of gamma */
+ png_fixed_point gamma_to_linear; /* For P_FILE, reciprocal of gamma */
int colormap_processing; /* PNG_CMAP_ values above */
} png_image_read_control;
@@ -1373,7 +1380,7 @@ png_image_read_header(png_voidp argument)
#ifdef PNG_COLORSPACE_SUPPORTED
/* Does the colorspace match sRGB? If there is no color endpoint
* (colorant) information assume yes, otherwise require the
- * 'ENDPOINTS_MATCHE_sRGB' colorspace flag to have been set. If the
+ * 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set. If the
* colorspace has been determined to be invalid ignore it.
*/
if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags
@@ -1562,17 +1569,24 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
*
* Or image data handling:
*
- * tRNS, bKGD, gAMA, cHRM, sRGB, iCCP and sBIT.
+ * tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT.
*
* This provides a small performance improvement and eliminates any
* potential vulnerability to security problems in the unused chunks.
+ *
+ * At present the iCCP chunk data isn't used, so iCCP chunk can be ignored
+ * too. This allows the simplified API to be compiled without iCCP support,
+ * however if the support is there the chunk is still checked to detect
+ * errors (which are unfortunately quite common.)
*/
{
static PNG_CONST png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
+# ifdef PNG_READ_iCCP_SUPPORTED
105, 67, 67, 80, '\0', /* iCCP */
+# endif
115, 66, 73, 84, '\0', /* sBIT */
115, 82, 71, 66, '\0', /* sRGB */
};
@@ -1609,25 +1623,25 @@ set_file_encoding(png_image_read_control *display)
{
if (png_gamma_not_sRGB(g))
{
- display->file_encoding = E_FILE;
+ display->file_encoding = P_FILE;
display->gamma_to_linear = png_reciprocal(g);
}
else
- display->file_encoding = E_sRGB;
+ display->file_encoding = P_sRGB;
}
else
- display->file_encoding = E_LINEAR8;
+ display->file_encoding = P_LINEAR8;
}
static unsigned int
decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
{
- if (encoding == E_FILE) /* double check */
+ if (encoding == P_FILE) /* double check */
encoding = display->file_encoding;
- if (encoding == E_NOTSET) /* must be the file encoding */
+ if (encoding == P_NOTSET) /* must be the file encoding */
{
set_file_encoding(display);
encoding = display->file_encoding;
@@ -1635,18 +1649,18 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)
switch (encoding)
{
- case E_FILE:
+ case P_FILE:
value = png_gamma_16bit_correct(value*257, display->gamma_to_linear);
break;
- case E_sRGB:
+ case P_sRGB:
value = png_sRGB_table[value];
break;
- case E_LINEAR:
+ case P_LINEAR:
break;
- case E_LINEAR8:
+ case P_LINEAR8:
value *= 257;
break;
@@ -1665,9 +1679,9 @@ png_colormap_compose(png_image_read_control *display,
png_uint_32 background, int encoding)
{
/* The file value is composed on the background, the background has the given
- * encoding and so does the result, the file is encoded with E_FILE and the
+ * encoding and so does the result, the file is encoded with P_FILE and the
* file and alpha are 8-bit values. The (output) encoding will always be
- * E_LINEAR or E_sRGB.
+ * P_LINEAR or P_sRGB.
*/
png_uint_32 f = decode_gamma(display, foreground, foreground_encoding);
png_uint_32 b = decode_gamma(display, background, encoding);
@@ -1677,7 +1691,7 @@ png_colormap_compose(png_image_read_control *display,
*/
f = f * alpha + b * (255-alpha);
- if (encoding == E_LINEAR)
+ if (encoding == P_LINEAR)
{
/* Scale to 65535; divide by 255, approximately (in fact this is extremely
* accurate, it divides by 255.00000005937181414556, with no overflow.)
@@ -1687,13 +1701,13 @@ png_colormap_compose(png_image_read_control *display,
f = (f+32768) >> 16;
}
- else /* E_sRGB */
+ else /* P_sRGB */
f = PNG_sRGB_FROM_LINEAR(f);
return f;
}
-/* NOTE: E_LINEAR values to this routine must be 16-bit, but E_FILE values must
+/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must
* be 8-bit.
*/
static void
@@ -1703,7 +1717,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
png_imagep image = display->image;
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) ?
- E_LINEAR : E_sRGB;
+ P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
(red != green || green != blue);
@@ -1713,18 +1727,18 @@ png_create_colormap_entry(png_image_read_control *display,
/* Update the cache with whether the file gamma is significantly different
* from sRGB.
*/
- if (encoding == E_FILE)
+ if (encoding == P_FILE)
{
- if (display->file_encoding == E_NOTSET)
+ if (display->file_encoding == P_NOTSET)
set_file_encoding(display);
- /* Note that the cached value may be E_FILE too, but if it is then the
+ /* Note that the cached value may be P_FILE too, but if it is then the
* gamma_to_linear member has been set.
*/
encoding = display->file_encoding;
}
- if (encoding == E_FILE)
+ if (encoding == P_FILE)
{
png_fixed_point g = display->gamma_to_linear;
@@ -1732,10 +1746,10 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_gamma_16bit_correct(green*257, g);
blue = png_gamma_16bit_correct(blue*257, g);
- if (convert_to_Y || output_encoding == E_LINEAR)
+ if (convert_to_Y || output_encoding == P_LINEAR)
{
alpha *= 257;
- encoding = E_LINEAR;
+ encoding = P_LINEAR;
}
else
@@ -1743,11 +1757,11 @@ png_create_colormap_entry(png_image_read_control *display,
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
- encoding = E_sRGB;
+ encoding = P_sRGB;
}
}
- else if (encoding == E_LINEAR8)
+ else if (encoding == P_LINEAR8)
{
/* This encoding occurs quite frequently in test cases because PngSuite
* includes a gAMA 1.0 chunk with most images.
@@ -1756,10 +1770,10 @@ png_create_colormap_entry(png_image_read_control *display,
green *= 257;
blue *= 257;
alpha *= 257;
- encoding = E_LINEAR;
+ encoding = P_LINEAR;
}
- else if (encoding == E_sRGB && (convert_to_Y || output_encoding == E_LINEAR))
+ else if (encoding == P_sRGB && (convert_to_Y || output_encoding == P_LINEAR))
{
/* The values are 8-bit sRGB values, but must be converted to 16-bit
* linear.
@@ -1768,11 +1782,11 @@ png_create_colormap_entry(png_image_read_control *display,
green = png_sRGB_table[green];
blue = png_sRGB_table[blue];
alpha *= 257;
- encoding = E_LINEAR;
+ encoding = P_LINEAR;
}
/* This is set if the color isn't gray but the output is. */
- if (encoding == E_LINEAR)
+ if (encoding == P_LINEAR)
{
if (convert_to_Y)
{
@@ -1780,7 +1794,7 @@ png_create_colormap_entry(png_image_read_control *display,
png_uint_32 y = (png_uint_32)6968 * red + (png_uint_32)23434 * green +
(png_uint_32)2366 * blue;
- if (output_encoding == E_LINEAR)
+ if (output_encoding == P_LINEAR)
y = (y + 16384) >> 15;
else
@@ -1789,19 +1803,19 @@ png_create_colormap_entry(png_image_read_control *display,
y = (y + 128) >> 8;
y *= 255;
y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);
- encoding = E_sRGB;
+ encoding = P_sRGB;
}
blue = red = green = y;
}
- else if (output_encoding == E_sRGB)
+ else if (output_encoding == P_sRGB)
{
red = PNG_sRGB_FROM_LINEAR(red * 255);
green = PNG_sRGB_FROM_LINEAR(green * 255);
blue = PNG_sRGB_FROM_LINEAR(blue * 255);
alpha = PNG_DIV257(alpha);
- encoding = E_sRGB;
+ encoding = P_sRGB;
}
}
@@ -1810,7 +1824,7 @@ png_create_colormap_entry(png_image_read_control *display,
/* Store the value. */
{
-# ifdef PNG_FORMAT_BGR_SUPPORTED
+# ifdef PNG_FORMAT_AFIRST_SUPPORTED
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
@@ -1822,7 +1836,7 @@ png_create_colormap_entry(png_image_read_control *display,
# define bgr 0
# endif
- if (output_encoding == E_LINEAR)
+ if (output_encoding == P_LINEAR)
{
png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap);
@@ -1877,7 +1891,7 @@ png_create_colormap_entry(png_image_read_control *display,
}
}
- else /* output encoding is E_sRGB */
+ else /* output encoding is P_sRGB */
{
png_bytep entry = png_voidcast(png_bytep, display->colormap);
@@ -1919,7 +1933,7 @@ make_gray_file_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
- png_create_colormap_entry(display, i, i, i, i, 255, E_FILE);
+ png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);
return i;
}
@@ -1930,7 +1944,7 @@ make_gray_colormap(png_image_read_control *display)
unsigned int i;
for (i=0; i<256; ++i)
- png_create_colormap_entry(display, i, i, i, i, 255, E_sRGB);
+ png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);
return i;
}
@@ -1969,13 +1983,13 @@ make_ga_colormap(png_image_read_control *display)
while (i < 231)
{
unsigned int gray = (i * 256 + 115) / 231;
- png_create_colormap_entry(display, i++, gray, gray, gray, 255, E_sRGB);
+ png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB);
}
/* 255 is used here for the component values for consistency with the code
* that undoes premultiplication in pngwrite.c.
*/
- png_create_colormap_entry(display, i++, 255, 255, 255, 0, E_sRGB);
+ png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB);
for (a=1; a<5; ++a)
{
@@ -1983,7 +1997,7 @@ make_ga_colormap(png_image_read_control *display)
for (g=0; g<6; ++g)
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
- E_sRGB);
+ P_sRGB);
}
return i;
@@ -2007,7 +2021,7 @@ make_rgb_colormap(png_image_read_control *display)
for (b=0; b<6; ++b)
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
- E_sRGB);
+ P_sRGB);
}
}
@@ -2030,11 +2044,11 @@ png_image_read_colormap(png_voidp argument)
const png_structrp png_ptr = image->opaque->png_ptr;
const png_uint_32 output_format = image->format;
const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) ?
- E_LINEAR : E_sRGB;
+ P_LINEAR : P_sRGB;
unsigned int cmap_entries;
unsigned int output_processing; /* Output processing option */
- unsigned int data_encoding = E_NOTSET; /* Encoding libpng must produce */
+ unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */
/* Background information; the background color and the index of this color
* in the color-map if it exists (else 256).
@@ -2054,7 +2068,7 @@ png_image_read_colormap(png_voidp argument)
png_ptr->num_trans > 0) /* alpha in input */ &&
((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */)
{
- if (output_encoding == E_LINEAR) /* compose on black */
+ if (output_encoding == P_LINEAR) /* compose on black */
back_b = back_g = back_r = 0;
else if (display->background == NULL /* no way to remove it */)
@@ -2078,7 +2092,7 @@ png_image_read_colormap(png_voidp argument)
}
}
- else if (output_encoding == E_LINEAR)
+ else if (output_encoding == P_LINEAR)
back_b = back_r = back_g = 65535;
else
@@ -2136,7 +2150,7 @@ png_image_read_colormap(png_voidp argument)
trans = png_ptr->trans_color.gray;
if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0)
- back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
+ back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* png_create_colormap_entry just takes an RGBA and writes the
@@ -2154,7 +2168,7 @@ png_image_read_colormap(png_voidp argument)
*/
if (i != trans)
png_create_colormap_entry(display, i, val, val, val, 255,
- E_FILE/*8-bit with file gamma*/);
+ P_FILE/*8-bit with file gamma*/);
/* Else this entry is transparent. The colors don't matter if
* there is an alpha channel (back_alpha == 0), but it does no
@@ -2170,7 +2184,7 @@ png_image_read_colormap(png_voidp argument)
}
/* We need libpng to preserve the original encoding. */
- data_encoding = E_FILE;
+ data_encoding = P_FILE;
/* The rows from libpng, while technically gray values, are now also
* color-map indicies; however, they may need to be expanded to 1
@@ -2199,7 +2213,7 @@ png_image_read_colormap(png_voidp argument)
* ensuring that the corresponding gray level matches the background
* color exactly.
*/
- data_encoding = E_sRGB;
+ data_encoding = P_sRGB;
if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)
png_error(png_ptr, "gray[16] color-map: too few entries");
@@ -2223,7 +2237,7 @@ png_image_read_colormap(png_voidp argument)
png_color_16 c;
png_uint_32 gray = back_g;
- if (output_encoding == E_LINEAR)
+ if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
@@ -2231,7 +2245,7 @@ png_image_read_colormap(png_voidp argument)
* matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 65535, E_LINEAR);
+ back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2252,7 +2266,7 @@ png_image_read_colormap(png_voidp argument)
break;
}
- back_alpha = output_encoding == E_LINEAR ? 65535 : 255;
+ back_alpha = output_encoding == P_LINEAR ? 65535 : 255;
}
/* output_processing means that the libpng-processed row will be
@@ -2289,7 +2303,7 @@ png_image_read_colormap(png_voidp argument)
* worry about tRNS matching - tRNS is ignored if there is an alpha
* channel.
*/
- data_encoding = E_sRGB;
+ data_encoding = P_sRGB;
if (output_format & PNG_FORMAT_FLAG_ALPHA)
{
@@ -2332,13 +2346,13 @@ png_image_read_colormap(png_voidp argument)
cmap_entries = make_gray_colormap(display);
- if (output_encoding == E_LINEAR)
+ if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches. */
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 65535, E_LINEAR);
+ back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the sRGB
@@ -2369,7 +2383,7 @@ png_image_read_colormap(png_voidp argument)
{
png_uint_32 gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray,
- 255, E_sRGB);
+ 255, P_sRGB);
}
/* NOTE: this preserves the full precision of the application
@@ -2377,7 +2391,7 @@ png_image_read_colormap(png_voidp argument)
*/
background_index = i;
png_create_colormap_entry(display, i++, back_r, back_g, back_b,
- output_encoding == E_LINEAR ? 65535U : 255U, output_encoding);
+ output_encoding == P_LINEAR ? 65535U : 255U, output_encoding);
/* For non-opaque input composite on the sRGB background - this
* requires inverting the encoding for each component. The input
@@ -2387,7 +2401,7 @@ png_image_read_colormap(png_voidp argument)
* represents. Consequently 'G' is always sRGB encoded, while
* 'A' is linear. We need the linear background colors.
*/
- if (output_encoding == E_sRGB) /* else already linear */
+ if (output_encoding == P_sRGB) /* else already linear */
{
/* This may produce a value not exactly matching the
* background, but that's ok because these numbers are only
@@ -2417,7 +2431,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, i++,
PNG_sRGB_FROM_LINEAR(gray + back_rx),
PNG_sRGB_FROM_LINEAR(gray + back_gx),
- PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, E_sRGB);
+ PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);
}
}
@@ -2444,7 +2458,7 @@ png_image_read_colormap(png_voidp argument)
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
-1);
- data_encoding = E_sRGB;
+ data_encoding = P_sRGB;
/* The output will now be one or two 8-bit gray or gray+alpha
* channels. The more complex case arises when the input has alpha.
@@ -2489,7 +2503,7 @@ png_image_read_colormap(png_voidp argument)
png_gamma_not_sRGB(png_ptr->colorspace.gamma))
{
cmap_entries = make_gray_file_colormap(display);
- data_encoding = E_FILE;
+ data_encoding = P_FILE;
}
else
@@ -2508,18 +2522,18 @@ png_image_read_colormap(png_voidp argument)
* it. Achieve this simply by ensuring that the entry
* selected for the background really is the background color.
*/
- if (data_encoding == E_FILE) /* from the fixup above */
+ if (data_encoding == P_FILE) /* from the fixup above */
{
/* The app supplied a gray which is in output_encoding, we
- * need to convert it to a value of the input (E_FILE)
+ * need to convert it to a value of the input (P_FILE)
* encoding then set this palette entry to the required
* output encoding.
*/
- if (output_encoding == E_sRGB)
- gray = png_sRGB_table[gray]; /* now E_LINEAR */
+ if (output_encoding == P_sRGB)
+ gray = png_sRGB_table[gray]; /* now P_LINEAR */
gray = PNG_DIV257(png_gamma_16bit_correct(gray,
- png_ptr->colorspace.gamma)); /* now E_FILE */
+ png_ptr->colorspace.gamma)); /* now P_FILE */
/* And make sure the corresponding palette entry contains
* exactly the required sRGB value.
@@ -2528,14 +2542,14 @@ png_image_read_colormap(png_voidp argument)
back_g, 0/*unused*/, output_encoding);
}
- else if (output_encoding == E_LINEAR)
+ else if (output_encoding == P_LINEAR)
{
gray = PNG_sRGB_FROM_LINEAR(gray * 255);
/* And make sure the corresponding palette entry matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
- back_g, 0/*unused*/, E_LINEAR);
+ back_g, 0/*unused*/, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2565,7 +2579,7 @@ png_image_read_colormap(png_voidp argument)
* to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube.
* Consequently we always want libpng to produce sRGB data.
*/
- data_encoding = E_sRGB;
+ data_encoding = P_sRGB;
/* Is there any transparency or alpha? */
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
@@ -2585,7 +2599,7 @@ png_image_read_colormap(png_voidp argument)
/* Add a transparent entry. */
png_create_colormap_entry(display, cmap_entries, 255, 255,
- 255, 0, E_sRGB);
+ 255, 0, P_sRGB);
/* This is stored as the background index for the processing
* algorithm.
@@ -2606,7 +2620,7 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
- r, g, b, 128, E_sRGB);
+ r, g, b, 128, P_sRGB);
}
}
@@ -2635,7 +2649,7 @@ png_image_read_colormap(png_voidp argument)
png_create_colormap_entry(display, cmap_entries, back_r,
back_g, back_b, 0/*unused*/, output_encoding);
- if (output_encoding == E_LINEAR)
+ if (output_encoding == P_LINEAR)
{
r = PNG_sRGB_FROM_LINEAR(back_r * 255);
g = PNG_sRGB_FROM_LINEAR(back_g * 255);
@@ -2675,11 +2689,11 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
- png_colormap_compose(display, r, E_sRGB, 128,
+ png_colormap_compose(display, r, P_sRGB, 128,
back_r, output_encoding),
- png_colormap_compose(display, g, E_sRGB, 128,
+ png_colormap_compose(display, g, P_sRGB, 128,
back_g, output_encoding),
- png_colormap_compose(display, b, E_sRGB, 128,
+ png_colormap_compose(display, b, P_sRGB, 128,
back_b, output_encoding),
0/*unused*/, output_encoding);
}
@@ -2738,7 +2752,7 @@ png_image_read_colormap(png_voidp argument)
num_trans = 0;
output_processing = PNG_CMAP_NONE;
- data_encoding = E_FILE; /* Don't change from color-map indicies */
+ data_encoding = P_FILE; /* Don't change from color-map indicies */
cmap_entries = png_ptr->num_palette;
if (cmap_entries > 256)
cmap_entries = 256;
@@ -2760,13 +2774,13 @@ png_image_read_colormap(png_voidp argument)
* on the sRGB color in 'back'.
*/
png_create_colormap_entry(display, i,
- png_colormap_compose(display, colormap[i].red, E_FILE,
+ png_colormap_compose(display, colormap[i].red, P_FILE,
trans[i], back_r, output_encoding),
- png_colormap_compose(display, colormap[i].green, E_FILE,
+ png_colormap_compose(display, colormap[i].green, P_FILE,
trans[i], back_g, output_encoding),
- png_colormap_compose(display, colormap[i].blue, E_FILE,
+ png_colormap_compose(display, colormap[i].blue, P_FILE,
trans[i], back_b, output_encoding),
- output_encoding == E_LINEAR ? trans[i] * 257U :
+ output_encoding == P_LINEAR ? trans[i] * 257U :
trans[i],
output_encoding);
}
@@ -2775,7 +2789,7 @@ png_image_read_colormap(png_voidp argument)
else
png_create_colormap_entry(display, i, colormap[i].red,
colormap[i].green, colormap[i].blue,
- i < num_trans ? trans[i] : 255U, E_FILE/*8-bit*/);
+ i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);
}
/* The PNG data may have indicies packed in fewer than 8 bits, it
@@ -2803,12 +2817,12 @@ png_image_read_colormap(png_voidp argument)
png_error(png_ptr, "bad data option (internal error)");
break;
- case E_sRGB:
+ case P_sRGB:
/* Change to 8-bit sRGB */
png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);
/* FALL THROUGH */
- case E_FILE:
+ case P_FILE:
if (png_ptr->bit_depth > 8)
png_set_scale_16(png_ptr);
break;
@@ -2885,7 +2899,6 @@ png_image_read_and_map(png_voidp argument)
break;
default:
- passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@@ -3204,7 +3217,6 @@ png_image_read_composite(png_voidp argument)
break;
default:
- passes = 0;
png_error(png_ptr, "unknown interlace type");
}
@@ -3353,11 +3365,15 @@ png_image_read_background(png_voidp argument)
break;
default:
- passes = 0;
png_error(png_ptr, "unknown interlace type");
}
- switch (png_get_bit_depth(png_ptr, info_ptr))
+ /* Use direct access to info_ptr here because otherwise the simplified API
+ * would require PNG_EASY_ACCESS_SUPPORTED (just for this.) Note this is
+ * checking the value after libpng expansions, not the original value in the
+ * PNG.
+ */
+ switch (info_ptr->bit_depth)
{
default:
png_error(png_ptr, "unexpected bit depth");
@@ -3365,7 +3381,7 @@ png_image_read_background(png_voidp argument)
case 8:
/* 8-bit sRGB gray values with an alpha channel; the alpha channel is
- * to be removed by composing on a backgroundi: either the row if
+ * to be removed by composing on a background: either the row if
* display->background is NULL or display->background->green if not.
* Unlike the code above ALPHA_OPTIMIZED has *not* been done.
*/
@@ -3505,8 +3521,10 @@ png_image_read_background(png_voidp argument)
unsigned int outchannels = 1+preserve_alpha;
int swap_alpha = 0;
- if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
- swap_alpha = 1;
+# ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
+ if (preserve_alpha && (image->format & PNG_FORMAT_FLAG_AFIRST))
+ swap_alpha = 1;
+# endif
for (pass = 0; pass < passes; ++pass)
{