aboutsummaryrefslogtreecommitdiff
path: root/pngrtran.c
diff options
context:
space:
mode:
Diffstat (limited to 'pngrtran.c')
-rw-r--r--pngrtran.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/pngrtran.c b/pngrtran.c
index ccc58ce6f..329434091 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
- * Copyright (c) 2018 Cosmin Truta
+ * Copyright (c) 2018-2019 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -1161,7 +1161,20 @@ png_init_palette_transformations(png_structrp png_ptr)
png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
}
-#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
+#ifdef PNG_READ_EXPAND_SUPPORTED
+#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
+ /* Initialize the accelerated palette expansion, if applicable. */
+ if ((png_ptr->transformations & PNG_EXPAND) != 0)
+ {
+ if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8))
+ {
+ png_ptr->riffled_palette = (png_bytep)png_malloc(png_ptr, 256 * 4);
+ png_riffle_palette_rgba8(png_ptr);
+ }
+ }
+#endif /* PNG_ARM_NEON_INTRINSICS_AVAILABLE */
+
+#ifdef PNG_READ_BACKGROUND_SUPPORTED
/* png_set_background handling - deals with the complexity of whether the
* background color is in the file format or the screen format in the case
* where an 'expand' will happen.
@@ -1182,24 +1195,25 @@ png_init_palette_transformations(png_structrp png_ptr)
png_ptr->palette[png_ptr->background.index].blue;
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
- if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
- {
- if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
- {
- /* Invert the alpha channel (in tRNS) unless the pixels are
- * going to be expanded, in which case leave it for later
- */
- int i, istop = png_ptr->num_trans;
-
- for (i=0; i<istop; i++)
- png_ptr->trans_alpha[i] = (png_byte)(255 -
- png_ptr->trans_alpha[i]);
- }
- }
+ if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
+ {
+ if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)
+ {
+ /* Invert the alpha channel (in tRNS) unless the pixels are
+ * going to be expanded, in which case leave it for later
+ */
+ int i, istop = png_ptr->num_trans;
+
+ for (i = 0; i < istop; i++)
+ png_ptr->trans_alpha[i] =
+ (png_byte)(255 - png_ptr->trans_alpha[i]);
+ }
+ }
#endif /* READ_INVERT_ALPHA */
}
} /* background expand and (therefore) no alpha association. */
-#endif /* READ_EXPAND && READ_BACKGROUND */
+#endif /* READ_BACKGROUND */
+#endif /* READ_EXPAND */
}
static void /* PRIVATE */
@@ -4320,9 +4334,11 @@ png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
* but sometimes row_info->bit_depth has been changed to 8.
* In these cases, the palette hasn't been riffled.
*/
- i = png_do_expand_palette_neon_rgba(png_ptr, row_info, row,
+ i = png_do_expand_palette_neon_rgba8(png_ptr, row_info, row,
&sp, &dp);
}
+#else
+ PNG_UNUSED(png_ptr)
#endif
for (; i < row_width; i++)
@@ -4349,8 +4365,10 @@ png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
dp = row + (size_t)(row_width * 3) - 1;
i = 0;
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
- i = png_do_expand_palette_neon_rgb(png_ptr, row_info, row,
+ i = png_do_expand_palette_neon_rgb8(png_ptr, row_info, row,
&sp, &dp);
+#else
+ PNG_UNUSED(png_ptr)
#endif
for (; i < row_width; i++)
@@ -4767,22 +4785,8 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
{
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
-#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
- if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8))
- {
- /* Allocate space for the decompressed full palette. */
- if (png_ptr->riffled_palette == NULL)
- {
- png_ptr->riffled_palette = png_malloc(png_ptr, 256*4);
- if (png_ptr->riffled_palette == NULL)
- png_error(png_ptr, "NULL row buffer");
- /* Build the RGBA palette. */
- png_riffle_palette_rgba(png_ptr, row_info);
- }
- }
-#endif
png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1,
- png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
+ png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
}
else