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

Side by Side Diff: third_party/libwebp/dec/frame.c

Issue 2149863002: libwebp: update to v0.5.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/libwebp/dec/buffer.c ('k') | third_party/libwebp/dec/idec.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 Google Inc. All Rights Reserved. 1 // Copyright 2010 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 // Frame-reconstruction function. Memory allocation. 10 // Frame-reconstruction function. Memory allocation.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 309 }
310 info->f_inner_ = i4x4; 310 info->f_inner_ = i4x4;
311 } 311 }
312 } 312 }
313 } 313 }
314 } 314 }
315 315
316 //------------------------------------------------------------------------------ 316 //------------------------------------------------------------------------------
317 // Dithering 317 // Dithering
318 318
319 // minimal amp that will provide a non-zero dithering effect
320 #define MIN_DITHER_AMP 4
321
319 #define DITHER_AMP_TAB_SIZE 12 322 #define DITHER_AMP_TAB_SIZE 12
320 static const int kQuantToDitherAmp[DITHER_AMP_TAB_SIZE] = { 323 static const int kQuantToDitherAmp[DITHER_AMP_TAB_SIZE] = {
321 // roughly, it's dqm->uv_mat_[1] 324 // roughly, it's dqm->uv_mat_[1]
322 8, 7, 6, 4, 4, 2, 2, 2, 1, 1, 1, 1 325 8, 7, 6, 4, 4, 2, 2, 2, 1, 1, 1, 1
323 }; 326 };
324 327
325 void VP8InitDithering(const WebPDecoderOptions* const options, 328 void VP8InitDithering(const WebPDecoderOptions* const options,
326 VP8Decoder* const dec) { 329 VP8Decoder* const dec) {
327 assert(dec != NULL); 330 assert(dec != NULL);
328 if (options != NULL) { 331 if (options != NULL) {
(...skipping 20 matching lines...) Expand all
349 // potentially allow alpha dithering 352 // potentially allow alpha dithering
350 dec->alpha_dithering_ = options->alpha_dithering_strength; 353 dec->alpha_dithering_ = options->alpha_dithering_strength;
351 if (dec->alpha_dithering_ > 100) { 354 if (dec->alpha_dithering_ > 100) {
352 dec->alpha_dithering_ = 100; 355 dec->alpha_dithering_ = 100;
353 } else if (dec->alpha_dithering_ < 0) { 356 } else if (dec->alpha_dithering_ < 0) {
354 dec->alpha_dithering_ = 0; 357 dec->alpha_dithering_ = 0;
355 } 358 }
356 } 359 }
357 } 360 }
358 361
359 // minimal amp that will provide a non-zero dithering effect 362 // Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
360 #define MIN_DITHER_AMP 4
361 #define DITHER_DESCALE 4
362 #define DITHER_DESCALE_ROUNDER (1 << (DITHER_DESCALE - 1))
363 #define DITHER_AMP_BITS 8
364 #define DITHER_AMP_CENTER (1 << DITHER_AMP_BITS)
365
366 static void Dither8x8(VP8Random* const rg, uint8_t* dst, int bps, int amp) { 363 static void Dither8x8(VP8Random* const rg, uint8_t* dst, int bps, int amp) {
367 int i, j; 364 uint8_t dither[64];
368 for (j = 0; j < 8; ++j) { 365 int i;
369 for (i = 0; i < 8; ++i) { 366 for (i = 0; i < 8 * 8; ++i) {
370 // TODO: could be made faster with SSE2 367 dither[i] = VP8RandomBits2(rg, VP8_DITHER_AMP_BITS + 1, amp);
371 const int bits =
372 VP8RandomBits2(rg, DITHER_AMP_BITS + 1, amp) - DITHER_AMP_CENTER;
373 // Convert to range: [-2,2] for dither=50, [-4,4] for dither=100
374 const int delta = (bits + DITHER_DESCALE_ROUNDER) >> DITHER_DESCALE;
375 const int v = (int)dst[i] + delta;
376 dst[i] = (v < 0) ? 0 : (v > 255) ? 255u : (uint8_t)v;
377 }
378 dst += bps;
379 } 368 }
369 VP8DitherCombine8x8(dither, dst, bps);
380 } 370 }
381 371
382 static void DitherRow(VP8Decoder* const dec) { 372 static void DitherRow(VP8Decoder* const dec) {
383 int mb_x; 373 int mb_x;
384 assert(dec->dither_); 374 assert(dec->dither_);
385 for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) { 375 for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) {
386 const VP8ThreadContext* const ctx = &dec->thread_ctx_; 376 const VP8ThreadContext* const ctx = &dec->thread_ctx_;
387 const VP8MBData* const data = ctx->mb_data_ + mb_x; 377 const VP8MBData* const data = ctx->mb_data_ + mb_x;
388 const int cache_id = ctx->id_; 378 const int cache_id = ctx->id_;
389 const int uv_bps = dec->cache_uv_stride_; 379 const int uv_bps = dec->cache_uv_stride_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (!is_last_row) { 445 if (!is_last_row) {
456 y_end -= extra_y_rows; 446 y_end -= extra_y_rows;
457 } 447 }
458 if (y_end > io->crop_bottom) { 448 if (y_end > io->crop_bottom) {
459 y_end = io->crop_bottom; // make sure we don't overflow on last row. 449 y_end = io->crop_bottom; // make sure we don't overflow on last row.
460 } 450 }
461 io->a = NULL; 451 io->a = NULL;
462 if (dec->alpha_data_ != NULL && y_start < y_end) { 452 if (dec->alpha_data_ != NULL && y_start < y_end) {
463 // TODO(skal): testing presence of alpha with dec->alpha_data_ is not a 453 // TODO(skal): testing presence of alpha with dec->alpha_data_ is not a
464 // good idea. 454 // good idea.
465 io->a = VP8DecompressAlphaRows(dec, y_start, y_end - y_start); 455 io->a = VP8DecompressAlphaRows(dec, io, y_start, y_end - y_start);
466 if (io->a == NULL) { 456 if (io->a == NULL) {
467 return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, 457 return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
468 "Could not decode alpha data."); 458 "Could not decode alpha data.");
469 } 459 }
470 } 460 }
471 if (y_start < io->crop_top) { 461 if (y_start < io->crop_top) {
472 const int delta_y = io->crop_top - y_start; 462 const int delta_y = io->crop_top - y_start;
473 y_start = io->crop_top; 463 y_start = io->crop_top;
474 assert(!(delta_y & 1)); 464 assert(!(delta_y & 1));
475 io->y += dec->cache_y_stride_ * delta_y; 465 io->y += dec->cache_y_stride_ * delta_y;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 803
814 int VP8InitFrame(VP8Decoder* const dec, VP8Io* const io) { 804 int VP8InitFrame(VP8Decoder* const dec, VP8Io* const io) {
815 if (!InitThreadContext(dec)) return 0; // call first. Sets dec->num_caches_. 805 if (!InitThreadContext(dec)) return 0; // call first. Sets dec->num_caches_.
816 if (!AllocateMemory(dec)) return 0; 806 if (!AllocateMemory(dec)) return 0;
817 InitIo(dec, io); 807 InitIo(dec, io);
818 VP8DspInit(); // Init critical function pointers and look-up tables. 808 VP8DspInit(); // Init critical function pointers and look-up tables.
819 return 1; 809 return 1;
820 } 810 }
821 811
822 //------------------------------------------------------------------------------ 812 //------------------------------------------------------------------------------
OLDNEW
« no previous file with comments | « third_party/libwebp/dec/buffer.c ('k') | third_party/libwebp/dec/idec.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698