[libpng16] Optimized absolute value calculation in filter selection, similar to

code in the PAETH decoder in pngrutil.c. Build with PNG_USE_ABS to use this.
This commit is contained in:
Glenn Randers-Pehrson 2016-06-29 21:52:53 -05:00
parent ed5a01d922
commit d9779744f9
3 changed files with 41 additions and 3 deletions

View File

@ -1,4 +1,4 @@
Libpng 1.6.24beta03 - June 23, 2016
Libpng 1.6.24beta03 - June 30, 2016
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@ -67,7 +67,10 @@ Version 1.6.24beta02 [June 23, 2016]
structure padding is fixable, but it would be a signficant change (moving
structure members around).
Version 1.6.24beta03 [June 23, 2016]
Version 1.6.24beta03 [June 30, 2016]
Optimized absolute value calculation in filter selection, similar to
code in the PAETH decoder in pngrutil.c. Build with PNG_USE_ABS to
use this.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -5638,7 +5638,10 @@ Version 1.6.24beta02 [June 23, 2016]
structure padding is fixable, but it would be a signficant change (moving
structure members around).
Version 1.6.24beta03 [June 23, 2016]
Version 1.6.24beta03 [June 30, 2016]
Optimized absolute value calculation in filter selection, similar to
code in the PAETH decoder in pngrutil.c. Build with PNG_USE_ABS to
use this.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

View File

@ -2262,14 +2262,22 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
i++, rp++, dp++)
{
v = *dp = *rp;
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
}
for (lp = png_ptr->row_buf + 1; i < row_bytes;
i++, rp++, lp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */
break;
@ -2294,7 +2302,11 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
i++, rp++, pp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */
break;
@ -2319,7 +2331,11 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
{
v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
}
for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
@ -2327,7 +2343,11 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
& 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */
break;
@ -2352,7 +2372,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
{
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
}
for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
@ -2381,7 +2405,11 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
if (sum > lmins) /* We are already worse, don't continue. */
break;
@ -2465,7 +2493,11 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
{
v = *rp;
#ifdef PNG_USE_ABS
sum += 128 - abs(v - 128);
#else
sum += (v < 128) ? v : 256 - v;
#endif
}
}