mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-25 05:08:21 +01:00
Try to reduce the sampling for the entropy image
This offers minor compression improvements. Change-Id: I4b3b1bb11ee83273c0e4c9f47e53b21cf7cd5f76
This commit is contained in:
parent
14f09ab75b
commit
7861947813
@ -496,15 +496,16 @@ static void CopyImageWithPrediction(int width, int height, int bits,
|
||||
|
||||
// Checks whether 'image' can be subsampled by finding the biggest power of 2
|
||||
// squares (defined by 'best_bits') of uniform value it is made out of.
|
||||
static void OptimizeSampling(uint32_t* const image, int full_width,
|
||||
int full_height, int bits, int* best_bits_out) {
|
||||
void VP8LOptimizeSampling(uint32_t* const image, int full_width,
|
||||
int full_height, int bits, int max_bits,
|
||||
int* best_bits_out) {
|
||||
int width = VP8LSubSampleSize(full_width, bits);
|
||||
int height = VP8LSubSampleSize(full_height, bits);
|
||||
int old_width, x, y, square_size;
|
||||
int best_bits = bits;
|
||||
*best_bits_out = bits;
|
||||
// Check rows first.
|
||||
while (best_bits < MAX_TRANSFORM_BITS) {
|
||||
while (best_bits < max_bits) {
|
||||
const int new_square_size = 1 << (best_bits + 1 - bits);
|
||||
int is_good = 1;
|
||||
square_size = 1 << (best_bits - bits);
|
||||
@ -609,7 +610,8 @@ static void GetBestPredictorsAndSampling(
|
||||
}
|
||||
WebPSafeFree(raw_data);
|
||||
|
||||
OptimizeSampling(all_modes, width, height, bits, best_bits);
|
||||
VP8LOptimizeSampling(all_modes, width, height, bits, MAX_TRANSFORM_BITS,
|
||||
best_bits);
|
||||
}
|
||||
|
||||
// Finds the best predictor for each tile, and converts the image to residuals
|
||||
@ -923,6 +925,7 @@ int VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
OptimizeSampling(image, width, height, bits, best_bits);
|
||||
VP8LOptimizeSampling(image, width, height, bits, MAX_TRANSFORM_BITS,
|
||||
best_bits);
|
||||
return 1;
|
||||
}
|
||||
|
@ -827,12 +827,12 @@ static int EncodeImageInternal(
|
||||
VP8LBitWriter* const bw, const uint32_t* const argb,
|
||||
VP8LHashChain* const hash_chain, VP8LBackwardRefs refs_array[4], int width,
|
||||
int height, int quality, int low_effort, const CrunchConfig* const config,
|
||||
int* cache_bits, int histogram_bits, size_t init_byte_position,
|
||||
int* cache_bits, int histogram_bits_in, size_t init_byte_position,
|
||||
int* const hdr_size, int* const data_size, const WebPPicture* const pic,
|
||||
int percent_range, int* const percent) {
|
||||
const uint32_t histogram_image_xysize =
|
||||
VP8LSubSampleSize(width, histogram_bits) *
|
||||
VP8LSubSampleSize(height, histogram_bits);
|
||||
VP8LSubSampleSize(width, histogram_bits_in) *
|
||||
VP8LSubSampleSize(height, histogram_bits_in);
|
||||
int remaining_percent = percent_range;
|
||||
int percent_start = *percent;
|
||||
VP8LHistogramSet* histogram_image = NULL;
|
||||
@ -851,8 +851,8 @@ static int EncodeImageInternal(
|
||||
int hdr_size_tmp;
|
||||
VP8LHashChain hash_chain_histogram; // histogram image hash chain
|
||||
size_t bw_size_best = ~(size_t)0;
|
||||
assert(histogram_bits >= MIN_HUFFMAN_BITS);
|
||||
assert(histogram_bits <= MAX_HUFFMAN_BITS);
|
||||
assert(histogram_bits_in >= MIN_HUFFMAN_BITS);
|
||||
assert(histogram_bits_in <= MAX_HUFFMAN_BITS);
|
||||
assert(hdr_size != NULL);
|
||||
assert(data_size != NULL);
|
||||
|
||||
@ -905,6 +905,7 @@ static int EncodeImageInternal(
|
||||
|
||||
for (i_cache = 0; i_cache < (sub_config->do_no_cache_ ? 2 : 1); ++i_cache) {
|
||||
const int cache_bits_tmp = (i_cache == 0) ? cache_bits_best : 0;
|
||||
int histogram_bits = histogram_bits_in;
|
||||
// Speed-up: no need to study the no-cache case if it was already studied
|
||||
// in i_cache == 0.
|
||||
if (i_cache == 1 && cache_bits_best == 0) break;
|
||||
@ -970,6 +971,8 @@ static int EncodeImageInternal(
|
||||
write_histogram_image = (histogram_image_size > 1);
|
||||
VP8LPutBits(bw, write_histogram_image, 1);
|
||||
if (write_histogram_image) {
|
||||
VP8LOptimizeSampling(histogram_argb, width, height, histogram_bits_in,
|
||||
MAX_HUFFMAN_BITS, &histogram_bits);
|
||||
VP8LPutBits(bw, histogram_bits - 2, 3);
|
||||
i_percent_range = i_remaining_percent / 2;
|
||||
i_remaining_percent -= i_percent_range;
|
||||
|
@ -117,6 +117,10 @@ int VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
||||
const WebPPicture* const pic, int percent_range,
|
||||
int* const percent, int* const best_bits);
|
||||
|
||||
void VP8LOptimizeSampling(uint32_t* const image, int full_width,
|
||||
int full_height, int bits, int max_bits,
|
||||
int* best_bits_out);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user