mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng16] Removed WRITE_WEIGHTED_FILTERED code, to save a few kbytes of the
compiled library size. It never worked properly and as far as we can tell, no one uses it. The png_set_filter_heuristics() and png_set_filter_heuristics_fixed() APIs are retained but deprecated and do nothing.
This commit is contained in:
269
pngwutil.c
269
pngwutil.c
@@ -2469,55 +2469,6 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
|
||||
|
||||
return (sum);
|
||||
}
|
||||
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
|
||||
#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
|
||||
#define PNG_HISHIFT 10
|
||||
#define PNG_LOMASK ((png_uint_32)0xffffL)
|
||||
#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
|
||||
|
||||
static png_size_t /* PRIVATE */
|
||||
png_increase_lmins(png_structrp png_ptr, png_size_t lmins)
|
||||
{
|
||||
/* We temporarily increase the "minimum sum" by the factor we
|
||||
* would reduce the sum of this filter, so that we can do the
|
||||
* early exit comparison without scaling the sum each time.
|
||||
*/
|
||||
int j;
|
||||
png_uint_32 lmhi, lmlo;
|
||||
lmlo = lmins & PNG_LOMASK;
|
||||
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (j = 0; j < png_ptr->num_prev_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == png_ptr->try_row[0])
|
||||
{
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
lmlo = (lmlo * png_ptr->inv_filter_costs[png_ptr->try_row[0]]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
lmhi = (lmhi * png_ptr->inv_filter_costs[png_ptr->try_row[0]]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (lmhi > PNG_HIMASK)
|
||||
lmins = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
lmins = (lmhi << PNG_HISHIFT) + lmlo;
|
||||
|
||||
return (lmins);
|
||||
}
|
||||
#endif /* WRITE_WEIGHTED_FILTER */
|
||||
|
||||
#endif /* WRITE_FILTER */
|
||||
|
||||
void /* PRIVATE */
|
||||
@@ -2530,22 +2481,11 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
png_bytep row_buf;
|
||||
png_bytep best_row;
|
||||
png_uint_32 bpp;
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
int num_p_filters = png_ptr->num_prev_filters;
|
||||
#endif
|
||||
png_size_t mins;
|
||||
png_size_t row_bytes = row_info->rowbytes;
|
||||
|
||||
png_debug(1, "in png_write_find_filter");
|
||||
|
||||
#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
|
||||
{
|
||||
/* These will never be selected so we need not test them. */
|
||||
filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Find out how many bytes offset each pixel is */
|
||||
bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
|
||||
@@ -2591,45 +2531,6 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
png_size_t i;
|
||||
int v;
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
png_uint_32 sumhi, sumlo;
|
||||
int j;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
|
||||
|
||||
/* Reduce the sum if we match any of the previous rows */
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Factor in the cost of this filter (this is here for completeness,
|
||||
* but it makes no sense to have a "cost" for the NONE filter, as
|
||||
* it has the minimum possible computational cost - none).
|
||||
*/
|
||||
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (sumhi > PNG_HIMASK)
|
||||
sum = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
sum = (sumhi << PNG_HISHIFT) + sumlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (PNG_SIZE_MAX/128 <= row_bytes)
|
||||
{
|
||||
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
|
||||
@@ -2666,48 +2567,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_size_t sum;
|
||||
png_size_t lmins = mins;
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
lmins = png_increase_lmins(png_ptr, lmins);
|
||||
#endif
|
||||
|
||||
sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins);
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (sumhi > PNG_HIMASK)
|
||||
sum = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
sum = (sumhi << PNG_HISHIFT) + sumlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sum < mins)
|
||||
{
|
||||
mins = sum;
|
||||
@@ -2731,48 +2593,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_size_t sum;
|
||||
png_size_t lmins = mins;
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
lmins = png_increase_lmins(png_ptr, lmins);
|
||||
#endif
|
||||
|
||||
sum = png_setup_up_row(png_ptr, row_bytes, lmins);
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (sumhi > PNG_HIMASK)
|
||||
sum = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
sum = (sumhi << PNG_HISHIFT) + sumlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sum < mins)
|
||||
{
|
||||
mins = sum;
|
||||
@@ -2796,48 +2619,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_size_t sum;
|
||||
png_size_t lmins = mins;
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
lmins = png_increase_lmins(png_ptr, lmins);
|
||||
#endif
|
||||
|
||||
sum= png_setup_avg_row(png_ptr, bpp, row_bytes, lmins);
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (sumhi > PNG_HIMASK)
|
||||
sum = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
sum = (sumhi << PNG_HISHIFT) + sumlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sum < mins)
|
||||
{
|
||||
mins = sum;
|
||||
@@ -2861,48 +2645,9 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_size_t sum;
|
||||
png_size_t lmins = mins;
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
lmins = png_increase_lmins(png_ptr, lmins);
|
||||
#endif
|
||||
|
||||
sum = png_setup_paeth_row(png_ptr, bpp, row_bytes, lmins);
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
|
||||
PNG_COST_SHIFT;
|
||||
|
||||
if (sumhi > PNG_HIMASK)
|
||||
sum = PNG_MAXSUM;
|
||||
|
||||
else
|
||||
sum = (sumhi << PNG_HISHIFT) + sumlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sum < mins)
|
||||
{
|
||||
mins = sum;
|
||||
@@ -2918,20 +2663,6 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
|
||||
/* Do the actual writing of the filtered row data from the chosen filter. */
|
||||
png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1);
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
/* Save the type of filter we picked this time for future calculations */
|
||||
if (png_ptr->num_prev_filters > 0)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 1; j < num_p_filters; j++)
|
||||
{
|
||||
png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
|
||||
}
|
||||
|
||||
png_ptr->prev_filters[j] = best_row[0];
|
||||
}
|
||||
#endif /* WRITE_WEIGHTED_FILTER */
|
||||
#endif /* WRITE_FILTER */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user