dnxhddata.c 55.2 KB
Newer Older
1 2
/*
 * VC3/DNxHD data.
3
 * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

22
#include "avcodec.h"
23
#include "dnxhddata.h"
24
#include "libavutil/common.h"
25

26 27
/* The quantization tables below are in zigzag order! */

28
/* Used in CID 1235, 1256, 1270 */
29
static const uint8_t dnxhd_1235_luma_weight[] = {
30 31 32 33 34 35 36 37
     0, 32, 32, 32, 33, 32, 32, 32,
    32, 31, 32, 33, 33, 33, 33, 35,
    36, 36, 34, 34, 36, 37, 37, 36,
    36, 35, 36, 38, 39, 39, 37, 36,
    37, 37, 39, 41, 42, 41, 39, 39,
    40, 41, 42, 43, 42, 42, 41, 41,
    41, 44, 47, 46, 46, 48, 51, 51,
    50, 50, 53, 55, 55, 56, 60, 60,
38 39
};

40
/* Used in CID 1235, 1256 */
41
static const uint8_t dnxhd_1235_chroma_weight[] = {
42 43 44 45 46 47 48 49
     0, 32, 33, 34, 34, 33, 34, 35,
    37, 40, 43, 42, 39, 38, 39, 41,
    43, 44, 47, 50, 55, 61, 63, 56,
    48, 46, 49, 54, 59, 58, 55, 58,
    63, 65, 67, 74, 84, 82, 75, 72,
    70, 74, 84, 87, 87, 94, 93, 81,
    75, 78, 83, 89, 91, 86, 82, 85,
    90, 90, 85, 79, 73, 73, 73, 73,
50 51
};

52
/* Used in CID 1237, 1253, 1259, 1273, 1274 */
Baptiste Coudurier's avatar
Baptiste Coudurier committed
53
static const uint8_t dnxhd_1237_luma_weight[] = {
54 55 56 57 58 59 60 61 62 63
     0,  32,  33,  34, 34, 36, 37, 36,
    36,  37,  38,  38, 38, 39, 41, 44,
    43,  41,  40,  41, 46, 49, 47, 46,
    47,  49,  51,  54, 60, 62, 59, 55,
    54,  56,  58,  61, 65, 66, 64, 63,
    66,  73,  78,  79, 80, 79, 78, 78,
    82,  87,  89,  90, 93, 95, 96, 97,
    97, 100, 104, 102, 98, 98, 99, 99,
};

64
/* Used in CID 1237, 1253, 1259, 1273, 1274 */
Baptiste Coudurier's avatar
Baptiste Coudurier committed
65
static const uint8_t dnxhd_1237_chroma_weight[] = {
66 67 68 69 70 71 72 73 74 75
     0,  32,  36,  39, 39, 38, 39,  41,
    45,  51,  57,  58, 53, 48, 47,  51,
    55,  58,  66,  75, 81, 83, 82,  78,
    73,  72,  74,  77, 83, 85, 83,  82,
    89,  99,  96,  90, 94, 97, 99, 105,
   109, 105,  95,  89, 92, 95, 94,  93,
    92,  88,  89,  90, 93, 95, 96,  97,
    97, 100, 104, 102, 98, 98, 99,  99,
};

76
/* Used in CID 1238, 1272 */
Baptiste Coudurier's avatar
Baptiste Coudurier committed
77
static const uint8_t dnxhd_1238_luma_weight[] = {
78 79 80 81 82 83 84 85 86 87
     0, 32, 32, 33, 34, 33, 33, 33,
    33, 33, 33, 33, 33, 35, 37, 37,
    36, 36, 35, 36, 38, 38, 36, 35,
    36, 37, 38, 41, 42, 41, 39, 38,
    38, 38, 39, 41, 42, 41, 39, 39,
    40, 41, 43, 44, 44, 44, 44, 44,
    45, 47, 47, 47, 49, 50, 51, 51,
    51, 53, 55, 57, 58, 59, 57, 57,
};

88
/* Used in CID 1238, 1272 */
Baptiste Coudurier's avatar
Baptiste Coudurier committed
89
static const uint8_t dnxhd_1238_chroma_weight[] = {
90 91 92 93 94 95 96 97 98 99
     0, 32, 35, 35, 35, 34, 34, 35,
    39, 43, 45, 45, 41, 39, 40, 41,
    42, 44, 48, 55, 59, 63, 65, 59,
    53, 52, 52, 55, 61, 62, 58, 58,
    63, 66, 66, 65, 70, 74, 70, 66,
    65, 68, 75, 77, 74, 74, 77, 76,
    73, 73, 73, 73, 76, 80, 89, 90,
    82, 77, 80, 86, 84, 82, 82, 82,
};

100
/* Used in CID 1241, 1271 */
101 102 103 104 105 106 107 108 109 110 111
static const uint8_t dnxhd_1241_luma_weight[] = {
     0, 32, 33, 34, 34, 35, 36, 37,
    36, 37, 38, 38, 38, 39, 39, 40,
    40, 38, 38, 39, 38, 37, 39, 41,
    41, 42, 43, 45, 45, 46, 47, 46,
    45, 43, 39, 37, 37, 40, 44, 45,
    45, 46, 46, 46, 47, 47, 46, 44,
    42, 43, 45, 47, 48, 49, 50, 49,
    48, 46, 47, 48, 48, 49, 49, 49,
};

112
/* Used in CID 1241, 1271 */
113 114 115 116 117 118 119 120 121 122 123
static const uint8_t dnxhd_1241_chroma_weight[] = {
     0, 32, 36, 38, 37, 37, 40, 41,
    40, 40, 42, 42, 41, 41, 41, 41,
    42, 43, 44, 44, 45, 46, 46, 45,
    44, 45, 45, 45, 45, 46, 47, 46,
    45, 44, 42, 41, 43, 45, 45, 47,
    48, 48, 48, 46, 47, 47, 46, 47,
    46, 45, 45, 47, 48, 49, 50, 49,
    48, 46, 48, 49, 48, 49, 49, 49,
};

Baptiste Coudurier's avatar
Baptiste Coudurier committed
124
static const uint8_t dnxhd_1242_luma_weight[] = {
125 126 127 128 129 130 131 132 133 134
     0, 32, 33, 33, 34, 35, 36, 35,
    33, 33, 35, 36, 37, 37, 38, 37,
    37, 37, 36, 37, 37, 37, 38, 39,
    37, 36, 37, 40, 42, 45, 46, 44,
    41, 42, 44, 45, 47, 49, 50, 48,
    46, 48, 49, 50, 52, 52, 50, 49,
    47, 48, 50, 50, 51, 51, 50, 49,
    49, 51, 52, 51, 49, 47, 47, 47,
};

