summaryrefslogtreecommitdiffstats
path: root/third_party/libwebp/enc/analysis.c
diff options
context:
space:
mode:
authorjzern@chromium.org <jzern@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 22:25:42 +0000
committerjzern@chromium.org <jzern@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 22:25:42 +0000
commitb7afef7463d25d0a6c366760ee507e62e4c052bd (patch)
tree85c318db49dfdb548cbb16a2e32f0c8d41d4a0cb /third_party/libwebp/enc/analysis.c
parentdd32d8a6f739d059b2965a9b7ba8a6eabe96ecc3 (diff)
downloadchromium_src-b7afef7463d25d0a6c366760ee507e62e4c052bd.zip
chromium_src-b7afef7463d25d0a6c366760ee507e62e4c052bd.tar.gz
chromium_src-b7afef7463d25d0a6c366760ee507e62e4c052bd.tar.bz2
libwebp: update snapshot to v0.1.3
adds sse2 optimizations for the encoder & decoder. BUG=108376 TEST=webkit layout tests Review URL: http://codereview.chromium.org/8529002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libwebp/enc/analysis.c')
-rw-r--r--third_party/libwebp/enc/analysis.c77
1 files changed, 19 insertions, 58 deletions
diff --git a/third_party/libwebp/enc/analysis.c b/third_party/libwebp/enc/analysis.c
index 41e12e8..c6609f8 100644
--- a/third_party/libwebp/enc/analysis.c
+++ b/third_party/libwebp/enc/analysis.c
@@ -20,52 +20,13 @@
extern "C" {
#endif
-#define MAX_COEFF_THRESH 64
#define MAX_ITERS_K_MEANS 6
-//-----------------------------------------------------------------------------
-// Compute susceptibility based on DCT-coeff histograms:
-// the higher, the "easier" the macroblock is to compress.
-
static int ClipAlpha(int alpha) {
return alpha < 0 ? 0 : alpha > 255 ? 255 : alpha;
}
-static int GetAlpha(const int histo[MAX_COEFF_THRESH]) {
- int num = 0, den = 0, val = 0;
- int k;
- int alpha;
- for (k = 0; k < MAX_COEFF_THRESH; ++k) {
- if (histo[k]) {
- val += histo[k];
- num += val * (k + 1);
- den += (k + 1) * (k + 1);
- }
- }
- // we scale the value to a usable [0..255] range
- alpha = den ? 10 * num / den - 5 : 0;
- return ClipAlpha(alpha);
-}
-
-static int CollectHistogram(const uint8_t* ref, const uint8_t* pred,
- int start_block, int end_block) {
- int histo[MAX_COEFF_THRESH] = { 0 };
- int16_t out[16];
- int j, k;
- for (j = start_block; j < end_block; ++j) {
- VP8FTransform(ref + VP8Scan[j], pred + VP8Scan[j], out);
- for (k = 0; k < 16; ++k) {
- const int v = abs(out[k]) >> 2;
- if (v) {
- const int bin = (v > MAX_COEFF_THRESH) ? MAX_COEFF_THRESH : v;
- histo[bin - 1]++;
- }
- }
- }
- return GetAlpha(histo);
-}
-
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Smooth the segment map by replacing isolated block by the majority of its
// neighbours.
@@ -86,11 +47,11 @@ static void SmoothSegmentMap(VP8Encoder* const enc) {
cnt[mb[-w - 1].segment_]++; // top-left
cnt[mb[-w + 0].segment_]++; // top
cnt[mb[-w + 1].segment_]++; // top-right
- cnt[mb[ - 1].segment_]++; // left
- cnt[mb[ + 1].segment_]++; // right
- cnt[mb[ w - 1].segment_]++; // bottom-left
- cnt[mb[ w + 0].segment_]++; // bottom
- cnt[mb[ w + 1].segment_]++; // bottom-right
+ cnt[mb[ - 1].segment_]++; // left
+ cnt[mb[ + 1].segment_]++; // right
+ cnt[mb[ w - 1].segment_]++; // bottom-left
+ cnt[mb[ w + 0].segment_]++; // bottom
+ cnt[mb[ w + 1].segment_]++; // bottom-right
for (n = 0; n < NUM_MB_SEGMENTS; ++n) {
if (cnt[n] >= majority_cnt_3_x_3_grid) {
majority_seg = n;
@@ -108,7 +69,7 @@ static void SmoothSegmentMap(VP8Encoder* const enc) {
free(tmp);
}
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Finalize Segment probability based on the coding tree
static int GetProba(int a, int b) {
@@ -178,7 +139,7 @@ static void SetSegmentAlphas(VP8Encoder* const enc,
}
}
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Simplified k-Means, to assign Nb segments based on alpha-histogram
static void AssignSegments(VP8Encoder* const enc, const int alphas[256]) {
@@ -259,7 +220,7 @@ static void AssignSegments(VP8Encoder* const enc, const int alphas[256]) {
SetSegmentAlphas(enc, centers, weighted_average); // pick some alphas.
}
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Macroblock analysis: collect histogram for each mode, deduce the maximal
// susceptibility and set best modes for this macroblock.
// Segment assignment is done later.
@@ -278,9 +239,9 @@ static int MBAnalyzeBestIntra16Mode(VP8EncIterator* const it) {
VP8MakeLuma16Preds(it);
for (mode = 0; mode < max_mode; ++mode) {
- const int alpha = CollectHistogram(it->yuv_in_ + Y_OFF,
- it->yuv_p_ + VP8I16ModeOffsets[mode],
- 0, 16);
+ const int alpha = VP8CollectHistogram(it->yuv_in_ + Y_OFF,
+ it->yuv_p_ + VP8I16ModeOffsets[mode],
+ 0, 16);
if (alpha > best_alpha) {
best_alpha = alpha;
best_mode = mode;
@@ -303,9 +264,9 @@ static int MBAnalyzeBestIntra4Mode(VP8EncIterator* const it,
VP8MakeIntra4Preds(it);
for (mode = 0; mode < max_mode; ++mode) {
- const int alpha = CollectHistogram(src,
- it->yuv_p_ + VP8I4ModeOffsets[mode],
- 0, 1);
+ const int alpha = VP8CollectHistogram(src,
+ it->yuv_p_ + VP8I4ModeOffsets[mode],
+ 0, 1);
if (alpha > best_mode_alpha) {
best_mode_alpha = alpha;
modes[it->i4_] = mode;
@@ -329,9 +290,9 @@ static int MBAnalyzeBestUVMode(VP8EncIterator* const it) {
int mode;
VP8MakeChroma8Preds(it);
for (mode = 0; mode < max_mode; ++mode) {
- const int alpha = CollectHistogram(it->yuv_in_ + U_OFF,
- it->yuv_p_ + VP8UVModeOffsets[mode],
- 16, 16 + 4 + 4);
+ const int alpha = VP8CollectHistogram(it->yuv_in_ + U_OFF,
+ it->yuv_p_ + VP8UVModeOffsets[mode],
+ 16, 16 + 4 + 4);
if (alpha > best_alpha) {
best_alpha = alpha;
best_mode = mode;
@@ -367,7 +328,7 @@ static void MBAnalyze(VP8EncIterator* const it,
it->mb_->alpha_ = best_alpha; // Informative only.
}
-//-----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Main analysis loop:
// Collect all susceptibilities for each macroblock and record their
// distribution in alphas[]. Segments is assigned a-posteriori, based on