mirror of
https://github.com/webmproject/libwebp.git
synced 2025-01-27 15:12:54 +01:00
Fix few nits
Add/remove few casts, fixed indentation. Change-Id: Icd141694201843c04e476f09142ce4be6e502dff
This commit is contained in:
parent
fef22704ec
commit
1c58526fe1
@ -541,26 +541,25 @@ static const PredictorFunc kPredictors[16] = {
|
||||
Predictor0, Predictor0 // <- padding security sentinels
|
||||
};
|
||||
|
||||
static float PredictionCostSpatial(const int* const counts, int weight_0,
|
||||
double exp_val, int n) {
|
||||
const int significant_symbols = n >> 4;
|
||||
static float PredictionCostSpatial(const int counts[256], int weight_0,
|
||||
double exp_val) {
|
||||
const int significant_symbols = 256 >> 4;
|
||||
const double exp_decay_factor = 0.6;
|
||||
double bits = weight_0 * counts[0];
|
||||
int i;
|
||||
for (i = 1; i < significant_symbols; ++i) {
|
||||
bits += exp_val * (counts[i] + counts[n - i]);
|
||||
bits += exp_val * (counts[i] + counts[256 - i]);
|
||||
exp_val *= exp_decay_factor;
|
||||
}
|
||||
return (float)(-0.1 * bits);
|
||||
}
|
||||
|
||||
// Compute the combined Shanon's entropy for distribution {X} and {X+Y}
|
||||
static float CombinedShannonEntropy(const int* const X,
|
||||
const int* const Y, int n) {
|
||||
static float CombinedShannonEntropy(const int X[256], const int Y[256]) {
|
||||
int i;
|
||||
double retval = 0.;
|
||||
int sumX = 0, sumXY = 0;
|
||||
for (i = 0; i < n; ++i) {
|
||||
for (i = 0; i < 256; ++i) {
|
||||
const int x = X[i];
|
||||
const int xy = x + Y[i];
|
||||
if (x != 0) {
|
||||
@ -583,8 +582,8 @@ static float PredictionCostSpatialHistogram(const int accumulated[4][256],
|
||||
double retval = 0;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
const double kExpValue = 0.94;
|
||||
retval += PredictionCostSpatial(tile[i], 1, kExpValue, 256);
|
||||
retval += CombinedShannonEntropy(tile[i], accumulated[i], 256);
|
||||
retval += PredictionCostSpatial(tile[i], 1, kExpValue);
|
||||
retval += CombinedShannonEntropy(tile[i], accumulated[i]);
|
||||
}
|
||||
return (float)retval;
|
||||
}
|
||||
@ -766,7 +765,7 @@ static void PredictorInverseTransform(const VP8LTransform* const transform,
|
||||
AddPixelsEq(data, pred2);
|
||||
// .. the rest:
|
||||
while (x < safe_width) {
|
||||
pred_func = kPredictors[((*pred_mode_src++) >> 8) & 0xf];
|
||||
pred_func = kPredictors[((*pred_mode_src++) >> 8) & 0xf];
|
||||
for (; t < tile_width; ++t, ++x) {
|
||||
const uint32_t pred = pred_func(data[x - 1], data + x - width);
|
||||
AddPixelsEq(data + x, pred);
|
||||
@ -839,7 +838,7 @@ static WEBP_INLINE void ColorCodeToMultipliers(uint32_t color_code,
|
||||
m->red_to_blue_ = (color_code >> 16) & 0xff;
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t MultipliersToColorCode(Multipliers* const m) {
|
||||
static WEBP_INLINE uint32_t MultipliersToColorCode(const Multipliers* const m) {
|
||||
return 0xff000000u |
|
||||
((uint32_t)(m->red_to_blue_) << 16) |
|
||||
((uint32_t)(m->green_to_blue_) << 8) |
|
||||
@ -852,13 +851,13 @@ static WEBP_INLINE uint32_t TransformColor(const Multipliers* const m,
|
||||
const uint32_t red = argb >> 16;
|
||||
uint32_t new_red = red;
|
||||
uint32_t new_blue = argb;
|
||||
new_red -= ColorTransformDelta(m->green_to_red_, green);
|
||||
new_red &= 0xff;
|
||||
new_blue -= ColorTransformDelta(m->green_to_blue_, green);
|
||||
new_blue -= ColorTransformDelta(m->red_to_blue_, red);
|
||||
new_blue &= 0xff;
|
||||
new_red -= ColorTransformDelta(m->green_to_red_, green);
|
||||
new_red &= 0xff;
|
||||
new_blue -= ColorTransformDelta(m->green_to_blue_, green);
|
||||
new_blue -= ColorTransformDelta(m->red_to_blue_, red);
|
||||
new_blue &= 0xff;
|
||||
return (argb & 0xff00ff00u) | (new_red << 16) | (new_blue);
|
||||
}
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t TransformColorInverse(const Multipliers* const m,
|
||||
uint32_t argb) {
|
||||
@ -917,8 +916,8 @@ static float PredictionCostCrossColor(const int accumulated[256],
|
||||
// Favor low entropy, locally and globally.
|
||||
// Favor small absolute values for PredictionCostSpatial
|
||||
static const double kExpValue = 2.4;
|
||||
return CombinedShannonEntropy(counts, accumulated, 256) +
|
||||
PredictionCostSpatial(counts, 3, kExpValue, 256);
|
||||
return CombinedShannonEntropy(counts, accumulated) +
|
||||
PredictionCostSpatial(counts, 3, kExpValue);
|
||||
}
|
||||
|
||||
static float GetPredictionCostCrossColorRed(
|
||||
@ -1630,4 +1629,3 @@ void VP8LDspInit(void) {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -455,7 +455,7 @@ static int GetHistoBinIndex(
|
||||
return bin_id;
|
||||
}
|
||||
|
||||
// Construct the Histogram from backward references.
|
||||
// Construct the histograms from backward references.
|
||||
static void HistogramBuild(
|
||||
int xsize, int histo_bits, const VP8LBackwardRefs* const backward_refs,
|
||||
VP8LHistogramSet* const init_histo) {
|
||||
@ -499,35 +499,33 @@ static void HistogramAnalyzeBin(
|
||||
int i;
|
||||
const int histo_size = init_histo->size;
|
||||
VP8LHistogram** const histograms = init_histo->histograms;
|
||||
if (bin_map != NULL) {
|
||||
const int bin_depth = init_histo->size + 1;
|
||||
DominantCostRange cost_range;
|
||||
DominantCostRangeInit(&cost_range);
|
||||
const int bin_depth = init_histo->size + 1;
|
||||
DominantCostRange cost_range;
|
||||
DominantCostRangeInit(&cost_range);
|
||||
|
||||
// Analyze the dominant (literal, red and blue) entropy costs.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
VP8LHistogram* const histo = histograms[i];
|
||||
UpdateHistogramCost(histo);
|
||||
// Copy histograms from init_histo[] to histo_image[].
|
||||
*histo_image->histograms[i] = *histo;
|
||||
UpdateDominantCostRange(histo, &cost_range);
|
||||
}
|
||||
// Analyze the dominant (literal, red and blue) entropy costs.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
VP8LHistogram* const histo = histograms[i];
|
||||
UpdateHistogramCost(histo);
|
||||
// Copy histograms from init_histo[] to histo_image[].
|
||||
*histo_image->histograms[i] = *histo;
|
||||
UpdateDominantCostRange(histo, &cost_range);
|
||||
}
|
||||
|
||||
// bin-hash histograms on three of the dominant (literal, red and blue)
|
||||
// symbol costs.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
int num_histos;
|
||||
VP8LHistogram* const histo = histograms[i];
|
||||
const int16_t bin_id = (int16_t)GetHistoBinIndex(histo, &cost_range);
|
||||
const int bin_offset = bin_id * bin_depth;
|
||||
// bin_map[n][0] for every bin 'n' maintains the counter for the number of
|
||||
// histograms in that bin.
|
||||
// Get and increment the num_histos in that bin.
|
||||
num_histos = ++bin_map[bin_offset];
|
||||
assert(bin_offset + num_histos < bin_depth * BIN_SIZE);
|
||||
// Add Histogram i'th index at num_histos (last) position in the bin_map.
|
||||
bin_map[bin_offset + num_histos] = i;
|
||||
}
|
||||
// bin-hash histograms on three of the dominant (literal, red and blue)
|
||||
// symbol costs.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
int num_histos;
|
||||
VP8LHistogram* const histo = histograms[i];
|
||||
const int16_t bin_id = (int16_t)GetHistoBinIndex(histo, &cost_range);
|
||||
const int bin_offset = bin_id * bin_depth;
|
||||
// bin_map[n][0] for every bin 'n' maintains the counter for the number of
|
||||
// histograms in that bin.
|
||||
// Get and increment the num_histos in that bin.
|
||||
num_histos = ++bin_map[bin_offset];
|
||||
assert(bin_offset + num_histos < bin_depth * BIN_SIZE);
|
||||
// Add histogram i'th index at num_histos (last) position in the bin_map.
|
||||
bin_map[bin_offset + num_histos] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,7 +563,6 @@ static void HistogramCombineBin(VP8LHistogramSet* const histo_image,
|
||||
VP8LHistogram* const histos,
|
||||
int bin_depth,
|
||||
int16_t* const bin_map) {
|
||||
int i;
|
||||
int bin_id;
|
||||
VP8LHistogram* cur_combo = histos;
|
||||
|
||||
@ -573,8 +570,9 @@ static void HistogramCombineBin(VP8LHistogramSet* const histo_image,
|
||||
const int bin_offset = bin_id * bin_depth;
|
||||
const int num_histos = bin_map[bin_offset];
|
||||
const int idx1 = bin_map[bin_offset + 1];
|
||||
for (i = 2; i <= num_histos; ++i) {
|
||||
const int idx2 = bin_map[bin_offset + i];
|
||||
int n;
|
||||
for (n = 2; n <= num_histos; ++n) {
|
||||
const int idx2 = bin_map[bin_offset + n];
|
||||
const double bit_cost_idx2 = histo_image->histograms[idx2]->bit_cost_;
|
||||
if (bit_cost_idx2 > 0.) {
|
||||
const double bit_cost_thresh = -bit_cost_idx2 * 0.1;
|
||||
@ -742,17 +740,13 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
if (bin_map == NULL) goto Error;
|
||||
}
|
||||
|
||||
// Construct the Histogram from backward references.
|
||||
// Construct the histogram from backward references.
|
||||
HistogramBuild(xsize, histo_bits, refs, init_histo);
|
||||
|
||||
if (bin_map != NULL) {
|
||||
// Partition Histograms to different entropy bins for three dominant
|
||||
// (literal red and blue) symbol costs and compute the histogram aggregate
|
||||
// bit_cost.
|
||||
HistogramAnalyzeBin(init_histo, histo_image, bin_map);
|
||||
HistogramCombineBin(histo_image, histos, bin_depth, bin_map);
|
||||
} else {
|
||||
// Compute the histogram aggregate bit_cost.
|
||||
HistogramAnalyze(init_histo, histo_image);
|
||||
}
|
||||
|
||||
@ -764,7 +758,7 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
Error:
|
||||
free(bin_map);
|
||||
free(init_histo);
|
||||
free(histos);
|
||||
|
@ -39,7 +39,7 @@ typedef struct {
|
||||
// Backward reference prefix-code histogram.
|
||||
int distance_[NUM_DISTANCE_CODES];
|
||||
int palette_code_bits_;
|
||||
double bit_cost_; // cached value of VP8LHistogramEstimateBits(this)
|
||||
double bit_cost_; // cached value of VP8LHistogramEstimateBits(this)
|
||||
double literal_cost_; // Cached values of dominant entropy costs:
|
||||
double red_cost_; // literal, red & blue.
|
||||
double blue_cost_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user