Baptiste Coudurier's avatar
Baptiste Coudurier committed
135
static const uint8_t dnxhd_1242_chroma_weight[] = {
136 137 138 139 140 141 142 143
     0, 32, 37, 42, 45, 45, 45, 44,
    38, 37, 40, 42, 44, 49, 51, 47,
    41, 40, 43, 44, 46, 48, 51, 54,
    51, 47, 47, 45, 47, 50, 51, 49,
    46, 47, 49, 47, 50, 55, 55, 51,
    48, 49, 51, 51, 52, 52, 54, 54,
    49, 49, 52, 53, 54, 54, 53, 53,
    55, 59, 63, 62, 60, 60, 60, 60,
Mans Rullgard's avatar
Mans Rullgard committed
144
};
145

Baptiste Coudurier's avatar
Baptiste Coudurier committed
146
static const uint8_t dnxhd_1243_luma_weight[] = {
147 148 149 150 151 152 153 154 155 156
     0, 32, 32, 33, 33, 35, 35, 35,
    35, 35, 35, 35, 34, 35, 38, 40,
    39, 37, 37, 37, 36, 35, 36, 38,
    40, 41, 42, 44, 45, 44, 42, 41,
    40, 38, 36, 36, 37, 38, 40, 43,
    44, 45, 45, 45, 45, 45, 45, 41,
    39, 41, 45, 47, 47, 48, 48, 48,
    46, 44, 45, 47, 47, 48, 47, 47,
};

Baptiste Coudurier's avatar
Baptiste Coudurier committed
157
static const uint8_t dnxhd_1243_chroma_weight[] = {
158 159 160 161 162 163 164 165 166 167
     0, 32, 36, 37, 36, 37, 39, 39,
    41, 43, 43, 42, 41, 41, 41, 42,
    43, 43, 43, 44, 44, 44, 46, 47,
    46, 45, 45, 45, 45, 46, 44, 44,
    45, 44, 42, 41, 43, 46, 45, 44,
    45, 45, 45, 46, 46, 46, 45, 44,
    45, 44, 45, 47, 47, 48, 49, 48,
    46, 45, 46, 47, 47, 48, 47, 47,
};

168
static const uint8_t dnxhd_1250_luma_weight[] = {
169 170 171 172 173 174 175 176
     0, 32, 32, 33, 34, 35, 35, 35,
    34, 34, 35, 36, 36, 36, 36, 36,
    37, 38, 38, 38, 38, 38, 39, 39,
    38, 38, 39, 41, 43, 43, 42, 41,
    40, 40, 39, 40, 41, 41, 39, 39,
    40, 42, 47, 50, 47, 45, 46, 46,
    44, 45, 46, 47, 49, 54, 58, 54,
    48, 49, 54, 57, 60, 62, 63, 63,
177 178 179
};

static const uint8_t dnxhd_1250_chroma_weight[] = {
180 181 182 183 184 185 186 187
     0, 32, 35, 36, 36, 35, 36, 39,
    41, 43, 45, 44, 41, 39, 40, 42,
    43, 43, 45, 48, 49, 51, 52, 50,
    50, 51, 51, 51, 51, 52, 53, 54,
    51, 49, 51, 52, 52, 56, 57, 55,
    54, 54, 55, 56, 55, 58, 58, 58,
    60, 61, 62, 62, 59, 57, 58, 58,
    61, 59, 59, 59, 60, 62, 63, 63,
188 189
};

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
static const uint8_t dnxhd_1251_luma_weight[] = {
     0, 32, 32, 34, 34, 34, 34, 35,
    35, 35, 36, 37, 36, 36, 35, 36,
    38, 38, 38, 38, 38, 38, 38, 38,
    38, 38, 39, 41, 44, 43, 41, 40,
    40, 40, 40, 39, 40, 41, 40, 39,
    40, 43, 46, 46, 44, 44, 44, 42,
    41, 43, 46, 48, 50, 55, 58, 53,
    48, 50, 55, 58, 61, 62, 62, 62,
};

static const uint8_t dnxhd_1251_chroma_weight[] = {
     0, 32, 35, 36, 36, 35, 36, 39,
    41, 43, 45, 44, 41, 39, 40, 42,
    43, 43, 45, 48, 48, 48, 50, 50,
    50, 51, 51, 51, 51, 52, 53, 54,
    51, 49, 51, 52, 52, 56, 57, 55,
    54, 54, 55, 56, 55, 58, 58, 58,
    60, 61, 62, 62, 59, 57, 58, 58,
    61, 59, 59, 59, 61, 62, 62, 62,
};

212
/* Used in CID 1252, 1258 */
213 214 215 216 217 218 219 220 221 222
static const uint8_t dnxhd_1252_luma_weight[] = {
      0,  32,  34, 35, 36, 36, 36, 37,
     36,  37,  39, 40, 41, 40, 40, 40,
     41,  41,  42, 41, 41, 43, 44, 44,
     45,  46,  48, 55, 60, 57, 52, 50,
     49,  49,  52, 52, 53, 55, 58, 62,
     65,  73,  82, 82, 80, 78, 73, 68,
     71,  82,  90, 90, 88, 87, 90, 95,
    100, 107, 103, 97, 95, 93, 99, 99,
};
223 224

/* Used in CID 1252, 1258 */
225 226 227 228 229 230 231 232 233 234 235
static const uint8_t dnxhd_1252_chroma_weight[] = {
      0,  32,  35,  36,  37,  37,  38,  40,
     42,  46,  49,  50,  50,  49,  49,  53,
     56,  56,  57,  58,  60,  62,  64,  65,
     63,  64,  64,  65,  66,  65,  67,  71,
     72,  74,  74,  74,  74,  77,  81,  78,
     72,  73,  82,  85,  89,  88,  84,  80,
     90, 100,  90,  90,  88,  87,  90,  95,
    114, 128, 125, 129, 134, 125, 116, 116,
};

236
/* Used in CID 1244, 1260 */
237
static const uint8_t dnxhd_1260_luma_weight[] = {
238 239 240 241 242 243 244 245
     0, 32, 33, 34, 36, 37, 37, 36,
    34, 33, 34, 35, 37, 38, 40, 41,
    40, 39, 38, 37, 34, 33, 34, 37,
    40, 44, 48, 52, 53, 49, 47, 45,
    42, 38, 36, 36, 38, 41, 43, 44,
    46, 49, 52, 54, 54, 49, 44, 44,
    44, 47, 51, 51, 52, 51, 48, 50,
    52, 53, 53, 50, 50, 54, 54, 54,
246 247
};

