OLD | NEW |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
7 // | 7 // |
8 // Header syntax writing | 8 // Header syntax writing |
9 // | 9 // |
10 // Author: Skal (pascal.massimino@gmail.com) | 10 // Author: Skal (pascal.massimino@gmail.com) |
11 | 11 |
12 #include <assert.h> | 12 #include <assert.h> |
13 | 13 |
14 #include "../webp/format_constants.h" | 14 #include "../utils/utils.h" |
| 15 #include "../webp/format_constants.h" // RIFF constants |
| 16 #include "../webp/mux_types.h" // ALPHA_FLAG |
15 #include "./vp8enci.h" | 17 #include "./vp8enci.h" |
16 | 18 |
17 #if defined(__cplusplus) || defined(c_plusplus) | 19 #if defined(__cplusplus) || defined(c_plusplus) |
18 extern "C" { | 20 extern "C" { |
19 #endif | 21 #endif |
20 | 22 |
21 //------------------------------------------------------------------------------ | 23 //------------------------------------------------------------------------------ |
22 // Helper functions | 24 // Helper functions |
23 | 25 |
24 // TODO(later): Move to webp/format_constants.h? | |
25 static void PutLE24(uint8_t* const data, uint32_t val) { | |
26 data[0] = (val >> 0) & 0xff; | |
27 data[1] = (val >> 8) & 0xff; | |
28 data[2] = (val >> 16) & 0xff; | |
29 } | |
30 | |
31 static void PutLE32(uint8_t* const data, uint32_t val) { | |
32 PutLE24(data, val); | |
33 data[3] = (val >> 24) & 0xff; | |
34 } | |
35 | |
36 static int IsVP8XNeeded(const VP8Encoder* const enc) { | 26 static int IsVP8XNeeded(const VP8Encoder* const enc) { |
37 return !!enc->has_alpha_; // Currently the only case when VP8X is needed. | 27 return !!enc->has_alpha_; // Currently the only case when VP8X is needed. |
38 // This could change in the future. | 28 // This could change in the future. |
39 } | 29 } |
40 | 30 |
41 static int PutPaddingByte(const WebPPicture* const pic) { | 31 static int PutPaddingByte(const WebPPicture* const pic) { |
42 | 32 |
43 const uint8_t pad_byte[1] = { 0 }; | 33 const uint8_t pad_byte[1] = { 0 }; |
44 return !!pic->writer(pad_byte, 1, pic); | 34 return !!pic->writer(pad_byte, 1, pic); |
45 } | 35 } |
(...skipping 20 matching lines...) Expand all Loading... |
66 uint8_t vp8x[CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE] = { | 56 uint8_t vp8x[CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE] = { |
67 'V', 'P', '8', 'X' | 57 'V', 'P', '8', 'X' |
68 }; | 58 }; |
69 uint32_t flags = 0; | 59 uint32_t flags = 0; |
70 | 60 |
71 assert(IsVP8XNeeded(enc)); | 61 assert(IsVP8XNeeded(enc)); |
72 assert(pic->width >= 1 && pic->height >= 1); | 62 assert(pic->width >= 1 && pic->height >= 1); |
73 assert(pic->width <= MAX_CANVAS_SIZE && pic->height <= MAX_CANVAS_SIZE); | 63 assert(pic->width <= MAX_CANVAS_SIZE && pic->height <= MAX_CANVAS_SIZE); |
74 | 64 |
75 if (enc->has_alpha_) { | 65 if (enc->has_alpha_) { |
76 flags |= ALPHA_FLAG_BIT; | 66 flags |= ALPHA_FLAG; |
77 } | 67 } |
78 | 68 |
79 PutLE32(vp8x + TAG_SIZE, VP8X_CHUNK_SIZE); | 69 PutLE32(vp8x + TAG_SIZE, VP8X_CHUNK_SIZE); |
80 PutLE32(vp8x + CHUNK_HEADER_SIZE, flags); | 70 PutLE32(vp8x + CHUNK_HEADER_SIZE, flags); |
81 PutLE24(vp8x + CHUNK_HEADER_SIZE + 4, pic->width - 1); | 71 PutLE24(vp8x + CHUNK_HEADER_SIZE + 4, pic->width - 1); |
82 PutLE24(vp8x + CHUNK_HEADER_SIZE + 7, pic->height - 1); | 72 PutLE24(vp8x + CHUNK_HEADER_SIZE + 7, pic->height - 1); |
83 if(!pic->writer(vp8x, sizeof(vp8x), pic)) { | 73 if(!pic->writer(vp8x, sizeof(vp8x), pic)) { |
84 return VP8_ENC_ERROR_BAD_WRITE; | 74 return VP8_ENC_ERROR_BAD_WRITE; |
85 } | 75 } |
86 return VP8_ENC_OK; | 76 return VP8_ENC_OK; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 VP8BitWriterInit(bw, mb_size * 7 / 8); // ~7 bits per macroblock | 310 VP8BitWriterInit(bw, mb_size * 7 / 8); // ~7 bits per macroblock |
321 #ifdef WEBP_EXPERIMENTAL_FEATURES | 311 #ifdef WEBP_EXPERIMENTAL_FEATURES |
322 VP8PutBitUniform(bw, need_extensions); // extensions | 312 VP8PutBitUniform(bw, need_extensions); // extensions |
323 #else | 313 #else |
324 VP8PutBitUniform(bw, 0); // colorspace | 314 VP8PutBitUniform(bw, 0); // colorspace |
325 #endif | 315 #endif |
326 VP8PutBitUniform(bw, 0); // clamp type | 316 VP8PutBitUniform(bw, 0); // clamp type |
327 | 317 |
328 PutSegmentHeader(bw, enc); | 318 PutSegmentHeader(bw, enc); |
329 PutFilterHeader(bw, &enc->filter_hdr_); | 319 PutFilterHeader(bw, &enc->filter_hdr_); |
330 VP8PutValue(bw, enc->config_->partitions, 2); | 320 VP8PutValue(bw, enc->num_parts_ == 8 ? 3 : |
| 321 enc->num_parts_ == 4 ? 2 : |
| 322 enc->num_parts_ == 2 ? 1 : 0, 2); |
331 PutQuant(bw, enc); | 323 PutQuant(bw, enc); |
332 VP8PutBitUniform(bw, 0); // no proba update | 324 VP8PutBitUniform(bw, 0); // no proba update |
333 VP8WriteProbas(bw, &enc->proba_); | 325 VP8WriteProbas(bw, &enc->proba_); |
334 pos2 = VP8BitWriterPos(bw); | 326 pos2 = VP8BitWriterPos(bw); |
335 VP8CodeIntraModes(enc); | 327 VP8CodeIntraModes(enc); |
336 VP8BitWriterFinish(bw); | 328 VP8BitWriterFinish(bw); |
337 | 329 |
338 #ifdef WEBP_EXPERIMENTAL_FEATURES | 330 #ifdef WEBP_EXPERIMENTAL_FEATURES |
339 if (need_extensions && !WriteExtensions(enc)) { | 331 if (need_extensions && !WriteExtensions(enc)) { |
340 return 0; | 332 return 0; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 enc->coded_size_ = (int)(CHUNK_HEADER_SIZE + riff_size); | 420 enc->coded_size_ = (int)(CHUNK_HEADER_SIZE + riff_size); |
429 ok = ok && WebPReportProgress(pic, final_percent, &enc->percent_); | 421 ok = ok && WebPReportProgress(pic, final_percent, &enc->percent_); |
430 return ok; | 422 return ok; |
431 } | 423 } |
432 | 424 |
433 //------------------------------------------------------------------------------ | 425 //------------------------------------------------------------------------------ |
434 | 426 |
435 #if defined(__cplusplus) || defined(c_plusplus) | 427 #if defined(__cplusplus) || defined(c_plusplus) |
436 } // extern "C" | 428 } // extern "C" |
437 #endif | 429 #endif |
OLD | NEW |