Fix few nits

Add/remove few casts, fixed indentation.

Change-Id: Icd141694201843c04e476f09142ce4be6e502dff
This commit is contained in:
Vikas Arora 2014-03-13 13:56:30 -07:00
parent fef22704ec
commit 1c58526fe1
3 changed files with 50 additions and 58 deletions

View File

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

View File

@ -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,7 +499,6 @@ 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);
@ -525,11 +524,10 @@ static void HistogramAnalyzeBin(
// 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.
// Add histogram i'th index at num_histos (last) position in the bin_map.
bin_map[bin_offset + num_histos] = i;
}
}
}
// Compact the histogram set by moving the valid one left in the set to the
// head and moving the ones that have been merged to other histograms towards
@ -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);
}