mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-19 23:36:45 +02:00
Fix member naming for VP8LHistogram
clang-tidy keeps complaining and that typedef will evolve in the future Change-Id: I734f2ae7dc0f4deac0dd391ae9f4b38c45507651
This commit is contained in:
parent
a1ad3f1e37
commit
ee8e8c620f
@ -599,13 +599,13 @@ static void AddVectorEq_C(const uint32_t* WEBP_RESTRICT a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ADD(X, ARG, LEN) do { \
|
#define ADD(X, ARG, LEN) do { \
|
||||||
if (a->is_used_[X]) { \
|
if (a->is_used[X]) { \
|
||||||
if (b->is_used_[X]) { \
|
if (b->is_used[X]) { \
|
||||||
VP8LAddVector(a->ARG, b->ARG, out->ARG, (LEN)); \
|
VP8LAddVector(a->ARG, b->ARG, out->ARG, (LEN)); \
|
||||||
} else { \
|
} else { \
|
||||||
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||||
} \
|
} \
|
||||||
} else if (b->is_used_[X]) { \
|
} else if (b->is_used[X]) { \
|
||||||
memcpy(&out->ARG[0], &b->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
memcpy(&out->ARG[0], &b->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||||
} else { \
|
} else { \
|
||||||
memset(&out->ARG[0], 0, (LEN) * sizeof(out->ARG[0])); \
|
memset(&out->ARG[0], 0, (LEN) * sizeof(out->ARG[0])); \
|
||||||
@ -613,8 +613,8 @@ static void AddVectorEq_C(const uint32_t* WEBP_RESTRICT a,
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ADD_EQ(X, ARG, LEN) do { \
|
#define ADD_EQ(X, ARG, LEN) do { \
|
||||||
if (a->is_used_[X]) { \
|
if (a->is_used[X]) { \
|
||||||
if (out->is_used_[X]) { \
|
if (out->is_used[X]) { \
|
||||||
VP8LAddVectorEq(a->ARG, out->ARG, (LEN)); \
|
VP8LAddVectorEq(a->ARG, out->ARG, (LEN)); \
|
||||||
} else { \
|
} else { \
|
||||||
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||||
@ -626,25 +626,25 @@ void VP8LHistogramAdd(const VP8LHistogram* WEBP_RESTRICT const a,
|
|||||||
const VP8LHistogram* WEBP_RESTRICT const b,
|
const VP8LHistogram* WEBP_RESTRICT const b,
|
||||||
VP8LHistogram* WEBP_RESTRICT const out) {
|
VP8LHistogram* WEBP_RESTRICT const out) {
|
||||||
int i;
|
int i;
|
||||||
const int literal_size = VP8LHistogramNumCodes(a->palette_code_bits_);
|
const int literal_size = VP8LHistogramNumCodes(a->palette_code_bits);
|
||||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
assert(a->palette_code_bits == b->palette_code_bits);
|
||||||
|
|
||||||
if (b != out) {
|
if (b != out) {
|
||||||
ADD(0, literal_, literal_size);
|
ADD(0, literal, literal_size);
|
||||||
ADD(1, red_, NUM_LITERAL_CODES);
|
ADD(1, red, NUM_LITERAL_CODES);
|
||||||
ADD(2, blue_, NUM_LITERAL_CODES);
|
ADD(2, blue, NUM_LITERAL_CODES);
|
||||||
ADD(3, alpha_, NUM_LITERAL_CODES);
|
ADD(3, alpha, NUM_LITERAL_CODES);
|
||||||
ADD(4, distance_, NUM_DISTANCE_CODES);
|
ADD(4, distance, NUM_DISTANCE_CODES);
|
||||||
for (i = 0; i < 5; ++i) {
|
for (i = 0; i < 5; ++i) {
|
||||||
out->is_used_[i] = (a->is_used_[i] | b->is_used_[i]);
|
out->is_used[i] = (a->is_used[i] | b->is_used[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ADD_EQ(0, literal_, literal_size);
|
ADD_EQ(0, literal, literal_size);
|
||||||
ADD_EQ(1, red_, NUM_LITERAL_CODES);
|
ADD_EQ(1, red, NUM_LITERAL_CODES);
|
||||||
ADD_EQ(2, blue_, NUM_LITERAL_CODES);
|
ADD_EQ(2, blue, NUM_LITERAL_CODES);
|
||||||
ADD_EQ(3, alpha_, NUM_LITERAL_CODES);
|
ADD_EQ(3, alpha, NUM_LITERAL_CODES);
|
||||||
ADD_EQ(4, distance_, NUM_DISTANCE_CODES);
|
ADD_EQ(4, distance, NUM_DISTANCE_CODES);
|
||||||
for (i = 0; i < 5; ++i) out->is_used_[i] |= a->is_used_[i];
|
for (i = 0; i < 5; ++i) out->is_used[i] |= a->is_used[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef ADD
|
#undef ADD
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "src/enc/histogram_enc.h"
|
#include "src/enc/histogram_enc.h"
|
||||||
#include "src/utils/color_cache_utils.h"
|
#include "src/utils/color_cache_utils.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
|
#include "src/webp/format_constants.h"
|
||||||
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
#define VALUES_IN_BYTE 256
|
#define VALUES_IN_BYTE 256
|
||||||
|
|
||||||
@ -76,16 +78,16 @@ static int CostModelBuild(CostModel* const m, int xsize, int cache_bits,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConvertPopulationCountTableToBitEstimates(
|
ConvertPopulationCountTableToBitEstimates(
|
||||||
VP8LHistogramNumCodes(histo->palette_code_bits_), histo->literal_,
|
VP8LHistogramNumCodes(histo->palette_code_bits), histo->literal,
|
||||||
m->literal_);
|
m->literal_);
|
||||||
ConvertPopulationCountTableToBitEstimates(
|
ConvertPopulationCountTableToBitEstimates(
|
||||||
VALUES_IN_BYTE, histo->red_, m->red_);
|
VALUES_IN_BYTE, histo->red, m->red_);
|
||||||
ConvertPopulationCountTableToBitEstimates(
|
ConvertPopulationCountTableToBitEstimates(
|
||||||
VALUES_IN_BYTE, histo->blue_, m->blue_);
|
VALUES_IN_BYTE, histo->blue, m->blue_);
|
||||||
ConvertPopulationCountTableToBitEstimates(
|
ConvertPopulationCountTableToBitEstimates(
|
||||||
VALUES_IN_BYTE, histo->alpha_, m->alpha_);
|
VALUES_IN_BYTE, histo->alpha, m->alpha_);
|
||||||
ConvertPopulationCountTableToBitEstimates(
|
ConvertPopulationCountTableToBitEstimates(
|
||||||
NUM_DISTANCE_CODES, histo->distance_, m->distance_);
|
NUM_DISTANCE_CODES, histo->distance, m->distance_);
|
||||||
ok = 1;
|
ok = 1;
|
||||||
|
|
||||||
Error:
|
Error:
|
||||||
|
@ -13,8 +13,9 @@
|
|||||||
#include "src/enc/backward_references_enc.h"
|
#include "src/enc/backward_references_enc.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "src/dsp/dsp.h"
|
#include "src/dsp/cpu.h"
|
||||||
#include "src/dsp/lossless.h"
|
#include "src/dsp/lossless.h"
|
||||||
#include "src/dsp/lossless_common.h"
|
#include "src/dsp/lossless_common.h"
|
||||||
#include "src/enc/histogram_enc.h"
|
#include "src/enc/histogram_enc.h"
|
||||||
@ -22,6 +23,8 @@
|
|||||||
#include "src/utils/color_cache_utils.h"
|
#include "src/utils/color_cache_utils.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
#include "src/webp/encode.h"
|
#include "src/webp/encode.h"
|
||||||
|
#include "src/webp/format_constants.h"
|
||||||
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
#define MIN_BLOCK_SIZE 256 // minimum block size for backward references
|
#define MIN_BLOCK_SIZE 256 // minimum block size for backward references
|
||||||
|
|
||||||
@ -793,20 +796,20 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
|||||||
// The keys of the caches can be derived from the longest one.
|
// The keys of the caches can be derived from the longest one.
|
||||||
int key = VP8LHashPix(pix, 32 - cache_bits_max);
|
int key = VP8LHashPix(pix, 32 - cache_bits_max);
|
||||||
// Do not use the color cache for cache_bits = 0.
|
// Do not use the color cache for cache_bits = 0.
|
||||||
++histos[0]->blue_[b];
|
++histos[0]->blue[b];
|
||||||
++histos[0]->literal_[g];
|
++histos[0]->literal[g];
|
||||||
++histos[0]->red_[r];
|
++histos[0]->red[r];
|
||||||
++histos[0]->alpha_[a];
|
++histos[0]->alpha[a];
|
||||||
// Deal with cache_bits > 0.
|
// Deal with cache_bits > 0.
|
||||||
for (i = cache_bits_max; i >= 1; --i, key >>= 1) {
|
for (i = cache_bits_max; i >= 1; --i, key >>= 1) {
|
||||||
if (VP8LColorCacheLookup(&hashers[i], key) == pix) {
|
if (VP8LColorCacheLookup(&hashers[i], key) == pix) {
|
||||||
++histos[i]->literal_[NUM_LITERAL_CODES + NUM_LENGTH_CODES + key];
|
++histos[i]->literal[NUM_LITERAL_CODES + NUM_LENGTH_CODES + key];
|
||||||
} else {
|
} else {
|
||||||
VP8LColorCacheSet(&hashers[i], key, pix);
|
VP8LColorCacheSet(&hashers[i], key, pix);
|
||||||
++histos[i]->blue_[b];
|
++histos[i]->blue[b];
|
||||||
++histos[i]->literal_[g];
|
++histos[i]->literal[g];
|
||||||
++histos[i]->red_[r];
|
++histos[i]->red[r];
|
||||||
++histos[i]->alpha_[a];
|
++histos[i]->alpha[a];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -820,7 +823,7 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
|||||||
uint32_t argb_prev = *argb ^ 0xffffffffu;
|
uint32_t argb_prev = *argb ^ 0xffffffffu;
|
||||||
VP8LPrefixEncode(len, &code, &extra_bits, &extra_bits_value);
|
VP8LPrefixEncode(len, &code, &extra_bits, &extra_bits_value);
|
||||||
for (i = 0; i <= cache_bits_max; ++i) {
|
for (i = 0; i <= cache_bits_max; ++i) {
|
||||||
++histos[i]->literal_[NUM_LITERAL_CODES + code];
|
++histos[i]->literal[NUM_LITERAL_CODES + code];
|
||||||
}
|
}
|
||||||
// Update the color caches.
|
// Update the color caches.
|
||||||
do {
|
do {
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "src/webp/config.h"
|
#include "src/webp/config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "src/dsp/lossless.h"
|
#include "src/dsp/lossless.h"
|
||||||
@ -21,6 +23,9 @@
|
|||||||
#include "src/enc/histogram_enc.h"
|
#include "src/enc/histogram_enc.h"
|
||||||
#include "src/enc/vp8i_enc.h"
|
#include "src/enc/vp8i_enc.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
|
#include "src/webp/encode.h"
|
||||||
|
#include "src/webp/format_constants.h"
|
||||||
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
// Number of partitions for the three dominant (literal, red and blue) symbol
|
// Number of partitions for the three dominant (literal, red and blue) symbol
|
||||||
// costs.
|
// costs.
|
||||||
@ -39,12 +44,12 @@ static int GetHistogramSize(int cache_bits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void HistogramClear(VP8LHistogram* const p) {
|
static void HistogramClear(VP8LHistogram* const p) {
|
||||||
uint32_t* const literal = p->literal_;
|
uint32_t* const literal = p->literal;
|
||||||
const int cache_bits = p->palette_code_bits_;
|
const int cache_bits = p->palette_code_bits;
|
||||||
const int histo_size = GetHistogramSize(cache_bits);
|
const int histo_size = GetHistogramSize(cache_bits);
|
||||||
memset(p, 0, histo_size);
|
memset(p, 0, histo_size);
|
||||||
p->palette_code_bits_ = cache_bits;
|
p->palette_code_bits = cache_bits;
|
||||||
p->literal_ = literal;
|
p->literal = literal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap two histogram pointers.
|
// Swap two histogram pointers.
|
||||||
@ -56,14 +61,14 @@ static void HistogramSwap(VP8LHistogram** const A, VP8LHistogram** const B) {
|
|||||||
|
|
||||||
static void HistogramCopy(const VP8LHistogram* const src,
|
static void HistogramCopy(const VP8LHistogram* const src,
|
||||||
VP8LHistogram* const dst) {
|
VP8LHistogram* const dst) {
|
||||||
uint32_t* const dst_literal = dst->literal_;
|
uint32_t* const dst_literal = dst->literal;
|
||||||
const int dst_cache_bits = dst->palette_code_bits_;
|
const int dst_cache_bits = dst->palette_code_bits;
|
||||||
const int literal_size = VP8LHistogramNumCodes(dst_cache_bits);
|
const int literal_size = VP8LHistogramNumCodes(dst_cache_bits);
|
||||||
const int histo_size = GetHistogramSize(dst_cache_bits);
|
const int histo_size = GetHistogramSize(dst_cache_bits);
|
||||||
assert(src->palette_code_bits_ == dst_cache_bits);
|
assert(src->palette_code_bits == dst_cache_bits);
|
||||||
memcpy(dst, src, histo_size);
|
memcpy(dst, src, histo_size);
|
||||||
dst->literal_ = dst_literal;
|
dst->literal = dst_literal;
|
||||||
memcpy(dst->literal_, src->literal_, literal_size * sizeof(*dst->literal_));
|
memcpy(dst->literal, src->literal, literal_size * sizeof(*dst->literal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VP8LFreeHistogram(VP8LHistogram* const histo) {
|
void VP8LFreeHistogram(VP8LHistogram* const histo) {
|
||||||
@ -87,7 +92,7 @@ void VP8LHistogramCreate(VP8LHistogram* const p,
|
|||||||
const VP8LBackwardRefs* const refs,
|
const VP8LBackwardRefs* const refs,
|
||||||
int palette_code_bits) {
|
int palette_code_bits) {
|
||||||
if (palette_code_bits >= 0) {
|
if (palette_code_bits >= 0) {
|
||||||
p->palette_code_bits_ = palette_code_bits;
|
p->palette_code_bits = palette_code_bits;
|
||||||
}
|
}
|
||||||
HistogramClear(p);
|
HistogramClear(p);
|
||||||
VP8LHistogramStoreRefs(refs, p);
|
VP8LHistogramStoreRefs(refs, p);
|
||||||
@ -95,16 +100,16 @@ void VP8LHistogramCreate(VP8LHistogram* const p,
|
|||||||
|
|
||||||
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits,
|
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits,
|
||||||
int init_arrays) {
|
int init_arrays) {
|
||||||
p->palette_code_bits_ = palette_code_bits;
|
p->palette_code_bits = palette_code_bits;
|
||||||
if (init_arrays) {
|
if (init_arrays) {
|
||||||
HistogramClear(p);
|
HistogramClear(p);
|
||||||
} else {
|
} else {
|
||||||
p->trivial_symbol_ = 0;
|
p->trivial_symbol = 0;
|
||||||
p->bit_cost_ = 0;
|
p->bit_cost = 0;
|
||||||
p->literal_cost_ = 0;
|
p->literal_cost = 0;
|
||||||
p->red_cost_ = 0;
|
p->red_cost = 0;
|
||||||
p->blue_cost_ = 0;
|
p->blue_cost = 0;
|
||||||
memset(p->is_used_, 0, sizeof(p->is_used_));
|
memset(p->is_used, 0, sizeof(p->is_used));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +120,7 @@ VP8LHistogram* VP8LAllocateHistogram(int cache_bits) {
|
|||||||
if (memory == NULL) return NULL;
|
if (memory == NULL) return NULL;
|
||||||
histo = (VP8LHistogram*)memory;
|
histo = (VP8LHistogram*)memory;
|
||||||
// literal_ won't necessary be aligned.
|
// literal_ won't necessary be aligned.
|
||||||
histo->literal_ = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
histo->literal = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
||||||
VP8LHistogramInit(histo, cache_bits, /*init_arrays=*/ 0);
|
VP8LHistogramInit(histo, cache_bits, /*init_arrays=*/ 0);
|
||||||
return histo;
|
return histo;
|
||||||
}
|
}
|
||||||
@ -131,7 +136,7 @@ static void HistogramSetResetPointers(VP8LHistogramSet* const set,
|
|||||||
memory = (uint8_t*) WEBP_ALIGN(memory);
|
memory = (uint8_t*) WEBP_ALIGN(memory);
|
||||||
set->histograms[i] = (VP8LHistogram*) memory;
|
set->histograms[i] = (VP8LHistogram*) memory;
|
||||||
// literal_ won't necessary be aligned.
|
// literal_ won't necessary be aligned.
|
||||||
set->histograms[i]->literal_ = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
set->histograms[i]->literal = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
||||||
memory += histo_size;
|
memory += histo_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +169,7 @@ VP8LHistogramSet* VP8LAllocateHistogramSet(int size, int cache_bits) {
|
|||||||
|
|
||||||
void VP8LHistogramSetClear(VP8LHistogramSet* const set) {
|
void VP8LHistogramSetClear(VP8LHistogramSet* const set) {
|
||||||
int i;
|
int i;
|
||||||
const int cache_bits = set->histograms[0]->palette_code_bits_;
|
const int cache_bits = set->histograms[0]->palette_code_bits;
|
||||||
const int size = set->max_size;
|
const int size = set->max_size;
|
||||||
const size_t total_size = HistogramSetTotalSize(size, cache_bits);
|
const size_t total_size = HistogramSetTotalSize(size, cache_bits);
|
||||||
uint8_t* memory = (uint8_t*)set;
|
uint8_t* memory = (uint8_t*)set;
|
||||||
@ -176,7 +181,7 @@ void VP8LHistogramSetClear(VP8LHistogramSet* const set) {
|
|||||||
set->size = size;
|
set->size = size;
|
||||||
HistogramSetResetPointers(set, cache_bits);
|
HistogramSetResetPointers(set, cache_bits);
|
||||||
for (i = 0; i < size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
set->histograms[i]->palette_code_bits_ = cache_bits;
|
set->histograms[i]->palette_code_bits = cache_bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,19 +206,19 @@ void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
|||||||
int (*const distance_modifier)(int, int),
|
int (*const distance_modifier)(int, int),
|
||||||
int distance_modifier_arg0) {
|
int distance_modifier_arg0) {
|
||||||
if (PixOrCopyIsLiteral(v)) {
|
if (PixOrCopyIsLiteral(v)) {
|
||||||
++histo->alpha_[PixOrCopyLiteral(v, 3)];
|
++histo->alpha[PixOrCopyLiteral(v, 3)];
|
||||||
++histo->red_[PixOrCopyLiteral(v, 2)];
|
++histo->red[PixOrCopyLiteral(v, 2)];
|
||||||
++histo->literal_[PixOrCopyLiteral(v, 1)];
|
++histo->literal[PixOrCopyLiteral(v, 1)];
|
||||||
++histo->blue_[PixOrCopyLiteral(v, 0)];
|
++histo->blue[PixOrCopyLiteral(v, 0)];
|
||||||
} else if (PixOrCopyIsCacheIdx(v)) {
|
} else if (PixOrCopyIsCacheIdx(v)) {
|
||||||
const int literal_ix =
|
const int literal_ix =
|
||||||
NUM_LITERAL_CODES + NUM_LENGTH_CODES + PixOrCopyCacheIdx(v);
|
NUM_LITERAL_CODES + NUM_LENGTH_CODES + PixOrCopyCacheIdx(v);
|
||||||
assert(histo->palette_code_bits_ != 0);
|
assert(histo->palette_code_bits != 0);
|
||||||
++histo->literal_[literal_ix];
|
++histo->literal[literal_ix];
|
||||||
} else {
|
} else {
|
||||||
int code, extra_bits;
|
int code, extra_bits;
|
||||||
VP8LPrefixEncodeBits(PixOrCopyLength(v), &code, &extra_bits);
|
VP8LPrefixEncodeBits(PixOrCopyLength(v), &code, &extra_bits);
|
||||||
++histo->literal_[NUM_LITERAL_CODES + code];
|
++histo->literal[NUM_LITERAL_CODES + code];
|
||||||
if (distance_modifier == NULL) {
|
if (distance_modifier == NULL) {
|
||||||
VP8LPrefixEncodeBits(PixOrCopyDistance(v), &code, &extra_bits);
|
VP8LPrefixEncodeBits(PixOrCopyDistance(v), &code, &extra_bits);
|
||||||
} else {
|
} else {
|
||||||
@ -221,7 +226,7 @@ void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
|||||||
distance_modifier(distance_modifier_arg0, PixOrCopyDistance(v)),
|
distance_modifier(distance_modifier_arg0, PixOrCopyDistance(v)),
|
||||||
&code, &extra_bits);
|
&code, &extra_bits);
|
||||||
}
|
}
|
||||||
++histo->distance_[code];
|
++histo->distance[code];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,17 +367,15 @@ static WEBP_INLINE uint64_t GetCombinedEntropy(const uint32_t* const X,
|
|||||||
|
|
||||||
// Estimates the Entropy + Huffman + other block overhead size cost.
|
// Estimates the Entropy + Huffman + other block overhead size cost.
|
||||||
uint64_t VP8LHistogramEstimateBits(VP8LHistogram* const p) {
|
uint64_t VP8LHistogramEstimateBits(VP8LHistogram* const p) {
|
||||||
return PopulationCost(p->literal_,
|
return PopulationCost(p->literal, VP8LHistogramNumCodes(p->palette_code_bits),
|
||||||
VP8LHistogramNumCodes(p->palette_code_bits_), NULL,
|
NULL, &p->is_used[0]) +
|
||||||
&p->is_used_[0]) +
|
PopulationCost(p->red, NUM_LITERAL_CODES, NULL, &p->is_used[1]) +
|
||||||
PopulationCost(p->red_, NUM_LITERAL_CODES, NULL, &p->is_used_[1]) +
|
PopulationCost(p->blue, NUM_LITERAL_CODES, NULL, &p->is_used[2]) +
|
||||||
PopulationCost(p->blue_, NUM_LITERAL_CODES, NULL, &p->is_used_[2]) +
|
PopulationCost(p->alpha, NUM_LITERAL_CODES, NULL, &p->is_used[3]) +
|
||||||
PopulationCost(p->alpha_, NUM_LITERAL_CODES, NULL, &p->is_used_[3]) +
|
PopulationCost(p->distance, NUM_DISTANCE_CODES, NULL, &p->is_used[4]) +
|
||||||
PopulationCost(p->distance_, NUM_DISTANCE_CODES, NULL,
|
((uint64_t)(VP8LExtraCost(p->literal + NUM_LITERAL_CODES,
|
||||||
&p->is_used_[4]) +
|
|
||||||
((uint64_t)(VP8LExtraCost(p->literal_ + NUM_LITERAL_CODES,
|
|
||||||
NUM_LENGTH_CODES) +
|
NUM_LENGTH_CODES) +
|
||||||
VP8LExtraCost(p->distance_, NUM_DISTANCE_CODES))
|
VP8LExtraCost(p->distance, NUM_DISTANCE_CODES))
|
||||||
<< LOG_2_PRECISION_BITS);
|
<< LOG_2_PRECISION_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,24 +396,24 @@ static WEBP_INLINE void SaturateAdd(uint64_t a, int64_t* b) {
|
|||||||
WEBP_NODISCARD static int GetCombinedHistogramEntropy(
|
WEBP_NODISCARD static int GetCombinedHistogramEntropy(
|
||||||
const VP8LHistogram* const a, const VP8LHistogram* const b,
|
const VP8LHistogram* const a, const VP8LHistogram* const b,
|
||||||
int64_t cost_threshold_in, uint64_t* cost) {
|
int64_t cost_threshold_in, uint64_t* cost) {
|
||||||
const int palette_code_bits = a->palette_code_bits_;
|
const int palette_code_bits = a->palette_code_bits;
|
||||||
int trivial_at_end = 0;
|
int trivial_at_end = 0;
|
||||||
const uint64_t cost_threshold = (uint64_t)cost_threshold_in;
|
const uint64_t cost_threshold = (uint64_t)cost_threshold_in;
|
||||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
assert(a->palette_code_bits == b->palette_code_bits);
|
||||||
if (cost_threshold_in <= 0) return 0;
|
if (cost_threshold_in <= 0) return 0;
|
||||||
*cost = GetCombinedEntropy(a->literal_, b->literal_,
|
*cost = GetCombinedEntropy(a->literal, b->literal,
|
||||||
VP8LHistogramNumCodes(palette_code_bits),
|
VP8LHistogramNumCodes(palette_code_bits),
|
||||||
a->is_used_[0], b->is_used_[0], 0);
|
a->is_used[0], b->is_used[0], 0);
|
||||||
// No need to add the extra cost as it is a constant that does not influence
|
// No need to add the extra cost as it is a constant that does not influence
|
||||||
// the histograms.
|
// the histograms.
|
||||||
if (*cost >= cost_threshold) return 0;
|
if (*cost >= cost_threshold) return 0;
|
||||||
|
|
||||||
if (a->trivial_symbol_ != VP8L_NON_TRIVIAL_SYM &&
|
if (a->trivial_symbol != VP8L_NON_TRIVIAL_SYM &&
|
||||||
a->trivial_symbol_ == b->trivial_symbol_) {
|
a->trivial_symbol == b->trivial_symbol) {
|
||||||
// A, R and B are all 0 or 0xff.
|
// A, R and B are all 0 or 0xff.
|
||||||
const uint32_t color_a = (a->trivial_symbol_ >> 24) & 0xff;
|
const uint32_t color_a = (a->trivial_symbol >> 24) & 0xff;
|
||||||
const uint32_t color_r = (a->trivial_symbol_ >> 16) & 0xff;
|
const uint32_t color_r = (a->trivial_symbol >> 16) & 0xff;
|
||||||
const uint32_t color_b = (a->trivial_symbol_ >> 0) & 0xff;
|
const uint32_t color_b = (a->trivial_symbol >> 0) & 0xff;
|
||||||
if ((color_a == 0 || color_a == 0xff) &&
|
if ((color_a == 0 || color_a == 0xff) &&
|
||||||
(color_r == 0 || color_r == 0xff) &&
|
(color_r == 0 || color_r == 0xff) &&
|
||||||
(color_b == 0 || color_b == 0xff)) {
|
(color_b == 0 || color_b == 0xff)) {
|
||||||
@ -418,20 +421,20 @@ WEBP_NODISCARD static int GetCombinedHistogramEntropy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*cost += GetCombinedEntropy(a->red_, b->red_, NUM_LITERAL_CODES,
|
*cost += GetCombinedEntropy(a->red, b->red, NUM_LITERAL_CODES, a->is_used[1],
|
||||||
a->is_used_[1], b->is_used_[1], trivial_at_end);
|
b->is_used[1], trivial_at_end);
|
||||||
if (*cost >= cost_threshold) return 0;
|
if (*cost >= cost_threshold) return 0;
|
||||||
|
|
||||||
*cost += GetCombinedEntropy(a->blue_, b->blue_, NUM_LITERAL_CODES,
|
*cost += GetCombinedEntropy(a->blue, b->blue, NUM_LITERAL_CODES,
|
||||||
a->is_used_[2], b->is_used_[2], trivial_at_end);
|
a->is_used[2], b->is_used[2], trivial_at_end);
|
||||||
if (*cost >= cost_threshold) return 0;
|
if (*cost >= cost_threshold) return 0;
|
||||||
|
|
||||||
*cost += GetCombinedEntropy(a->alpha_, b->alpha_, NUM_LITERAL_CODES,
|
*cost += GetCombinedEntropy(a->alpha, b->alpha, NUM_LITERAL_CODES,
|
||||||
a->is_used_[3], b->is_used_[3], trivial_at_end);
|
a->is_used[3], b->is_used[3], trivial_at_end);
|
||||||
if (*cost >= cost_threshold) return 0;
|
if (*cost >= cost_threshold) return 0;
|
||||||
|
|
||||||
*cost += GetCombinedEntropy(a->distance_, b->distance_, NUM_DISTANCE_CODES,
|
*cost += GetCombinedEntropy(a->distance, b->distance, NUM_DISTANCE_CODES,
|
||||||
a->is_used_[4], b->is_used_[4], 0);
|
a->is_used[4], b->is_used[4], 0);
|
||||||
// No need to add the extra cost as it is a constant that does not influence
|
// No need to add the extra cost as it is a constant that does not influence
|
||||||
// the histograms.
|
// the histograms.
|
||||||
if (*cost >= cost_threshold) return 0;
|
if (*cost >= cost_threshold) return 0;
|
||||||
@ -443,8 +446,8 @@ static WEBP_INLINE void HistogramAdd(const VP8LHistogram* const a,
|
|||||||
const VP8LHistogram* const b,
|
const VP8LHistogram* const b,
|
||||||
VP8LHistogram* const out) {
|
VP8LHistogram* const out) {
|
||||||
VP8LHistogramAdd(a, b, out);
|
VP8LHistogramAdd(a, b, out);
|
||||||
out->trivial_symbol_ = (a->trivial_symbol_ == b->trivial_symbol_)
|
out->trivial_symbol = (a->trivial_symbol == b->trivial_symbol)
|
||||||
? a->trivial_symbol_
|
? a->trivial_symbol
|
||||||
: VP8L_NON_TRIVIAL_SYM;
|
: VP8L_NON_TRIVIAL_SYM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,13 +464,13 @@ WEBP_NODISCARD static int HistogramAddEval(const VP8LHistogram* const a,
|
|||||||
VP8LHistogram* const out,
|
VP8LHistogram* const out,
|
||||||
int64_t cost_threshold) {
|
int64_t cost_threshold) {
|
||||||
uint64_t cost;
|
uint64_t cost;
|
||||||
const uint64_t sum_cost = a->bit_cost_ + b->bit_cost_;
|
const uint64_t sum_cost = a->bit_cost + b->bit_cost;
|
||||||
SaturateAdd(sum_cost, &cost_threshold);
|
SaturateAdd(sum_cost, &cost_threshold);
|
||||||
if (!GetCombinedHistogramEntropy(a, b, cost_threshold, &cost)) return 0;
|
if (!GetCombinedHistogramEntropy(a, b, cost_threshold, &cost)) return 0;
|
||||||
|
|
||||||
HistogramAdd(a, b, out);
|
HistogramAdd(a, b, out);
|
||||||
out->bit_cost_ = cost;
|
out->bit_cost = cost;
|
||||||
out->palette_code_bits_ = a->palette_code_bits_;
|
out->palette_code_bits = a->palette_code_bits;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,10 +485,10 @@ WEBP_NODISCARD static int HistogramAddThresh(const VP8LHistogram* const a,
|
|||||||
int64_t* cost_out) {
|
int64_t* cost_out) {
|
||||||
uint64_t cost;
|
uint64_t cost;
|
||||||
assert(a != NULL && b != NULL);
|
assert(a != NULL && b != NULL);
|
||||||
SaturateAdd(a->bit_cost_, &cost_threshold);
|
SaturateAdd(a->bit_cost, &cost_threshold);
|
||||||
if (!GetCombinedHistogramEntropy(a, b, cost_threshold, &cost)) return 0;
|
if (!GetCombinedHistogramEntropy(a, b, cost_threshold, &cost)) return 0;
|
||||||
|
|
||||||
*cost_out = (int64_t)cost - (int64_t)a->bit_cost_;
|
*cost_out = (int64_t)cost - (int64_t)a->bit_cost;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,35 +516,34 @@ static void DominantCostRangeInit(DominantCostRange* const c) {
|
|||||||
|
|
||||||
static void UpdateDominantCostRange(
|
static void UpdateDominantCostRange(
|
||||||
const VP8LHistogram* const h, DominantCostRange* const c) {
|
const VP8LHistogram* const h, DominantCostRange* const c) {
|
||||||
if (c->literal_max_ < h->literal_cost_) c->literal_max_ = h->literal_cost_;
|
if (c->literal_max_ < h->literal_cost) c->literal_max_ = h->literal_cost;
|
||||||
if (c->literal_min_ > h->literal_cost_) c->literal_min_ = h->literal_cost_;
|
if (c->literal_min_ > h->literal_cost) c->literal_min_ = h->literal_cost;
|
||||||
if (c->red_max_ < h->red_cost_) c->red_max_ = h->red_cost_;
|
if (c->red_max_ < h->red_cost) c->red_max_ = h->red_cost;
|
||||||
if (c->red_min_ > h->red_cost_) c->red_min_ = h->red_cost_;
|
if (c->red_min_ > h->red_cost) c->red_min_ = h->red_cost;
|
||||||
if (c->blue_max_ < h->blue_cost_) c->blue_max_ = h->blue_cost_;
|
if (c->blue_max_ < h->blue_cost) c->blue_max_ = h->blue_cost;
|
||||||
if (c->blue_min_ > h->blue_cost_) c->blue_min_ = h->blue_cost_;
|
if (c->blue_min_ > h->blue_cost) c->blue_min_ = h->blue_cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateHistogramCost(VP8LHistogram* const h) {
|
static void UpdateHistogramCost(VP8LHistogram* const h) {
|
||||||
uint32_t alpha_sym, red_sym, blue_sym;
|
uint32_t alpha_sym, red_sym, blue_sym;
|
||||||
const uint64_t alpha_cost =
|
const uint64_t alpha_cost =
|
||||||
PopulationCost(h->alpha_, NUM_LITERAL_CODES, &alpha_sym, &h->is_used_[3]);
|
PopulationCost(h->alpha, NUM_LITERAL_CODES, &alpha_sym, &h->is_used[3]);
|
||||||
// No need to add the extra cost as it is a constant that does not influence
|
// No need to add the extra cost as it is a constant that does not influence
|
||||||
// the histograms.
|
// the histograms.
|
||||||
const uint64_t distance_cost =
|
const uint64_t distance_cost =
|
||||||
PopulationCost(h->distance_, NUM_DISTANCE_CODES, NULL, &h->is_used_[4]);
|
PopulationCost(h->distance, NUM_DISTANCE_CODES, NULL, &h->is_used[4]);
|
||||||
const int num_codes = VP8LHistogramNumCodes(h->palette_code_bits_);
|
const int num_codes = VP8LHistogramNumCodes(h->palette_code_bits);
|
||||||
h->literal_cost_ =
|
h->literal_cost = PopulationCost(h->literal, num_codes, NULL, &h->is_used[0]);
|
||||||
PopulationCost(h->literal_, num_codes, NULL, &h->is_used_[0]);
|
h->red_cost =
|
||||||
h->red_cost_ =
|
PopulationCost(h->red, NUM_LITERAL_CODES, &red_sym, &h->is_used[1]);
|
||||||
PopulationCost(h->red_, NUM_LITERAL_CODES, &red_sym, &h->is_used_[1]);
|
h->blue_cost =
|
||||||
h->blue_cost_ =
|
PopulationCost(h->blue, NUM_LITERAL_CODES, &blue_sym, &h->is_used[2]);
|
||||||
PopulationCost(h->blue_, NUM_LITERAL_CODES, &blue_sym, &h->is_used_[2]);
|
h->bit_cost =
|
||||||
h->bit_cost_ = h->literal_cost_ + h->red_cost_ + h->blue_cost_ +
|
h->literal_cost + h->red_cost + h->blue_cost + alpha_cost + distance_cost;
|
||||||
alpha_cost + distance_cost;
|
|
||||||
if ((alpha_sym | red_sym | blue_sym) == VP8L_NON_TRIVIAL_SYM) {
|
if ((alpha_sym | red_sym | blue_sym) == VP8L_NON_TRIVIAL_SYM) {
|
||||||
h->trivial_symbol_ = VP8L_NON_TRIVIAL_SYM;
|
h->trivial_symbol = VP8L_NON_TRIVIAL_SYM;
|
||||||
} else {
|
} else {
|
||||||
h->trivial_symbol_ =
|
h->trivial_symbol =
|
||||||
((uint32_t)alpha_sym << 24) | (red_sym << 16) | (blue_sym << 0);
|
((uint32_t)alpha_sym << 24) | (red_sym << 16) | (blue_sym << 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,14 +560,14 @@ static int GetBinIdForEntropy(uint64_t min, uint64_t max, uint64_t val) {
|
|||||||
|
|
||||||
static int GetHistoBinIndex(const VP8LHistogram* const h,
|
static int GetHistoBinIndex(const VP8LHistogram* const h,
|
||||||
const DominantCostRange* const c, int low_effort) {
|
const DominantCostRange* const c, int low_effort) {
|
||||||
int bin_id = GetBinIdForEntropy(c->literal_min_, c->literal_max_,
|
int bin_id =
|
||||||
h->literal_cost_);
|
GetBinIdForEntropy(c->literal_min_, c->literal_max_, h->literal_cost);
|
||||||
assert(bin_id < NUM_PARTITIONS);
|
assert(bin_id < NUM_PARTITIONS);
|
||||||
if (!low_effort) {
|
if (!low_effort) {
|
||||||
bin_id = bin_id * NUM_PARTITIONS
|
bin_id = bin_id * NUM_PARTITIONS
|
||||||
+ GetBinIdForEntropy(c->red_min_, c->red_max_, h->red_cost_);
|
+ GetBinIdForEntropy(c->red_min_, c->red_max_, h->red_cost);
|
||||||
bin_id = bin_id * NUM_PARTITIONS
|
bin_id = bin_id * NUM_PARTITIONS
|
||||||
+ GetBinIdForEntropy(c->blue_min_, c->blue_max_, h->blue_cost_);
|
+ GetBinIdForEntropy(c->blue_min_, c->blue_max_, h->blue_cost);
|
||||||
assert(bin_id < BIN_SIZE);
|
assert(bin_id < BIN_SIZE);
|
||||||
}
|
}
|
||||||
return bin_id;
|
return bin_id;
|
||||||
@ -611,8 +613,8 @@ static void HistogramCopyAndAnalyze(VP8LHistogramSet* const orig_histo,
|
|||||||
|
|
||||||
// Skip the histogram if it is completely empty, which can happen for tiles
|
// Skip the histogram if it is completely empty, which can happen for tiles
|
||||||
// with no information (when they are skipped because of LZ77).
|
// with no information (when they are skipped because of LZ77).
|
||||||
if (!histo->is_used_[0] && !histo->is_used_[1] && !histo->is_used_[2]
|
if (!histo->is_used[0] && !histo->is_used[1] && !histo->is_used[2]
|
||||||
&& !histo->is_used_[3] && !histo->is_used_[4]) {
|
&& !histo->is_used[3] && !histo->is_used[4]) {
|
||||||
// The first histogram is always used. If an histogram is empty, we set
|
// The first histogram is always used. If an histogram is empty, we set
|
||||||
// its id to be the same as the previous one: this will improve
|
// its id to be the same as the previous one: this will improve
|
||||||
// compressibility for later LZ77.
|
// compressibility for later LZ77.
|
||||||
@ -693,7 +695,7 @@ static void HistogramCombineEntropyBin(
|
|||||||
cluster_mappings[clusters[idx]] = clusters[first];
|
cluster_mappings[clusters[idx]] = clusters[first];
|
||||||
} else {
|
} else {
|
||||||
// try to merge #idx into #first (both share the same bin_id)
|
// try to merge #idx into #first (both share the same bin_id)
|
||||||
const uint64_t bit_cost = histograms[idx]->bit_cost_;
|
const uint64_t bit_cost = histograms[idx]->bit_cost;
|
||||||
const int64_t bit_cost_thresh =
|
const int64_t bit_cost_thresh =
|
||||||
-DivRound((int64_t)bit_cost * combine_cost_factor, 100);
|
-DivRound((int64_t)bit_cost * combine_cost_factor, 100);
|
||||||
if (HistogramAddEval(histograms[first], histograms[idx], cur_combo,
|
if (HistogramAddEval(histograms[first], histograms[idx], cur_combo,
|
||||||
@ -704,9 +706,9 @@ static void HistogramCombineEntropyBin(
|
|||||||
// histogram pairs. In that case, we fallback to combining
|
// histogram pairs. In that case, we fallback to combining
|
||||||
// histograms as usual to avoid increasing the header size.
|
// histograms as usual to avoid increasing the header size.
|
||||||
const int try_combine =
|
const int try_combine =
|
||||||
(cur_combo->trivial_symbol_ != VP8L_NON_TRIVIAL_SYM) ||
|
(cur_combo->trivial_symbol != VP8L_NON_TRIVIAL_SYM) ||
|
||||||
((histograms[idx]->trivial_symbol_ == VP8L_NON_TRIVIAL_SYM) &&
|
((histograms[idx]->trivial_symbol == VP8L_NON_TRIVIAL_SYM) &&
|
||||||
(histograms[first]->trivial_symbol_ == VP8L_NON_TRIVIAL_SYM));
|
(histograms[first]->trivial_symbol == VP8L_NON_TRIVIAL_SYM));
|
||||||
const int max_combine_failures = 32;
|
const int max_combine_failures = 32;
|
||||||
if (try_combine ||
|
if (try_combine ||
|
||||||
bin_info[bin_id].num_combine_failures >= max_combine_failures) {
|
bin_info[bin_id].num_combine_failures >= max_combine_failures) {
|
||||||
@ -805,7 +807,7 @@ WEBP_NODISCARD static int HistoQueueUpdatePair(const VP8LHistogram* const h1,
|
|||||||
const VP8LHistogram* const h2,
|
const VP8LHistogram* const h2,
|
||||||
int64_t cost_threshold,
|
int64_t cost_threshold,
|
||||||
HistogramPair* const pair) {
|
HistogramPair* const pair) {
|
||||||
const int64_t sum_cost = h1->bit_cost_ + h2->bit_cost_;
|
const int64_t sum_cost = h1->bit_cost + h2->bit_cost;
|
||||||
SaturateAdd(sum_cost, &cost_threshold);
|
SaturateAdd(sum_cost, &cost_threshold);
|
||||||
if (!GetCombinedHistogramEntropy(h1, h2, cost_threshold, &pair->cost_combo)) {
|
if (!GetCombinedHistogramEntropy(h1, h2, cost_threshold, &pair->cost_combo)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -883,7 +885,7 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo,
|
|||||||
const int idx1 = histo_queue.queue[0].idx1;
|
const int idx1 = histo_queue.queue[0].idx1;
|
||||||
const int idx2 = histo_queue.queue[0].idx2;
|
const int idx2 = histo_queue.queue[0].idx2;
|
||||||
HistogramAdd(histograms[idx2], histograms[idx1], histograms[idx1]);
|
HistogramAdd(histograms[idx2], histograms[idx1], histograms[idx1]);
|
||||||
histograms[idx1]->bit_cost_ = histo_queue.queue[0].cost_combo;
|
histograms[idx1]->bit_cost = histo_queue.queue[0].cost_combo;
|
||||||
|
|
||||||
// Remove merged histogram.
|
// Remove merged histogram.
|
||||||
HistogramSetRemoveHistogram(image_histo, idx2, num_used);
|
HistogramSetRemoveHistogram(image_histo, idx2, num_used);
|
||||||
@ -1004,7 +1006,7 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
|||||||
// Merge the histograms and remove best_idx2 from the queue.
|
// Merge the histograms and remove best_idx2 from the queue.
|
||||||
HistogramAdd(histograms[best_idx2], histograms[best_idx1],
|
HistogramAdd(histograms[best_idx2], histograms[best_idx1],
|
||||||
histograms[best_idx1]);
|
histograms[best_idx1]);
|
||||||
histograms[best_idx1]->bit_cost_ = histo_queue.queue[0].cost_combo;
|
histograms[best_idx1]->bit_cost = histo_queue.queue[0].cost_combo;
|
||||||
HistogramSetRemoveHistogram(image_histo, best_idx2, num_used);
|
HistogramSetRemoveHistogram(image_histo, best_idx2, num_used);
|
||||||
// Parse the queue and update each pair that deals with best_idx1,
|
// Parse the queue and update each pair that deals with best_idx1,
|
||||||
// best_idx2 or image_histo_size.
|
// best_idx2 or image_histo_size.
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
#ifndef WEBP_ENC_HISTOGRAM_ENC_H_
|
#ifndef WEBP_ENC_HISTOGRAM_ENC_H_
|
||||||
#define WEBP_ENC_HISTOGRAM_ENC_H_
|
#define WEBP_ENC_HISTOGRAM_ENC_H_
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "src/enc/backward_references_enc.h"
|
#include "src/enc/backward_references_enc.h"
|
||||||
|
#include "src/webp/encode.h"
|
||||||
#include "src/webp/format_constants.h"
|
#include "src/webp/format_constants.h"
|
||||||
#include "src/webp/types.h"
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
@ -31,20 +30,20 @@ extern "C" {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
// literal_ contains green literal, palette-code and
|
// literal_ contains green literal, palette-code and
|
||||||
// copy-length-prefix histogram
|
// copy-length-prefix histogram
|
||||||
uint32_t* literal_; // Pointer to the allocated buffer for literal.
|
uint32_t* literal; // Pointer to the allocated buffer for literal.
|
||||||
uint32_t red_[NUM_LITERAL_CODES];
|
uint32_t red[NUM_LITERAL_CODES];
|
||||||
uint32_t blue_[NUM_LITERAL_CODES];
|
uint32_t blue[NUM_LITERAL_CODES];
|
||||||
uint32_t alpha_[NUM_LITERAL_CODES];
|
uint32_t alpha[NUM_LITERAL_CODES];
|
||||||
// Backward reference prefix-code histogram.
|
// Backward reference prefix-code histogram.
|
||||||
uint32_t distance_[NUM_DISTANCE_CODES];
|
uint32_t distance[NUM_DISTANCE_CODES];
|
||||||
int palette_code_bits_;
|
int palette_code_bits;
|
||||||
uint32_t trivial_symbol_; // True, if histograms for Red, Blue & Alpha
|
uint32_t trivial_symbol; // True, if histograms for Red, Blue & Alpha
|
||||||
// literal symbols are single valued.
|
// literal symbols are single valued.
|
||||||
uint64_t bit_cost_; // cached value of bit cost.
|
uint64_t bit_cost; // cached value of bit cost.
|
||||||
uint64_t literal_cost_; // Cached values of dominant entropy costs:
|
uint64_t literal_cost; // Cached values of dominant entropy costs:
|
||||||
uint64_t red_cost_; // literal, red & blue.
|
uint64_t red_cost; // literal, red & blue.
|
||||||
uint64_t blue_cost_;
|
uint64_t blue_cost;
|
||||||
uint8_t is_used_[5]; // 5 for literal, red, blue, alpha, distance
|
uint8_t is_used[5]; // 5 for literal, red, blue, alpha, distance
|
||||||
} VP8LHistogram;
|
} VP8LHistogram;
|
||||||
|
|
||||||
// Collection of histograms with fixed capacity, allocated as one
|
// Collection of histograms with fixed capacity, allocated as one
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "src/dsp/lossless.h"
|
#include "src/dsp/lossless.h"
|
||||||
#include "src/dsp/lossless_common.h"
|
#include "src/dsp/lossless_common.h"
|
||||||
@ -24,9 +25,11 @@
|
|||||||
#include "src/utils/bit_writer_utils.h"
|
#include "src/utils/bit_writer_utils.h"
|
||||||
#include "src/utils/huffman_encode_utils.h"
|
#include "src/utils/huffman_encode_utils.h"
|
||||||
#include "src/utils/palette.h"
|
#include "src/utils/palette.h"
|
||||||
|
#include "src/utils/thread_utils.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
#include "src/webp/encode.h"
|
#include "src/webp/encode.h"
|
||||||
#include "src/webp/format_constants.h"
|
#include "src/webp/format_constants.h"
|
||||||
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
// Maximum number of histogram images (sub-blocks).
|
// Maximum number of histogram images (sub-blocks).
|
||||||
#define MAX_HUFF_IMAGE_SIZE 2600
|
#define MAX_HUFF_IMAGE_SIZE 2600
|
||||||
@ -440,7 +443,7 @@ static int GetHuffBitLengthsAndCodes(
|
|||||||
assert(histo != NULL);
|
assert(histo != NULL);
|
||||||
for (k = 0; k < 5; ++k) {
|
for (k = 0; k < 5; ++k) {
|
||||||
const int num_symbols =
|
const int num_symbols =
|
||||||
(k == 0) ? VP8LHistogramNumCodes(histo->palette_code_bits_) :
|
(k == 0) ? VP8LHistogramNumCodes(histo->palette_code_bits) :
|
||||||
(k == 4) ? NUM_DISTANCE_CODES : 256;
|
(k == 4) ? NUM_DISTANCE_CODES : 256;
|
||||||
codes[k].num_symbols = num_symbols;
|
codes[k].num_symbols = num_symbols;
|
||||||
total_length_size += num_symbols;
|
total_length_size += num_symbols;
|
||||||
@ -478,11 +481,11 @@ static int GetHuffBitLengthsAndCodes(
|
|||||||
for (i = 0; i < histogram_image_size; ++i) {
|
for (i = 0; i < histogram_image_size; ++i) {
|
||||||
HuffmanTreeCode* const codes = &huffman_codes[5 * i];
|
HuffmanTreeCode* const codes = &huffman_codes[5 * i];
|
||||||
VP8LHistogram* const histo = histogram_image->histograms[i];
|
VP8LHistogram* const histo = histogram_image->histograms[i];
|
||||||
VP8LCreateHuffmanTree(histo->literal_, 15, buf_rle, huff_tree, codes + 0);
|
VP8LCreateHuffmanTree(histo->literal, 15, buf_rle, huff_tree, codes + 0);
|
||||||
VP8LCreateHuffmanTree(histo->red_, 15, buf_rle, huff_tree, codes + 1);
|
VP8LCreateHuffmanTree(histo->red, 15, buf_rle, huff_tree, codes + 1);
|
||||||
VP8LCreateHuffmanTree(histo->blue_, 15, buf_rle, huff_tree, codes + 2);
|
VP8LCreateHuffmanTree(histo->blue, 15, buf_rle, huff_tree, codes + 2);
|
||||||
VP8LCreateHuffmanTree(histo->alpha_, 15, buf_rle, huff_tree, codes + 3);
|
VP8LCreateHuffmanTree(histo->alpha, 15, buf_rle, huff_tree, codes + 3);
|
||||||
VP8LCreateHuffmanTree(histo->distance_, 15, buf_rle, huff_tree, codes + 4);
|
VP8LCreateHuffmanTree(histo->distance, 15, buf_rle, huff_tree, codes + 4);
|
||||||
}
|
}
|
||||||
ok = 1;
|
ok = 1;
|
||||||
End:
|
End:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user