Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 1 | /* |
| 2 | * copyright (c) 2002-2004 Michael Niedermayer <[email protected]> |
| 3 | * copyright (c) 2004 Maarten Daniels |
| 4 | * |
| 5 | * This file is part of FFmpeg. |
| 6 | * |
| 7 | * FFmpeg is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * FFmpeg is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with FFmpeg; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file |
| 24 | * H.261 tables. |
| 25 | */ |
| 26 | |
| 27 | #include <stdint.h> |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 28 | |
Vittorio Giovara | dc0c70e | 2014-03-22 23:34:13 | [diff] [blame] | 29 | #include "mpegutils.h" |
Diego Biurrun | 8a776ad | 2013-04-04 12:56:01 | [diff] [blame] | 30 | #include "rl.h" |
Måns Rullgård | 9954545 | 2007-06-16 22:59:13 | [diff] [blame] | 31 | #include "h261.h" |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 32 | |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 33 | // H.261 VLC table for macroblock addressing |
| 34 | const uint8_t ff_h261_mba_code[35] = { |
| 35 | 1, 3, 2, 3, |
| 36 | 2, 3, 2, 7, |
| 37 | 6, 11, 10, 9, |
| 38 | 8, 7, 6, 23, |
| 39 | 22, 21, 20, 19, |
| 40 | 18, 35, 34, 33, |
| 41 | 32, 31, 30, 29, |
| 42 | 28, 27, 26, 25, |
| 43 | 24, |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 44 | 15, // (MBA stuffing) |
| 45 | 1 // (start code) |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | const uint8_t ff_h261_mba_bits[35] = { |
| 49 | 1, 3, 3, 4, |
| 50 | 4, 5, 5, 7, |
| 51 | 7, 8, 8, 8, |
| 52 | 8, 8, 8, 10, |
| 53 | 10, 10, 10, 10, |
| 54 | 10, 11, 11, 11, |
| 55 | 11, 11, 11, 11, |
| 56 | 11, 11, 11, 11, |
| 57 | 11, |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 58 | 11, // (MBA stuffing) |
| 59 | 16 // (start code) |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 60 | }; |
| 61 | |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 62 | // H.261 VLC table for macroblock type |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 63 | const uint8_t ff_h261_mtype_code[10] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 64 | 1, 1, 1, 1, |
| 65 | 1, 1, 1, 1, |
| 66 | 1, 1 |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | const uint8_t ff_h261_mtype_bits[10] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 70 | 4, 7, 1, 5, |
| 71 | 9, 8, 10, 3, |
| 72 | 2, 6 |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 73 | }; |
| 74 | |
Andreas Rheinhardt | 0876b16 | 2024-06-02 16:48:39 | [diff] [blame] | 75 | const uint16_t ff_h261_mtype_map[10] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 76 | MB_TYPE_INTRA4x4, |
| 77 | MB_TYPE_INTRA4x4 | MB_TYPE_QUANT, |
| 78 | MB_TYPE_CBP, |
| 79 | MB_TYPE_CBP | MB_TYPE_QUANT, |
| 80 | MB_TYPE_16x16, |
| 81 | MB_TYPE_16x16 | MB_TYPE_CBP, |
| 82 | MB_TYPE_16x16 | MB_TYPE_CBP | MB_TYPE_QUANT, |
| 83 | MB_TYPE_16x16 | MB_TYPE_H261_FIL, |
| 84 | MB_TYPE_16x16 | MB_TYPE_H261_FIL | MB_TYPE_CBP, |
| 85 | MB_TYPE_16x16 | MB_TYPE_H261_FIL | MB_TYPE_CBP | MB_TYPE_QUANT |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 86 | }; |
| 87 | |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 88 | // H.261 VLC table for motion vectors |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 89 | const uint8_t ff_h261_mv_tab[17][2] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 90 | { 1, 1 }, { 1, 2 }, { 1, 3 }, { 1, 4 }, { 3, 6 }, { 5, 7 }, { 4, 7 }, { 3, 7 }, |
| 91 | { 11, 9 }, { 10, 9 }, { 9, 9 }, { 17, 10 }, { 16, 10 }, { 15, 10 }, { 14, 10 }, { 13, 10 }, { 12, 10 } |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 92 | }; |
| 93 | |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 94 | // H.261 VLC table for coded block pattern |
| 95 | const uint8_t ff_h261_cbp_tab[63][2] = { |
| 96 | { 11, 5 }, { 9, 5 }, { 13, 6 }, { 13, 4 }, { 23, 7 }, { 19, 7 }, { 31, 8 }, { 12, 4 }, |
| 97 | { 22, 7 }, { 18, 7 }, { 30, 8 }, { 19, 5 }, { 27, 8 }, { 23, 8 }, { 19, 8 }, { 11, 4 }, |
| 98 | { 21, 7 }, { 17, 7 }, { 29, 8 }, { 17, 5 }, { 25, 8 }, { 21, 8 }, { 17, 8 }, { 15, 6 }, |
| 99 | { 15, 8 }, { 13, 8 }, { 3, 9 }, { 15, 5 }, { 11, 8 }, { 7, 8 }, { 7, 9 }, { 10, 4 }, |
| 100 | { 20, 7 }, { 16, 7 }, { 28, 8 }, { 14, 6 }, { 14, 8 }, { 12, 8 }, { 2, 9 }, { 16, 5 }, |
| 101 | { 24, 8 }, { 20, 8 }, { 16, 8 }, { 14, 5 }, { 10, 8 }, { 6, 8 }, { 6, 9 }, { 18, 5 }, |
| 102 | { 26, 8 }, { 22, 8 }, { 18, 8 }, { 13, 5 }, { 9, 8 }, { 5, 8 }, { 5, 9 }, { 12, 5 }, |
| 103 | { 8, 8 }, { 4, 8 }, { 4, 9 }, { 7, 3 }, { 10, 5 }, { 8, 5 }, { 12, 6 } |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 104 | }; |
| 105 | |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 106 | // H.261 VLC table for transform coefficients |
Andreas Rheinhardt | 3874442 | 2024-06-15 15:21:16 | [diff] [blame] | 107 | const uint16_t ff_h261_tcoeff_vlc[65][2] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 108 | { 0x2, 2 }, { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, |
| 109 | { 0x6, 7 }, { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, |
| 110 | { 0x1d, 12 }, { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, |
| 111 | { 0x1a, 13 }, { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, |
| 112 | { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 }, |
| 113 | { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x5, 4 }, |
| 114 | { 0x4, 7 }, { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, |
| 115 | { 0x7, 5 }, { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, |
| 116 | { 0x6, 5 }, { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, |
| 117 | { 0x9, 10 }, { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, |
| 118 | { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 }, |
| 119 | { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 }, |
| 120 | { 0x23, 8 }, { 0x22, 8 }, { 0x20, 8 }, { 0xe, 10 }, |
| 121 | { 0xd, 10 }, { 0x8, 10 }, { 0x1f, 12 }, { 0x1a, 12 }, |
| 122 | { 0x19, 12 }, { 0x17, 12 }, { 0x16, 12 }, { 0x1f, 13 }, |
| 123 | { 0x1e, 13 }, { 0x1d, 13 }, { 0x1c, 13 }, { 0x1b, 13 }, |
| 124 | { 0x1, 6 } // escape |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 125 | }; |
| 126 | |
Andreas Rheinhardt | 3874442 | 2024-06-15 15:21:16 | [diff] [blame] | 127 | const int8_t ff_h261_tcoeff_level[64] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 128 | 0, 1, 2, 3, 4, 5, 6, 7, |
| 129 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 130 | 1, 2, 3, 4, 5, 6, 7, 1, |
| 131 | 2, 3, 4, 5, 1, 2, 3, 4, |
| 132 | 1, 2, 3, 1, 2, 3, 1, 2, |
| 133 | 1, 2, 1, 2, 1, 2, 1, 2, |
| 134 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 135 | 1, 1, 1, 1, 1, 1, 1, 1 |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 136 | }; |
| 137 | |
Andreas Rheinhardt | 3874442 | 2024-06-15 15:21:16 | [diff] [blame] | 138 | const int8_t ff_h261_tcoeff_run[64] = { |
Michael Niedermayer | 04b0fd7 | 2013-04-05 19:53:57 | [diff] [blame] | 139 | 0, |
| 140 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 141 | 0, 0, 0, 0, 0, 0, 0, 1, |
| 142 | 1, 1, 1, 1, 1, 1, 2, 2, |
| 143 | 2, 2, 2, 3, 3, 3, 3, 4, |
| 144 | 4, 4, 5, 5, 5, 6, 6, 7, |
| 145 | 7, 8, 8, 9, 9, 10, 10, 11, |
| 146 | 12, 13, 14, 15, 16, 17, 18, 19, |
| 147 | 20, 21, 22, 23, 24, 25, 26 |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | RLTable ff_h261_rl_tcoeff = { |
| 151 | 64, |
| 152 | 64, |
Andreas Rheinhardt | 3874442 | 2024-06-15 15:21:16 | [diff] [blame] | 153 | ff_h261_tcoeff_vlc, |
| 154 | ff_h261_tcoeff_run, |
| 155 | ff_h261_tcoeff_level, |
Reimar Döffinger | 5735f76 | 2012-04-10 21:13:59 | [diff] [blame] | 156 | }; |