Restore the ANSI C compliance after adding the ARM optimization

Also apply style and formatting fixes
This commit is contained in:
Cosmin Truta 2018-09-04 00:15:30 -04:00
parent 7734cda20c
commit b66ed71131
2 changed files with 57 additions and 46 deletions

View File

@ -22,11 +22,7 @@ png_riffle_palette_rgba(png_structrp png_ptr, png_row_infop row_info)
png_bytep riffled_palette = png_ptr->riffled_palette; png_bytep riffled_palette = png_ptr->riffled_palette;
png_const_bytep trans_alpha = png_ptr->trans_alpha; png_const_bytep trans_alpha = png_ptr->trans_alpha;
int num_trans = png_ptr->num_trans; int num_trans = png_ptr->num_trans;
int i;
if (row_info->bit_depth != 8) {
png_error(png_ptr, "bit_depth must be 8 for png_riffle_palette_rgba");
return;
}
/* Initially black, opaque. */ /* Initially black, opaque. */
uint8x16x4_t w = {{ uint8x16x4_t w = {{
@ -36,10 +32,17 @@ png_riffle_palette_rgba(png_structrp png_ptr, png_row_infop row_info)
vdupq_n_u8(0xff), vdupq_n_u8(0xff),
}}; }};
int i; if (row_info->bit_depth != 8)
{
png_error(png_ptr, "bit_depth must be 8 for png_riffle_palette_rgba");
return;
}
/* First, riffle the RGB colours into a RGBA palette, the A value is /* First, riffle the RGB colours into a RGBA palette, the A value is
* set to opaque for now. */ * set to opaque for now.
for (i = 0; i < (1 << row_info->bit_depth); i += 16) { */
for (i = 0; i < (1 << row_info->bit_depth); i += 16)
{
uint8x16x3_t v = vld3q_u8((png_const_bytep)(palette + i)); uint8x16x3_t v = vld3q_u8((png_const_bytep)(palette + i));
w.val[0] = v.val[0]; w.val[0] = v.val[0];
w.val[1] = v.val[1]; w.val[1] = v.val[1];
@ -48,33 +51,32 @@ png_riffle_palette_rgba(png_structrp png_ptr, png_row_infop row_info)
} }
/* Fix up the missing transparency values. */ /* Fix up the missing transparency values. */
for (i = 0; i < num_trans; i++) { for (i = 0; i < num_trans; i++)
riffled_palette[(i << 2) + 3] = trans_alpha[i]; riffled_palette[(i << 2) + 3] = trans_alpha[i];
}
} }
/* Expands a palettized row into RGBA. */ /* Expands a palettized row into RGBA. */
int int
png_do_expand_palette_neon_rgba(png_structrp png_ptr, png_row_infop row_info, png_do_expand_palette_neon_rgba(png_structrp png_ptr, png_row_infop row_info,
png_const_bytep row, const png_bytepp ssp, const png_bytepp ddp) png_const_bytep row, png_bytepp ssp, png_bytepp ddp)
{ {
png_uint_32 row_width = row_info->width; png_uint_32 row_width = row_info->width;
const png_uint_32 *riffled_palette = (const png_uint_32*)png_ptr->riffled_palette; const png_uint_32 *riffled_palette =
(const png_uint_32 *)png_ptr->riffled_palette;
const png_int_32 pixels_per_chunk = 4; const png_int_32 pixels_per_chunk = 4;
int i;
if (row_width < pixels_per_chunk) { if (row_width < pixels_per_chunk)
return 0; return 0;
}
/* This function originally gets the last byte of the output row. /* This function originally gets the last byte of the output row.
The NEON part writes forward from a given position, so we have * The NEON part writes forward from a given position, so we have
to seek this back by 4 pixels x 4 bytes. */ * to seek this back by 4 pixels x 4 bytes.
*/
*ddp = *ddp - ((pixels_per_chunk * sizeof(png_uint_32)) - 1); *ddp = *ddp - ((pixels_per_chunk * sizeof(png_uint_32)) - 1);
int i; for (i = 0; i < row_width; i += pixels_per_chunk)
for (i = 0; i < row_width; i += pixels_per_chunk) { {
uint32x4_t cur; uint32x4_t cur;
png_bytep sp = *ssp - i, dp = *ddp - (i << 2); png_bytep sp = *ssp - i, dp = *ddp - (i << 2);
cur = vld1q_dup_u32 (riffled_palette + *(sp - 3)); cur = vld1q_dup_u32 (riffled_palette + *(sp - 3));
@ -83,8 +85,10 @@ png_do_expand_palette_neon_rgba(png_structrp png_ptr, png_row_infop row_info,
cur = vld1q_lane_u32(riffled_palette + *(sp - 0), cur, 3); cur = vld1q_lane_u32(riffled_palette + *(sp - 0), cur, 3);
vst1q_u32((void *)dp, cur); vst1q_u32((void *)dp, cur);
} }
if (i != row_width) { if (i != row_width)
i -= pixels_per_chunk; /* Remove the amount that wasn't processed. */ {
/* Remove the amount that wasn't processed. */
i -= pixels_per_chunk;
} }
/* Decrement output pointers. */ /* Decrement output pointers. */
@ -96,21 +100,21 @@ png_do_expand_palette_neon_rgba(png_structrp png_ptr, png_row_infop row_info,
/* Expands a palettized row into RGB format. */ /* Expands a palettized row into RGB format. */
int int
png_do_expand_palette_neon_rgb(png_structrp png_ptr, png_row_infop row_info, png_do_expand_palette_neon_rgb(png_structrp png_ptr, png_row_infop row_info,
png_const_bytep row, const png_bytepp ssp, const png_bytepp ddp) png_const_bytep row, png_bytepp ssp, png_bytepp ddp)
{ {
png_uint_32 row_width = row_info->width; png_uint_32 row_width = row_info->width;
png_const_bytep palette = (png_const_bytep)png_ptr->palette; png_const_bytep palette = (png_const_bytep)png_ptr->palette;
const png_uint_32 pixels_per_chunk = 8; const png_uint_32 pixels_per_chunk = 8;
int i;
if (row_width <= pixels_per_chunk) { if (row_width <= pixels_per_chunk)
return 0; return 0;
}
/* Seeking this back by 8 pixels x 3 bytes. */ /* Seeking this back by 8 pixels x 3 bytes. */
*ddp = *ddp - ((pixels_per_chunk * sizeof(png_color)) - 1); *ddp = *ddp - ((pixels_per_chunk * sizeof(png_color)) - 1);
int i; for (i = 0; i < row_width; i += pixels_per_chunk)
for (i = 0; i < row_width; i += pixels_per_chunk) { {
uint8x8x3_t cur; uint8x8x3_t cur;
png_bytep sp = *ssp - i, dp = *ddp - ((i << 1) + i); png_bytep sp = *ssp - i, dp = *ddp - ((i << 1) + i);
cur = vld3_dup_u8(palette + sizeof(png_color) * (*(sp - 7))); cur = vld3_dup_u8(palette + sizeof(png_color) * (*(sp - 7)));
@ -124,8 +128,10 @@ png_do_expand_palette_neon_rgb(png_structrp png_ptr, png_row_infop row_info,
vst3_u8((void *)dp, cur); vst3_u8((void *)dp, cur);
} }
if (i != row_width) { if (i != row_width)
i -= pixels_per_chunk; /* Remove the amount that wasn't processed. */ {
/* Remove the amount that wasn't processed. */
i -= pixels_per_chunk;
} }
/* Decrement output pointers. */ /* Decrement output pointers. */

View File

@ -4203,8 +4203,8 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
*/ */
static void static void
png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info, png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha, png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha,
int num_trans) int num_trans)
{ {
int shift, value; int shift, value;
png_bytep sp, dp; png_bytep sp, dp;
@ -4310,11 +4310,14 @@ png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
i = 0; i = 0;
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE #ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
if (png_ptr->riffled_palette != NULL) { if (png_ptr->riffled_palette != NULL)
{
/* The RGBA optimization works with png_ptr->bit_depth == 8 /* The RGBA optimization works with png_ptr->bit_depth == 8
but sometimes row_info->bit_depth has been changed to 8. * but sometimes row_info->bit_depth has been changed to 8.
In these cases, the palette hasn't been riffled. */ * In these cases, the palette hasn't been riffled.
i = png_do_expand_palette_neon_rgba(png_ptr, row_info, row, &sp, &dp); */
i = png_do_expand_palette_neon_rgba(png_ptr, row_info, row,
&sp, &dp);
} }
#endif #endif
@ -4342,7 +4345,8 @@ png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
dp = row + (size_t)(row_width * 3) - 1; dp = row + (size_t)(row_width * 3) - 1;
i = 0; i = 0;
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE #ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
i = png_do_expand_palette_neon_rgb(png_ptr, row_info, row, &sp, &dp); i = png_do_expand_palette_neon_rgb(png_ptr, row_info, row,
&sp, &dp);
#endif #endif
for (; i < row_width; i++) for (; i < row_width; i++)
@ -4760,17 +4764,18 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE #ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8)) { if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8))
/* Allocate space for the decompressed full palette. */ {
if (png_ptr->riffled_palette == NULL) { /* Allocate space for the decompressed full palette. */
png_ptr->riffled_palette = png_malloc(png_ptr, 256*4); if (png_ptr->riffled_palette == NULL)
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"); png_error(png_ptr, "NULL row buffer");
} /* Build the RGBA palette. */
/* Build the RGBA palette. */ png_riffle_palette_rgba(png_ptr, row_info);
png_riffle_palette_rgba(png_ptr, row_info); }
} }
}
#endif #endif
png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1, 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);