| 1 | /* |
| 2 | * vlc.c |
| 3 | * |
| 4 | * Copyright (C) Charles 'Buck' Krasic - April 2000 |
| 5 | * Copyright (C) Erik Walthinsen - April 2000 |
| 6 | * |
| 7 | * This file is part of libdv, a free DV (IEC 61834/SMPTE 314M) |
| 8 | * codec. |
| 9 | * |
| 10 | * libdv is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU Lesser Public License as published by |
| 12 | * the Free Software Foundation; either version 2.1, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | * libdv is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser Public License |
| 21 | * along with libdv; see the file COPYING. If not, write to |
| 22 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | * The libdv homepage is http://libdv.sourceforge.net/. |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #if HAVE_CONFIG_H |
| 29 | # include <config.h> |
| 30 | #endif |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | #include "vlc.h" |
| 34 | |
| 35 | /* We will used five vlc tables, divided into what I term vlc |
| 36 | * "classes". A vlc class is identified by the codeword prefix, and |
| 37 | * its corresponding lookup table indexed by codeword suffix. The |
| 38 | * classes are organized by ranges of vlc codeword lengths as follows: |
| 39 | * |
| 40 | * class 0: incomplete vlcs (less than 3 bits available to decode); |
| 41 | * class 1: 2 <= length <= 5; |
| 42 | * class 2: 6 <= length <= 9; |
| 43 | * class 3: 10 <= length <= 12; |
| 44 | * class 4: length == 13 |
| 45 | * class 5: length == 15 |
| 46 | * |
| 47 | * The sizes of the respective lookup tables are: 1, 32, 128, 64, 64, 256 (all 32 bit elements). */ |
| 48 | |
| 49 | /* 2 or less bits available (no class selector) */ |
| 50 | static int8_t dv_vlc_class_broken[1] = { 0 }; |
| 51 | |
| 52 | /* 3 - 6 bits available (no class selector) */ |
| 53 | static int8_t dv_vlc_class_lookup1[1] = { 1 }; |
| 54 | |
| 55 | /* compact "rolled up" syntax not available for all compilers. |
| 56 | * It is safe to remove the "rolled" code, but it is left here |
| 57 | * until a code review agrees that the compiler safe code is |
| 58 | * identical. */ |
| 59 | |
| 60 | /* 7 - 10 bits available class selector is [0:1] */ |
| 61 | #ifdef __GNUC__ |
| 62 | static int8_t dv_vlc_class_lookup2[4] = { |
| 63 | [0x0 ... 0x2] = 1, |
| 64 | [0x3 ] = 2, |
| 65 | }; /* dv_vlc_class_lookup2 */ |
| 66 | #else /* ! __GNUC__ */ |
| 67 | static int8_t dv_vlc_class_lookup2[4] = { |
| 68 | 1, 1, 1, 2 |
| 69 | }; /* dv_vlc_class_lookup2 */ |
| 70 | #endif /* ! __GNUC__ */ |
| 71 | |
| 72 | /* 11 - 16 bits available, class selector is [0:6] */ |
| 73 | #ifdef __GNUC__ |
| 74 | static int8_t dv_vlc_class_lookup3[128] = { |
| 75 | [0x00 ... 0x5f] = 1, |
| 76 | [0x60 ... 0x7b] = 2, |
| 77 | [0x7c ... 0x7d] = 3, |
| 78 | [0x7e ] = 0, |
| 79 | [0x7f ] = 0 |
| 80 | }; /* dv_vlc_class_lookup3 */ |
| 81 | #else /* ! __GNUC__ */ |
| 82 | static int8_t dv_vlc_class_lookup3[128] = { |
| 83 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x00 ... 0x0f */ |
| 84 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x10 ... 0x1f */ |
| 85 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x20 ... 0x2f */ |
| 86 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x30 ... 0x3f */ |
| 87 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 ... 0x4f */ |
| 88 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 ... 0x5f */ |
| 89 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x60 ... 0x6f */ |
| 90 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 0, /* 0x70 ... 0x7f */ |
| 91 | }; /* dv_vlc_class_lookup3 */ |
| 92 | #endif /* ! __GNUC__ */ |
| 93 | |
| 94 | #ifdef __GNUC__ |
| 95 | static int8_t dv_vlc_class_lookup4[128] = { |
| 96 | [0x00 ... 0x5f] = 1, |
| 97 | [0x60 ... 0x7b] = 2, |
| 98 | [0x7c ... 0x7d] = 3, |
| 99 | [0x7e ] = 4, |
| 100 | [0x7f ] = 0 |
| 101 | }; /* dv_vlc_class_lookup4 */ |
| 102 | #else /* ! __GNUC__ */ |
| 103 | static int8_t dv_vlc_class_lookup4[128] = { |
| 104 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x00 ... 0x0f */ |
| 105 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x10 ... 0x1f */ |
| 106 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x20 ... 0x2f */ |
| 107 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x30 ... 0x3f */ |
| 108 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 ... 0x4f */ |
| 109 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 ... 0x5f */ |
| 110 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x60 ... 0x6f */ |
| 111 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 0, /* 0x70 ... 0x7f */ |
| 112 | }; /* dv_vlc_class_lookup4 */ |
| 113 | #endif /* ! __GNUC__ */ |
| 114 | |
| 115 | #ifdef __GNUC__ |
| 116 | int8_t dv_vlc_class_lookup5[128] = { |
| 117 | [0x00 ... 0x5f] = 1, |
| 118 | [0x60 ... 0x7b] = 2, |
| 119 | [0x7c ... 0x7d] = 3, |
| 120 | [0x7e ] = 4, |
| 121 | [0x7f ] = 5 |
| 122 | }; /* dv_vlc_class_lookup5 */ |
| 123 | #else /* ! __GNUC__ */ |
| 124 | int8_t dv_vlc_class_lookup5[128] = { |
| 125 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x00 ... 0x0f */ |
| 126 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x10 ... 0x1f */ |
| 127 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x20 ... 0x2f */ |
| 128 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x30 ... 0x3f */ |
| 129 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 ... 0x4f */ |
| 130 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 ... 0x5f */ |
| 131 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x60 ... 0x6f */ |
| 132 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 5, /* 0x70 ... 0x7f */ |
| 133 | }; /* dv_vlc_class_lookup5 */ |
| 134 | #endif /* ! __GNUC__ */ |
| 135 | |
| 136 | /* Indexed by number of bits available */ |
| 137 | |
| 138 | /* bitmask to extract class index, given x bits of left-aligned input |
| 139 | * the class index is derived from y prefix bits */ |
| 140 | |
| 141 | /* --------------------------------------------------------------------------- |
| 142 | * now initialized at runtime STL |
| 143 | */ |
| 144 | int8_t *dv_vlc_classes[64]; |
| 145 | int dv_vlc_class_index_mask[64]; |
| 146 | int dv_vlc_class_index_rshift[64]; |
| 147 | |
| 148 | #ifdef __GNUC__ |
| 149 | const dv_vlc_tab_t dv_vlc_broken[1] = { [0] = {run: -1, amp: -1, len: VLC_NOBITS} }; |
| 150 | #else /* ! __GNUC__ */ |
| 151 | const dv_vlc_tab_t dv_vlc_broken[1] = { {-1, VLC_NOBITS, -1} }; |
| 152 | #endif /* ! __GNUC__ */ |
| 153 | |
| 154 | #ifdef __GNUC__ |
| 155 | const dv_vlc_tab_t dv_vlc_lookup1[32] = { |
| 156 | /* prefix 00 */ |
| 157 | [0x00 ... 0x07] = {run: 0, amp: 1, len: 1+2}, /* 00s */ |
| 158 | /* prefix 010 */ |
| 159 | [0x08 ... 0x0b] = {run: 0, amp: 2, len: 1+3}, /* 010s */ |
| 160 | /* prefix 011 */ |
| 161 | [0x0c ... 0x0d] = {run: -1, amp: 0, len: 4}, /* 0110 (EOB) */ |
| 162 | [0x0e ... 0x0f] = {run: 1, amp: 1, len: 1+4}, /* 0111s */ |
| 163 | /* prefix 100 */ |
| 164 | [0x10 ... 0x11] = {run: 0, amp: 3, len: 1+4}, /* 1000s */ |
| 165 | [0x12 ... 0x13] = {run: 0, amp: 4, len: 1+4}, /* 1001s */ |
| 166 | /* prefix 101 */ |
| 167 | [0x14 ] = {run: 2, amp: 1, len: 1+5}, /* 10100s */ |
| 168 | [0x15 ] = {run: 1, amp: 2, len: 1+5}, /* 10101s */ |
| 169 | [0x16 ] = {run: 0, amp: 5, len: 1+5}, /* 10110s */ |
| 170 | [0x17 ] = {run: 0, amp: 6, len: 1+5}, /* 10111s */ |
| 171 | /* prefix 110-111 */ |
| 172 | [0x18 ... 0x1f] = {run: -1, amp: -1, len: VLC_NOBITS}, |
| 173 | }; /* dv_vlc_lookup1 */ |
| 174 | #else /* ! __GNUC__ */ |
| 175 | const dv_vlc_tab_t dv_vlc_lookup1[32] = { |
| 176 | /* prefix 00 */ |
| 177 | {0, 1+2, 1}, {0, 1+2, 1}, {0, 1+2, 1}, {0, 1+2, 1}, |
| 178 | {0, 1+2, 1}, {0, 1+2, 1}, {0, 1+2, 1}, {0, 1+2, 1}, |
| 179 | /* prefix 010 */ |
| 180 | {0, 1+3, 2}, {0, 1+3, 2}, {0, 1+3, 2}, {0, 1+3, 2}, |
| 181 | /* prefix 011 */ |
| 182 | {-1, 4, 0}, {-1, 4, 0}, |
| 183 | { 1, 1+4, 1}, { 1, 1+4, 1}, |
| 184 | /* prefix 100 */ |
| 185 | { 0, 1+4, 3}, { 0, 1+4, 3}, |
| 186 | { 0, 1+4, 4}, { 0, 1+4, 4}, |
| 187 | /* prefix 101 */ |
| 188 | { 2, 1+5, 1}, |
| 189 | { 1, 1+5, 2}, |
| 190 | { 0, 1+5, 5}, |
| 191 | { 0, 1+5, 6}, |
| 192 | /* prefix 110-111 */ |
| 193 | { -1,VLC_NOBITS,-1}, { -1,VLC_NOBITS, -1}, { -1,VLC_NOBITS,-1}, |
| 194 | { -1,VLC_NOBITS,-1}, { -1,VLC_NOBITS, -1}, { -1,VLC_NOBITS,-1}, |
| 195 | { -1,VLC_NOBITS,-1}, { -1,VLC_NOBITS, -1}, |
| 196 | }; /* dv_vlc_lookup1 */ |
| 197 | #endif /* ! __GNUC__ */ |
| 198 | |
| 199 | dv_vlc_tab_t dv_vlc_class1_shortcut[128]; |
| 200 | |
| 201 | #ifdef __GNUC__ |
| 202 | const dv_vlc_tab_t dv_vlc_lookup2[128] = { |
| 203 | /* prefix 110 */ |
| 204 | [0x00 ... 0x07] = {run: 3, amp: 1, len: 1+6}, /* 110000s */ |
| 205 | [0x08 ... 0x0f] = {run: 4, amp: 1, len: 1+6}, /* 110001s */ |
| 206 | [0x10 ... 0x17] = {run: 0, amp: 7, len: 1+6}, /* 110010s */ |
| 207 | [0x18 ... 0x1f] = {run: 0, amp: 8, len: 1+6}, /* 110011s */ |
| 208 | /* prefix 1101 */ |
| 209 | [0x20 ... 0x23] = {run: 5, amp: 1, len: 1+7}, /* 1101000s */ |
| 210 | [0x24 ... 0x27] = {run: 6, amp: 1, len: 1+7}, /* 1101001s */ |
| 211 | [0x28 ... 0x2b] = {run: 2, amp: 2, len: 1+7}, /* 1101010s */ |
| 212 | [0x2c ... 0x2f] = {run: 1, amp: 3, len: 1+7}, /* 1101011s */ |
| 213 | [0x30 ... 0x33] = {run: 1, amp: 4, len: 1+7}, /* 1101100s */ |
| 214 | [0x34 ... 0x37] = {run: 0, amp: 9, len: 1+7}, /* 1101101s */ |
| 215 | [0x38 ... 0x3b] = {run: 0, amp: 10, len: 1+7}, /* 1101110s */ |
| 216 | [0x3c ... 0x3f] = {run: 0, amp: 11, len: 1+7}, /* 1101111s */ |
| 217 | /* prefix 1110 */ |
| 218 | [0x40 ... 0x41] = {run: 7, amp: 1, len: 1+8}, /* 11100000s */ |
| 219 | [0x42 ... 0x43] = {run: 8, amp: 1, len: 1+8}, /* 11100001s */ |
| 220 | [0x44 ... 0x45] = {run: 9, amp: 1, len: 1+8}, /* 11100010s */ |
| 221 | [0x46 ... 0x47] = {run: 10, amp: 1, len: 1+8}, /* 11100011s */ |
| 222 | [0x48 ... 0x49] = {run: 3, amp: 2, len: 1+8}, /* 11100100s */ |
| 223 | [0x4a ... 0x4b] = {run: 4, amp: 2, len: 1+8}, /* 11100101s */ |
| 224 | [0x4c ... 0x4d] = {run: 2, amp: 3, len: 1+8}, /* 11100110s */ |
| 225 | [0x4e ... 0x4f] = {run: 1, amp: 5, len: 1+8}, /* 11100111s */ |
| 226 | [0x50 ... 0x51] = {run: 1, amp: 6, len: 1+8}, /* 11101000s */ |
| 227 | [0x52 ... 0x53] = {run: 1, amp: 7, len: 1+8}, /* 11101001s */ |
| 228 | [0x54 ... 0x55] = {run: 0, amp: 12, len: 1+8}, /* 11101010s */ |
| 229 | [0x56 ... 0x57] = {run: 0, amp: 13, len: 1+8}, /* 11101011s */ |
| 230 | [0x58 ... 0x59] = {run: 0, amp: 14, len: 1+8}, /* 11101100s */ |
| 231 | [0x5a ... 0x5b] = {run: 0, amp: 15, len: 1+8}, /* 11101101s */ |
| 232 | [0x5c ... 0x5d] = {run: 0, amp: 16, len: 1+8}, /* 11101110s */ |
| 233 | [0x5e ... 0x5f] = {run: 0, amp: 17, len: 1+8}, /* 11101111s */ |
| 234 | /* prefix 1111 0 */ |
| 235 | [0x60 ] = {run: 11, amp: 1, len: 1+9}, /* 1111 0000 0s */ |
| 236 | [0x61 ] = {run: 12, amp: 1, len: 1+9}, /* 1111 0000 1s */ |
| 237 | [0x62 ] = {run: 13, amp: 1, len: 1+9}, /* 1111 0001 0s */ |
| 238 | [0x63 ] = {run: 14, amp: 1, len: 1+9}, /* 1111 0001 1s */ |
| 239 | [0x64 ] = {run: 5, amp: 2, len: 1+9}, /* 1111 0010 0s */ |
| 240 | [0x65 ] = {run: 6, amp: 2, len: 1+9}, /* 1111 0010 1s */ |
| 241 | [0x66 ] = {run: 3, amp: 3, len: 1+9}, /* 1111 0011 0s */ |
| 242 | [0x67 ] = {run: 4, amp: 3, len: 1+9}, /* 1111 0011 1s */ |
| 243 | [0x68 ] = {run: 2, amp: 4, len: 1+9}, /* 1111 0100 0s */ |
| 244 | [0x69 ] = {run: 2, amp: 5, len: 1+9}, /* 1111 0100 1s */ |
| 245 | [0x6a ] = {run: 1, amp: 8, len: 1+9}, /* 1111 0101 0s */ |
| 246 | [0x6b ] = {run: 0, amp: 18, len: 1+9}, /* 1111 0101 1s */ |
| 247 | [0x6c ] = {run: 0, amp: 19, len: 1+9}, /* 1111 0110 0s */ |
| 248 | [0x6d ] = {run: 0, amp: 20, len: 1+9}, /* 1111 0110 1s */ |
| 249 | [0x6e ] = {run: 0, amp: 21, len: 1+9}, /* 1111 0111 0s */ |
| 250 | [0x6f ] = {run: 0, amp: 22, len: 1+9}, /* 1111 0111 1s */ |
| 251 | /* prefix 1111 1 */ |
| 252 | [0x70 ... 0x7f] = {run: -1, amp: -1, len: VLC_NOBITS}, |
| 253 | }; /* dv_vlc_lookup2 */ |
| 254 | #else /* ! __GNUC__ */ |
| 255 | const dv_vlc_tab_t dv_vlc_lookup2[128] = { |
| 256 | /* prefix 110 */ |
| 257 | {3, 1+6, 1}, {3, 1+6, 1}, {3, 1+6, 1}, {3, 1+6, 1}, |
| 258 | {3, 1+6, 1}, {3, 1+6, 1}, {3, 1+6, 1}, {3, 1+6, 1}, |
| 259 | {4, 1+6, 1}, {4, 1+6, 1}, {4, 1+6, 1}, {4, 1+6, 1}, |
| 260 | {4, 1+6, 1}, {4, 1+6, 1}, {4, 1+6, 1}, {4, 1+6, 1}, |
| 261 | {0, 1+6, 7}, {0, 1+6, 7}, {0, 1+6, 7}, {0, 1+6, 7}, |
| 262 | {0, 1+6, 7}, {0, 1+6, 7}, {0, 1+6, 7}, {0, 1+6, 7}, |
| 263 | {0, 1+6, 8}, {0, 1+6, 8}, {0, 1+6, 8}, {0, 1+6, 8}, |
| 264 | {0, 1+6, 8}, {0, 1+6, 8}, {0, 1+6, 8}, {0, 1+6, 8}, |
| 265 | |
| 266 | /* prefix 1101 */ |
| 267 | {5, 1+7, 1}, {5, 1+7, 1}, {5, 1+7, 1}, {5, 1+7, 1}, |
| 268 | {6, 1+7, 1}, {6, 1+7, 1}, {6, 1+7, 1}, {6, 1+7, 1}, |
| 269 | {2, 1+7, 2}, {2, 1+7, 2}, {2, 1+7, 2}, {2, 1+7, 2}, |
| 270 | {1, 1+7, 3}, {1, 1+7, 3}, {1, 1+7, 3}, {1, 1+7, 3}, |
| 271 | {1, 1+7, 4}, {1, 1+7, 4}, {1, 1+7, 4}, {1, 1+7, 4}, |
| 272 | {0, 1+7, 9}, {0, 1+7, 9}, {0, 1+7, 9}, {0, 1+7, 9}, |
| 273 | {0, 1+7, 10}, {0, 1+7, 10}, {0, 1+7, 10}, {0, 1+7, 10}, |
| 274 | {0, 1+7, 11}, {0, 1+7, 11}, {0, 1+7, 11}, {0, 1+7, 11}, |
| 275 | |
| 276 | /* prefix 1110 */ |
| 277 | {7, 1+8, 1}, {7, 1+8, 1}, |
| 278 | {8, 1+8, 1}, {8, 1+8, 1}, |
| 279 | {9, 1+8, 1}, {9, 1+8, 1}, |
| 280 | {10, 1+8, 1}, {10, 1+8, 1}, |
| 281 | {3, 1+8, 2}, {3, 1+8, 2}, |
| 282 | {4, 1+8, 2}, {4, 1+8, 2}, |
| 283 | {2, 1+8, 3}, {2, 1+8, 3}, |
| 284 | {1, 1+8, 5}, {1, 1+8, 5}, |
| 285 | {1, 1+8, 6}, {1, 1+8, 6}, |
| 286 | {1, 1+8, 7}, {1, 1+8, 7}, |
| 287 | {0, 1+8, 12}, {0, 1+8, 12}, |
| 288 | {0, 1+8, 13}, {0, 1+8, 13}, |
| 289 | {0, 1+8, 14}, {0, 1+8, 14}, |
| 290 | {0, 1+8, 15}, {0, 1+8, 15}, |
| 291 | {0, 1+8, 16}, {0, 1+8, 16}, |
| 292 | {0, 1+8, 17}, {0, 1+8, 17}, |
| 293 | |
| 294 | /* prefix 1111 0 */ |
| 295 | {11, 1+9, 1}, /* 1111 0000 0s */ |
| 296 | {12, 1+9, 1}, /* 1111 0000 1s */ |
| 297 | {13, 1+9, 1}, /* 1111 0001 0s */ |
| 298 | {14, 1+9, 1}, /* 1111 0001 1s */ |
| 299 | {5, 1+9, 2}, /* 1111 0010 0s */ |
| 300 | {6, 1+9, 2}, /* 1111 0010 1s */ |
| 301 | {3, 1+9, 3}, /* 1111 0011 0s */ |
| 302 | {4, 1+9, 3}, /* 1111 0011 1s */ |
| 303 | {2, 1+9, 4}, /* 1111 0100 0s */ |
| 304 | {2, 1+9, 5}, /* 1111 0100 1s */ |
| 305 | {1, 1+9, 8}, /* 1111 0101 0s */ |
| 306 | {0, 1+9, 18}, /* 1111 0101 1s */ |
| 307 | {0, 1+9, 19}, /* 1111 0110 0s */ |
| 308 | {0, 1+9, 20}, /* 1111 0110 1s */ |
| 309 | {0, 1+9, 21}, /* 1111 0111 0s */ |
| 310 | {0, 1+9, 22}, /* 1111 0111 1s */ |
| 311 | |
| 312 | /* prefix 1111 1 */ |
| 313 | {-1, VLC_NOBITS, -1}, |
| 314 | {-1, VLC_NOBITS, -1}, |
| 315 | {-1, VLC_NOBITS, -1}, |
| 316 | {-1, VLC_NOBITS, -1}, |
| 317 | {-1, VLC_NOBITS, -1}, |
| 318 | {-1, VLC_NOBITS, -1}, |
| 319 | {-1, VLC_NOBITS, -1}, |
| 320 | {-1, VLC_NOBITS, -1}, |
| 321 | {-1, VLC_NOBITS, -1}, |
| 322 | {-1, VLC_NOBITS, -1}, |
| 323 | {-1, VLC_NOBITS, -1}, |
| 324 | {-1, VLC_NOBITS, -1}, |
| 325 | {-1, VLC_NOBITS, -1}, |
| 326 | {-1, VLC_NOBITS, -1}, |
| 327 | {-1, VLC_NOBITS, -1}, |
| 328 | {-1, VLC_NOBITS, -1}, |
| 329 | }; /* dv_vlc_lookup2 */ |
| 330 | #endif /* ! __GNUC__ */ |
| 331 | |
| 332 | #ifdef __GNUC__ |
| 333 | const dv_vlc_tab_t dv_vlc_lookup3[64] = { |
| 334 | /* len 10+1/prefix 1111 1000 */ |
| 335 | [0x00 ... 0x03] = {run: 5, amp: 3, len: 1+10}, /* 1111 1000 00s */ |
| 336 | [0x04 ... 0x07] = {run: 3, amp: 4, len: 1+10}, /* 1111 1000 01s */ |
| 337 | [0x08 ... 0x0b] = {run: 3, amp: 5, len: 1+10}, /* 1111 1000 10s */ |
| 338 | [0x0c ... 0x0f] = {run: 2, amp: 6, len: 1+10}, /* 1111 1000 11s */ |
| 339 | /* len 10+1/prefix 1111 1001 0 */ |
| 340 | [0x10 ... 0x13] = {run: 1, amp: 9, len: 1+10}, /* 1111 1001 00s */ |
| 341 | [0x14 ... 0x17] = {run: 1, amp: 10, len: 1+10}, /* 1111 1001 01s */ |
| 342 | /* len 10+1/prefix 1111 1001 10 */ |
| 343 | [0x18 ... 0x1b] = {run: 1, amp: 11, len: 1+10}, /* 1111 1001 10s */ |
| 344 | /* len 11/prefix 1111 1001 11 */ |
| 345 | [0x1c ... 0x1d] = {run: 0, amp: 0, len: 11}, /* 1111 1001 110s */ |
| 346 | [0x1e ... 0x1f] = {run: 1, amp: 0, len: 11}, /* 1111 1001 111s */ |
| 347 | /* len 11+1/prefix 1111 1010 0 */ |
| 348 | [0x20 ... 0x21] = {run: 6, amp: 3, len: 1+11}, /* 1111 1010 000s */ |
| 349 | [0x22 ... 0x23] = {run: 4, amp: 4, len: 1+11}, /* 1111 1010 001s */ |
| 350 | [0x24 ... 0x25] = {run: 3, amp: 6, len: 1+11}, /* 1111 1010 010s */ |
| 351 | [0x26 ... 0x27] = {run: 1, amp: 12, len: 1+11}, /* 1111 1010 011s */ |
| 352 | /* len 11+1/prefix 1111 1010 10 */ |
| 353 | [0x28 ... 0x29] = {run: 1, amp: 13, len: 1+11}, /* 1111 1010 100s */ |
| 354 | [0x2a ... 0x2b] = {run: 1, amp: 14, len: 1+11}, /* 1111 1010 101s */ |
| 355 | /* len 12/prefix 1111 1010 11 */ |
| 356 | [0x2c ] = {run: 2, amp: 0, len: 12}, /* 1111 1010 1100 */ |
| 357 | [0x2d ] = {run: 3, amp: 0, len: 12}, /* 1111 1010 1101 */ |
| 358 | [0x2e ] = {run: 4, amp: 0, len: 12}, /* 1111 1010 1110 */ |
| 359 | [0x2f ] = {run: 5, amp: 0, len: 12}, /* 1111 1010 1111 */ |
| 360 | /* len 12+1/prefix 1111 1011 */ |
| 361 | [0x30 ] = {run: 7, amp: 2, len: 1+12}, /* 1111 1011 0000s */ |
| 362 | [0x31 ] = {run: 8, amp: 2, len: 1+12}, /* 1111 1011 0001s */ |
| 363 | [0x32 ] = {run: 9, amp: 2, len: 1+12}, /* 1111 1011 0010s */ |
| 364 | [0x33 ] = {run: 10,amp: 2, len: 1+12}, /* 1111 1011 0011s */ |
| 365 | [0x34 ] = {run: 7, amp: 3, len: 1+12}, /* 1111 1011 0100s */ |
| 366 | [0x35 ] = {run: 8, amp: 3, len: 1+12}, /* 1111 1011 0101s */ |
| 367 | [0x36 ] = {run: 4, amp: 5, len: 1+12}, /* 1111 1011 0110s */ |
| 368 | [0x37 ] = {run: 3, amp: 7, len: 1+12}, /* 1111 1011 0111s */ |
| 369 | [0x38 ] = {run: 2, amp: 7, len: 1+12}, /* 1111 1011 1000s */ |
| 370 | [0x39 ] = {run: 2, amp: 8, len: 1+12}, /* 1111 1011 1001s */ |
| 371 | [0x3a ] = {run: 2, amp: 9, len: 1+12}, /* 1111 1011 1010s */ |
| 372 | [0x3b ] = {run: 2, amp: 10, len: 1+12}, /* 1111 1011 1011s */ |
| 373 | [0x3c ] = {run: 2, amp: 11, len: 1+12}, /* 1111 1011 1100s */ |
| 374 | [0x3d ] = {run: 1, amp: 15, len: 1+12}, /* 1111 1011 1101s */ |
| 375 | [0x3e ] = {run: 1, amp: 16, len: 1+12}, /* 1111 1011 1110s */ |
| 376 | [0x3f ] = {run: 1, amp: 17, len: 1+12}, /* 1111 1011 1111s */ |
| 377 | }; /* dv_vlc_lookup3 */ |
| 378 | #else /* ! __GNUC__ */ |
| 379 | const dv_vlc_tab_t dv_vlc_lookup3[64] = { |
| 380 | /* len 10+1/prefix 1111 1000 */ |
| 381 | {5, 1+10, 3}, /* 1111 1000 00s */ |
| 382 | {5, 1+10, 3}, /* 1111 1000 00s */ |
| 383 | {5, 1+10, 3}, /* 1111 1000 00s */ |
| 384 | {5, 1+10, 3}, /* 1111 1000 00s */ |
| 385 | |
| 386 | {3, 1+10, 4}, /* 1111 1000 01s */ |
| 387 | {3, 1+10, 4}, /* 1111 1000 01s */ |
| 388 | {3, 1+10, 4}, /* 1111 1000 01s */ |
| 389 | {3, 1+10, 4}, /* 1111 1000 01s */ |
| 390 | |
| 391 | {3, 1+10, 5}, /* 1111 1000 10s */ |
| 392 | {3, 1+10, 5}, /* 1111 1000 10s */ |
| 393 | {3, 1+10, 5}, /* 1111 1000 10s */ |
| 394 | {3, 1+10, 5}, /* 1111 1000 10s */ |
| 395 | |
| 396 | {2, 1+10, 6}, /* 1111 1000 11s */ |
| 397 | {2, 1+10, 6}, /* 1111 1000 11s */ |
| 398 | {2, 1+10, 6}, /* 1111 1000 11s */ |
| 399 | {2, 1+10, 6}, /* 1111 1000 11s */ |
| 400 | |
| 401 | /* len 10+1/prefix 1111 1001 0 */ |
| 402 | {1, 1+10, 9}, /* 1111 1001 00s */ |
| 403 | {1, 1+10, 9}, /* 1111 1001 00s */ |
| 404 | {1, 1+10, 9}, /* 1111 1001 00s */ |
| 405 | {1, 1+10, 9}, /* 1111 1001 00s */ |
| 406 | |
| 407 | {1, 1+10, 10}, /* 1111 1001 01s */ |
| 408 | {1, 1+10, 10}, /* 1111 1001 01s */ |
| 409 | {1, 1+10, 10}, /* 1111 1001 01s */ |
| 410 | {1, 1+10, 10}, /* 1111 1001 01s */ |
| 411 | /* len 10+1/prefix 1111 1001 10 */ |
| 412 | {1, 1+10, 11}, /* 1111 1001 10s */ |
| 413 | {1, 1+10, 11}, /* 1111 1001 10s */ |
| 414 | {1, 1+10, 11}, /* 1111 1001 10s */ |
| 415 | {1, 1+10, 11}, /* 1111 1001 10s */ |
| 416 | /* len 11/prefix 1111 1001 11 */ |
| 417 | {0, 11, 0}, /* 1111 1001 110s */ |
| 418 | {0, 11, 0}, /* 1111 1001 110s */ |
| 419 | |
| 420 | {1, 11, 0}, /* 1111 1001 111s */ |
| 421 | {1, 11, 0}, /* 1111 1001 111s */ |
| 422 | /* len 11+1/prefix 1111 1010 0 */ |
| 423 | {6, 1+11, 3}, /* 1111 1010 000s */ |
| 424 | {6, 1+11, 3}, /* 1111 1010 000s */ |
| 425 | {4, 1+11, 4}, /* 1111 1010 001s */ |
| 426 | {4, 1+11, 4}, /* 1111 1010 001s */ |
| 427 | {3, 1+11, 6}, /* 1111 1010 010s */ |
| 428 | {3, 1+11, 6}, /* 1111 1010 010s */ |
| 429 | {1, 1+11, 12}, /* 1111 1010 011s */ |
| 430 | {1, 1+11, 12}, /* 1111 1010 011s */ |
| 431 | /* len 11+1/prefix 1111 1010 10 */ |
| 432 | {1, 1+11, 13}, /* 1111 1010 100s */ |
| 433 | {1, 1+11, 13}, /* 1111 1010 100s */ |
| 434 | {1, 1+11, 14}, /* 1111 1010 101s */ |
| 435 | {1, 1+11, 14}, /* 1111 1010 101s */ |
| 436 | /* len 12/prefix 1111 1010 11 */ |
| 437 | {2, 12, 0}, /* 1111 1010 1100 */ |
| 438 | {3, 12, 0}, /* 1111 1010 1101 */ |
| 439 | {4, 12, 0}, /* 1111 1010 1110 */ |
| 440 | {5, 12, 0}, /* 1111 1010 1111 */ |
| 441 | /* len 12+1/prefix 1111 1011 */ |
| 442 | {7, 1+12, 2}, /* 1111 1011 0000s */ |
| 443 | {8, 1+12, 2}, /* 1111 1011 0001s */ |
| 444 | {9, 1+12, 2}, /* 1111 1011 0010s */ |
| 445 | {10,1+12, 2}, /* 1111 1011 0011s */ |
| 446 | {7, 1+12, 3}, /* 1111 1011 0100s */ |
| 447 | {8, 1+12, 3}, /* 1111 1011 0101s */ |
| 448 | {4, 1+12, 5}, /* 1111 1011 0110s */ |
| 449 | {3, 1+12, 7}, /* 1111 1011 0111s */ |
| 450 | {2, 1+12, 7}, /* 1111 1011 1000s */ |
| 451 | {2, 1+12, 8}, /* 1111 1011 1001s */ |
| 452 | {2, 1+12, 9}, /* 1111 1011 1010s */ |
| 453 | {2, 1+12, 10}, /* 1111 1011 1011s */ |
| 454 | {2, 1+12, 11}, /* 1111 1011 1100s */ |
| 455 | {1, 1+12, 15}, /* 1111 1011 1101s */ |
| 456 | {1, 1+12, 16}, /* 1111 1011 1110s */ |
| 457 | {1, 1+12, 17}, /* 1111 1011 1111s */ |
| 458 | }; /* dv_vlc_lookup3 */ |
| 459 | #endif /* ! __GNUC__ */ |
| 460 | |
| 461 | #ifdef __GNUC__ |
| 462 | dv_vlc_tab_t dv_vlc_lookup4[64] = { /* len 13/prefix 1111 110 */ |
| 463 | [0 ... 63] = {run: 0, amp: -1, len: VLC_ERROR}, |
| 464 | }; /* dv_vlc_lookup4 */ |
| 465 | #else /* ! __GNUC__ */ |
| 466 | dv_vlc_tab_t dv_vlc_lookup4[64] = { /* len 13/prefix 1111 110 */ |
| 467 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 468 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 469 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 470 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 471 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 472 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 473 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 474 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 475 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 476 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 477 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 478 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 479 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 480 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 481 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 482 | {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0,VLC_ERROR, -1}, {0, VLC_ERROR, -1}, |
| 483 | /* [0 ... 63] = {run: 0, amp: -1, len: VLC_ERROR}, */ |
| 484 | }; /* dv_vlc_lookup4 */ |
| 485 | #endif /* ! __GNUC__ */ |
| 486 | |
| 487 | #ifdef __GNUC__ |
| 488 | dv_vlc_tab_t dv_vlc_lookup5[256] = { /* len 15+1/prefix 1111 111 */ |
| 489 | [0 ... 255] = {run: 0, amp: -1, len: VLC_ERROR}, |
| 490 | }; /* dv_vlc_lookup6 */ |
| 491 | #else /* ! __GNUC__ */ |
| 492 | dv_vlc_tab_t dv_vlc_lookup5[256] = { /* len 15+1/prefix 1111 111 */ |
| 493 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 494 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 495 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 496 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 497 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 498 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 499 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 500 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 501 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 502 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 503 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 504 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 505 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 506 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 507 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 508 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 509 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 510 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 511 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 512 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 513 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 514 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 515 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 516 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 517 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 518 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 519 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 520 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 521 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 522 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 523 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 524 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 525 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 526 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 527 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 528 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 529 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 530 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 531 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 532 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 533 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 534 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 535 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 536 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 537 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 538 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 539 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 540 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 541 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 542 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 543 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 544 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 545 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 546 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 547 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 548 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 549 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 550 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 551 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 552 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 553 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 554 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 555 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 556 | {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, {0,VLC_ERROR,-1}, |
| 557 | }; /* dv_vlc_lookup5 */ |
| 558 | #endif /* ! __GNUC__ */ |
| 559 | |
| 560 | |
| 561 | const dv_vlc_tab_t *dv_vlc_lookups[6] = { |
| 562 | dv_vlc_broken, |
| 563 | dv_vlc_lookup1, |
| 564 | dv_vlc_lookup2, |
| 565 | dv_vlc_lookup3, |
| 566 | dv_vlc_lookup4, |
| 567 | dv_vlc_lookup5, |
| 568 | }; /* dv_vlc_lookups */ |
| 569 | |
| 570 | #ifdef __GNUC__ |
| 571 | const int dv_vlc_index_mask[6] = { |
| 572 | [0] = 0x0000, /* no choice */ |
| 573 | [1] = 0xf800, /* 5 bit selector [0:4] */ |
| 574 | [2] = 0x3f80, /* 7 bit selector [2:8] */ |
| 575 | [3] = 0x03f0, /* 6 bit selector [6:11] */ |
| 576 | [4] = 0x01f8, /* 6 bit selector [7:12] */ |
| 577 | [5] = 0x01fe, /* 8 bit selector [7:14] */ |
| 578 | }; /* dv_vlc_index_mask */ |
| 579 | #else /* ! __GNUC__ */ |
| 580 | const int dv_vlc_index_mask[6] = { |
| 581 | 0x0000, /* no choice */ |
| 582 | 0xf800, /* 5 bit selector [0:4] */ |
| 583 | 0x3f80, /* 7 bit selector [2:8] */ |
| 584 | 0x03f0, /* 6 bit selector [6:11] */ |
| 585 | 0x01f8, /* 6 bit selector [7:12] */ |
| 586 | 0x01fe, /* 8 bit selector [7:14] */ |
| 587 | }; /* dv_vlc_index_mask */ |
| 588 | #endif /* ! __GNUC__ */ |
| 589 | |
| 590 | #ifdef __GNUC__ |
| 591 | const int dv_vlc_index_rshift[6] = { |
| 592 | [0] = 0, |
| 593 | [1] = 11, |
| 594 | [2] = 7, |
| 595 | [3] = 4, |
| 596 | [4] = 3, |
| 597 | [5] = 1, |
| 598 | }; /* */ |
| 599 | #else /* ! __GNUC__ */ |
| 600 | const int dv_vlc_index_rshift[6] = { |
| 601 | 0, |
| 602 | 11, |
| 603 | 7, |
| 604 | 4, |
| 605 | 3, |
| 606 | 1, |
| 607 | }; /* */ |
| 608 | #endif /* ! __GNUC__ */ |
| 609 | |
| 610 | #ifdef __GNUC__ |
| 611 | const int sign_mask[17] = { |
| 612 | [1] = 0x1 << 15, |
| 613 | [2] = 0x1 << 14, |
| 614 | [3] = 0x1 << 13, |
| 615 | [4] = 0x1 << 12, |
| 616 | [5] = 0x1 << 11, |
| 617 | [6] = 0x1 << 10, |
| 618 | [7] = 0x1 << 9, |
| 619 | [8] = 0x1 << 8, |
| 620 | [9] = 0x1 << 7, |
| 621 | [10] = 0x1 << 6, |
| 622 | [11] = 0x1 << 5, |
| 623 | [12] = 0x1 << 4, |
| 624 | [13] = 0x1 << 3, |
| 625 | [14] = 0x1 << 2, |
| 626 | [15] = 0x1 << 1, |
| 627 | [16] = 0x1, |
| 628 | }; |
| 629 | #else /* ! __GNUC__ */ |
| 630 | const int sign_mask[17] = { |
| 631 | 0x0, |
| 632 | 0x1 << 15, |
| 633 | 0x1 << 14, |
| 634 | 0x1 << 13, |
| 635 | 0x1 << 12, |
| 636 | 0x1 << 11, |
| 637 | 0x1 << 10, |
| 638 | 0x1 << 9, |
| 639 | 0x1 << 8, |
| 640 | 0x1 << 7, |
| 641 | 0x1 << 6, |
| 642 | 0x1 << 5, |
| 643 | 0x1 << 4, |
| 644 | 0x1 << 3, |
| 645 | 0x1 << 2, |
| 646 | 0x1 << 1, |
| 647 | 0x1, |
| 648 | }; |
| 649 | #endif /* ! __GNUC__ */ |
| 650 | |
| 651 | |
| 652 | #ifdef __GNUC__ |
| 653 | const int sign_rshift[17] = { |
| 654 | [1] = 15, |
| 655 | [2] = 14, |
| 656 | [3] = 13, |
| 657 | [4] = 12, |
| 658 | [5] = 11, |
| 659 | [6] = 10, |
| 660 | [7] = 9, |
| 661 | [8] = 8, |
| 662 | [9] = 7, |
| 663 | [10] = 6, |
| 664 | [11] = 5, |
| 665 | [12] = 4, |
| 666 | [13] = 3, |
| 667 | [14] = 2, |
| 668 | [15] = 1, |
| 669 | }; |
| 670 | #else /* ! __GNUC__ */ |
| 671 | const int sign_rshift[17] = { |
| 672 | 0, |
| 673 | 15, |
| 674 | 14, |
| 675 | 13, |
| 676 | 12, |
| 677 | 11, |
| 678 | 10, |
| 679 | 9, |
| 680 | 8, |
| 681 | 7, |
| 682 | 6, |
| 683 | 5, |
| 684 | 4, |
| 685 | 3, |
| 686 | 2, |
| 687 | 1, |
| 688 | }; |
| 689 | #endif /* ! __GNUC__ */ |
| 690 | |
| 691 | void dv_construct_vlc_table() { |
| 692 | int i; |
| 693 | |
| 694 | /* ------------------------------------------------------------------------- |
| 695 | * converted some static initialisations to run time, BUG #231580 STL |
| 696 | */ |
| 697 | /* Indexed by number of bits available */ |
| 698 | for (i = 0; i <= 2; ++i) |
| 699 | dv_vlc_classes [i] = &dv_vlc_class_broken [0]; |
| 700 | for (i = 3; i <= 6; ++i) |
| 701 | dv_vlc_classes [i] = &dv_vlc_class_lookup1 [0]; |
| 702 | for (i = 7; i <= 10; ++i) |
| 703 | dv_vlc_classes [i] = &dv_vlc_class_lookup2 [0]; |
| 704 | for (i = 11; i <= 12; ++i) |
| 705 | dv_vlc_classes [i] = &dv_vlc_class_lookup3 [0]; |
| 706 | for (i = 13; i <= 15; ++i) |
| 707 | dv_vlc_classes [i] = &dv_vlc_class_lookup4 [0]; |
| 708 | for (i = 16; i <= 63; ++i) |
| 709 | dv_vlc_classes [i] = &dv_vlc_class_lookup5 [0]; |
| 710 | |
| 711 | /* ------------------------------------------------------------------------- |
| 712 | * bitmask to extract class index, given x bits of left-aligned input |
| 713 | * the class index is derived from y prefix bits |
| 714 | */ |
| 715 | for (i = 0; i <= 6; i++) { |
| 716 | dv_vlc_class_index_mask [i] = 0x0000; |
| 717 | dv_vlc_class_index_rshift [i] = 0; |
| 718 | } |
| 719 | for (i = 7; i <= 10; i++) { |
| 720 | dv_vlc_class_index_mask [i] = 0xC000; |
| 721 | dv_vlc_class_index_rshift [i] = 14; |
| 722 | } |
| 723 | for (i = 11; i <= 63; i++) { |
| 724 | dv_vlc_class_index_mask [i] = 0xFE00; |
| 725 | dv_vlc_class_index_rshift [i] = 9; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | for(i=6; i<62; i++) { |
| 730 | dv_vlc_lookup4[i].run = i; |
| 731 | dv_vlc_lookup4[i].amp = 0; |
| 732 | dv_vlc_lookup4[i].len = 13; |
| 733 | } /* for */ |
| 734 | for(i=23; i<256; i++) { |
| 735 | dv_vlc_lookup5[i].run = 0; |
| 736 | dv_vlc_lookup5[i].amp = i; |
| 737 | dv_vlc_lookup5[i].len = 1 + 15; |
| 738 | } /* for */ |
| 739 | |
| 740 | /* Build dv_vlc_class1_shortcut[] by attempting to match class 1 and |
| 741 | class 2 vlcs. */ |
| 742 | for (i = 0; i < 128; i++) { |
| 743 | unsigned int bits = i << 9; |
| 744 | unsigned int ms7 = ((bits & 0xfe00) >> 9); |
| 745 | const dv_vlc_t *result; |
| 746 | |
| 747 | if (ms7 <= 0x5f) { |
| 748 | /* class 1 */ |
| 749 | result = &dv_vlc_lookup1[i >> 2]; |
| 750 | } else if (ms7 <= 0x7b) { |
| 751 | /* class 2 */ |
| 752 | result = &dv_vlc_lookup2[(bits & dv_vlc_index_mask[2]) >> dv_vlc_index_rshift[2]]; |
| 753 | if (result->len > 7) |
| 754 | result = NULL; |
| 755 | } else { |
| 756 | result = NULL; |
| 757 | } |
| 758 | |
| 759 | /* result is non-NULL if a vlc matched. */ |
| 760 | if (result) { |
| 761 | dv_vlc_class1_shortcut[i] = *result; |
| 762 | if ((result->amp > 0) && ((bits >> sign_rshift[result->len]) & 1)) |
| 763 | dv_vlc_class1_shortcut[i].amp *= -1; |
| 764 | } else { |
| 765 | dv_vlc_class1_shortcut[i] = dv_vlc_lookup1[0x1f]; |
| 766 | } |
| 767 | } |
| 768 | } /* dv_construct_vlc_table */ |
| 769 | |
| 770 | /* Note we assume bits is right (lsb) aligned, and that (0 < maxbits < |
| 771 | * 17). This may look crazy, but there are no branches here. */ |
| 772 | |
| 773 | #if (!ARCH_X86) && (!ARCH_X86_64) |
| 774 | void dv_decode_vlc(int bits,int maxbits, dv_vlc_t *result) { |
| 775 | #ifdef __GNUC__ |
| 776 | static dv_vlc_t vlc_broken = {run: -1, amp: -1, len: VLC_NOBITS}; |
| 777 | #else /* ! __GNUC__ */ |
| 778 | static dv_vlc_t vlc_broken = {-1, VLC_NOBITS, -1}; |
| 779 | #endif /* ! __GNUC__ */ |
| 780 | dv_vlc_t *results[2] = { &vlc_broken, result }; |
| 781 | int klass, has_sign, amps[2]; |
| 782 | |
| 783 | /* note that BITS is left aligned */ |
| 784 | klass = dv_vlc_classes[maxbits][(bits & (dv_vlc_class_index_mask[maxbits])) >> (dv_vlc_class_index_rshift[maxbits])]; |
| 785 | *result = dv_vlc_lookups[klass][(bits & (dv_vlc_index_mask[klass])) >> (dv_vlc_index_rshift[klass])]; |
| 786 | amps[1] = -(amps[0] = result->amp); |
| 787 | has_sign = amps[0] > 0; |
| 788 | result->amp = amps[has_sign & /* or vlc not valid */ |
| 789 | (bits >> sign_rshift[result->len])]; |
| 790 | *result = *results[maxbits >= result->len]; |
| 791 | } /* dv_decode_vlc */ |
| 792 | |
| 793 | /* Fastpath version of previous function; assumes full 16bits are |
| 794 | available, which eleminates left align of input, check for enough |
| 795 | bits at end, and hardcodes lookups on maxbits. */ |
| 796 | |
| 797 | void __dv_decode_vlc(int bits, dv_vlc_t *result) { |
| 798 | int klass, has_sign, amps[2]; |
| 799 | |
| 800 | klass = dv_vlc_classes[16][(bits & (dv_vlc_class_index_mask[16])) >> (dv_vlc_class_index_rshift[16])]; |
| 801 | *result = dv_vlc_lookups[klass][(bits & (dv_vlc_index_mask[klass])) >> (dv_vlc_index_rshift[klass])]; |
| 802 | amps[1] = -(amps[0] = result->amp); |
| 803 | has_sign = amps[0] > 0; |
| 804 | result->amp = amps[has_sign & /* or vlc not valid */ |
| 805 | (bits >> sign_rshift[result->len])]; |
| 806 | } /* __dv_decode_vlc */ |
| 807 | #endif /* (! ARCH_X86) && (!ARCH_X86_64) */ |