OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 Google Inc. |
| 2 // |
| 3 // This code is licensed under the same terms as WebM: |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
| 6 // ----------------------------------------------------------------------------- |
| 7 // |
| 8 // Quantizer initialization |
| 9 // |
| 10 // Author: Skal (pascal.massimino@gmail.com) |
| 11 |
| 12 #include "vp8i.h" |
| 13 |
| 14 #if defined(__cplusplus) || defined(c_plusplus) |
| 15 extern "C" { |
| 16 #endif |
| 17 |
| 18 static inline int clip(int v, int M) { |
| 19 return v < 0 ? 0 : v > M ? M : v; |
| 20 } |
| 21 |
| 22 // Paragraph 14.1 |
| 23 static const uint8_t kDcTable[128] = { |
| 24 4, 5, 6, 7, 8, 9, 10, 10, |
| 25 11, 12, 13, 14, 15, 16, 17, 17, |
| 26 18, 19, 20, 20, 21, 21, 22, 22, |
| 27 23, 23, 24, 25, 25, 26, 27, 28, |
| 28 29, 30, 31, 32, 33, 34, 35, 36, |
| 29 37, 37, 38, 39, 40, 41, 42, 43, |
| 30 44, 45, 46, 46, 47, 48, 49, 50, |
| 31 51, 52, 53, 54, 55, 56, 57, 58, |
| 32 59, 60, 61, 62, 63, 64, 65, 66, |
| 33 67, 68, 69, 70, 71, 72, 73, 74, |
| 34 75, 76, 76, 77, 78, 79, 80, 81, |
| 35 82, 83, 84, 85, 86, 87, 88, 89, |
| 36 91, 93, 95, 96, 98, 100, 101, 102, |
| 37 104, 106, 108, 110, 112, 114, 116, 118, |
| 38 122, 124, 126, 128, 130, 132, 134, 136, |
| 39 138, 140, 143, 145, 148, 151, 154, 157 |
| 40 }; |
| 41 |
| 42 static const uint16_t kAcTable[128] = { |
| 43 4, 5, 6, 7, 8, 9, 10, 11, |
| 44 12, 13, 14, 15, 16, 17, 18, 19, |
| 45 20, 21, 22, 23, 24, 25, 26, 27, |
| 46 28, 29, 30, 31, 32, 33, 34, 35, |
| 47 36, 37, 38, 39, 40, 41, 42, 43, |
| 48 44, 45, 46, 47, 48, 49, 50, 51, |
| 49 52, 53, 54, 55, 56, 57, 58, 60, |
| 50 62, 64, 66, 68, 70, 72, 74, 76, |
| 51 78, 80, 82, 84, 86, 88, 90, 92, |
| 52 94, 96, 98, 100, 102, 104, 106, 108, |
| 53 110, 112, 14, 116, 119, 122, 125, 128, |
| 54 131, 134, 37, 140, 143, 146, 149, 152, |
| 55 155, 158, 161, 164, 167, 170, 173, 177, |
| 56 181, 185, 189, 193, 197, 201, 205, 209, |
| 57 213, 217, 221, 225, 229, 234, 239, 245, |
| 58 249, 254, 259, 264, 269, 274, 279, 284 |
| 59 }; |
| 60 |
| 61 //----------------------------------------------------------------------------- |
| 62 // Paragraph 9.6 |
| 63 |
| 64 void VP8ParseQuant(VP8Decoder* const dec) { |
| 65 VP8BitReader* const br = &dec->br_; |
| 66 const int base_q0 = VP8GetValue(br, 7); |
| 67 const int dqy1_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; |
| 68 const int dqy2_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; |
| 69 const int dqy2_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; |
| 70 const int dquv_dc = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; |
| 71 const int dquv_ac = VP8Get(br) ? VP8GetSignedValue(br, 4) : 0; |
| 72 |
| 73 const VP8SegmentHeader* const hdr = &dec->segment_hdr_; |
| 74 for (int i = 0; i < NUM_MB_SEGMENTS; ++i) { |
| 75 int q; |
| 76 if (hdr->use_segment_) { |
| 77 q = hdr->quantizer_[i]; |
| 78 if (!hdr->absolute_delta_) { |
| 79 q += base_q0; |
| 80 } |
| 81 } else { |
| 82 if (i > 0) { |
| 83 dec->dqm_[i] = dec->dqm_[0]; |
| 84 continue; |
| 85 } else { |
| 86 q = base_q0; |
| 87 } |
| 88 } |
| 89 VP8QuantMatrix* const m = &dec->dqm_[i]; |
| 90 m->y1_mat_[0] = kDcTable[clip(q + dqy1_dc, 127)]; |
| 91 m->y1_mat_[1] = kAcTable[clip(q + 0, 127)]; |
| 92 |
| 93 m->y2_mat_[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2; |
| 94 // TODO(skal): make it another table? |
| 95 m->y2_mat_[1] = kAcTable[clip(q + dqy2_ac, 127)] * 155 / 100; |
| 96 if (m->y2_mat_[1] < 8) m->y2_mat_[1] = 8; |
| 97 |
| 98 m->uv_mat_[0] = kDcTable[clip(q + dquv_ac, 117)]; |
| 99 m->uv_mat_[1] = kAcTable[clip(q + dquv_dc, 127)]; |
| 100 } |
| 101 } |
| 102 |
| 103 //----------------------------------------------------------------------------- |
| 104 |
| 105 #if defined(__cplusplus) || defined(c_plusplus) |
| 106 } // extern "C" |
| 107 #endif |
OLD | NEW |