mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 21:39:59 +02:00
Unify some entropy functions.
The code and logic is unified when computing bit entropy + Huffman cost. Speed-wise, we gain 8% for lossless encoding. Logic-wise, the beginning/end of the distributions are handled properly and the compression ratio does not change much. Change-Id: Ifa91d7d3e667c9a9a421faec4e845ecb6479a633
This commit is contained in:
@ -217,51 +217,31 @@ static double ExtraCostCombined(const uint32_t* const X,
|
||||
);
|
||||
|
||||
// Returns the various RLE counts
|
||||
static VP8LStreaks HuffmanCostCount(const uint32_t* population, int length) {
|
||||
int i;
|
||||
int streak = 0;
|
||||
VP8LStreaks stats;
|
||||
int* const pstreaks = &stats.streaks[0][0];
|
||||
int* const pcnts = &stats.counts[0];
|
||||
static WEBP_INLINE void GetEntropyUnrefinedHelper(
|
||||
uint32_t val, int i, uint32_t* const val_prev, int* const i_prev,
|
||||
VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats) {
|
||||
int* const pstreaks = &stats->streaks[0][0];
|
||||
int* const pcnts = &stats->counts[0];
|
||||
int temp0, temp1, temp2, temp3;
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
for (i = 0; i < length - 1; ++i) {
|
||||
++streak;
|
||||
if (population[i] == population[i + 1]) {
|
||||
continue;
|
||||
const int streak = i - *i_prev;
|
||||
|
||||
// Gather info for the bit entropy.
|
||||
if (*val_prev != 0) {
|
||||
bit_entropy->sum += (*val_prev) * streak;
|
||||
bit_entropy->nonzeros += streak;
|
||||
bit_entropy->nonzero_code = *i_prev;
|
||||
bit_entropy->entropy -= VP8LFastSLog2(*val_prev) * streak;
|
||||
if (bit_entropy->max_val < *val_prev) {
|
||||
bit_entropy->max_val = *val_prev;
|
||||
}
|
||||
temp0 = (population[i] != 0);
|
||||
HUFFMAN_COST_PASS
|
||||
streak = 0;
|
||||
}
|
||||
++streak;
|
||||
temp0 = (population[i] != 0);
|
||||
|
||||
// Gather info for the Huffman cost.
|
||||
temp0 = (*val_prev != 0);
|
||||
HUFFMAN_COST_PASS
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
static VP8LStreaks HuffmanCostCombinedCount(const uint32_t* X,
|
||||
const uint32_t* Y, int length) {
|
||||
int i;
|
||||
int streak = 0;
|
||||
uint32_t xy_prev = 0xffffffff;
|
||||
VP8LStreaks stats;
|
||||
int* const pstreaks = &stats.streaks[0][0];
|
||||
int* const pcnts = &stats.counts[0];
|
||||
int temp0, temp1, temp2, temp3;
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
for (i = 0; i < length; ++i) {
|
||||
const uint32_t xy = X[i] + Y[i];
|
||||
++streak;
|
||||
if (xy != xy_prev) {
|
||||
temp0 = (xy != 0);
|
||||
HUFFMAN_COST_PASS
|
||||
streak = 0;
|
||||
xy_prev = xy;
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
*val_prev = val;
|
||||
*i_prev = i;
|
||||
}
|
||||
|
||||
#define ASM_START \
|
||||
@ -399,14 +379,7 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitMIPS32(void) {
|
||||
VP8LFastLog2Slow = FastLog2Slow;
|
||||
VP8LExtraCost = ExtraCost;
|
||||
VP8LExtraCostCombined = ExtraCostCombined;
|
||||
VP8LHuffmanCostCount = HuffmanCostCount;
|
||||
// TODO(mips team): rewrite VP8LGetCombinedEntropy (which used to use
|
||||
// HuffmanCostCombinedCount) with MIPS optimizations
|
||||
#if 0
|
||||
VP8LHuffmanCostCombinedCount = HuffmanCostCombinedCount;
|
||||
#else
|
||||
(void)HuffmanCostCombinedCount;
|
||||
#endif
|
||||
VP8LGetEntropyUnrefinedHelper = GetEntropyUnrefinedHelper;
|
||||
VP8LHistogramAdd = HistogramAdd;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user