1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #include "common/scummsys.h" 24 25 /* VLC code 26 * 27 * Original copyright note: * Intel Indeo 4 (IV41, IV42, etc.) video decoder for ffmpeg 28 * written, produced, and directed by Alan Smithee 29 */ 30 31 #ifndef IMAGE_CODECS_INDEO_VLC_H 32 #define IMAGE_CODECS_INDEO_VLC_H 33 34 #include "image/codecs/indeo/get_bits.h" 35 36 namespace Image { 37 namespace Indeo { 38 39 #define VLC_TYPE int16 40 41 enum VLCFlag { 42 INIT_VLC_LE = 2, 43 INIT_VLC_USE_NEW_STATIC = 4 44 }; 45 46 struct VLCcode { 47 uint8 bits; 48 uint16 symbol; 49 50 /** 51 * codeword, with the first bit-to-be-read in the msb 52 * (even if intended for a little-endian bitstream reader) 53 */ 54 uint32 code; 55 }; 56 57 struct VLC { 58 private: 59 static int compareVlcSpec(const void *a, const void *b); 60 61 /** 62 * Gets a value of a given size from a table 63 * @param table Table to get data from 64 * @param idx Index of value to retrieve 65 * @param wrap Size of elements with alignment 66 * @param size Size of elements 67 */ 68 static uint getData(const void *table, uint idx, uint wrap, uint size); 69 public: 70 int _bits; 71 VLC_TYPE (*_table)[2]; ///< code, bits 72 int _tableSize, _tableAllocated; 73 74 VLC(); 75 76 /* Build VLC decoding tables suitable for use with get_vlc(). 77 78 'nbBits' sets the decoding table size (2^nbBits) entries. The 79 bigger it is, the faster is the decoding. But it should not be too 80 big to save memory and L1 cache. '9' is a good compromise. 81 82 'nbCodes' : number of vlcs codes 83 84 'bits' : table which gives the size (in bits) of each vlc code. 85 86 'codes' : table which gives the bit pattern of of each vlc code. 87 88 'symbols' : table which gives the values to be returned from get_vlc(). 89 90 'xxx_wrap' : give the number of bytes between each entry of the 91 'bits' or 'codes' tables. 92 93 'xxx_size' : gives the number of bytes of each entry of the 'bits' 94 or 'codes' tables. 95 96 'wrap' and 'size' make it possible to use any memory configuration and types 97 (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. 98 99 'useStatic' should be set to 1 for tables, which should be freed 100 with av_free_static(), 0 if freeVlc() will be used. 101 */ 102 int init_vlc(int nbBits, int nbCodes, const void *bits, int bitsWrap, 103 int bitsSize, const void *codes, int codesWrap, int codesSize, 104 const void *symbols, int symbolsWrap, int symbolsSize, int flags); 105 106 int init_vlc(int nbBits, int nbCodes, const void *bits, int bitsWrap, int bitsSize, 107 const void *codes, int codesWrap, int codesSize, int flags); 108 109 /** 110 * Free VLC data 111 */ 112 void freeVlc(); 113 114 115 /** 116 * Build VLC decoding tables suitable for use with get_vlc(). 117 * 118 * @param tableNbBits max length of vlc codes to store directly in this table 119 * (Longer codes are delegated to subtables.) 120 * 121 * @param nbCodes number of elements in codes[] 122 * 123 * @param codes descriptions of the vlc codes 124 * These must be ordered such that codes going into the same subtable are contiguous. 125 * Sorting by VLCcode.code is sufficient, though not necessary. 126 */ 127 int buildTable(int tableNbBits, int nbCodes, VLCcode *codes, int flags); 128 129 int allocTable(int size, int useStatic); 130 }; 131 132 } // End of namespace Indeo 133 } // End of namespace Image 134 135 #endif 136