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

Side by Side Diff: third_party/libwebp/enc/quant.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 // Quantization 10 // Quantization
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // none of these constants should be < 1 271 // none of these constants should be < 1
272 CheckLambdaValue(&m->lambda_i4_); 272 CheckLambdaValue(&m->lambda_i4_);
273 CheckLambdaValue(&m->lambda_i16_); 273 CheckLambdaValue(&m->lambda_i16_);
274 CheckLambdaValue(&m->lambda_uv_); 274 CheckLambdaValue(&m->lambda_uv_);
275 CheckLambdaValue(&m->lambda_mode_); 275 CheckLambdaValue(&m->lambda_mode_);
276 CheckLambdaValue(&m->lambda_trellis_i4_); 276 CheckLambdaValue(&m->lambda_trellis_i4_);
277 CheckLambdaValue(&m->lambda_trellis_i16_); 277 CheckLambdaValue(&m->lambda_trellis_i16_);
278 CheckLambdaValue(&m->lambda_trellis_uv_); 278 CheckLambdaValue(&m->lambda_trellis_uv_);
279 CheckLambdaValue(&m->tlambda_); 279 CheckLambdaValue(&m->tlambda_);
280 280
281 m->min_disto_ = 10 * m->y1_.q_[0]; // quantization-aware min disto 281 m->min_disto_ = 20 * m->y1_.q_[0]; // quantization-aware min disto
282 m->max_edge_ = 0; 282 m->max_edge_ = 0;
283 283
284 m->i4_penalty_ = 1000 * q_i4 * q_i4; 284 m->i4_penalty_ = 1000 * q_i4 * q_i4;
285 } 285 }
286 } 286 }
287 287
288 //------------------------------------------------------------------------------ 288 //------------------------------------------------------------------------------
289 // Initialize filtering parameters 289 // Initialize filtering parameters
290 290
291 // Very small filter-strength values have close to no visual effect. So we can 291 // Very small filter-strength values have close to no visual effect. So we can
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 867 }
868 868
869 //------------------------------------------------------------------------------ 869 //------------------------------------------------------------------------------
870 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost. 870 // RD-opt decision. Reconstruct each modes, evalue distortion and bit-cost.
871 // Pick the mode is lower RD-cost = Rate + lambda * Distortion. 871 // Pick the mode is lower RD-cost = Rate + lambda * Distortion.
872 872
873 static void StoreMaxDelta(VP8SegmentInfo* const dqm, const int16_t DCs[16]) { 873 static void StoreMaxDelta(VP8SegmentInfo* const dqm, const int16_t DCs[16]) {
874 // We look at the first three AC coefficients to determine what is the average 874 // We look at the first three AC coefficients to determine what is the average
875 // delta between each sub-4x4 block. 875 // delta between each sub-4x4 block.
876 const int v0 = abs(DCs[1]); 876 const int v0 = abs(DCs[1]);
877 const int v1 = abs(DCs[4]); 877 const int v1 = abs(DCs[2]);
878 const int v2 = abs(DCs[5]); 878 const int v2 = abs(DCs[4]);
879 int max_v = (v0 > v1) ? v1 : v0; 879 int max_v = (v1 > v0) ? v1 : v0;
880 max_v = (v2 > max_v) ? v2 : max_v; 880 max_v = (v2 > max_v) ? v2 : max_v;
881 if (max_v > dqm->max_edge_) dqm->max_edge_ = max_v; 881 if (max_v > dqm->max_edge_) dqm->max_edge_ = max_v;
882 } 882 }
883 883
884 static void SwapModeScore(VP8ModeScore** a, VP8ModeScore** b) { 884 static void SwapModeScore(VP8ModeScore** a, VP8ModeScore** b) {
885 VP8ModeScore* const tmp = *a; 885 VP8ModeScore* const tmp = *a;
886 *a = *b; 886 *a = *b;
887 *b = tmp; 887 *b = tmp;
888 } 888 }
889 889
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 950 }
951 if (rd_best != rd) { 951 if (rd_best != rd) {
952 memcpy(rd, rd_best, sizeof(*rd)); 952 memcpy(rd, rd_best, sizeof(*rd));
953 } 953 }
954 SetRDScore(dqm->lambda_mode_, rd); // finalize score for mode decision. 954 SetRDScore(dqm->lambda_mode_, rd); // finalize score for mode decision.
955 VP8SetIntra16Mode(it, rd->mode_i16); 955 VP8SetIntra16Mode(it, rd->mode_i16);
956 956
957 // we have a blocky macroblock (only DCs are non-zero) with fairly high 957 // we have a blocky macroblock (only DCs are non-zero) with fairly high
958 // distortion, record max delta so we can later adjust the minimal filtering 958 // distortion, record max delta so we can later adjust the minimal filtering
959 // strength needed to smooth these blocks out. 959 // strength needed to smooth these blocks out.
960 if ((rd->nz & 0xffff) == 0 && rd->D > dqm->min_disto_) { 960 if ((rd->nz & 0x100ffff) == 0x1000000 && rd->D > dqm->min_disto_) {
961 StoreMaxDelta(dqm, rd->y_dc_levels); 961 StoreMaxDelta(dqm, rd->y_dc_levels);
962 } 962 }
963 } 963 }
964 964
965 //------------------------------------------------------------------------------ 965 //------------------------------------------------------------------------------
966 966
967 // return the cost array corresponding to the surrounding prediction modes. 967 // return the cost array corresponding to the surrounding prediction modes.
968 static const uint16_t* GetCostModeI4(VP8EncIterator* const it, 968 static const uint16_t* GetCostModeI4(VP8EncIterator* const it,
969 const uint8_t modes[16]) { 969 const uint8_t modes[16]) {
970 const int preds_w = it->enc_->preds_w_; 970 const int preds_w = it->enc_->preds_w_;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 int mode; 1148 int mode;
1149 int is_i16 = try_both_modes || (it->mb_->type_ == 1); 1149 int is_i16 = try_both_modes || (it->mb_->type_ == 1);
1150 1150
1151 const VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_]; 1151 const VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
1152 // Some empiric constants, of approximate order of magnitude. 1152 // Some empiric constants, of approximate order of magnitude.
1153 const int lambda_d_i16 = 106; 1153 const int lambda_d_i16 = 106;
1154 const int lambda_d_i4 = 11; 1154 const int lambda_d_i4 = 11;
1155 const int lambda_d_uv = 120; 1155 const int lambda_d_uv = 120;
1156 score_t score_i4 = dqm->i4_penalty_; 1156 score_t score_i4 = dqm->i4_penalty_;
1157 score_t i4_bit_sum = 0; 1157 score_t i4_bit_sum = 0;
1158 const score_t bit_limit = it->enc_->mb_header_limit_; 1158 const score_t bit_limit = try_both_modes ? it->enc_->mb_header_limit_
1159 : MAX_COST; // no early-out allowed
1159 1160
1160 if (is_i16) { // First, evaluate Intra16 distortion 1161 if (is_i16) { // First, evaluate Intra16 distortion
1161 int best_mode = -1; 1162 int best_mode = -1;
1162 const uint8_t* const src = it->yuv_in_ + Y_OFF_ENC; 1163 const uint8_t* const src = it->yuv_in_ + Y_OFF_ENC;
1163 for (mode = 0; mode < NUM_PRED_MODES; ++mode) { 1164 for (mode = 0; mode < NUM_PRED_MODES; ++mode) {
1164 const uint8_t* const ref = it->yuv_p_ + VP8I16ModeOffsets[mode]; 1165 const uint8_t* const ref = it->yuv_p_ + VP8I16ModeOffsets[mode];
1165 const score_t score = VP8SSE16x16(src, ref) * RD_DISTO_MULT 1166 const score_t score = VP8SSE16x16(src, ref) * RD_DISTO_MULT
1166 + VP8FixedCostsI16[mode] * lambda_d_i16; 1167 + VP8FixedCostsI16[mode] * lambda_d_i16;
1167 if (mode > 0 && VP8FixedCostsI16[mode] > bit_limit) { 1168 if (mode > 0 && VP8FixedCostsI16[mode] > bit_limit) {
1168 continue; 1169 continue;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 // At this point we have heuristically decided intra16 / intra4. 1275 // At this point we have heuristically decided intra16 / intra4.
1275 // For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower). 1276 // For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower).
1276 // For method <= 1, we don't re-examine the decision but just go ahead with 1277 // For method <= 1, we don't re-examine the decision but just go ahead with
1277 // quantization/reconstruction. 1278 // quantization/reconstruction.
1278 RefineUsingDistortion(it, (method >= 2), (method >= 1), rd); 1279 RefineUsingDistortion(it, (method >= 2), (method >= 1), rd);
1279 } 1280 }
1280 is_skipped = (rd->nz == 0); 1281 is_skipped = (rd->nz == 0);
1281 VP8SetSkip(it, is_skipped); 1282 VP8SetSkip(it, is_skipped);
1282 return is_skipped; 1283 return is_skipped;
1283 } 1284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698