Index: third_party/libwebp/enc/frame.c |
diff --git a/third_party/libwebp/enc/frame.c b/third_party/libwebp/enc/frame.c |
index 5b7a40b9ad0b01ed6e52d7cfd5de68a6e71d1336..57fc471d17c74574e894666418ca29bee099327e 100644 |
--- a/third_party/libwebp/enc/frame.c |
+++ b/third_party/libwebp/enc/frame.c |
@@ -185,6 +185,13 @@ static int GetProba(int a, int b) { |
: (255 * a + total / 2) / total; // rounded proba |
} |
+static void ResetSegments(VP8Encoder* const enc) { |
+ int n; |
+ for (n = 0; n < enc->mb_w_ * enc->mb_h_; ++n) { |
+ enc->mb_info_[n].segment_ = 0; |
+ } |
+} |
+ |
static void SetSegmentProbas(VP8Encoder* const enc) { |
int p[NUM_MB_SEGMENTS] = { 0 }; |
int n; |
@@ -206,6 +213,7 @@ static void SetSegmentProbas(VP8Encoder* const enc) { |
enc->segment_hdr_.update_map_ = |
(probas[0] != 255) || (probas[1] != 255) || (probas[2] != 255); |
+ if (!enc->segment_hdr_.update_map_) ResetSegments(enc); |
enc->segment_hdr_.size_ = |
p[0] * (VP8BitCost(0, probas[0]) + VP8BitCost(0, probas[1])) + |
p[1] * (VP8BitCost(0, probas[0]) + VP8BitCost(1, probas[1])) + |
@@ -406,9 +414,7 @@ static int RecordTokens(VP8EncIterator* const it, const VP8ModeScore* const rd, |
VP8InitResidual(0, 1, enc, &res); |
VP8SetResidualCoeffs(rd->y_dc_levels, &res); |
it->top_nz_[8] = it->left_nz_[8] = |
- VP8RecordCoeffTokens(ctx, 1, |
- res.first, res.last, res.coeffs, tokens); |
- VP8RecordCoeffs(ctx, &res); |
+ VP8RecordCoeffTokens(ctx, &res, tokens); |
VP8InitResidual(1, 0, enc, &res); |
} else { |
VP8InitResidual(0, 3, enc, &res); |
@@ -420,9 +426,7 @@ static int RecordTokens(VP8EncIterator* const it, const VP8ModeScore* const rd, |
const int ctx = it->top_nz_[x] + it->left_nz_[y]; |
VP8SetResidualCoeffs(rd->y_ac_levels[x + y * 4], &res); |
it->top_nz_[x] = it->left_nz_[y] = |
- VP8RecordCoeffTokens(ctx, res.coeff_type, |
- res.first, res.last, res.coeffs, tokens); |
- VP8RecordCoeffs(ctx, &res); |
+ VP8RecordCoeffTokens(ctx, &res, tokens); |
} |
} |
@@ -434,9 +438,7 @@ static int RecordTokens(VP8EncIterator* const it, const VP8ModeScore* const rd, |
const int ctx = it->top_nz_[4 + ch + x] + it->left_nz_[4 + ch + y]; |
VP8SetResidualCoeffs(rd->uv_levels[ch * 2 + x + y * 2], &res); |
it->top_nz_[4 + ch + x] = it->left_nz_[4 + ch + y] = |
- VP8RecordCoeffTokens(ctx, 2, |
- res.first, res.last, res.coeffs, tokens); |
- VP8RecordCoeffs(ctx, &res); |
+ VP8RecordCoeffTokens(ctx, &res, tokens); |
} |
} |
} |
@@ -814,7 +816,7 @@ int VP8EncTokenLoop(VP8Encoder* const enc) { |
num_pass_left, stats.last_value, stats.value, |
stats.last_q, stats.q, stats.dq); |
#endif |
- if (size_p0 > PARTITION0_SIZE_LIMIT) { |
+ if (enc->max_i4_header_bits_ > 0 && size_p0 > PARTITION0_SIZE_LIMIT) { |
++num_pass_left; |
enc->max_i4_header_bits_ >>= 1; // strengthen header bit limitation... |
continue; // ...and start over |