[libpng16] Avoid filter-selection heuristic sum calculations in cases where
only one filter is a candidate for selection. This trades off code size (added png_setup_*_row_only() functions) for speed.
This commit is contained in:
parent
9928ee0a52
commit
f7d5419816
7
ANNOUNCE
7
ANNOUNCE
@ -1,4 +1,4 @@
|
|||||||
Libpng 1.6.24beta04 - July 4, 2016
|
Libpng 1.6.24beta04 - July 8, 2016
|
||||||
|
|
||||||
This is not intended to be a public release. It will be replaced
|
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.
|
within a few weeks by a public version or by another test version.
|
||||||
@ -77,6 +77,11 @@ Version 1.6.24beta03 [July 4, 2016]
|
|||||||
Relocated misplaced #endif in png.c sRGB profile checking.
|
Relocated misplaced #endif in png.c sRGB profile checking.
|
||||||
Fixed two Coverity issues in pngcp.c.
|
Fixed two Coverity issues in pngcp.c.
|
||||||
|
|
||||||
|
Version 1.6.24beta04 [July 8, 2016]
|
||||||
|
Avoid filter-selection heuristic sum calculations in cases where only one
|
||||||
|
filter is a candidate for selection. This trades off code size (added
|
||||||
|
png_setup_*_row_only() functions) for speed.
|
||||||
|
|
||||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
(subscription required; visit
|
(subscription required; visit
|
||||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||||
|
5
CHANGES
5
CHANGES
@ -5648,6 +5648,11 @@ Version 1.6.24beta03 [July 4, 2016]
|
|||||||
Relocated misplaced #endif in png.c sRGB profile checking.
|
Relocated misplaced #endif in png.c sRGB profile checking.
|
||||||
Fixed two Coverity issues in pngcp.c.
|
Fixed two Coverity issues in pngcp.c.
|
||||||
|
|
||||||
|
Version 1.6.24beta04 [July 8, 2016]
|
||||||
|
Avoid filter-selection heuristic sum calculations in cases where only one
|
||||||
|
filter is a candidate for selection. This trades off code size (added
|
||||||
|
png_setup_*_row_only() functions) for speed.
|
||||||
|
|
||||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||||
(subscription required; visit
|
(subscription required; visit
|
||||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||||
|
113
pngwutil.c
113
pngwutil.c
@ -2286,6 +2286,28 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||||||
return (sum);
|
return (sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_setup_sub_row_only(png_structrp png_ptr, const png_uint_32 bpp,
|
||||||
|
const png_size_t row_bytes)
|
||||||
|
{
|
||||||
|
png_bytep rp, dp, lp;
|
||||||
|
png_size_t i;
|
||||||
|
|
||||||
|
png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
|
||||||
|
|
||||||
|
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp;
|
||||||
|
i++, rp++, dp++)
|
||||||
|
{
|
||||||
|
*dp = *rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (lp = png_ptr->row_buf + 1; i < row_bytes;
|
||||||
|
i++, rp++, lp++, dp++)
|
||||||
|
{
|
||||||
|
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static png_size_t /* PRIVATE */
|
static png_size_t /* PRIVATE */
|
||||||
png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
||||||
const png_size_t lmins)
|
const png_size_t lmins)
|
||||||
@ -2314,6 +2336,21 @@ png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,
|
|||||||
|
|
||||||
return (sum);
|
return (sum);
|
||||||
}
|
}
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_setup_up_row_only(png_structrp png_ptr, const png_size_t row_bytes)
|
||||||
|
{
|
||||||
|
png_bytep rp, dp, pp;
|
||||||
|
png_size_t i;
|
||||||
|
|
||||||
|
png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
|
||||||
|
|
||||||
|
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
|
||||||
|
pp = png_ptr->prev_row + 1; i < row_bytes;
|
||||||
|
i++, rp++, pp++, dp++)
|
||||||
|
{
|
||||||
|
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static png_size_t /* PRIVATE */
|
static png_size_t /* PRIVATE */
|
||||||
png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
|
png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
|
||||||
@ -2355,6 +2392,27 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||||||
|
|
||||||
return (sum);
|
return (sum);
|
||||||
}
|
}
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_setup_avg_row_only(png_structrp png_ptr, const png_uint_32 bpp,
|
||||||
|
const png_size_t row_bytes)
|
||||||
|
{
|
||||||
|
png_bytep rp, dp, pp, lp;
|
||||||
|
png_uint_32 i;
|
||||||
|
|
||||||
|
png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;
|
||||||
|
|
||||||
|
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
|
||||||
|
pp = png_ptr->prev_row + 1; i < bpp; i++)
|
||||||
|
{
|
||||||
|
*dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)
|
||||||
|
{
|
||||||
|
*dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
|
||||||
|
& 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static png_size_t /* PRIVATE */
|
static png_size_t /* PRIVATE */
|
||||||
png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
||||||
@ -2417,6 +2475,48 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
|||||||
|
|
||||||
return (sum);
|
return (sum);
|
||||||
}
|
}
|
||||||
|
static void /* PRIVATE */
|
||||||
|
png_setup_paeth_row_only(png_structrp png_ptr, const png_uint_32 bpp,
|
||||||
|
const png_size_t row_bytes)
|
||||||
|
{
|
||||||
|
png_bytep rp, dp, pp, cp, lp;
|
||||||
|
png_size_t i;
|
||||||
|
|
||||||
|
png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||||
|
|
||||||
|
for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,
|
||||||
|
pp = png_ptr->prev_row + 1; i < bpp; i++)
|
||||||
|
{
|
||||||
|
*dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
int a, b, c, pa, pb, pc, p;
|
||||||
|
|
||||||
|
b = *pp++;
|
||||||
|
c = *cp++;
|
||||||
|
a = *lp++;
|
||||||
|
|
||||||
|
p = b - c;
|
||||||
|
pc = a - c;
|
||||||
|
|
||||||
|
#ifdef PNG_USE_ABS
|
||||||
|
pa = abs(p);
|
||||||
|
pb = abs(pc);
|
||||||
|
pc = abs(p + pc);
|
||||||
|
#else
|
||||||
|
pa = p < 0 ? -p : p;
|
||||||
|
pb = pc < 0 ? -pc : pc;
|
||||||
|
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
|
||||||
|
|
||||||
|
*dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif /* WRITE_FILTER */
|
#endif /* WRITE_FILTER */
|
||||||
|
|
||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
@ -2508,12 +2608,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||||||
if (filter_to_do == PNG_FILTER_SUB)
|
if (filter_to_do == PNG_FILTER_SUB)
|
||||||
/* It's the only filter so no testing is needed */
|
/* It's the only filter so no testing is needed */
|
||||||
{
|
{
|
||||||
/* Passing PNG_SIZE_MAX here and below prevents the 'setup' function
|
png_setup_sub_row_only(png_ptr, bpp, row_bytes);
|
||||||
* breaking out of the loop when lmins is exceeded. Optimizing
|
|
||||||
* compilers should notice that we don't use the returned sum, and
|
|
||||||
* therefore 'setup' should refrain from calculating and returning "sum".
|
|
||||||
*/
|
|
||||||
(void) png_setup_sub_row(png_ptr, bpp, row_bytes, PNG_SIZE_MAX);
|
|
||||||
best_row = png_ptr->try_row;
|
best_row = png_ptr->try_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2539,7 +2634,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||||||
/* Up filter */
|
/* Up filter */
|
||||||
if (filter_to_do == PNG_FILTER_UP)
|
if (filter_to_do == PNG_FILTER_UP)
|
||||||
{
|
{
|
||||||
(void) png_setup_up_row(png_ptr, row_bytes, PNG_SIZE_MAX);
|
png_setup_up_row_only(png_ptr, row_bytes);
|
||||||
best_row = png_ptr->try_row;
|
best_row = png_ptr->try_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2565,7 +2660,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||||||
/* Avg filter */
|
/* Avg filter */
|
||||||
if (filter_to_do == PNG_FILTER_AVG)
|
if (filter_to_do == PNG_FILTER_AVG)
|
||||||
{
|
{
|
||||||
(void) png_setup_avg_row(png_ptr, bpp, row_bytes, PNG_SIZE_MAX);
|
png_setup_avg_row_only(png_ptr, bpp, row_bytes);
|
||||||
best_row = png_ptr->try_row;
|
best_row = png_ptr->try_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2591,7 +2686,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
|||||||
/* Paeth filter */
|
/* Paeth filter */
|
||||||
if ((filter_to_do == PNG_FILTER_PAETH) != 0)
|
if ((filter_to_do == PNG_FILTER_PAETH) != 0)
|
||||||
{
|
{
|
||||||
(void) png_setup_paeth_row(png_ptr, bpp, row_bytes, PNG_SIZE_MAX);
|
png_setup_paeth_row_only(png_ptr, bpp, row_bytes);
|
||||||
best_row = png_ptr->try_row;
|
best_row = png_ptr->try_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user