Huff.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
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
00099
00100
00101 const int DCTSIZE = 8;
00102 const int DCTSIZE2 = 64;
00103
00104
00105 typedef struct {
00106 unsigned int cbp;
00107 int num_bits;
00108 }
coded_block_pattern_entry;
00109
00110
00111
00112 typedef struct {
00113 int value;
00114 int num_bits;
00115 }
mb_addr_inc_entry;
00116
00117
00118 typedef struct {
00119 unsigned int mb_quant;
00120 unsigned int mb_motion_forward;
00121 unsigned int mb_motion_backward;
00122 unsigned int mb_pattern;
00123 unsigned int mb_intra;
00124 int num_bits;
00125 }
mb_type_entry;
00126
00127
00128 typedef struct {
00129 int code;
00130
00131
00132
00133
00134 int num_bits;
00135 }
motion_vectors_entry;
00136
00137
00138 typedef struct {
00139 int run;
00140 int level;
00141 int num_bits;
00142 }
dct_coeff_tab;
00143
00144
00145 typedef struct {
00146 unsigned int value;
00147 int num_bits;
00148 }
dct_dc_size_entry;
00149
00150 typedef struct {
00151
00152 int data;
00153 int num_bits;
00154 }
dct_coeff_encode_tab;
00155
00156 typedef short DCTELEM;
00157 typedef DCTELEM DCTBLOCK[
DCTSIZE2];
00158
00159
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
00166 const int DCT_COEFF_FIRST = 0;
00167 const int DCT_COEFF_NEXT = 1;
00168
00169
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
00181
00182 static mb_addr_inc_entry mb_addr_inc[];
00183
00184
00185
00186
00187 static mb_type_entry mb_type_I[];
00188
00189
00190
00191 static mb_type_entry mb_type_P[];
00192
00193
00194
00195 static mb_type_entry mb_type_B[];
00196
00197
00198
00199
00200 static coded_block_pattern_entry coded_block_pattern[];
00201
00202
00203
00204
00205
00206 static motion_vectors_entry motion_vectors[];
00207
00208
00209
00210
00211
00212 static dct_dc_size_entry dct_dc_size_luminance[];
00213 static dct_dc_size_entry dct_dc_size_luminance1[];
00214
00215
00216
00217
00218 static dct_dc_size_entry dct_dc_size_chrominance[];
00219 static dct_dc_size_entry dct_dc_size_chrominance1[];
00220
00221
00222
00223
00224
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
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 };
00244
00245
#endif
Generated on Sun Mar 6 13:35:49 2005 for Komssys by
1.3.8