mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
Move some more defines to format_constants.h
Also remove some duplicate const/defines. Change-Id: I0ec48866b874f546022d72e938fb65669b0b3211
This commit is contained in:
parent
c13f663261
commit
e75dc80516
@ -17,6 +17,7 @@
|
||||
#include "./backward_references.h"
|
||||
#include "./histogram.h"
|
||||
#include "../utils/color_cache.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
#define VALUES_IN_BYTE 256
|
||||
|
||||
@ -306,7 +307,7 @@ typedef struct {
|
||||
double red_[VALUES_IN_BYTE];
|
||||
double literal_[PIX_OR_COPY_CODES_MAX];
|
||||
double blue_[VALUES_IN_BYTE];
|
||||
double distance_[DISTANCE_CODES_MAX];
|
||||
double distance_[NUM_DISTANCE_CODES];
|
||||
int cache_bits_;
|
||||
} CostModel;
|
||||
|
||||
@ -347,7 +348,7 @@ static int CostModelBuild(CostModel* const p, int xsize, int ysize,
|
||||
VP8LConvertPopulationCountTableToBitEstimates(
|
||||
VALUES_IN_BYTE, &histo.alpha_[0], &p->alpha_[0]);
|
||||
VP8LConvertPopulationCountTableToBitEstimates(
|
||||
DISTANCE_CODES_MAX, &histo.distance_[0], &p->distance_[0]);
|
||||
NUM_DISTANCE_CODES, &histo.distance_[0], &p->distance_[0]);
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
@ -363,7 +364,7 @@ static WEBP_INLINE double GetLiteralCost(const CostModel* const p, uint32_t v) {
|
||||
}
|
||||
|
||||
static WEBP_INLINE double GetCacheCost(const CostModel* const p, uint32_t idx) {
|
||||
const int literal_idx = VALUES_IN_BYTE + kLengthCodes + idx;
|
||||
const int literal_idx = VALUES_IN_BYTE + NUM_LENGTH_CODES + idx;
|
||||
return p->literal_[literal_idx];
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Backward reference distance prefix codes
|
||||
#define DISTANCE_CODES_MAX 40
|
||||
|
||||
// Compression constants
|
||||
#define CODE_LENGTH_CODES 19
|
||||
static const int kLengthCodes = 24;
|
||||
// The spec allows 11, we use 9 bits to reduce memory consumption in encoding.
|
||||
// Having 9 instead of 11 removes about 0.25 % of compression density.
|
||||
static const int kColorCacheBitsMax = 9;
|
||||
|
@ -106,7 +106,7 @@ void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const p,
|
||||
++p->literal_[PixOrCopyLiteral(v, 1)];
|
||||
++p->blue_[PixOrCopyLiteral(v, 0)];
|
||||
} else if (PixOrCopyIsCacheIdx(v)) {
|
||||
int literal_ix = 256 + kLengthCodes + PixOrCopyCacheIdx(v);
|
||||
int literal_ix = 256 + NUM_LENGTH_CODES + PixOrCopyCacheIdx(v);
|
||||
++p->literal_[literal_ix];
|
||||
} else {
|
||||
int code, extra_bits_count, extra_bits_value;
|
||||
@ -176,14 +176,14 @@ double VP8LHistogramEstimateBitsBulk(const VP8LHistogram* const p) {
|
||||
BitsEntropy(&p->red_[0], 256) +
|
||||
BitsEntropy(&p->blue_[0], 256) +
|
||||
BitsEntropy(&p->alpha_[0], 256) +
|
||||
BitsEntropy(&p->distance_[0], DISTANCE_CODES_MAX);
|
||||
BitsEntropy(&p->distance_[0], NUM_DISTANCE_CODES);
|
||||
// Compute the extra bits cost.
|
||||
int i;
|
||||
for (i = 2; i < kLengthCodes - 2; ++i) {
|
||||
for (i = 2; i < NUM_LENGTH_CODES - 2; ++i) {
|
||||
retval +=
|
||||
(i >> 1) * p->literal_[256 + i + 2];
|
||||
}
|
||||
for (i = 2; i < DISTANCE_CODES_MAX - 2; ++i) {
|
||||
for (i = 2; i < NUM_DISTANCE_CODES - 2; ++i) {
|
||||
retval += (i >> 1) * p->distance_[i + 2];
|
||||
}
|
||||
return retval;
|
||||
@ -237,7 +237,7 @@ double VP8LHistogramEstimateBitsHeader(const VP8LHistogram* const p) {
|
||||
HuffmanCost(&p->red_[0], 256) +
|
||||
HuffmanCost(&p->literal_[0], VP8LHistogramNumCodes(p)) +
|
||||
HuffmanCost(&p->blue_[0], 256) +
|
||||
HuffmanCost(&p->distance_[0], DISTANCE_CODES_MAX);
|
||||
HuffmanCost(&p->distance_[0], NUM_DISTANCE_CODES);
|
||||
}
|
||||
|
||||
static void HistogramBuildImage(int xsize, int histo_bits,
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "./backward_references.h"
|
||||
#include "../webp/format_constants.h"
|
||||
#include "../webp/types.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
@ -36,7 +37,7 @@ typedef struct {
|
||||
int blue_[256];
|
||||
int alpha_[256];
|
||||
// Backward reference prefix-code histogram.
|
||||
int distance_[DISTANCE_CODES_MAX];
|
||||
int distance_[NUM_DISTANCE_CODES];
|
||||
int palette_code_bits_;
|
||||
double bit_cost_; // cached value of VP8LHistogramEstimateBits(this)
|
||||
} VP8LHistogram;
|
||||
@ -86,7 +87,7 @@ static WEBP_INLINE void VP8LHistogramAdd(VP8LHistogram* const p,
|
||||
for (i = 0; i < PIX_OR_COPY_CODES_MAX; ++i) {
|
||||
p->literal_[i] += a->literal_[i];
|
||||
}
|
||||
for (i = 0; i < DISTANCE_CODES_MAX; ++i) {
|
||||
for (i = 0; i < NUM_DISTANCE_CODES; ++i) {
|
||||
p->distance_[i] += a->distance_[i];
|
||||
}
|
||||
for (i = 0; i < 256; ++i) {
|
||||
@ -103,7 +104,7 @@ static WEBP_INLINE void VP8LHistogramRemove(VP8LHistogram* const p,
|
||||
p->literal_[i] -= a->literal_[i];
|
||||
assert(p->literal_[i] >= 0);
|
||||
}
|
||||
for (i = 0; i < DISTANCE_CODES_MAX; ++i) {
|
||||
for (i = 0; i < NUM_DISTANCE_CODES; ++i) {
|
||||
p->distance_[i] -= a->distance_[i];
|
||||
assert(p->distance_[i] >= 0);
|
||||
}
|
||||
@ -118,7 +119,7 @@ static WEBP_INLINE void VP8LHistogramRemove(VP8LHistogram* const p,
|
||||
}
|
||||
|
||||
static WEBP_INLINE int VP8LHistogramNumCodes(const VP8LHistogram* const p) {
|
||||
return 256 + kLengthCodes +
|
||||
return 256 + NUM_LENGTH_CODES +
|
||||
((p->palette_code_bits_ > 0) ? (1 << p->palette_code_bits_) : 0);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "../dsp/lossless.h"
|
||||
#include "../utils/bit_writer.h"
|
||||
#include "../utils/huffman_encode.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
@ -163,7 +164,7 @@ static int GetHuffBitLengthsAndCodes(
|
||||
HuffmanTreeCode* const codes = &huffman_codes[5 * i];
|
||||
for (k = 0; k < 5; ++k) {
|
||||
const int num_symbols = (k == 0) ? VP8LHistogramNumCodes(histo)
|
||||
: (k == 4) ? DISTANCE_CODES_MAX
|
||||
: (k == 4) ? NUM_DISTANCE_CODES
|
||||
: 256;
|
||||
codes[k].num_symbols = num_symbols;
|
||||
total_length_size += num_symbols;
|
||||
@ -402,7 +403,7 @@ static void StoreImageToBitMask(
|
||||
const HuffmanTreeCode* const codes = huffman_codes + 5 * histogram_ix;
|
||||
if (PixOrCopyIsCacheIdx(v)) {
|
||||
const int code = PixOrCopyCacheIdx(v);
|
||||
const int literal_ix = 256 + kLengthCodes + code;
|
||||
const int literal_ix = 256 + NUM_LENGTH_CODES + code;
|
||||
WriteHuffmanCode(bw, codes, literal_ix);
|
||||
} else if (PixOrCopyIsLiteral(v)) {
|
||||
static const int order[] = { 1, 2, 0, 3 };
|
||||
|
@ -12,12 +12,12 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "./huffman.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_ALLOWED_CODE_LENGTH 15
|
||||
#define NON_EXISTENT_SYMBOL (-1)
|
||||
|
||||
static void TreeNodeInit(HuffmanTreeNode* const node) {
|
||||
|
@ -11,14 +11,12 @@
|
||||
|
||||
#ifdef USE_LOSSLESS_ENCODER
|
||||
|
||||
#include "./huffman_encode.h"
|
||||
|
||||
#define MAX_BITS 16 // maximum allowed length for the codes
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "./huffman_encode.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Util function to optimize the symbol map for RLE coding
|
||||
@ -285,7 +283,7 @@ static int GenerateOptimalTree(const int* const histogram, int histogram_size,
|
||||
static HuffmanTreeToken* CodeRepeatedValues(int repetitions,
|
||||
HuffmanTreeToken* tokens,
|
||||
int value, int prev_value) {
|
||||
assert(value < MAX_BITS);
|
||||
assert(value <= MAX_ALLOWED_CODE_LENGTH);
|
||||
if (value != prev_value) {
|
||||
tokens->code = value;
|
||||
tokens->extra_bits = 0;
|
||||
@ -387,10 +385,10 @@ static uint32_t ReverseBits(int num_bits, uint32_t bits) {
|
||||
int i = 0;
|
||||
while (i < num_bits) {
|
||||
i += 4;
|
||||
retval |= kReversedBits[bits & 0xf] << (MAX_BITS - i);
|
||||
retval |= kReversedBits[bits & 0xf] << (MAX_ALLOWED_CODE_LENGTH + 1 - i);
|
||||
bits >>= 4;
|
||||
}
|
||||
retval >>= (MAX_BITS - num_bits);
|
||||
retval >>= (MAX_ALLOWED_CODE_LENGTH + 1 - num_bits);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -399,21 +397,21 @@ static void ConvertBitDepthsToSymbols(HuffmanTreeCode* const tree) {
|
||||
// 0 bit-depth means that the symbol does not exist.
|
||||
int i;
|
||||
int len;
|
||||
uint32_t next_code[MAX_BITS];
|
||||
int depth_count[MAX_BITS] = { 0 };
|
||||
uint32_t next_code[MAX_ALLOWED_CODE_LENGTH + 1];
|
||||
int depth_count[MAX_ALLOWED_CODE_LENGTH + 1] = { 0 };
|
||||
|
||||
assert(tree != NULL);
|
||||
len = tree->num_symbols;
|
||||
for (i = 0; i < len; ++i) {
|
||||
const int code_length = tree->code_lengths[i];
|
||||
assert(code_length < MAX_BITS);
|
||||
assert(code_length <= MAX_ALLOWED_CODE_LENGTH);
|
||||
++depth_count[code_length];
|
||||
}
|
||||
depth_count[0] = 0; // ignore unused symbol
|
||||
next_code[0] = 0;
|
||||
{
|
||||
uint32_t code = 0;
|
||||
for (i = 1; i < MAX_BITS; ++i) {
|
||||
for (i = 1; i <= MAX_ALLOWED_CODE_LENGTH; ++i) {
|
||||
code = (code + depth_count[i - 1]) << 1;
|
||||
next_code[i] = code;
|
||||
}
|
||||
|
@ -29,11 +29,14 @@
|
||||
#define MAX_CACHE_BITS 11
|
||||
#define HUFFMAN_CODES_PER_META_CODE 5
|
||||
#define ARGB_BLACK 0xff000000
|
||||
|
||||
#define DEFAULT_CODE_LENGTH 8
|
||||
#define MAX_ALLOWED_CODE_LENGTH 15
|
||||
|
||||
#define NUM_LITERAL_CODES 256
|
||||
#define NUM_LENGTH_CODES 24
|
||||
#define NUM_DISTANCE_CODES 40
|
||||
#define CODE_LENGTH_CODES 19
|
||||
|
||||
#define TRANSFORM_PRESENT 1 // The bit to be written when next data
|
||||
// to be read is a transform.
|
||||
|
Loading…
Reference in New Issue
Block a user