Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Huff.h

Go to the documentation of this file.
00001 /* Copyright (C) 1998 Oregon Graduate Institute of Science & Technology 00002 * Copyright (c) 1995 The Regents of the University of California. 00003 * 00004 * See the file COPYRIGHT, which should have been supplied with this 00005 * package, for licensing details. We may be contacted through email 00006 * at <quasar-help@cse.ogi.edu>. 00007 */ 00008 00009 #ifndef HUFF_H 00010 #define HUFF_H 00011 00012 #include "bitwise.h" 00013 00014 #define SPEG_DCT_DC_SIZE(cur, type, totbits) \ 00015 do { \ 00016 SPEG_BW_GETHUFFN(cur, res, Huff::dct_dc_size_##type, .num_bits, 5); \ 00017 if (res != 31) { \ 00018 bits = Huff::dct_dc_size_##type[res].num_bits; \ 00019 val = Huff::dct_dc_size_##type[res].value; \ 00020 res >>= 5 - bits; \ 00021 } \ 00022 else { \ 00023 SPEG_BW_GETHUFFN(cur, res, Huff::dct_dc_size_##type##1, .num_bits, (totbits - 5)); \ 00024 bits = Huff::dct_dc_size_##type##1[res].num_bits + 5; \ 00025 val = Huff::dct_dc_size_##type##1[res].value; \ 00026 if (res == SPEG_ERROR) goto fail_slice; \ 00027 res |= (31 << (totbits - 5)); \ 00028 res >>= totbits - bits; \ 00029 } \ 00030 } while (0) 00031 00032 #define SPEG_COEFF_RD(cur, dct_coeff, r, l) \ 00033 do { \ 00034 SPEG_BW_GETHUFFN(cur, res, dct_coeff, .num_bits, 8); \ 00035 r = dct_coeff[res].run; \ 00036 l = dct_coeff[res].level; \ 00037 if (!l) { \ 00038 if (r == ESCAPE) { \ 00039 SPEG_BW_GETN(cur, res, 14); \ 00040 r = res >> 8; \ 00041 if (res & 0x7f) \ 00042 l = (int)((res & 0xff) << 24) >> 24; \ 00043 else { \ 00044 SPEG_BW_GETN(cur, l, 8); \ 00045 if (res & 0x80) { \ 00046 if (!l) \ 00047 goto fail_slice; \ 00048 l -= 256; \ 00049 } \ 00050 } \ 00051 } \ 00052 else if (r == SUBTABLE) { \ 00053 SPEG_BW_GETHUFFN(cur, res, Huff::dct_coeff_sub, .num_bits, 10); \ 00054 r = Huff::dct_coeff_sub[res].run; \ 00055 l = Huff::dct_coeff_sub[res].level; \ 00056 if (r == SPEG_ERROR) goto fail_slice; \ 00057 SPEG_BW_GETN(cur, res, 1); \ 00058 if (res) \ 00059 l = -l; \ 00060 } \ 00061 } \ 00062 else if (r != END_OF_BLOCK) { \ 00063 SPEG_BW_GETN(cur, res, 1); \ 00064 if (res) \ 00065 l = -l; \ 00066 } \ 00067 } while (0) 00068 00069 #define SPEG_COEFF_WR(out, r, l) \ 00070 do { \ 00071 int tmp = l; \ 00072 int sign = tmp < 0; \ 00073 if (sign) \ 00074 tmp = -tmp; \ 00075 --tmp; \ 00076 if (tmp < 40 && r < 32) { \ 00077 res = Huff::dct_coeff_encode[tmp][r].data; \ 00078 if (res != SUBTABLE) { \ 00079 bits = Huff::dct_coeff_encode[tmp][r].num_bits; \ 00080 res |= sign; \ 00081 SPEG_BW_PUTN(out, res, bits); \ 00082 break; \ 00083 } \ 00084 } \ 00085 res = 0x40 | r; \ 00086 if (tmp < 127) { \ 00087 res <<= 8; \ 00088 res |= l & 0xff; \ 00089 SPEG_BW_PUTN(out, res, 20); \ 00090 } \ 00091 else { \ 00092 res <<= 16; \ 00093 res |= l & 0xff | (sign << 15); \ 00094 SPEG_BW_PUTN(out, res, 28); \ 00095 } \ 00096 } while (0) 00097 00098 /* Misc DCT definitions */ 00099 //#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ 00100 //#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ 00101 const int DCTSIZE = 8; 00102 const int DCTSIZE2 = 64; 00103 00104 /* Structures for an entry in the decoding table of coded_block_pattern */ 00105 typedef struct { 00106 unsigned int cbp; /* coded_block_pattern */ 00107 int num_bits; /* length of the Huffman code */ 00108 } coded_block_pattern_entry; 00109 00110 /* Structure for an entry in the decoding table of 00111 * macroblock_address_increment */ 00112 typedef struct { 00113 int value; /* value for macroblock_address_increment */ 00114 int num_bits; /* length of the Huffman code */ 00115 } mb_addr_inc_entry; 00116 00117 /* Structure for an entry in the decoding table of macroblock_type */ 00118 typedef struct { 00119 unsigned int mb_quant; /* macroblock_quant */ 00120 unsigned int mb_motion_forward; /* macroblock_motion_forward */ 00121 unsigned int mb_motion_backward; /* macroblock_motion_backward */ 00122 unsigned int mb_pattern; /* macroblock_pattern */ 00123 unsigned int mb_intra; /* macroblock_intra */ 00124 int num_bits; /* length of the Huffman code */ 00125 } mb_type_entry; 00126 00127 /* Structure for an entry in the decoding table of motion vectors */ 00128 typedef struct { 00129 int code; /* value for motion_horizontal_forward_code, 00130 * motion_vertical_forward_code, 00131 * motion_horizontal_backward_code, or 00132 * motion_vertical_backward_code. 00133 */ 00134 int num_bits; /* length of the Huffman code */ 00135 } motion_vectors_entry; 00136 00137 /* DCT coeff tables. */ 00138 typedef struct { 00139 int run; 00140 int level; 00141 int num_bits; 00142 } dct_coeff_tab; 00143 00144 /* Structure for an entry in the decoding table of dct_dc_size */ 00145 typedef struct { 00146 unsigned int value; /* value of dct_dc_size (luminance or chrominance) */ 00147 int num_bits; /* length of the Huffman code */ 00148 } dct_dc_size_entry; 00149 00150 typedef struct { 00151 //unsigned int data; 00152 int data; 00153 int num_bits; 00154 } dct_coeff_encode_tab; 00155 00156 typedef short DCTELEM; 00157 typedef DCTELEM DCTBLOCK[DCTSIZE2]; 00158 00159 /* Code for unbound values in decoding tables */ 00160 const int SPEG_ERROR = (-0x7fff); 00161 00162 const int SPEG_MACRO_BLOCK_STUFFING = 0; 00163 const int SPEG_MACRO_BLOCK_ESCAPE = 34; 00164 00165 /* Two types of DCT Coefficients */ 00166 const int DCT_COEFF_FIRST = 0; 00167 const int DCT_COEFF_NEXT = 1; 00168 00169 /* Special values for DCT Coefficients */ 00170 const int END_OF_BLOCK = 64; 00171 const int ESCAPE = 0; 00172 const int SUBTABLE = -1; 00173 00174 00175 class Huff 00176 { 00177 00178 public: 00179 00180 /* Decoding table for macroblock_address_increment */ 00181 //extern mb_addr_inc_entry mb_addr_inc[2048]; 00182 static mb_addr_inc_entry mb_addr_inc[]; 00183 00184 00185 /* Decoding table for macroblock_type in I-frame pictures */ 00186 //extern mb_type_entry mb_type_I[4]; 00187 static mb_type_entry mb_type_I[]; 00188 00189 /* Decoding table for macroblock_type in predictive-coded pictures */ 00190 //extern mb_type_entry mb_type_P[64]; 00191 static mb_type_entry mb_type_P[]; 00192 00193 /* Decoding table for macroblock_type in bidirectionally-coded pictures */ 00194 //extern mb_type_entry mb_type_B[64]; 00195 static mb_type_entry mb_type_B[]; 00196 00197 00198 /* External declaration of coded block pattern table. */ 00199 //extern coded_block_pattern_entry coded_block_pattern[512]; 00200 static coded_block_pattern_entry coded_block_pattern[]; 00201 00202 00203 00204 /* Decoding table for motion vectors */ 00205 //extern motion_vectors_entry motion_vectors[2048]; 00206 static motion_vectors_entry motion_vectors[]; 00207 00208 00209 /* External declaration of dct dc size lumiance table. */ 00210 //extern dct_dc_size_entry dct_dc_size_luminance[32]; 00211 //extern dct_dc_size_entry dct_dc_size_luminance1[16]; 00212 static dct_dc_size_entry dct_dc_size_luminance[]; 00213 static dct_dc_size_entry dct_dc_size_luminance1[]; 00214 00215 /* External declaration of dct dc size chrom table. */ 00216 //extern dct_dc_size_entry dct_dc_size_chrominance[32]; 00217 //extern dct_dc_size_entry dct_dc_size_chrominance1[32]; 00218 static dct_dc_size_entry dct_dc_size_chrominance[]; 00219 static dct_dc_size_entry dct_dc_size_chrominance1[]; 00220 00221 00222 //extern dct_coeff_tab dct_coeff_first[256]; 00223 //extern dct_coeff_tab dct_coeff_next[256]; 00224 //extern dct_coeff_tab dct_coeff_sub[1024]; 00225 static dct_coeff_tab dct_coeff_first[]; 00226 static dct_coeff_tab dct_coeff_next[]; 00227 static dct_coeff_tab dct_coeff_sub[]; 00228 00229 //extern dct_coeff_encode_tab dct_coeff_encode[40][32]; 00230 static dct_coeff_encode_tab dct_coeff_encode[40][32]; 00231 00232 00233 static void init_tables(void); 00234 00235 private: 00236 00237 static void init_mb_addr_inc (); 00238 static void init_mb_type_I (); 00239 static void init_mb_type_P (); 00240 static void init_mb_type_B (); 00241 static void init_motion_vectors (); 00242 00243 }; // end of class 00244 00245 #endif /* HUFF_H */

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8