248
/* Used in CID 1244, 1260 */
249
static const uint8_t dnxhd_1260_chroma_weight[] = {
250 251 252 253 254 255 256 257
     0, 32, 34, 38, 42, 40, 38, 36,
    35, 35, 38, 42, 43, 43, 42, 40,
    38, 39, 43, 43, 42, 41, 43, 43,
    42, 44, 46, 45, 45, 46, 47, 46,
    44, 44, 45, 46, 46, 46, 50, 50,
    47, 47, 49, 49, 49, 49, 51, 53,
    51, 49, 53, 57, 56, 52, 50, 52,
    56, 56, 53, 53, 53, 54, 58, 58,
258 259
};

260
/* Used in CID 1235, 1236, 1241, 1250, 1256, 1257, 1270, 1271 */
261 262 263 264
static const uint8_t dnxhd_1235_dc_codes[14] = {
    10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127,
};

265
/* Used in CID 1235, 1236, 1241, 1250, 1256, 1257, 1270, 1271 */
266 267 268 269
static const uint8_t dnxhd_1235_dc_bits[14] = {
    4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7,
};

270
/* Used in CID 1237, 1238, 1242, 1243, 1251, 1252, 1253, 1258, 1259, 1260, 1272, 1273, 1274 */
271 272 273 274
static const uint8_t dnxhd_1237_dc_codes[12] = {
    0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63,
};

275
/* Used in CID 1237, 1238, 1242, 1243, 1251, 1252, 1253, 1258, 1259, 1260, 1272, 1273, 1274 */
276 277 278 279
static const uint8_t dnxhd_1237_dc_bits[12] = {
    3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6,
};

280
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
281
static const uint16_t dnxhd_1237_ac_codes[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        0,     1,     4,     5,    12,    26,    27,    56,
       57,    58,    59,   120,   121,   244,   245,   246,
      247,   248,   498,   499,   500,   501,   502,  1006,
     1007,  1008,  1009,  1010,  1011,  2024,  2025,  2026,
     2027,  2028,  2029,  2030,  2031,  4064,  4065,  4066,
     4067,  4068,  4069,  4070,  4071,  4072,  4073,  8148,
     8149,  8150,  8151,  8152,  8153,  8154,  8155,  8156,
     8157,  8158, 16318, 16319, 16320, 16321, 16322, 16323,
    16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331,
    16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673,
    32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681,
    32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374,
    65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382,
    65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390,
    65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398,
    65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406,
    65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414,
    65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
    65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535,
315 316
};

317
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
318
static const uint8_t dnxhd_1237_ac_bits[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
     2,  2,  3,  3,  4,  5,  5,  6,  6,  6,  6,  7,  7,  8,  8,  8,
     8,  8,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 11, 11, 11,
    11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16,
336 337
};

338
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
static const uint8_t dnxhd_1237_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   0, 0,   7, 0,   9, 0,   5, 2,  11, 0,
     13, 0,  15, 0,   7, 2,  17, 0,  19, 0,  21, 0,  23, 0,  25, 0,
      9, 2,  11, 2,  27, 0,  29, 0,  31, 0,  33, 0,  13, 2,  35, 0,
     37, 0,  39, 0,  41, 0,  43, 0,  15, 2,  45, 0,  47, 0,  49, 0,
     51, 0,  53, 0,  55, 0,  17, 2,  19, 2,  57, 0,  59, 0,  61, 0,
     63, 0,  65, 0,  67, 0,  69, 0,  21, 2,  23, 2,  25, 2,  71, 0,
     73, 0,  75, 0,  77, 0,  79, 0,  81, 0,  83, 0,  27, 2,  29, 2,
     31, 2,  33, 2,  85, 0,  87, 0,  89, 0,  91, 0,  93, 0,  95, 0,
     97, 0,  99, 0, 101, 0, 103, 0, 105, 0,  35, 2,  37, 2,  39, 2,
     41, 2,  43, 2, 107, 0, 109, 0, 111, 0, 113, 0, 115, 0, 117, 0,
    119, 0, 121, 0, 123, 0, 129, 0,   3, 1,  45, 2,  47, 2,  49, 2,
     51, 2,  53, 2,  55, 2, 125, 0, 127, 0,   5, 1,   7, 1,   9, 1,
     11, 1,  13, 1,  15, 1,  17, 1,  19, 1,  21, 1,  23, 1,  25, 1,
     27, 1,  29, 1,  31, 1,  33, 1,  35, 1,  37, 1,  39, 1,  41, 1,
     43, 1,  45, 1,  47, 1,  49, 1,  51, 1,  53, 1,  55, 1,  57, 1,
     59, 1,  61, 1,  63, 1,  65, 1,  67, 1,  69, 1,  71, 1,  73, 1,
     75, 1,  77, 1,  79, 1,  81, 1,  83, 1,  85, 1,  87, 1,  89, 1,
     91, 1,  93, 1,  95, 1,  97, 1,  99, 1, 101, 1, 103, 1, 105, 1,
    107, 1, 109, 1, 111, 1, 113, 1, 115, 1, 117, 1, 119, 1, 121, 1,
    123, 1, 125, 1, 127, 1, 129, 1,  57, 2,  59, 2,  61, 2,  63, 2,
     65, 2,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
373 374
};

375
/* Used in CID 1238, 1240, 1243, 1272 */
376
static const uint16_t dnxhd_1238_ac_codes[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
        0,     1,     4,    10,    11,    24,    25,    26,
       54,    55,    56,    57,   116,   117,   118,   119,
      240,   241,   242,   243,   244,   245,   492,   493,
      494,   495,   496,   497,   498,   499,  1000,  1001,
     1002,  1003,  1004,  1005,  1006,  1007,  1008,  2018,
     2019,  2020,  2021,  2022,  2023,  2024,  2025,  2026,
     2027,  4056,  4057,  4058,  4059,  4060,  4061,  4062,
     4063,  4064,  4065,  4066,  4067,  4068,  4069,  8140,
     8141,  8142,  8143,  8144,  8145,  8146,  8147,  8148,
     8149,  8150,  8151,  8152,  8153,  8154,  8155,  8156,
    16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321,
    16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329,
    16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337,
    16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684,
    32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692,
    32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700,
    32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414,
    65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
    65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535,
410 411
};

412
/* Used in CID 1238, 1240, 1243, 1272 */
413
static const uint8_t dnxhd_1238_ac_bits[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
     2,  2,  3,  4,  4,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,
     8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16,
431 432
};

