/*
* Canopus HQ/HQA decoder
*
* 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
*/
#include "hq_hqa.h"
#define MAT_SIZE 64
static const uint8_t cbp_vlc_bits[16] = {
0x04, 0x1C, 0x1D, 0x09, 0x1E, 0x0B, 0x1B, 0x08,
0x1F, 0x1A, 0x0C, 0x07, 0x0A, 0x06, 0x05, 0x00,
};
static const uint8_t cbp_vlc_lens[16] = {
4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2,
};
static const int32_t qmat00[MAT_SIZE] = {
0x0040000, 0x000B18B, 0x00058C5, 0x000B1B1, 0x00082D3, 0x000B1B1,
0x000A953, 0x000827B, 0x00104F7, 0x000A953, 0x0009000, 0x000EADD,
0x001037B, 0x000756E, 0x0009000, 0x000776D, 0x000696A, 0x000E987,
0x000E987, 0x000D2D4, 0x000776D, 0x0016BAF, 0x0014B4C, 0x001A21A,
0x001BA75, 0x001A21A, 0x000A5A6, 0x000B5D8, 0x000611E, 0x000811D,
0x00150B6, 0x00181B0, 0x00181B0, 0x00150B6, 0x0020474, 0x0018477,
0x0022710, 0x001FD1E, 0x001366C, 0x0015000, 0x001366C, 0x000FE8F,
0x00044E2, 0x0008A6D, 0x000EA30, 0x0010E47, 0x0010E47, 0x001D460,
0x00229B2, 0x001FCB2, 0x0019FA3, 0x000D94C, 0x000CFD2, 0x0007F2D,
0x000DEED, 0x0014D5E, 0x0029ABD, 0x0037BB5, 0x002D16B, 0x001FECE,
0x000B45B, 0x0011521, 0x0022A42, 0x0012B9C,
};
static const int32_t qmat01[MAT_SIZE] = {
0x0040000, 0x000B18B, 0x00058C5, 0x000B1B1, 0x00082D3, 0x000B1B1,
0x000EB2D, 0x000B53A, 0x0016A73, 0x000EB2D, 0x000D000, 0x0014632,
0x0016314, 0x000A319, 0x000D000, 0x000A36D, 0x0009041, 0x0014BDA,
0x0014BDA, 0x0012081, 0x000A36D, 0x0016BAF, 0x0014B4C, 0x001A21A,
0x001BA75, 0x001A21A, 0x000A5A6, 0x000B5D8, 0x000611E, 0x000811D,
0x00150B6, 0x00181B0, 0x00181B0, 0x00150B6, 0x0020474, 0x0018477,
0x0045A60, 0x004058C, 0x0026CD9, 0x002A000, 0x0026CD9, 0x00202C6,
0x0008B4C, 0x00114D9, 0x001D977, 0x0021C8F, 0x0021C8F, 0x003B2EF,
0x0045365, 0x007FD2A, 0x00675E5, 0x0036A1F, 0x0033AF3, 0x001FF4B,
0x001C010, 0x0029E24, 0x0053C47, 0x007003E, 0x005A9C7, 0x004024C,
0x0016A72, 0x0022A42, 0x0045485, 0x0025738,
};
static const int32_t qmat02[MAT_SIZE] = {
0x0040000, 0x0016315, 0x000B18B, 0x0016363, 0x00105A6, 0x0016363,
0x00152A7, 0x00104F7, 0x00209EE, 0x00152A7, 0x0012000, 0x001D5B9,
0x00206F6, 0x000EADD, 0x0012000, 0x000EEDA, 0x000D2D4, 0x001D30D,
0x001D30D, 0x001A5A9, 0x000EEDA, 0x002D75E, 0x0029698, 0x0034433,
0x00374EB, 0x0034433, 0x0014B4C, 0x0016BAF, 0x000C23C, 0x001023A,
0x002A16C, 0x0030360, 0x0030360, 0x002A16C, 0x00408E9, 0x00308EF,
0x0044E21, 0x003FA3C, 0x0026CD9, 0x002A000, 0x0026CD9, 0x001FD1E,
0x00089C4, 0x00114D9, 0x001D460, 0x0021C8F, 0x0021C8F, 0x003A8C0,
0x0045365, 0x003F964, 0x0033F47, 0x001B297, 0x0019FA3, 0x000FE59,
0x001BDDA, 0x0029ABD, 0x0053579, 0x006F76A, 0x005A2D7, 0x003FD9D,
0x00168B6, 0x0022A42, 0x0045485, 0x0025738,
};
static const int32_t qmat03[MAT_SIZE] = {
0x0040000, 0x0016315, 0x000B18B, 0x0016363, 0x00105A6, 0x0016363,
0x001D65A, 0x0016A73, 0x002D4E7, 0x001D65A, 0x001A000, 0x0028C65,
0x002C628, 0x0014632, 0x001A000, 0x00146D9, 0x0012081, 0x00297B5,
0x00297B5, 0x0024102, 0x00146D9, 0x002D75E, 0x0029698, 0x0034433,
0x00374EB, 0x0034433, 0x0014B4C, 0x0016BAF, 0x000C23C, 0x001023A,
0x002A16C, 0x0030360, 0x0030360, 0x002A16C, 0x00408E9, 0x00308EF,
0x008B4C0, 0x0080B18, 0x004D9B2, 0x0054000, 0x004D9B2, 0x004058C,
0x0011698, 0x00229B2, 0x003B2EF, 0x004391E, 0x004391E, 0x00765DD,
0x008A6CA, 0x00FFA54, 0x00CEBCA, 0x006D43E, 0x00675E5, 0x003FE95,
0x003801F, 0x0053C47, 0x00A788E, 0x00E007C, 0x00B538D, 0x0080498,
0x002D4E3, 0x0045485, 0x008A90A, 0x004AE71,
};
static const int32_t qmat04[MAT_SIZE] = {
0x0040000, 0x00214A0, 0x0010A50, 0x0021514, 0x0018879, 0x0021514,
0x001FBFA, 0x0018772, 0x0030EE5, 0x001FBFA, 0x001B000, 0x002C096,
0x0030A71, 0x001604B, 0x001B000, 0x0016647, 0x0013C3F, 0x002BC94,
0x002BC94, 0x002787D, 0x0016647, 0x004430D, 0x003E1E4, 0x004E64D,
0x0052F60, 0x004E64D, 0x001F0F2, 0x0022187, 0x001235A, 0x0018357,
0x003F223, 0x0048510, 0x0048510, 0x003F223, 0x0060D5D, 0x0048D66,
0x0067531, 0x005F75A, 0x003A345, 0x003F000, 0x003A345, 0x002FBAD,
0x000CEA6, 0x0019F46, 0x002BE90, 0x0032AD6, 0x0032AD6, 0x0057D20,
0x0067D17, 0x005F616, 0x004DEEA, 0x0028BE3, 0x0026F75, 0x0017D86,
0x0029CC8, 0x003E81B, 0x007D036, 0x00A731F, 0x0087442, 0x005FC6B,
0x0021D11, 0x0033F64, 0x0067EC7, 0x00382D5,
};
static const int32_t qmat05[MAT_SIZE] = {
0x0040000, 0x00214A0, 0x0010A50, 0x0021514, 0x0018879, 0x0021514,
0x002C186, 0x0021FAD, 0x0043F5A, 0x002C186, 0x0027000, 0x003D297,
0x004293C, 0x001E94C, 0x0027000, 0x001EA46, 0x001B0C2, 0x003E38F,
0x003E38F, 0x0036183, 0x001EA46, 0x004430D, 0x003E1E4, 0x004E64D,
0x0052F60, 0x004E64D, 0x001F0F2, 0x0022187, 0x001235A, 0x0018357,
0x003F223, 0x0048510, 0x0048510, 0x003F223, 0x0060D5D, 0x0048D66,
0x00D0F1F, 0x00C10A4, 0x007468B, 0x007E000, 0x007468B, 0x0060852,
0x001A1E4, 0x0033E8C, 0x0058C66, 0x00655AD, 0x00655AD, 0x00B18CC,
0x00CFA2F, 0x017F77F, 0x01361B0, 0x00A3E5C, 0x009B0D8, 0x005FDE0,
0x005402F, 0x007DA6B, 0x00FB4D5, 0x01500BA, 0x010FD54, 0x00C06E5,
0x0043F55, 0x0067EC7, 0x00CFD8F, 0x00705A9,
};
static const int32_t qmat06[MAT_SIZE] = {
0x0040000, 0x002C62A, 0x0016315, 0x002C6C5, 0x0020B4C, 0x002C6C5,
0x002A54E, 0x00209EE, 0x00413DC, 0x002A54E, 0x0024000, 0x003AB73,
0x0040DEC, 0x001D5B9, 0x0024000, 0x001DDB4, 0x001A5A9, 0x003A61B,
0x003A61B, 0x0034B52, 0x001DDB4, 0x005AEBC, 0x0052D2F, 0x0068867,
0x006E9D6, 0x0068867, 0x0029698, 0x002D75E, 0x0018477, 0x0020474,
0x00542D9, 0x00606C0, 0x00606C0, 0x00542D9, 0x00811D1, 0x00611DE,
0x0089C42, 0x007F478, 0x004D9B2, 0x0054000, 0x004D9B2, 0x003FA3C,
0x0011388, 0x00229B2, 0x003A8C0, 0x004391E, 0x004391E, 0x0075180,
0x008A6CA, 0x007F2C9, 0x0067E8E, 0x003652F, 0x0033F47, 0x001FCB2,
0x0037BB5, 0x0053579, 0x00A6AF3, 0x00DEED4, 0x00B45AE, 0x007FB39,
0x002D16B, 0x0045485, 0x008A90A, 0x004AE71,
};
static const int32_t qmat07[MAT_SIZE] = {
0x0040000, 0x002C62A, 0x0016315, 0x002C6C5, 0x0020B4C, 0x002C6C5,
0x003ACB3, 0x002D4E7, 0x005A9CE, 0x003ACB3, 0x0034000, 0x00518CA,
0x0058C50, 0x0028C65, 0x0034000, 0x0028DB3, 0x0024102, 0x0052F69,
0x0052F69, 0x0048204, 0x0028DB3, 0x005AEBC, 0x0052D2F, 0x0068867,
0x006E9D6, 0x0068867, 0x0029698, 0x002D75E, 0x0018477, 0x0020474,
0x00542D9, 0x00606C0, 0x00606C0, 0x00542D9, 0x00811D1, 0x00611DE,
0x011697F, 0x0101631, 0x009B363, 0x00A8000, 0x009B363, 0x0080B18,
0x0022D30, 0x0045365, 0x00765DD, 0x008723C, 0x008723C, 0x00ECBBB,
0x0114D94, 0x01FF4A9, 0x019D795, 0x00DA87B, 0x00CEBCA, 0x007FD2A,
0x007003E, 0x00A788E, 0x014F11C, 0x01C00F8, 0x016A71B, 0x0100931,
0x005A9C7, 0x008A90A, 0x0115214, 0x0095CE2,
};
static const int32_t qmat08[MAT_SIZE] = {
0x0040000, 0x00377B5, 0x001BBDA, 0x0037876, 0x0028E1E, 0x0037876,
0x0034EA1, 0x0028C69, 0x00518D3, 0x0034EA1, 0x002D000, 0x004964F,
0x0051167, 0x0024B28, 0x002D000, 0x0025521, 0x0020F13, 0x0048FA1,
0x0048FA1, 0x0041E26, 0x0025521, 0x0071A6B, 0x006787B, 0x0082A80,
0x008A44B, 0x0082A80, 0x0033C3E, 0x0038D36, 0x001E595, 0x0028591,
0x006938F, 0x0078870, 0x0078870, 0x006938F, 0x00A1646, 0x0079655,
0x00AC352, 0x009F196, 0x006101E, 0x0069000, 0x006101E, 0x004F8CB,
0x001586A, 0x002B41F, 0x00492F