| OLD | NEW |
| 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 // Header syntax writing | 10 // Header syntax writing |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return 1; | 179 return 1; |
| 180 | 180 |
| 181 // Error. | 181 // Error. |
| 182 Error: | 182 Error: |
| 183 return WebPEncodingSetError(pic, err); | 183 return WebPEncodingSetError(pic, err); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Segmentation header | 186 // Segmentation header |
| 187 static void PutSegmentHeader(VP8BitWriter* const bw, | 187 static void PutSegmentHeader(VP8BitWriter* const bw, |
| 188 const VP8Encoder* const enc) { | 188 const VP8Encoder* const enc) { |
| 189 const VP8SegmentHeader* const hdr = &enc->segment_hdr_; | 189 const VP8EncSegmentHeader* const hdr = &enc->segment_hdr_; |
| 190 const VP8Proba* const proba = &enc->proba_; | 190 const VP8EncProba* const proba = &enc->proba_; |
| 191 if (VP8PutBitUniform(bw, (hdr->num_segments_ > 1))) { | 191 if (VP8PutBitUniform(bw, (hdr->num_segments_ > 1))) { |
| 192 // We always 'update' the quant and filter strength values | 192 // We always 'update' the quant and filter strength values |
| 193 const int update_data = 1; | 193 const int update_data = 1; |
| 194 int s; | 194 int s; |
| 195 VP8PutBitUniform(bw, hdr->update_map_); | 195 VP8PutBitUniform(bw, hdr->update_map_); |
| 196 if (VP8PutBitUniform(bw, update_data)) { | 196 if (VP8PutBitUniform(bw, update_data)) { |
| 197 // we always use absolute values, not relative ones | 197 // we always use absolute values, not relative ones |
| 198 VP8PutBitUniform(bw, 1); // (segment_feature_mode = 1. Paragraph 9.3.) | 198 VP8PutBitUniform(bw, 1); // (segment_feature_mode = 1. Paragraph 9.3.) |
| 199 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { | 199 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { |
| 200 VP8PutSignedValue(bw, enc->dqm_[s].quant_, 7); | 200 VP8PutSignedBits(bw, enc->dqm_[s].quant_, 7); |
| 201 } | 201 } |
| 202 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { | 202 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { |
| 203 VP8PutSignedValue(bw, enc->dqm_[s].fstrength_, 6); | 203 VP8PutSignedBits(bw, enc->dqm_[s].fstrength_, 6); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 if (hdr->update_map_) { | 206 if (hdr->update_map_) { |
| 207 for (s = 0; s < 3; ++s) { | 207 for (s = 0; s < 3; ++s) { |
| 208 if (VP8PutBitUniform(bw, (proba->segments_[s] != 255u))) { | 208 if (VP8PutBitUniform(bw, (proba->segments_[s] != 255u))) { |
| 209 VP8PutValue(bw, proba->segments_[s], 8); | 209 VP8PutBits(bw, proba->segments_[s], 8); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Filtering parameters header | 216 // Filtering parameters header |
| 217 static void PutFilterHeader(VP8BitWriter* const bw, | 217 static void PutFilterHeader(VP8BitWriter* const bw, |
| 218 const VP8FilterHeader* const hdr) { | 218 const VP8EncFilterHeader* const hdr) { |
| 219 const int use_lf_delta = (hdr->i4x4_lf_delta_ != 0); | 219 const int use_lf_delta = (hdr->i4x4_lf_delta_ != 0); |
| 220 VP8PutBitUniform(bw, hdr->simple_); | 220 VP8PutBitUniform(bw, hdr->simple_); |
| 221 VP8PutValue(bw, hdr->level_, 6); | 221 VP8PutBits(bw, hdr->level_, 6); |
| 222 VP8PutValue(bw, hdr->sharpness_, 3); | 222 VP8PutBits(bw, hdr->sharpness_, 3); |
| 223 if (VP8PutBitUniform(bw, use_lf_delta)) { | 223 if (VP8PutBitUniform(bw, use_lf_delta)) { |
| 224 // '0' is the default value for i4x4_lf_delta_ at frame #0. | 224 // '0' is the default value for i4x4_lf_delta_ at frame #0. |
| 225 const int need_update = (hdr->i4x4_lf_delta_ != 0); | 225 const int need_update = (hdr->i4x4_lf_delta_ != 0); |
| 226 if (VP8PutBitUniform(bw, need_update)) { | 226 if (VP8PutBitUniform(bw, need_update)) { |
| 227 // we don't use ref_lf_delta => emit four 0 bits | 227 // we don't use ref_lf_delta => emit four 0 bits |
| 228 VP8PutValue(bw, 0, 4); | 228 VP8PutBits(bw, 0, 4); |
| 229 // we use mode_lf_delta for i4x4 | 229 // we use mode_lf_delta for i4x4 |
| 230 VP8PutSignedValue(bw, hdr->i4x4_lf_delta_, 6); | 230 VP8PutSignedBits(bw, hdr->i4x4_lf_delta_, 6); |
| 231 VP8PutValue(bw, 0, 3); // all others unused | 231 VP8PutBits(bw, 0, 3); // all others unused |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Nominal quantization parameters | 236 // Nominal quantization parameters |
| 237 static void PutQuant(VP8BitWriter* const bw, | 237 static void PutQuant(VP8BitWriter* const bw, |
| 238 const VP8Encoder* const enc) { | 238 const VP8Encoder* const enc) { |
| 239 VP8PutValue(bw, enc->base_quant_, 7); | 239 VP8PutBits(bw, enc->base_quant_, 7); |
| 240 VP8PutSignedValue(bw, enc->dq_y1_dc_, 4); | 240 VP8PutSignedBits(bw, enc->dq_y1_dc_, 4); |
| 241 VP8PutSignedValue(bw, enc->dq_y2_dc_, 4); | 241 VP8PutSignedBits(bw, enc->dq_y2_dc_, 4); |
| 242 VP8PutSignedValue(bw, enc->dq_y2_ac_, 4); | 242 VP8PutSignedBits(bw, enc->dq_y2_ac_, 4); |
| 243 VP8PutSignedValue(bw, enc->dq_uv_dc_, 4); | 243 VP8PutSignedBits(bw, enc->dq_uv_dc_, 4); |
| 244 VP8PutSignedValue(bw, enc->dq_uv_ac_, 4); | 244 VP8PutSignedBits(bw, enc->dq_uv_ac_, 4); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Partition sizes | 247 // Partition sizes |
| 248 static int EmitPartitionsSize(const VP8Encoder* const enc, | 248 static int EmitPartitionsSize(const VP8Encoder* const enc, |
| 249 WebPPicture* const pic) { | 249 WebPPicture* const pic) { |
| 250 uint8_t buf[3 * (MAX_NUM_PARTITIONS - 1)]; | 250 uint8_t buf[3 * (MAX_NUM_PARTITIONS - 1)]; |
| 251 int p; | 251 int p; |
| 252 for (p = 0; p < enc->num_parts_ - 1; ++p) { | 252 for (p = 0; p < enc->num_parts_ - 1; ++p) { |
| 253 const size_t part_size = VP8BitWriterSize(enc->parts_ + p); | 253 const size_t part_size = VP8BitWriterSize(enc->parts_ + p); |
| 254 if (part_size >= VP8_MAX_PARTITION_SIZE) { | 254 if (part_size >= VP8_MAX_PARTITION_SIZE) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 270 | 270 |
| 271 pos1 = VP8BitWriterPos(bw); | 271 pos1 = VP8BitWriterPos(bw); |
| 272 if (!VP8BitWriterInit(bw, mb_size * 7 / 8)) { // ~7 bits per macroblock | 272 if (!VP8BitWriterInit(bw, mb_size * 7 / 8)) { // ~7 bits per macroblock |
| 273 return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY); | 273 return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY); |
| 274 } | 274 } |
| 275 VP8PutBitUniform(bw, 0); // colorspace | 275 VP8PutBitUniform(bw, 0); // colorspace |
| 276 VP8PutBitUniform(bw, 0); // clamp type | 276 VP8PutBitUniform(bw, 0); // clamp type |
| 277 | 277 |
| 278 PutSegmentHeader(bw, enc); | 278 PutSegmentHeader(bw, enc); |
| 279 PutFilterHeader(bw, &enc->filter_hdr_); | 279 PutFilterHeader(bw, &enc->filter_hdr_); |
| 280 VP8PutValue(bw, enc->num_parts_ == 8 ? 3 : | 280 VP8PutBits(bw, enc->num_parts_ == 8 ? 3 : |
| 281 enc->num_parts_ == 4 ? 2 : | 281 enc->num_parts_ == 4 ? 2 : |
| 282 enc->num_parts_ == 2 ? 1 : 0, 2); | 282 enc->num_parts_ == 2 ? 1 : 0, 2); |
| 283 PutQuant(bw, enc); | 283 PutQuant(bw, enc); |
| 284 VP8PutBitUniform(bw, 0); // no proba update | 284 VP8PutBitUniform(bw, 0); // no proba update |
| 285 VP8WriteProbas(bw, &enc->proba_); | 285 VP8WriteProbas(bw, &enc->proba_); |
| 286 pos2 = VP8BitWriterPos(bw); | 286 pos2 = VP8BitWriterPos(bw); |
| 287 VP8CodeIntraModes(enc); | 287 VP8CodeIntraModes(enc); |
| 288 VP8BitWriterFinish(bw); | 288 VP8BitWriterFinish(bw); |
| 289 | 289 |
| 290 pos3 = VP8BitWriterPos(bw); | 290 pos3 = VP8BitWriterPos(bw); |
| 291 | 291 |
| 292 if (enc->pic_->stats) { | 292 if (enc->pic_->stats) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 ok = PutPaddingByte(pic); | 374 ok = PutPaddingByte(pic); |
| 375 } | 375 } |
| 376 | 376 |
| 377 enc->coded_size_ = (int)(CHUNK_HEADER_SIZE + riff_size); | 377 enc->coded_size_ = (int)(CHUNK_HEADER_SIZE + riff_size); |
| 378 ok = ok && WebPReportProgress(pic, final_percent, &enc->percent_); | 378 ok = ok && WebPReportProgress(pic, final_percent, &enc->percent_); |
| 379 return ok; | 379 return ok; |
| 380 } | 380 } |
| 381 | 381 |
| 382 //------------------------------------------------------------------------------ | 382 //------------------------------------------------------------------------------ |
| 383 | 383 |
| OLD | NEW |