433
/* Used in CID 1238, 1240, 1243, 1272 */
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
static const uint8_t dnxhd_1238_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   7, 0,   0, 0,   9, 0,  11, 0,   5, 2,
     13, 0,  15, 0,  17, 0,   7, 2,  19, 0,  21, 0,  23, 0,   9, 2,
     25, 0,  27, 0,  29, 0,  31, 0,  33, 0,  11, 2,  35, 0,  37, 0,
     39, 0,  41, 0,  43, 0,  45, 0,  13, 2,  15, 2,  47, 0,  49, 0,
     51, 0,  53, 0,  55, 0,  57, 0,  59, 0,  17, 2,  19, 2,  61, 0,
     63, 0,  65, 0,  67, 0,  69, 0,  71, 0,  73, 0,  75, 0,  21, 2,
     23, 2,  77, 0,  79, 0,  81, 0,  83, 0,  85, 0,  87, 0,  89, 0,
     91, 0,  93, 0,  95, 0,  97, 0,  25, 2,  27, 2,  29, 2,  99, 0,
    101, 0, 103, 0, 105, 0, 107, 0, 109, 0, 111, 0, 113, 0, 115, 0,
    117, 0, 119, 0, 121, 0, 123, 0,  31, 2,  33, 2,  35, 2,  37, 2,
    125, 0, 127, 0, 129, 0,   3, 1,   5, 1,   7, 1,   9, 1,  11, 1,
     13, 1,  15, 1,  17, 1,  19, 1,  21, 1,  23, 1,  25, 1,  27, 1,
     29, 1,  31, 1,  33, 1,  39, 2,  41, 2,  43, 2,  45, 2,  47, 2,
     49, 2,  35, 1,  37, 1,  39, 1,  41, 1,  43, 1,  45, 1,  47, 1,
     49, 1,  51, 1,  53, 1,  55, 1,  57, 1,  59, 1,  61, 1,  63, 1,
     65, 1,  67, 1,  69, 1,  71, 1,  73, 1,  75, 1,  81, 1,  51, 2,
     53, 2,  55, 2,  57, 2,  59, 2,  61, 2,  77, 1,  79, 1,  83, 1,
     85, 1,  87, 1,  89, 1,  91, 1,  93, 1,  95, 1,  97, 1,  99, 1,
    101, 1, 103, 1, 105, 1, 107, 1, 109, 1, 111, 1, 113, 1, 115, 1,
    117, 1, 119, 1, 121, 1, 123, 1, 125, 1, 127, 1, 129, 1,  63, 2,
     65, 2,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
468 469
}; /* 0 is EOB */

470
/* Used in CID 1235, 1236, 1241, 1256, 1257, 1270, 1271 */
471
static const uint16_t dnxhd_1235_ac_codes[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        0,     1,     4,    10,    11,    24,    25,    26,
       54,    55,    56,    57,   116,   117,   118,   119,
      240,   241,   242,   243,   244,   245,   492,   493,
      494,   495,   496,   497,   498,   998,   999,  1000,
     1001,  1002,  1003,  1004,  1005,  1006,  1007,  2016,
     2017,  2018,  2019,  2020,  2021,  2022,  2023,  2024,
     2025,  2026,  4054,  4055,  4056,  4057,  4058,  4059,
     4060,  4061,  4062,  4063,  4064,  4065,  4066,  4067,
     4068,  4069,  8140,  8141,  8142,  8143,  8144,  8145,
     8146,  8147,  8148,  8149,  8150,  8151,  8152,  8153,
     8154,  8155,  8156,  8157, 16316, 16317, 16318, 16319,
    16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
    16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
    16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681,
    32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689,
    32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697,
    32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705,
    32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422,
    65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535,
505 506
};

507
/* Used in CID 1235, 1236, 1241, 1256, 1257, 1270, 1271 */
508
static const uint8_t dnxhd_1235_ac_bits[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
     2,  2,  3,  4,  4,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,
     8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16,
526 527
};

528
/* Used in CID 1235, 1241, 1256, 1270, 1271 */
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
static const uint8_t dnxhd_1235_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   7, 0,   0, 0,   9, 0,  11, 0,   5, 2,
     13, 0,  15, 0,  17, 0,   7, 2,  19, 0,  21, 0,  23, 0,   9, 2,
     25, 0,  27, 0,  29, 0,  31, 0,  33, 0,  11, 2,  35, 0,  37, 0,
     39, 0,  41, 0,  43, 0,  13, 2,  15, 2,  45, 0,  47, 0,  49, 0,
     51, 0,  53, 0,  55, 0,  57, 0,  59, 0,  17, 2,  19, 2,  61, 0,
     63, 0,  65, 0,  67, 0,  69, 0,  71, 0,  73, 0,  75, 0,  77, 0,
     21, 2,  23, 2,  79, 0,  81, 0,  83, 0,  85, 0,  87, 0,  89, 0,
     91, 0,  93, 0,  95, 0,  97, 0,  99, 0, 101, 0,  25, 2,  27, 2,
     29, 2,  31, 2, 103, 0, 105, 0, 107, 0, 109, 0, 111, 0, 113, 0,
    115, 0, 117, 0, 119, 0, 121, 0, 123, 0, 125, 0, 127, 0,   3, 1,
     33, 2,  35, 2,  37, 2,  39, 2, 129, 0,   5, 1,   7, 1,   9, 1,
     11, 1,  13, 1,  15, 1,  17, 1,  19, 1,  21, 1,  23, 1,  25, 1,
     27, 1,  29, 1,  31, 1,  33, 1,  35, 1,  41, 2,  43, 2,  45, 2,
     47, 2,  49, 2,  37, 1,  39, 1,  41, 1,  43, 1,  45, 1,  47, 1,
     49, 1,  51, 1,  53, 1,  55, 1,  57, 1,  59, 1,  61, 1,  63, 1,
     65, 1,  67, 1,  69, 1,  71, 1,  73, 1,  75, 1,  77, 1,  79, 1,
     81, 1,  83, 1,  85, 1,  51, 2,  53, 2,  55, 2,  57, 2,  59, 2,
     61, 2,  63, 2,  65, 2,  87, 1,  89, 1,  91, 1,  93, 1,  95, 1,
     97, 1,  99, 1, 101, 1, 103, 1, 105, 1, 107, 1, 109, 1, 111, 1,
    113, 1, 115, 1, 117, 1, 119, 1, 121, 1, 123, 1, 125, 1, 127, 1,
    129, 1,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
