Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/libwebp/enc/cost.c

Issue 2584033003: libwebp-0.5.2-rc2 (Closed)
Patch Set: layout tests Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source 4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Cost tables for level and modes 10 // Cost tables for level and modes
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 } 275 }
276 } 276 }
277 return R; 277 return R;
278 } 278 }
279 279
280 280
281 //------------------------------------------------------------------------------ 281 //------------------------------------------------------------------------------
282 // Recording of token probabilities. 282 // Recording of token probabilities.
283 283
284 // Record proba context used
285 static int Record(int bit, proba_t* const stats) {
286 proba_t p = *stats;
287 if (p >= 0xffff0000u) { // an overflow is inbound.
288 p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2.
289 }
290 // record bit count (lower 16 bits) and increment total count (upper 16 bits).
291 p += 0x00010000u + bit;
292 *stats = p;
293 return bit;
294 }
295
296 // We keep the table-free variant around for reference, in case. 284 // We keep the table-free variant around for reference, in case.
297 #define USE_LEVEL_CODE_TABLE 285 #define USE_LEVEL_CODE_TABLE
298 286
299 // Simulate block coding, but only record statistics. 287 // Simulate block coding, but only record statistics.
300 // Note: no need to record the fixed probas. 288 // Note: no need to record the fixed probas.
301 int VP8RecordCoeffs(int ctx, const VP8Residual* const res) { 289 int VP8RecordCoeffs(int ctx, const VP8Residual* const res) {
302 int n = res->first; 290 int n = res->first;
303 // should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1 291 // should be stats[VP8EncBands[n]], but it's equivalent for n=0 or 1
304 proba_t* s = res->stats[n][ctx]; 292 proba_t* s = res->stats[n][ctx];
305 if (res->last < 0) { 293 if (res->last < 0) {
306 Record(0, s + 0); 294 VP8RecordStats(0, s + 0);
307 return 0; 295 return 0;
308 } 296 }
309 while (n <= res->last) { 297 while (n <= res->last) {
310 int v; 298 int v;
311 Record(1, s + 0); // order of record doesn't matter 299 VP8RecordStats(1, s + 0); // order of record doesn't matter
312 while ((v = res->coeffs[n++]) == 0) { 300 while ((v = res->coeffs[n++]) == 0) {
313 Record(0, s + 1); 301 VP8RecordStats(0, s + 1);
314 s = res->stats[VP8EncBands[n]][0]; 302 s = res->stats[VP8EncBands[n]][0];
315 } 303 }
316 Record(1, s + 1); 304 VP8RecordStats(1, s + 1);
317 if (!Record(2u < (unsigned int)(v + 1), s + 2)) { // v = -1 or 1 305 if (!VP8RecordStats(2u < (unsigned int)(v + 1), s + 2)) { // v = -1 or 1
318 s = res->stats[VP8EncBands[n]][1]; 306 s = res->stats[VP8EncBands[n]][1];
319 } else { 307 } else {
320 v = abs(v); 308 v = abs(v);
321 #if !defined(USE_LEVEL_CODE_TABLE) 309 #if !defined(USE_LEVEL_CODE_TABLE)
322 if (!Record(v > 4, s + 3)) { 310 if (!VP8RecordStats(v > 4, s + 3)) {
323 if (Record(v != 2, s + 4)) 311 if (VP8RecordStats(v != 2, s + 4))
324 Record(v == 4, s + 5); 312 VP8RecordStats(v == 4, s + 5);
325 } else if (!Record(v > 10, s + 6)) { 313 } else if (!VP8RecordStats(v > 10, s + 6)) {
326 Record(v > 6, s + 7); 314 VP8RecordStats(v > 6, s + 7);
327 } else if (!Record((v >= 3 + (8 << 2)), s + 8)) { 315 } else if (!VP8RecordStats((v >= 3 + (8 << 2)), s + 8)) {
328 Record((v >= 3 + (8 << 1)), s + 9); 316 VP8RecordStats((v >= 3 + (8 << 1)), s + 9);
329 } else { 317 } else {
330 Record((v >= 3 + (8 << 3)), s + 10); 318 VP8RecordStats((v >= 3 + (8 << 3)), s + 10);
331 } 319 }
332 #else 320 #else
333 if (v > MAX_VARIABLE_LEVEL) { 321 if (v > MAX_VARIABLE_LEVEL) {
334 v = MAX_VARIABLE_LEVEL; 322 v = MAX_VARIABLE_LEVEL;
335 } 323 }
336 324
337 { 325 {
338 const int bits = VP8LevelCodes[v - 1][1]; 326 const int bits = VP8LevelCodes[v - 1][1];
339 int pattern = VP8LevelCodes[v - 1][0]; 327 int pattern = VP8LevelCodes[v - 1][0];
340 int i; 328 int i;
341 for (i = 0; (pattern >>= 1) != 0; ++i) { 329 for (i = 0; (pattern >>= 1) != 0; ++i) {
342 const int mask = 2 << i; 330 const int mask = 2 << i;
343 if (pattern & 1) Record(!!(bits & mask), s + 3 + i); 331 if (pattern & 1) VP8RecordStats(!!(bits & mask), s + 3 + i);
344 } 332 }
345 } 333 }
346 #endif 334 #endif
347 s = res->stats[VP8EncBands[n]][2]; 335 s = res->stats[VP8EncBands[n]][2];
348 } 336 }
349 } 337 }
350 if (n < 16) Record(0, s + 0); 338 if (n < 16) VP8RecordStats(0, s + 0);
351 return 1; 339 return 1;
352 } 340 }
353 341
354 //------------------------------------------------------------------------------ 342 //------------------------------------------------------------------------------
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698