Move some more defines to format_constants.h

Also remove some duplicate const/defines.

Change-Id: I0ec48866b874f546022d72e938fb65669b0b3211
This commit is contained in:
Urvang Joshi
2012-05-24 17:45:05 +05:30
parent c13f663261
commit e75dc80516
8 changed files with 30 additions and 32 deletions

View File

@ -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];
}

View File

@ -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;

View File

@ -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,

View File

@ -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);
}

View File

@ -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 };