563 564
};

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
static const uint16_t dnxhd_1250_ac_codes[257] = {
        0,     1,     4,    10,    11,    24,    25,    26,
       54,    55,    56,    57,   116,   117,   118,   119,
      240,   241,   242,   243,   244,   245,   492,   493,
      494,   495,   496,   497,   498,   998,   999,  1000,
     1001,  1002,  1003,  1004,  1005,  1006,  2014,  2015,
     2016,  2017,  2018,  2019,  2020,  2021,  2022,  2023,
     2024,  2025,  4052,  4053,  4054,  4055,  4056,  4057,
     4058,  4059,  4060,  4061,  4062,  4063,  4064,  4065,
     4066,  4067,  8136,  8137,  8138,  8139,  8140,  8141,
     8142,  8143,  8144,  8145,  8146,  8147,  8148,  8149,
     8150,  8151,  8152,  8153,  8154,  8155,  8156, 16314,
    16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322,
    16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330,
    16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338,
    32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685,
    32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693,
    32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701,
    32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709,
    32710, 32711, 32712, 65426, 65427, 65428, 65429, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535
};
static const uint8_t dnxhd_1250_ac_bits[257] = {
     2,  2,  3,  4,  4,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,
     8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16
};
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653

static const uint8_t dnxhd_1250_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   7, 0,   0, 0,   9, 0,  11, 0,   5, 2,
     13, 0,  15, 0,  17, 0,   7, 2,  19, 0,  21, 0,  23, 0,   9, 2,
     25, 0,  27, 0,  29, 0,  31, 0,  33, 0,  11, 2,  35, 0,  37, 0,
     39, 0,  41, 0,  43, 0,  45, 0,  13, 2,  47, 0,  49, 0,  51, 0,
     53, 0,  55, 0,  57, 0,  59, 0,  15, 2,  17, 2,  61, 0,  63, 0,
     65, 0,  67, 0,  69, 0,  71, 0,  73, 0,  75, 0,  77, 0,  79, 0,
     19, 2,  21, 2,  81, 0,  83, 0,  85, 0,  87, 0,  89, 0,  91, 0,
     93, 0,  95, 0,  97, 0,  99, 0, 101, 0, 103, 0, 105, 0,  23, 2,
     25, 2,  27, 2, 107, 0, 109, 0, 111, 0, 113, 0, 115, 0, 117, 0,
    119, 0, 121, 0, 123, 0, 125, 0, 127, 0, 129, 0,   3, 1,   5, 1,
      7, 1,   9, 1,  11, 1,  29, 2,  31, 2,  33, 2,  35, 2,  13, 1,
     15, 1,  17, 1,  19, 1,  21, 1,  23, 1,  25, 1,  27, 1,  29, 1,
     31, 1,  33, 1,  35, 1,  37, 1,  39, 1,  41, 1,  43, 1,  45, 1,
     47, 1,  49, 1,  51, 1,  53, 1,  37, 2,  39, 2,  41, 2,  43, 2,
     55, 1,  57, 1,  59, 1,  61, 1,  63, 1,  65, 1,  67, 1,  69, 1,
     71, 1,  73, 1,  75, 1,  77, 1,  79, 1,  81, 1,  83, 1,  85, 1,
     87, 1,  89, 1,  91, 1,  93, 1,  95, 1,  97, 1,  99, 1, 101, 1,
    103, 1, 105, 1, 107, 1, 111, 1, 113, 1,  45, 2,  47, 2,  49, 2,
     51, 2,  53, 2,  55, 2, 109, 1, 115, 1, 117, 1, 119, 1, 121, 1,
    123, 1, 125, 1, 127, 1, 129, 1,  57, 2,  59, 2,  61, 2,  63, 2,
     65, 2,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
654 655
};

656
static const uint16_t dnxhd_1251_ac_codes[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
        0,     1,     4,    10,    11,    24,    25,    26,
       54,    55,    56,    57,   116,   117,   118,   119,
      240,   241,   242,   243,   244,   245,   492,   493,
      494,   495,   496,   497,   996,   997,   998,   999,
     1000,  1001,  1002,  1003,  1004,  1005,  2012,  2013,
     2014,  2015,  2016,  2017,  2018,  2019,  2020,  2021,
     2022,  2023,  2024,  2025,  4052,  4053,  4054,  4055,
     4056,  4057,  4058,  4059,  4060,  4061,  4062,  4063,
     4064,  4065,  4066,  8134,  8135,  8136,  8137,  8138,
     8139,  8140,  8141,  8142,  8143,  8144,  8145,  8146,
     8147,  8148,  8149,  8150,  8151,  8152,  8153,  8154,
     8155,  8156, 16314, 16315, 16316, 16317, 16318, 16319,
    16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
    16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
    16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683,
    32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691,
    32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699,
    32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707,
    32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535,
690
};
Mans Rullgard's avatar
Mans Rullgard committed
691

692
static const uint8_t dnxhd_1251_ac_bits[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
     2,  2,  3,  4,  4,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,
     8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
    12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16,
710
};
Mans Rullgard's avatar
Mans Rullgard committed
711

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
static const uint8_t dnxhd_1251_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   7, 0,   0, 0,   9, 0,  11, 0,   5, 2,
     13, 0,  15, 0,  17, 0,   7, 2,  19, 0,  21, 0,  23, 0,   9, 2,
     25, 0,  27, 0,  29, 0,  31, 0,  33, 0,  11, 2,  35, 0,  37, 0,
     39, 0,  41, 0,  43, 0,  13, 2,  45, 0,  47, 0,  49, 0,  51, 0,
     53, 0,  55, 0,  57, 0,  59, 0,  15, 2,  17, 2,  61, 0,  63, 0,
     65, 0,  67, 0,  69, 0,  71, 0,  73, 0,  75, 0,  77, 0,  79, 0,
     81, 0,  19, 2,  21, 2,  23, 2,  83, 0,  85, 0,  87, 0,  89, 0,
     91, 0,  93, 0,  95, 0,  97, 0,  99, 0, 101, 0, 103, 0, 105, 0,
     25, 2,  27, 2,  29, 2, 107, 0, 109, 0, 111, 0, 113, 0, 115, 0,
    117, 0, 119, 0, 121, 0, 123, 0, 125, 0, 127, 0, 129, 0,   3, 1,
      5, 1,   7, 1,   9, 1,  11, 1,  13, 1,  15, 1,  17, 1,  31, 2,
     33, 2,  35, 2,  19, 1,  21, 1,  23, 1,  25, 1,  27, 1,  29, 1,
     31, 1,  33, 1,  35, 1,  37, 1,  39, 1,  41, 1,  43, 1,  45, 1,
     47, 1,  49, 1,  51, 1,  53, 1,  55, 1,  57, 1,  59, 1,  37, 2,
     39, 2,  41, 2,  43, 2,  45, 2,  61, 1,  63, 1,  65, 1,  67, 1,
     69, 1,  71, 1,  73, 1,  75, 1,  77, 1,  79, 1,  81, 1,  83, 1,
     85, 1,  87, 1,  89, 1,  91, 1,  93, 1,  95, 1,  97, 1,  99, 1,
    101, 1, 103, 1, 105, 1, 107, 1, 109, 1, 111, 1, 113, 1, 115, 1,
    117, 1,  47, 2,  49, 2,  51, 2,  53, 2,  55, 2,  57, 2, 119, 1,
    121, 1, 123, 1, 125, 1, 127, 1, 129, 1,  59, 2,  61, 2,  63, 2,
     65, 2,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
