|
|
|
@ -1090,11 +1090,11 @@ unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_byt |
|
|
|
|
int filter_type; |
|
|
|
|
if (force_filter > -1) { |
|
|
|
|
filter_type = force_filter; |
|
|
|
|
stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer); |
|
|
|
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer); |
|
|
|
|
} else { // Estimate the best filter by running through all of them:
|
|
|
|
|
int best_filter = 0, best_filter_val = 0x7fffffff, est, i; |
|
|
|
|
for (filter_type = 0; filter_type < 5; filter_type++) { |
|
|
|
|
stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer); |
|
|
|
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer); |
|
|
|
|
|
|
|
|
|
// Estimate the entropy of the line using this filter; the less, the better.
|
|
|
|
|
est = 0; |
|
|
|
@ -1107,7 +1107,7 @@ unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_byt |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
|
|
|
|
|
stbiw__encode_png_line(const_cast<unsigned char*>(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer); |
|
|
|
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer); |
|
|
|
|
filter_type = best_filter; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|