746
};
Mans Rullgard's avatar
Mans Rullgard committed
747

748
/* Used in CID 1252, 1258 */
749
static const uint16_t dnxhd_1252_ac_codes[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
        0,     1,     4,    10,    11,    12,    26,    27,
       56,    57,    58,   118,   119,   120,   242,   243,
      244,   245,   246,   247,   496,   497,   498,   499,
      500,  1002,  1003,  1004,  1005,  1006,  1007,  1008,
     1009,  2020,  2021,  2022,  2023,  2024,  2025,  2026,
     2027,  2028,  2029,  4060,  4061,  4062,  4063,  4064,
     4065,  4066,  4067,  4068,  4069,  4070,  4071,  8144,
     8145,  8146,  8147,  8148,  8149,  8150,  8151,  8152,
     8153,  8154,  8155,  8156,  8157,  8158, 16318, 16319,
    16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327,
    16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335,
    32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679,
    32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687,
    32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390,
    65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398,
    65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406,
    65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414,
    65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422,
    65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430,
    65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438,
    65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446,
    65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454,
    65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462,
    65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470,
    65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478,
    65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486,
    65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494,
    65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502,
    65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510,
    65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518,
    65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526,
    65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534,
    65535,
783
};
Mans Rullgard's avatar
Mans Rullgard committed
784

785
/* Used in CID 1252, 1258 */
786
static const uint8_t dnxhd_1252_ac_bits[257] = {
Mans Rullgard's avatar
Mans Rullgard committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
     2,  2,  3,  4,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  8,  8,
     8,  8,  8,  8,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10,
    10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
    12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
    13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
    14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
    16,
804
};
Mans Rullgard's avatar
Mans Rullgard committed
805

806
/* Used in CID 1252, 1258 */
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
static const uint8_t dnxhd_1252_ac_info[2*257] = {
      3, 0,   3, 2,   5, 0,   7, 0,   5, 2,   0, 0,   9, 0,  11, 0,
     13, 0,  15, 0,   7, 2,  17, 0,  19, 0,  21, 0,  23, 0,  25, 0,
     27, 0,  29, 0,   9, 2,  11, 2,  31, 0,  33, 0,  35, 0,  37, 0,
     13, 2,  39, 0,  41, 0,  43, 0,  45, 0,  47, 0,  49, 0,  15, 2,
     17, 2,  51, 0,  53, 0,  55, 0,  57, 0,  59, 0,  61, 0,  63, 0,
     65, 0,  19, 2,  21, 2,  67, 0,  69, 0,  71, 0,  73, 0,  75, 0,
     77, 0,  79, 0,  81, 0,  83, 0,  23, 2,  25, 2,  27, 2,  85, 0,
     87, 0,  89, 0,  91, 0,  93, 0,  95, 0,  97, 0,  99, 0, 101, 0,
    103, 0, 105, 0, 107, 0,  29, 2,  31, 2,  33, 2, 109, 0, 111, 0,
    113, 0, 115, 0, 117, 0, 119, 0, 121, 0, 123, 0, 125, 0, 127, 0,
    129, 0,   3, 1,   5, 1,   7, 1,  35, 2,  37, 2,  39, 2,  41, 2,
      9, 1,  11, 1,  13, 1,  15, 1,  17, 1,  19, 1,  21, 1,  23, 1,
     25, 1,  27, 1,  29, 1,  31, 1,  33, 1,  35, 1,  37, 1,  39, 1,
     41, 1,  43, 1,  43, 2,  45, 2,  47, 2,  49, 2,  51, 2,  45, 1,
     47, 1,  49, 1,  51, 1,  53, 1,  55, 1,  57, 1,  59, 1,  61, 1,
     63, 1,  65, 1,  67, 1,  69, 1,  71, 1,  73, 1,  75, 1,  77, 1,
     79, 1,  81, 1,  83, 1,  85, 1,  87, 1,  89, 1,  91, 1,  93, 1,
     95, 1,  97, 1,  99, 1, 101, 1, 103, 1, 105, 1, 107, 1, 109, 1,
    111, 1, 113, 1, 115, 1, 117, 1, 119, 1, 121, 1, 123, 1, 125, 1,
    127, 1, 129, 1,  53, 2,  55, 2,  57, 2,  59, 2,  61, 2,  63, 2,
     65, 2,  67, 2,  69, 2,  71, 2,  73, 2,  75, 2,  77, 2,  79, 2,
     81, 2,  83, 2,  85, 2,  87, 2,  89, 2,  91, 2,  93, 2,  95, 2,
     97, 2,  99, 2, 101, 2, 103, 2, 105, 2, 107, 2, 109, 2, 111, 2,
    113, 2, 115, 2, 117, 2, 119, 2, 121, 2, 123, 2, 125, 2, 127, 2,
    129, 2,   3, 3,   5, 3,   7, 3,   9, 3,  11, 3,  13, 3,  15, 3,
     17, 3,  19, 3,  21, 3,  23, 3,  25, 3,  27, 3,  29, 3,  31, 3,
     33, 3,  35, 3,  37, 3,  39, 3,  41, 3,  43, 3,  45, 3,  47, 3,
     49, 3,  51, 3,  53, 3,  55, 3,  57, 3,  59, 3,  61, 3,  63, 3,
     65, 3,  67, 3,  69, 3,  71, 3,  73, 3,  75, 3,  77, 3,  79, 3,
     81, 3,  83, 3,  85, 3,  87, 3,  89, 3,  91, 3,  93, 3,  95, 3,
     97, 3,  99, 3, 101, 3, 103, 3, 105, 3, 107, 3, 109, 3, 111, 3,
    113, 3, 115, 3, 117, 3, 119, 3, 121, 3, 123, 3, 125, 3, 127, 3,
    129, 3,
841 842
};

843
/* Used in CID 1235, 1238, 1241, 1243, 1256, 1270, 1271, 1272 */
844 845 846 847 848 849 850 851 852 853 854
static const uint16_t dnxhd_1235_run_codes[62] = {
       0,    4,   10,   11,   24,   25,   26,   27,
      56,   57,   58,   59,  120,  242,  486,  487,
     488,  489,  980,  981,  982,  983,  984,  985,
     986,  987,  988,  989,  990,  991,  992,  993,
     994,  995,  996,  997,  998,  999, 1000, 1001,
    1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
    1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
    1018, 1019, 1020, 1021, 1022, 1023,
};

855
/* Used in CID 1235, 1238, 1241, 1243, 1256, 1270, 1271, 1272 */
856 857 858 859 860 861 862
static const uint8_t dnxhd_1235_run_bits[62] = {
     1,  3,  4,  4,  5,  5,  5,  5,  6,  6,  6,  6,  7,  8,  9,  9,
     9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};

863
/* Used in CID 1235, 1241, 1256, 1270, 1271 */
864 865 866 867 868 869 870
static const uint8_t dnxhd_1235_run[62] = {
     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
    18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
    33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
    49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};

871
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
872 873 874 875 876 877 878 879 880 881 882
static const uint16_t dnxhd_1237_run_codes[62] = {
       0,    4,   10,   11,   24,   25,   26,   54,
      55,   56,   57,   58,  118,  119,  240,  482,
     483,  484,  485,  486,  487,  488,  489,  490,
     491,  492,  493,  494,  990,  991,  992,  993,
     994,  995,  996,  997,  998,  999, 1000, 1001,
    1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
    1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
    1018, 1019, 1020, 1021, 1022, 1023,
};

883
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
884 885 886 887 888 889 890
static const uint8_t dnxhd_1237_run_bits[62] = {
     1,  3,  4,  4,  5,  5,  5,  6,  6,  6,  6,  6,  7,  7,  8,  9,
     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};

891
/* Used in CID 1237, 1242, 1253, 1259, 1260, 1273, 1274 */
892 893 894 895 896 897 898
static const uint8_t dnxhd_1237_run[62] = {
     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
    17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25,
    26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
    42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56,
};

899
/* Used in CID 1238, 1243, 1272 */
900 901 902 903 904 905 906
static const uint8_t dnxhd_1238_run[62] = {
     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
    20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
    33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
    49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};

907
/* Used in CID 1250, 1251, 1252, 1258 */
908 909 910 911 912 913 914 915 916 917 918
static const uint16_t dnxhd_1250_run_codes[62] = {
       0,    4,    5,   12,   26,   27,   28,   58,
     118,  119,  120,  242,  486,  487,  976,  977,
     978,  979,  980,  981,  982,  983,  984,  985,
     986,  987,  988,  989,  990,  991,  992,  993,
     994,  995,  996,  997,  998,  999, 1000, 1001,
    1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009,
    1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017,
    1018, 1019, 1020, 1021, 1022, 1023,
};

919
/* Used in CID 1250, 1251, 1252, 1258 */
920 921 922 923 924 925 926
static const uint8_t dnxhd_1250_run_bits[62] = {
     1,  3,  3,  4,  5,  5,  5,  6,  7,  7,  7,  8,  9,  9, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
};

927
/* Used in CID 1250, 1251, 1252, 1258 */
928 929 930 931 932 933 934
static const uint8_t dnxhd_1250_run[62] = {
     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
    17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
    33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
    49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
};

935
const CIDEntry ff_dnxhd_cid_table[] = {
936 937
    { 1235, 1920, 1080, 917504, 917504,
      0, 6, 10, 4,
938
      dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight,
939
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
940
      dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
941
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
942 943
      { 175, 185, 365, 440 },
      { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } },
944 945
    { 1237, 1920, 1080, 606208, 606208,
      0, 4, 8, 3,
Baptiste Coudurier's avatar
Baptiste Coudurier committed
946
      dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
947
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
948
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
949
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
950 951
      { 115, 120, 145, 240, 290 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
952 953
    { 1238, 1920, 1080, 917504, 917504,
      0, 4, 8, 4,
Baptiste Coudurier's avatar
Baptiste Coudurier committed
954
      dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight,
955
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
956
      dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
957
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1238_run,
958 959
      { 175, 185, 220, 365, 440 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
960 961
    { 1241, 1920, 1080, 917504, 458752,
      DNXHD_INTERLACED, 6, 10, 4,
962
      dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight,
963
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
964
      dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
965
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
966 967
      { 185, 220 },
      { { 25, 1 }, { 30000, 1001 } } },
968 969
    { 1242, 1920, 1080, 606208, 303104,
      DNXHD_INTERLACED, 4, 8, 3,
Baptiste Coudurier's avatar
Baptiste Coudurier committed
970
      dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight,
971
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
972
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
973
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
974 975
      { 120, 145 },
      { { 25, 1 }, { 30000, 1001 } } },
976 977
    { 1243, 1920, 1080, 917504, 458752,
      DNXHD_INTERLACED, 4, 8, 4,
Baptiste Coudurier's avatar
Baptiste Coudurier committed
978
      dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight,
979
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
980
      dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
981
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1238_run,
982 983
      { 185, 220 },
      { { 25, 1 }, { 30000, 1001 } } },
984 985 986 987 988 989 990 991
    { 1244, 1440, 1080, 606208, 303104,
      DNXHD_INTERLACED, 4, 8, 3,
      dnxhd_1260_luma_weight, dnxhd_1260_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
      { 120, 145 },
      { { 25, 1 }, { 30000, 1001 } } },
992 993
    { 1250, 1280,  720, 458752, 458752,
      0, 6, 10, 4,
994
      dnxhd_1250_luma_weight, dnxhd_1250_chroma_weight,
995
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
996
      dnxhd_1250_ac_codes, dnxhd_1250_ac_bits, dnxhd_1250_ac_info,
997
      dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
998 999
      { 90, 90, 180, 220 },
      { { 24000, 1001 }, { 25, 1 }, { 50, 1 }, { 60000, 1001 } } },
1000 1001
    { 1251, 1280,  720, 458752, 458752,
      0, 4, 8, 4,
1002
      dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight,
1003
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1004
      dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_info,
1005
      dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
1006 1007
      { 90, 90, 110, 180, 220 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
1008 1009
    { 1252, 1280,  720, 303104, 303104,
      0, 4, 8, 5,
1010
      dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight,
1011
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1012
      dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_info,
1013
      dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
1014 1015
      { 60, 60, 75, 120, 145 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
1016 1017
    { 1253, 1920, 1080, 188416, 188416,
      0, 4, 8, 3,
1018 1019
      dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1020
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
1021
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
1022 1023
      { 36, 36, 45, 75, 90 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
1024 1025
    { 1256, 1920, 1080, 1835008, 1835008,
      DNXHD_444, 6, 10, 4,
1026
      dnxhd_1235_luma_weight, dnxhd_1235_luma_weight,
1027
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
1028
      dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
1029
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
1030 1031
      { 350, 390, 440, 730, 880 },
      { { 24000, 1001 }, { 25, 1 }, { 30000, 1001 }, { 50, 1 }, { 60000, 1001 } } },
1032 1033
    { 1258, 960, 720, 212992, 212992,
      0, 4, 8, 5,
1034
      dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight,
1035
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1036
      dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_info,
1037
      dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run,
1038
      { 42, 60, 75, 115 } },
1039 1040
    { 1259, 1440, 1080, 417792, 417792,
      0, 4, 8, 3,
1041
      dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
1042
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1043
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
1044 1045
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
      { 63, 84, 100, 110 } },
1046
    { 1260, 1440, 1080, 835584, 417792,
1047
      DNXHD_INTERLACED | DNXHD_MBAFF, 4, 8, 3,
1048 1049
      dnxhd_1260_luma_weight, dnxhd_1260_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1050
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
1051 1052
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
      { 80, 90, 100, 110 } },
1053
    { 1270, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
1054
      DNXHD_444, 6, DNXHD_VARIABLE, 4,
1055 1056
      dnxhd_1235_luma_weight, dnxhd_1235_luma_weight,
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
1057
      dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
1058
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
1059
      { 0 }, { { 0 } }, { 57344, 255} },
1060 1061 1062 1063
    { 1271, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
      0, 6, DNXHD_VARIABLE, 4,
      dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight,
      dnxhd_1235_dc_codes, dnxhd_1235_dc_bits,
1064
      dnxhd_1235_ac_codes, dnxhd_1235_ac_bits, dnxhd_1235_ac_info,
1065
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1235_run,
1066
      { 0 }, { { 0 } }, { 28672, 255} },
1067 1068 1069 1070
    { 1272, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
      0, 4, 8, 4,
      dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1071
      dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_info,
1072
      dnxhd_1235_run_codes, dnxhd_1235_run_bits, dnxhd_1238_run,
1073
      { 0 }, { { 0 } }, { 28672, 255} },
1074 1075 1076 1077
    { 1273, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
      0, 4, 8, 3,
      dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1078
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
1079
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
1080
      { 0 }, { { 0 } }, { 18944, 255} },
1081 1082 1083 1084
    { 1274, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE, DNXHD_VARIABLE,
      0, 4, 8, 3,
      dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight,
      dnxhd_1237_dc_codes, dnxhd_1237_dc_bits,
1085
      dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_info,
1086
      dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
1087
      { 0 }, { { 0 } }, { 5888, 255} },
1088 1089 1090 1091 1092
};

int ff_dnxhd_get_cid_table(int cid)
{
    int i;
1093
    for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++)
1094 1095 1096 1097
        if (ff_dnxhd_cid_table[i].cid == cid)
            return i;
    return -1;
}
1098

1099 1100 1101 1102 1103 1104 1105 1106
int avpriv_dnxhd_get_frame_size(int cid)
{
    int i = ff_dnxhd_get_cid_table(cid);
    if (i<0)
        return i;
    return ff_dnxhd_cid_table[i].frame_size;
}

1107 1108 1109 1110 1111
int avpriv_dnxhd_get_interlaced(int cid)
{
    int i = ff_dnxhd_get_cid_table(cid);
    if (i < 0)
        return i;
1112
    return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0;
1113 1114
}

1115
#if LIBAVCODEC_VERSION_MAJOR < 58
1116 1117
uint64_t avpriv_dnxhd_parse_header_prefix(const uint8_t *buf)
{
1118
    return ff_dnxhd_parse_header_prefix(buf);
1119
}
1120
#endif
1121

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
static int dnxhd_find_hr_cid(AVCodecContext *avctx)
{
    switch (avctx->profile) {
    case FF_PROFILE_DNXHR_444:
        return 1270;
    case FF_PROFILE_DNXHR_HQX:
        return 1271;
    case FF_PROFILE_DNXHR_HQ:
        return 1272;
    case FF_PROFILE_DNXHR_SQ:
        return 1273;
    case FF_PROFILE_DNXHR_LB:
        return 1274;
    }
    return 0;
}

1139
int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth)
1140 1141
{
    int i, j;
1142
    int mbs = avctx->bit_rate / 1000000;
1143 1144 1145 1146

    if (avctx->profile != FF_PROFILE_DNXHD)
        return dnxhd_find_hr_cid(avctx);

1147 1148
    if (!mbs)
        return 0;
1149
    for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) {
1150
        const CIDEntry *cid = &ff_dnxhd_cid_table[i];
1151
        int interlaced = cid->flags & DNXHD_INTERLACED ? 1 : 0;
1152
        if (cid->width == avctx->width && cid->height == avctx->height &&
1153
            interlaced == !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) &&
1154
            !(cid->flags & DNXHD_444) && cid->bit_depth == bit_depth) {
1155 1156 1157 1158 1159
            if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL &&
                cid->flags & DNXHD_MBAFF) {
                av_log(avctx, AV_LOG_WARNING, "Profile selected is experimental\n");
                continue;
            }
1160
            for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) {
1161 1162 1163 1164 1165 1166 1167
                if (cid->bit_rates[j] == mbs)
                    return cid->cid;
            }
        }
    }
    return 0;
}
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178

void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel)
{
    int i, j;
    for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) {
        const CIDEntry *cid = &ff_dnxhd_cid_table[i];
        for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) {
            if (!cid->bit_rates[j])
                break;

            av_log(avctx, loglevel, "Frame size: %dx%d%c; bitrate: %dMbps; pixel format: %s; framerate: %d/%d\n",
1179
                   cid->width, cid->height, cid->flags & DNXHD_INTERLACED ? 'i' : 'p', cid->bit_rates[j],
1180 1181 1182 1183
                   cid->bit_depth == 10 ? "yuv422p10" : "yuv422p", cid->frame_rates[j].num, cid->frame_rates[j].den);
        }
    }
}