59#include "mpeg_berkley.h"
74int isMachineLittleEndian();
75unsigned long int fw_ntohl(
unsigned long int networklong){
76 unsigned long int hostlong = 0;
78 hostlong |= (networklong & 0xFF000000) >> 24;
79 hostlong |= (networklong & 0x00FF0000) >> 8;
80 hostlong |= (networklong & 0x0000FF00) << 8;
81 hostlong |= (networklong & 0x000000FF) << 24;
85unsigned short int fw_ntohs(
unsigned short int networkshort){
86 unsigned short int hostshort = 0;
88 hostshort |= (networkshort & 0xFF00) >> 8;
89 hostshort |= (networkshort & 0x00FF) << 8;
93unsigned short int fw_htons(
unsigned short hostshort)
95 unsigned short int networkshort = 0;
96 if(isMachineLittleEndian()){
97 networkshort |= (hostshort & 0x00ff) << 8;
98 networkshort |= (hostshort & 0xff00) >> 8;
100 networkshort = hostshort;
105unsigned long int fw_htonl(
unsigned long hostlong)
107 unsigned long int networklong = 0;
108 if(isMachineLittleEndian()){
110 unsigned char *s = (
unsigned char *)&hostlong;
111 networklong = ((
unsigned long)s[0]) << 24 | ((
unsigned long)s[1]) << 16 | ((
unsigned long)s[2]) << 8 | s[3];
113 networklong |= (hostlong & 0x000000ff) << 24;
114 networklong |= (hostlong & 0x0000ff00) << 8;
115 networklong |= (hostlong & 0x00ff0000) >> 8;
116 networklong |= (hostlong & 0xff000000) >> 24;
120 networklong = hostlong;
126#define NO_SANITY_CHECKS
127extern const int zigzag_direct[];
151{ {(
unsigned int)MPGERROR, 0}, {(
unsigned int)MPGERROR, 0}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
152 {58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
153 {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
154 {38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8},
155 {43, 8}, {43, 8}, {23, 8}, {23, 8}, {51, 8}, {51, 8}, {15, 8}, {15, 8},
156 {42, 8}, {42, 8}, {22, 8}, {22, 8}, {50, 8}, {50, 8}, {14, 8}, {14, 8},
157 {41, 8}, {41, 8}, {21, 8}, {21, 8}, {49, 8}, {49, 8}, {13, 8}, {13, 8},
158 {35, 8}, {35, 8}, {19, 8}, {19, 8}, {11, 8}, {11, 8}, {7, 8}, {7, 8},
159 {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
160 {10, 7}, {10, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7},
161 {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
162 {9, 7}, {9, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7},
163 {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6},
164 {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6},
165 {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6},
166 {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6},
167 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
168 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
169 {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
170 {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5},
171 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
172 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
173 {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
174 {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5},
175 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
176 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
177 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
178 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
179 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
180 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
181 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
182 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
183 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
184 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
185 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
186 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
187 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
188 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
189 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
190 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
191 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
192 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
193 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
194 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
195 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
196 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
197 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
198 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
199 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
200 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
201 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
202 {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
203 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
204 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
205 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
206 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
207 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
208 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
209 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
210 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
211 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
212 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
213 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
214 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}
219{ {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
220 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
221 {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
222 {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {(
unsigned int)MPGERROR, 0}
226{ {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
227 {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9}
232{ {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
233 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
234 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
235 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {(
unsigned int)MPGERROR, 0}
239{ {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
240 {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
241 {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
242 {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10, 10}, {11, 10}
247unsigned short int dct_coeff_tbl_0[256] =
2490xffff, 0xffff, 0xffff, 0xffff,
2500xffff, 0xffff, 0xffff, 0xffff,
2510xffff, 0xffff, 0xffff, 0xffff,
2520xffff, 0xffff, 0xffff, 0xffff,
2530x052f, 0x051f, 0x050f, 0x04ff,
2540x183f, 0x402f, 0x3c2f, 0x382f,
2550x342f, 0x302f, 0x2c2f, 0x7c1f,
2560x781f, 0x741f, 0x701f, 0x6c1f,
2570x028e, 0x028e, 0x027e, 0x027e,
2580x026e, 0x026e, 0x025e, 0x025e,
2590x024e, 0x024e, 0x023e, 0x023e,
2600x022e, 0x022e, 0x021e, 0x021e,
2610x020e, 0x020e, 0x04ee, 0x04ee,
2620x04de, 0x04de, 0x04ce, 0x04ce,
2630x04be, 0x04be, 0x04ae, 0x04ae,
2640x049e, 0x049e, 0x048e, 0x048e,
2650x01fd, 0x01fd, 0x01fd, 0x01fd,
2660x01ed, 0x01ed, 0x01ed, 0x01ed,
2670x01dd, 0x01dd, 0x01dd, 0x01dd,
2680x01cd, 0x01cd, 0x01cd, 0x01cd,
2690x01bd, 0x01bd, 0x01bd, 0x01bd,
2700x01ad, 0x01ad, 0x01ad, 0x01ad,
2710x019d, 0x019d, 0x019d, 0x019d,
2720x018d, 0x018d, 0x018d, 0x018d,
2730x017d, 0x017d, 0x017d, 0x017d,
2740x016d, 0x016d, 0x016d, 0x016d,
2750x015d, 0x015d, 0x015d, 0x015d,
2760x014d, 0x014d, 0x014d, 0x014d,
2770x013d, 0x013d, 0x013d, 0x013d,
2780x012d, 0x012d, 0x012d, 0x012d,
2790x011d, 0x011d, 0x011d, 0x011d,
2800x010d, 0x010d, 0x010d, 0x010d,
2810x282c, 0x282c, 0x282c, 0x282c,
2820x282c, 0x282c, 0x282c, 0x282c,
2830x242c, 0x242c, 0x242c, 0x242c,
2840x242c, 0x242c, 0x242c, 0x242c,
2850x143c, 0x143c, 0x143c, 0x143c,
2860x143c, 0x143c, 0x143c, 0x143c,
2870x0c4c, 0x0c4c, 0x0c4c, 0x0c4c,
2880x0c4c, 0x0c4c, 0x0c4c, 0x0c4c,
2890x085c, 0x085c, 0x085c, 0x085c,
2900x085c, 0x085c, 0x085c, 0x085c,
2910x047c, 0x047c, 0x047c, 0x047c,
2920x047c, 0x047c, 0x047c, 0x047c,
2930x046c, 0x046c, 0x046c, 0x046c,
2940x046c, 0x046c, 0x046c, 0x046c,
2950x00fc, 0x00fc, 0x00fc, 0x00fc,
2960x00fc, 0x00fc, 0x00fc, 0x00fc,
2970x00ec, 0x00ec, 0x00ec, 0x00ec,
2980x00ec, 0x00ec, 0x00ec, 0x00ec,
2990x00dc, 0x00dc, 0x00dc, 0x00dc,
3000x00dc, 0x00dc, 0x00dc, 0x00dc,
3010x00cc, 0x00cc, 0x00cc, 0x00cc,
3020x00cc, 0x00cc, 0x00cc, 0x00cc,
3030x681c, 0x681c, 0x681c, 0x681c,
3040x681c, 0x681c, 0x681c, 0x681c,
3050x641c, 0x641c, 0x641c, 0x641c,
3060x641c, 0x641c, 0x641c, 0x641c,
3070x601c, 0x601c, 0x601c, 0x601c,
3080x601c, 0x601c, 0x601c, 0x601c,
3090x5c1c, 0x5c1c, 0x5c1c, 0x5c1c,
3100x5c1c, 0x5c1c, 0x5c1c, 0x5c1c,
3110x581c, 0x581c, 0x581c, 0x581c,
3120x581c, 0x581c, 0x581c, 0x581c,
315unsigned short int dct_coeff_tbl_1[16] =
3170x00bb, 0x202b, 0x103b, 0x00ab,
3180x084b, 0x1c2b, 0x541b, 0x501b,
3190x009b, 0x4c1b, 0x481b, 0x045b,
3200x0c3b, 0x008b, 0x182b, 0x441b,
323unsigned short int dct_coeff_tbl_2[4] =
3250x4019, 0x1429, 0x0079, 0x0839,
328unsigned short int dct_coeff_tbl_3[4] =
3300x0449, 0x3c19, 0x3819, 0x1029,
333unsigned short int dct_coeff_next[256] =
3350xffff, 0xffff, 0xffff, 0xffff,
3360xf7d5, 0xf7d5, 0xf7d5, 0xf7d5,
3370x0826, 0x0826, 0x2416, 0x2416,
3380x0046, 0x0046, 0x2016, 0x2016,
3390x1c15, 0x1c15, 0x1c15, 0x1c15,
3400x1815, 0x1815, 0x1815, 0x1815,
3410x0425, 0x0425, 0x0425, 0x0425,
3420x1415, 0x1415, 0x1415, 0x1415,
3430x3417, 0x0067, 0x3017, 0x2c17,
3440x0c27, 0x0437, 0x0057, 0x2817,
3450x0034, 0x0034, 0x0034, 0x0034,
3460x0034, 0x0034, 0x0034, 0x0034,
3470x1014, 0x1014, 0x1014, 0x1014,
3480x1014, 0x1014, 0x1014, 0x1014,
3490x0c14, 0x0c14, 0x0c14, 0x0c14,
3500x0c14, 0x0c14, 0x0c14, 0x0c14,
3510x0023, 0x0023, 0x0023, 0x0023,
3520x0023, 0x0023, 0x0023, 0x0023,
3530x0023, 0x0023, 0x0023, 0x0023,
3540x0023, 0x0023, 0x0023, 0x0023,
3550x0813, 0x0813, 0x0813, 0x0813,
3560x0813, 0x0813, 0x0813, 0x0813,
3570x0813, 0x0813, 0x0813, 0x0813,
3580x0813, 0x0813, 0x0813, 0x0813,
3590x0412, 0x0412, 0x0412, 0x0412,
3600x0412, 0x0412, 0x0412, 0x0412,
3610x0412, 0x0412, 0x0412, 0x0412,
3620x0412, 0x0412, 0x0412, 0x0412,
3630x0412, 0x0412, 0x0412, 0x0412,
3640x0412, 0x0412, 0x0412, 0x0412,
3650x0412, 0x0412, 0x0412, 0x0412,
3660x0412, 0x0412, 0x0412, 0x0412,
3670xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3680xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3690xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3700xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3710xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3720xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3730xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3740xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3750xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3760xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3770xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3780xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3790xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3800xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3810xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3820xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
3830x0011, 0x0011, 0x0011, 0x0011,
3840x0011, 0x0011, 0x0011, 0x0011,
3850x0011, 0x0011, 0x0011, 0x0011,
3860x0011, 0x0011, 0x0011, 0x0011,
3870x0011, 0x0011, 0x0011, 0x0011,
3880x0011, 0x0011, 0x0011, 0x0011,
3890x0011, 0x0011, 0x0011, 0x0011,
3900x0011, 0x0011, 0x0011, 0x0011,
3910x0011, 0x0011, 0x0011, 0x0011,
3920x0011, 0x0011, 0x0011, 0x0011,
3930x0011, 0x0011, 0x0011, 0x0011,
3940x0011, 0x0011, 0x0011, 0x0011,
3950x0011, 0x0011, 0x0011, 0x0011,
3960x0011, 0x0011, 0x0011, 0x0011,
3970x0011, 0x0011, 0x0011, 0x0011,
3980x0011, 0x0011, 0x0011, 0x0011,
401unsigned short int dct_coeff_first[256] =
4030xffff, 0xffff, 0xffff, 0xffff,
4040xf7d5, 0xf7d5, 0xf7d5, 0xf7d5,
4050x0826, 0x0826, 0x2416, 0x2416,
4060x0046, 0x0046, 0x2016, 0x2016,
4070x1c15, 0x1c15, 0x1c15, 0x1c15,
4080x1815, 0x1815, 0x1815, 0x1815,
4090x0425, 0x0425, 0x0425, 0x0425,
4100x1415, 0x1415, 0x1415, 0x1415,
4110x3417, 0x0067, 0x3017, 0x2c17,
4120x0c27, 0x0437, 0x0057, 0x2817,
4130x0034, 0x0034, 0x0034, 0x0034,
4140x0034, 0x0034, 0x0034, 0x0034,
4150x1014, 0x1014, 0x1014, 0x1014,
4160x1014, 0x1014, 0x1014, 0x1014,
4170x0c14, 0x0c14, 0x0c14, 0x0c14,
4180x0c14, 0x0c14, 0x0c14, 0x0c14,
4190x0023, 0x0023, 0x0023, 0x0023,
4200x0023, 0x0023, 0x0023, 0x0023,
4210x0023, 0x0023, 0x0023, 0x0023,
4220x0023, 0x0023, 0x0023, 0x0023,
4230x0813, 0x0813, 0x0813, 0x0813,
4240x0813, 0x0813, 0x0813, 0x0813,
4250x0813, 0x0813, 0x0813, 0x0813,
4260x0813, 0x0813, 0x0813, 0x0813,
4270x0412, 0x0412, 0x0412, 0x0412,
4280x0412, 0x0412, 0x0412, 0x0412,
4290x0412, 0x0412, 0x0412, 0x0412,
4300x0412, 0x0412, 0x0412, 0x0412,
4310x0412, 0x0412, 0x0412, 0x0412,
4320x0412, 0x0412, 0x0412, 0x0412,
4330x0412, 0x0412, 0x0412, 0x0412,
4340x0412, 0x0412, 0x0412, 0x0412,
4350x0010, 0x0010, 0x0010, 0x0010,
4360x0010, 0x0010, 0x0010, 0x0010,
4370x0010, 0x0010, 0x0010, 0x0010,
4380x0010, 0x0010, 0x0010, 0x0010,
4390x0010, 0x0010, 0x0010, 0x0010,
4400x0010, 0x0010, 0x0010, 0x0010,
4410x0010, 0x0010, 0x0010, 0x0010,
4420x0010, 0x0010, 0x0010, 0x0010,
4430x0010, 0x0010, 0x0010, 0x0010,
4440x0010, 0x0010, 0x0010, 0x0010,
4450x0010, 0x0010, 0x0010, 0x0010,
4460x0010, 0x0010, 0x0010, 0x0010,
4470x0010, 0x0010, 0x0010, 0x0010,
4480x0010, 0x0010, 0x0010, 0x0010,
4490x0010, 0x0010, 0x0010, 0x0010,
4500x0010, 0x0010, 0x0010, 0x0010,
4510x0010, 0x0010, 0x0010, 0x0010,
4520x0010, 0x0010, 0x0010, 0x0010,
4530x0010, 0x0010, 0x0010, 0x0010,
4540x0010, 0x0010, 0x0010, 0x0010,
4550x0010, 0x0010, 0x0010, 0x0010,
4560x0010, 0x0010, 0x0010, 0x0010,
4570x0010, 0x0010, 0x0010, 0x0010,
4580x0010, 0x0010, 0x0010, 0x0010,
4590x0010, 0x0010, 0x0010, 0x0010,
4600x0010, 0x0010, 0x0010, 0x0010,
4610x0010, 0x0010, 0x0010, 0x0010,
4620x0010, 0x0010, 0x0010, 0x0010,
4630x0010, 0x0010, 0x0010, 0x0010,
4640x0010, 0x0010, 0x0010, 0x0010,
4650x0010, 0x0010, 0x0010, 0x0010,
4660x0010, 0x0010, 0x0010, 0x0010,
470#define ASSIGN1(start, end, step, val, num) \
471 for (i = start; i < end; i+= step) { \
472 for (j = 0; j < step; j++) { \
473 mb_addr_inc[i+j].value = val; \
474 mb_addr_inc[i+j].num_bits = num; \
503 for (i = 0; i < 8; i++) {
504 mb_addr_inc[i].value = MPGERROR;
505 mb_addr_inc[i].num_bits = 0;
508 mb_addr_inc[8].value = MACRO_BLOCK_ESCAPE;
509 mb_addr_inc[8].num_bits = 11;
511 for (i = 9; i < 15; i++) {
512 mb_addr_inc[i].value = MPGERROR;
513 mb_addr_inc[i].num_bits = 0;
516 mb_addr_inc[15].value = MACRO_BLOCK_STUFFING;
517 mb_addr_inc[15].num_bits = 11;
519 for (i = 16; i < 24; i++) {
520 mb_addr_inc[i].value = MPGERROR;
521 mb_addr_inc[i].num_bits = 0;
526 ASSIGN1(24, 36, 1, val, 11);
527 ASSIGN1(36, 48, 2, val, 10);
528 ASSIGN1(48, 96, 8, val, 8);
529 ASSIGN1(96, 128, 16, val, 7);
530 ASSIGN1(128, 256, 64, val, 5);
531 ASSIGN1(256, 512, 128, val, 4);
532 ASSIGN1(512, 1024, 256, val, 3);
533 ASSIGN1(1024, 2048, 1024, val, 1);
538#define ASSIGN2(start, end, quant, motion_forward, motion_backward, pattern, intra, num, mb_type) \
539 for (i = start; i < end; i ++) { \
540 mb_type[i].mb_quant = quant; \
541 mb_type[i].mb_motion_forward = motion_forward; \
542 mb_type[i].mb_motion_backward = motion_backward; \
543 mb_type[i].mb_pattern = pattern; \
544 mb_type[i].mb_intra = intra; \
545 mb_type[i].num_bits = num; \
572 mb_type_P[0].mb_quant = mb_type_P[0].mb_motion_forward
573 = mb_type_P[0].mb_motion_backward = mb_type_P[0].mb_pattern
574 = mb_type_P[0].mb_intra = (
unsigned int) MPGERROR;
575 mb_type_P[0].num_bits = 0;
577 ASSIGN2(1, 2, 1, 0, 0, 0, 1, 6, mb_type_P)
578 ASSIGN2(2, 4, 1, 0, 0, 1, 0, 5, mb_type_P)
579 ASSIGN2(4, 6, 1, 1, 0, 1, 0, 5, mb_type_P);
580 ASSIGN2(6, 8, 0, 0, 0, 0, 1, 5, mb_type_P);
581 ASSIGN2(8, 16, 0, 1, 0, 0, 0, 3, mb_type_P);
582 ASSIGN2(16, 32, 0, 0, 0, 1, 0, 2, mb_type_P);
583 ASSIGN2(32, 64, 0, 1, 0, 1, 0, 1, mb_type_P);
611 mb_type_B[0].mb_quant = mb_type_B[0].mb_motion_forward
612 = mb_type_B[0].mb_motion_backward = mb_type_B[0].mb_pattern
613 = mb_type_B[0].mb_intra = (
unsigned int) MPGERROR;
614 mb_type_B[0].num_bits = 0;
616 ASSIGN2(1, 2, 1, 0, 0, 0, 1, 6, mb_type_B);
617 ASSIGN2(2, 3, 1, 0, 1, 1, 0, 6, mb_type_B);
618 ASSIGN2(3, 4, 1, 1, 0, 1, 0, 6, mb_type_B);
619 ASSIGN2(4, 6, 1, 1, 1, 1, 0, 5, mb_type_B);
620 ASSIGN2(6, 8, 0, 0, 0, 0, 1, 5, mb_type_B);
621 ASSIGN2(8, 12, 0, 1, 0, 0, 0, 4, mb_type_B);
622 ASSIGN2(12, 16, 0, 1, 0, 1, 0, 4, mb_type_B);
623 ASSIGN2(16, 24, 0, 0, 1, 0, 0, 3, mb_type_B);
624 ASSIGN2(24, 32, 0, 0, 1, 1, 0, 3, mb_type_B);
625 ASSIGN2(32, 48, 0, 1, 1, 0, 0, 2, mb_type_B);
626 ASSIGN2(48, 64, 0, 1, 1, 1, 0, 2, mb_type_B);
631#define ASSIGN3(start, end, step, val, num) \
632 for (i = start; i < end; i+= step) { \
633 for (j = 0; j < step / 2; j++) { \
634 motion_vectors[i+j].code = val; \
635 motion_vectors[i+j].num_bits = num; \
637 for (j = step / 2; j < step; j++) { \
638 motion_vectors[i+j].code = -val; \
639 motion_vectors[i+j].num_bits = num; \
670 for (i = 0; i < 24; i++) {
671 motion_vectors[i].code = MPGERROR;
672 motion_vectors[i].num_bits = 0;
675 ASSIGN3(24, 36, 2, val, 11);
676 ASSIGN3(36, 48, 4, val, 10);
677 ASSIGN3(48, 96, 16, val, 8);
678 ASSIGN3(96, 128, 32, val, 7);
679 ASSIGN3(128, 256, 128, val, 5);
680 ASSIGN3(256, 512, 256, val, 4);
681 ASSIGN3(512, 1024, 512, val, 3);
682 ASSIGN3(1024, 2048, 1024, val, 1);
687extern void init_pre_idct();
715 init_motion_vectors();
748decodeDCTDCSizeLum(value)
756 *value = dct_dc_size_luminance[index].value;
757 flush_bits(dct_dc_size_luminance[index].num_bits);
762 *value = dct_dc_size_luminance1[index].value;
763 flush_bits(dct_dc_size_luminance1[index].num_bits);
790decodeDCTDCSizeChrom(value)
798 *value = dct_dc_size_chrominance[index].value;
799 flush_bits(dct_dc_size_chrominance[index].num_bits);
804 *value = dct_dc_size_chrominance1[index].value;
805 flush_bits(dct_dc_size_chrominance1[index].num_bits);
862decodeDCTCoeff(dct_coeff_tbl, run, level)
863unsigned short int *dct_coeff_tbl;
867 unsigned int temp, index ;
868 unsigned int value, next32bits, flushed;
882 show_bits32(next32bits);
886 index = next32bits >> 24;
889 value = dct_coeff_tbl[index];
890 *run = (value & RUN_MASK) >> RUN_SHIFT;
891 if (*run == END_OF_BLOCK) {
892 *level = END_OF_BLOCK;
897 flushed = (value & NUM_MASK) + 1;
898 next32bits &= bitMask[flushed];
899 if (*run != ESCAPE) {
900 *level = (value & LEVEL_MASK) >> LEVEL_SHIFT;
903 if (next32bits >> (31-flushed)) *level = -*level;
909 temp = next32bits >> (18-flushed);
911 next32bits &= bitMask[flushed];
916 *level = next32bits >> (24-flushed);
919 assert(*level >= 128);
920 }
else if (temp != 128) {
922 *level = ((int) (temp << 24)) >> 24;
925 *level = next32bits >> (24-flushed);
928 *level = *level - 256;
929 assert(*level <= -128 && *level >= -255);
939 index = next32bits >> 22;
940 value = dct_coeff_tbl_2[index & 3];
942 else if (index == 3) {
944 index = next32bits >> 22;
945 value = dct_coeff_tbl_3[index & 3];
949 index = next32bits >> 20;
950 value = dct_coeff_tbl_1[index & 15];
954 index = next32bits >> 16;
955 value = dct_coeff_tbl_0[index & 255];
957 *run = (value & RUN_MASK) >> RUN_SHIFT;
958 *level = (value & LEVEL_MASK) >> LEVEL_SHIFT;
968 flushed = (value & NUM_MASK) + 2;
969 if ((next32bits >> (32-flushed)) & 0x1) *level = -*level;
997decodeDCTCoeffFirst(run, level)
1001 decodeDCTCoeff(dct_coeff_first, run, level);
1027decodeDCTCoeffNext(run, level)
1031 decodeDCTCoeff(dct_coeff_next, run, level);
1036number_of_bits_set(a)
1040 if(a & 1)
return 1 + number_of_bits_set(a >> 1);
1041 return(number_of_bits_set(a >> 1));
1049free_bits_at_bottom(a)
1053 if(!a)
return sizeof(
unsigned long) * 8;
1054 if(((
long)a) & 1l)
return 0;
1055 return 1 + free_bits_at_bottom ( a >> 1);
1058static int *L_tab=NULL, *Cr_r_tab=NULL, *Cr_g_tab=NULL, *Cb_g_tab=NULL,
1066static long *r_2_pix=NULL;
1067static long *g_2_pix=NULL;
1068static long *b_2_pix=NULL;
1069static long *r_2_pix_alloc=NULL;
1070static long *g_2_pix_alloc=NULL;
1071static long *b_2_pix_alloc=NULL;
1092InitColorDither(thirty2)
1099 unsigned long red_mask = 0xff;
1100 unsigned long green_mask = 0xff00;
1101 unsigned long blue_mask = 0xff0000;
1106 L_tab = (
int *)malloc(256*
sizeof(
int));
1108 Cr_r_tab = (
int *)malloc(256*
sizeof(
int));
1110 Cr_g_tab = (
int *)malloc(256*
sizeof(
int));
1112 Cb_g_tab = (
int *)malloc(256*
sizeof(
int));
1114 Cb_b_tab = (
int *)malloc(256*
sizeof(
int));
1116 if (r_2_pix_alloc==NULL)
1117 r_2_pix_alloc = (
long *)malloc(768*
sizeof(
long));
1118 if (g_2_pix_alloc==NULL)
1119 g_2_pix_alloc = (
long *)malloc(768*
sizeof(
long));
1120 if (b_2_pix_alloc==NULL)
1121 b_2_pix_alloc = (
long *)malloc(768*
sizeof(
long));
1123 if (L_tab == NULL ||
1128 r_2_pix_alloc == NULL ||
1129 g_2_pix_alloc == NULL ||
1130 b_2_pix_alloc == NULL) {
1131 fprintf(stderr,
"Could not get enough memory in InitColorDither\n");
1135 for (i=0; i<256; i++) {
1139 CB -= 128; CR -= 128;
1140 Cr_r_tab[i] = (0.419/0.299) * CR;
1141 Cr_g_tab[i] = -(0.299/0.419) * CR;
1142 Cb_g_tab[i] = -(0.114/0.331) * CB;
1143 Cb_b_tab[i] = (0.587/0.331) * CB;
1149 for (i = 0; i < 256; i++) {
1150 r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(red_mask));
1151 r_2_pix_alloc[i + 256] <<= free_bits_at_bottom(red_mask);
1152 g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(green_mask));
1153 g_2_pix_alloc[i + 256] <<= free_bits_at_bottom(green_mask);
1154 b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(blue_mask));
1155 b_2_pix_alloc[i + 256] <<= free_bits_at_bottom(blue_mask);
1171 for (i = 0; i < 256; i++) {
1172 r_2_pix_alloc[i] = r_2_pix_alloc[256];
1173 r_2_pix_alloc[i+ 512] = r_2_pix_alloc[511];
1174 g_2_pix_alloc[i] = g_2_pix_alloc[256];
1175 g_2_pix_alloc[i+ 512] = g_2_pix_alloc[511];
1176 b_2_pix_alloc[i] = b_2_pix_alloc[256];
1177 b_2_pix_alloc[i+ 512] = b_2_pix_alloc[511];
1180 r_2_pix = r_2_pix_alloc + 256;
1181 g_2_pix = g_2_pix_alloc + 256;
1182 b_2_pix = b_2_pix_alloc + 256;
1209Color32DitherImage(lum, cr, cb, out, rows, cols)
1219 unsigned int *row1, *row2;
1220 unsigned char *lum2;
1226 int cols_2 = cols / 2;
1228 row1 = (
unsigned int *)out;
1229 row2 = row1 + cols_2 + cols_2;
1230 lum2 = lum + cols_2 + cols_2;
1231 for (y=0; y<rows; y+=2) {
1232 for (x=0; x<cols_2; x++) {
1237 cr_r = Cr_r_tab[CR];
1238 cr_g = Cr_g_tab[CR];
1239 cb_g = Cb_g_tab[CB];
1240 cb_b = Cb_b_tab[CB];
1242 L = L_tab[(int) *lum++];
1245 G = L + cr_g + cb_g;
1248 *row1++ = (r_2_pix[R] | g_2_pix[G] | b_2_pix[B]);
1250 L = L_tab[(int) *lum++];
1253 G = L + cr_g + cb_g;
1256 *row1++ = (r_2_pix[R] | g_2_pix[G] | b_2_pix[B]);
1262 L = L_tab [(int) *lum2++];
1264 G = L + cr_g + cb_g;
1267 *row2++ = (r_2_pix[R] | g_2_pix[G] | b_2_pix[B]);
1269 L = L_tab [(int) *lum2++];
1271 G = L + cr_g + cb_g;
1274 *row2++ = (r_2_pix[R] | g_2_pix[G] | b_2_pix[B]);
1276 lum += cols_2 + cols_2;
1277 lum2 += cols_2 + cols_2;
1278 row1 += cols_2 + cols_2;
1279 row2 += cols_2 + cols_2;
1285unsigned char pixel[256];
1313 unsigned int r, g, b;
1321 static GLubyte *Image = NULL;
1322 static int lastsize = 0;
1324 if(Image == NULL || blockSize != lastsize)
1325 Image = realloc(Image,blockSize);
1332 p = (
unsigned int *)
vid_stream->current->display + i*hsize;
1336 g = (*p >> PPM_BITS) & 0xff;
1337 b = (*p >> (2*PPM_BITS)) & 0xff;
1354 dataPointer = realloc(dataPointer,blockSize * (*frameCount));
1355 tmpptr = dataPointer + (blockSize * ((*frameCount)-1));
1357 memcpy (tmpptr, Image, blockSize);
1363unsigned int nBitMask[] = { 0x00000000, 0x80000000, 0xc0000000, 0xe0000000,
1364 0xf0000000, 0xf8000000, 0xfc000000, 0xfe000000,
1365 0xff000000, 0xff800000, 0xffc00000, 0xffe00000,
1366 0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000,
1367 0xffff0000, 0xffff8000, 0xffffc000, 0xffffe000,
1368 0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00,
1369 0xffffff00, 0xffffff80, 0xffffffc0, 0xffffffe0,
1370 0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe};
1372unsigned int bitMask[] = { 0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff,
1373 0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff,
1374 0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff,
1375 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff,
1376 0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff,
1377 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
1378 0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f,
1379 0x0000000f, 0x00000007, 0x00000003, 0x00000001};
1381unsigned int rBitMask[] = { 0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
1382 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
1383 0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
1384 0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
1385 0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
1386 0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
1387 0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
1388 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000};
1390unsigned int bitTest[] = { 0x80000000, 0x40000000, 0x20000000, 0x10000000,
1391 0x08000000, 0x04000000, 0x02000000, 0x01000000,
1392 0x00800000, 0x00400000, 0x00200000, 0x00100000,
1393 0x00080000, 0x00040000, 0x00020000, 0x00010000,
1394 0x00008000, 0x00004000, 0x00002000, 0x00001000,
1395 0x00000800, 0x00000400, 0x00000200, 0x00000100,
1396 0x00000080, 0x00000040, 0x00000020, 0x00000010,
1397 0x00000008, 0x00000004, 0x00000002, 0x00000001};
1429 fprintf (stderr,
"\n");
1430 perror(
"Unexpected read error.");
1432 else if ((status == 0) && (
vid_stream->buf_length < 1)) {
1433 printf(
"\nImproper or missing sequence end code.\n");
1469 unsigned int stream;
1475 return NO_VID_STREAM;
1479 show_bitsn(num, stream);
1485 if (mask == stream) {
1487 }
else ret_value = FALSE;
1516 unsigned int size, marker;
1522 size = EXT_BUF_SIZE;
1526 dataPtr = (
char *) malloc(size);
1533 while (!next_bits(24, 0x000001,
vid_stream)) {
1541 dataPtr[marker] = (char) data;
1546 if (marker == size) {
1547 size += EXT_BUF_SIZE;
1548 dataPtr = (
char *) realloc(dataPtr, size);
1554 dataPtr = (
char *) realloc(dataPtr, marker);
1590 return NO_VID_STREAM;
1603 flush_bits((8-byteoff));
1629 if (state < 2) state++;
1634 else if (data == 1) {
1638 if (state == 2) state++;
1685 return STREAM_UNDERFLOW;
1714 unsigned int size, marker;
1723 if (!data)
return NULL;
1727 size = EXT_BUF_SIZE;
1728 dataPtr = (
char *) malloc(size);
1743 dataPtr[marker] = (char) data;
1748 if (marker == size) {
1749 size += EXT_BUF_SIZE;
1750 dataPtr = (
char *) realloc(dataPtr, size);
1758 dataPtr = (
char *) realloc(dataPtr, marker);
1770#define Sign(num) ((num > 0) ? 1 : ((num == 0) ? 0 : -1))
1796#define DCT_recon blockPtr->dct_recon
1797#define DCT_dc_y_past blockPtr->dct_dc_y_past
1798#define DCT_dc_cr_past blockPtr->dct_dc_cr_past
1799#define DCT_dc_cb_past blockPtr->dct_dc_cb_past
1801#define DECODE_DCT_COEFF_FIRST DecodeDCTCoeffFirst
1802#define DECODE_DCT_COEFF_NEXT DecodeDCTCoeffNext
1810 unsigned int temp_curBits;
1813 unsigned int *temp_bitBuffer;
1826 temp_bitBuffer = bitBuffer;
1838 register unsigned int curBits = temp_curBits;
1839 register int bitOffset = temp_bitOffset;
1840 register int bufLength = temp_bufLength;
1841 register unsigned int *bitBuffer = temp_bitBuffer;
1845 int size, level=0, i, run, pos, coeff;
1846 short int *reconptr;
1847 unsigned char *iqmatrixptr, *niqmatrixptr;
1850 reconptr = DCT_recon[0];
1859 p = (
int *) reconptr;
1861 p[0] = p[1] = p[2] = p[3] = p[4] = p[5] = p[6] = p[7] = p[8] = p[9] =
1862 p[10] = p[11] = p[12] = p[13] = p[14] = p[15] = p[16] = p[17] = p[18] =
1863 p[19] = p[20] = p[21] = p[22] = p[23] = p[24] = p[25] = p[26] = p[27] =
1864 p[28] = p[29] = p[30] = p[31] = 0;
1889 unsigned int next16bits, index, flushed;
1891 show_bits16(next16bits);
1892 index = next16bits >> (16-5);
1894 size = dct_dc_size_luminance[index].value;
1895 flushed = dct_dc_size_luminance[index].num_bits;
1897 index = next16bits >> (16-9);
1899 size = dct_dc_size_luminance1[index].value;
1900 flushed = dct_dc_size_luminance1[index].num_bits;
1902 next16bits &= bitMask[16+flushed];
1906 diff = next16bits >> (16-flushed);
1907 if (!(diff & bitTest[32-size])) {
1908 diff = rBitMask[size] | (diff + 1);
1913 flush_bits(flushed);
1921 coeff += DCT_dc_y_past;
1923 DCT_dc_y_past = coeff;
1925 coeff = DCT_dc_y_past + (diff << 3);
1926 DCT_dc_y_past = coeff;
1936 unsigned int next16bits, index, flushed;
1938 show_bits16(next16bits);
1939 index = next16bits >> (16-5);
1941 size = dct_dc_size_chrominance[index].value;
1942 flushed = dct_dc_size_chrominance[index].num_bits;
1944 index = next16bits >> (16-10);
1946 size = dct_dc_size_chrominance1[index].value;
1947 flushed = dct_dc_size_chrominance1[index].num_bits;
1949 next16bits &= bitMask[16+flushed];
1953 diff = next16bits >> (16-flushed);
1954 if (!(diff & bitTest[32-size])) {
1955 diff = rBitMask[size] | (diff + 1);
1960 flush_bits(flushed);
1970 coeff += DCT_dc_cr_past;
1972 DCT_dc_cr_past = coeff;
1979 coeff += DCT_dc_cb_past;
1981 DCT_dc_cb_past = coeff;
1988 coeffCount = (coeff != 0);
1993 iqmatrixptr =
vid_stream->intra_quant_matrix[0];
1997 DECODE_DCT_COEFF_NEXT(run, level);
1999 if (run >= END_OF_BLOCK)
break;
2002 pos = zigzag_direct[i];
2006 coeff = ((level<<1) * qscale *
2007 ((
int) (iqmatrixptr[pos]))) / 16;
2008 coeff += (1 - (coeff & 1));
2010 coeff = ((level<<1) * qscale *
2011 ((
int) (*(iqmatrixptr+pos)))) >> 4;
2012 coeff -= (1 - (coeff & 1));
2014 reconptr[pos] = coeff;
2018 static int jcount = 0;
2020 printf(
" %d ",jcount);
2027 niqmatrixptr =
vid_stream->non_intra_quant_matrix[0];
2030 DECODE_DCT_COEFF_FIRST(run, level);
2033 pos = zigzag_direct[i];
2037 coeff = (((level<<1) - 1) * qscale *
2038 ((int) (niqmatrixptr[pos]))) / 16;
2039 if ((coeff & 1) == 0) {coeff = coeff + 1;}
2041 coeff = (((level<<1) + 1) * qscale *
2042 ((int) (*(niqmatrixptr+pos)))) >> 4;
2043 coeff = (coeff-1) | 1;
2046 reconptr[pos] = coeff;
2055 DECODE_DCT_COEFF_NEXT(run, level);
2057 if (run >= END_OF_BLOCK) {
2062 pos = zigzag_direct[i];
2064 coeff = (((level<<1) - 1) * qscale *
2065 ((int) (niqmatrixptr[pos]))) / 16;
2066 if ((coeff & 1) == 0) {coeff = coeff + 1;}
2068 coeff = (((level<<1) + 1) * qscale *
2069 ((int) (*(niqmatrixptr+pos)))) >> 4;
2070 coeff = (coeff-1) | 1;
2072 reconptr[pos] = coeff;
2084 if (coeffCount == 1) {
2085 j_rev_dct_sparse (reconptr, pos);
2090 float_idct(reconptr);
2093 j_rev_dct(reconptr);
2103 temp_bitBuffer = bitBuffer;
2112 bitBuffer = temp_bitBuffer;
2118#undef DCT_dc_cr_past
2119#undef DCT_dc_cb_past
2145 unsigned int size, run;
2159 DecodeDCTDCSizeLum(size);
2164 get_bitsn(size, diff);
2174 DecodeDCTDCSizeChrom(size);
2179 get_bitsn(size, diff);
2190 DECODE_DCT_COEFF_FIRST(run, level);
2203 DECODE_DCT_COEFF_NEXT(run, level);
2205 if (run >= END_OF_BLOCK)
break;
2214static void ReconIMBlock();
2215static void ReconPMBlock();
2216static void ReconBMBlock();
2217static void ReconBiMBlock();
2218static void ReconSkippedBlock();
2219static void DoPictureDisplay();
2220static int ParseSeqHead();
2221static int ParseGOP();
2222static int ParsePicture();
2223static int ParseSlice();
2224static int ParseMacroBlock();
2225static void ProcessSkippedPFrameMBlocks();
2226static void ProcessSkippedBFrameMBlocks();
2230#define Sign(num) ((num > 0) ? 1 : ((num == 0) ? 0 : -1))
2236const int zigzag[64][2] = {
2237 {0, 0}, {1, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {3, 0}, {2, 1},
2238 {1, 2}, {0, 3}, {0, 4}, {1, 3}, {2, 2}, {3, 1}, {4, 0}, {5, 0},
2239 {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}, {0, 6}, {1, 5}, {2, 4},
2240 {3, 3}, {4, 2}, {5, 1}, {6, 0}, {7, 0}, {6, 1}, {5, 2}, {4, 3},
2241 {3, 4}, {2, 5}, {1, 6}, {0, 7}, {1, 7}, {2, 6}, {3, 5}, {4, 4},
2242 {5, 3}, {6, 2}, {7, 1}, {7, 2}, {6, 3}, {5, 4}, {4, 5}, {3, 6},
2243 {2, 7}, {3, 7}, {4, 6}, {5, 5}, {6, 4}, {7, 3}, {7, 4}, {6, 5},
2244 {5, 6}, {4, 7}, {5, 7}, {6, 6}, {7, 5}, {7, 6}, {6, 7}, {7, 7}};
2247const int zigzag_direct[64] = {
2248 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12,
2249 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35,
2250 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
2251 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63};
2256const int scan[8][8] = {
2257 {0, 1, 5, 6, 14, 15, 27, 28},
2258 {2, 4, 7, 13, 16, 26, 29, 42},
2259 {3, 8, 12, 17, 25, 30, 41, 43},
2260 {9, 11, 18, 24, 31, 40, 44, 53},
2261 {10, 19, 23, 32, 39, 45, 52, 54},
2262 {20, 22, 33, 38, 46, 51, 55, 60},
2263 {21, 34, 37, 47, 50, 56, 59, 61},
2264 {35, 36, 48, 49, 57, 58, 62, 63}};
2267static int No_P_Flag = FALSE;
2268static int No_B_Flag = FALSE;
2280#define MAX_NEG_CROP 2048
2281#define NUM_CROP_ENTRIES (2048+2*MAX_NEG_CROP)
2282static unsigned char cropTbl[NUM_CROP_ENTRIES];
2336 for (i = (-MAX_NEG_CROP); i < NUM_CROP_ENTRIES - MAX_NEG_CROP; i++) {
2338 cropTbl[i + MAX_NEG_CROP] = 0;
2340 }
else if (i >= 2047) {
2341 cropTbl[i + MAX_NEG_CROP] = 2047;
2343 }
else if (i >= 255) {
2344 cropTbl[i + MAX_NEG_CROP] = 255;
2346 cropTbl[i + MAX_NEG_CROP] = i;
2372mpg_NewVidStream(buffer_len)
2373 unsigned int buffer_len;
2377 static const unsigned char default_intra_matrix[64] = {
2378 8, 16, 19, 22, 26, 27, 29, 34,
2379 16, 16, 22, 24, 27, 29, 34, 37,
2380 19, 22, 26, 27, 29, 34, 34, 38,
2381 22, 22, 26, 27, 29, 34, 37, 40,
2382 22, 26, 27, 29, 32, 35, 40, 48,
2383 26, 27, 29, 32, 35, 40, 48, 58,
2384 26, 27, 29, 34, 38, 46, 56, 69,
2385 27, 29, 35, 38, 46, 56, 69, 83};
2394 buffer_len = (buffer_len + 3) >> 2;
2402 new->group.ext_data = NULL;
2403 new->group.user_data = NULL;
2404 new->picture.extra_info = NULL;
2405 new->picture.user_data = NULL;
2406 new->picture.ext_data = NULL;
2407 new->slice.extra_info = NULL;
2408 new->ext_data = NULL;
2409 new->user_data = NULL;
2413 for (i = 0; i < 8; i++) {
2414 for (j = 0; j < 8; j++) {
2415 new->intra_quant_matrix[i][j] = default_intra_matrix[i * 8 + j];
2421 for (i = 0; i < 8; i++) {
2422 for (j = 0; j < 8; j++) {
2423 new->non_intra_quant_matrix[i][j] = 16;
2429 new->current =
new->past =
new->future = NULL;
2430 for (i = 0; i < RING_BUF_SIZE; i++) {
2431 new->ring[i] = NULL;
2437 new->buf_start = (
unsigned int *) malloc(buffer_len * 4);
2444 new->max_buf_length = buffer_len - 1;
2448 new->bit_offset = 0;
2449 new->buf_length = 0;
2450 new->buffer =
new->buf_start;
2453 new->film_has_ended = FALSE;
2454 new->filename = NULL;
2455 new->EOF_flag = FALSE;
2480Destroympeg_VidStream(astream)
2485 if (astream->ext_data != NULL)
2486 free(astream->ext_data);
2488 if (astream->user_data != NULL)
2489 free(astream->user_data);
2491 if (astream->group.ext_data != NULL)
2492 free(astream->group.ext_data);
2494 if (astream->group.user_data != NULL)
2495 free(astream->group.user_data);
2497 if (astream->picture.extra_info != NULL)
2498 free(astream->picture.extra_info);
2500 if (astream->picture.ext_data != NULL)
2501 free(astream->picture.ext_data);
2503 if (astream->picture.user_data != NULL)
2504 free(astream->picture.user_data);
2506 if (astream->slice.extra_info != NULL)
2507 free(astream->slice.extra_info);
2509 if (astream->buf_start != NULL)
2510 free(astream->buf_start);
2512 for (i = 0; i < RING_BUF_SIZE; i++) {
2513 if (astream->ring[i] != NULL) {
2514 DestroyPictImage(astream->ring[i]);
2515 astream->ring[i] = NULL;
2519 free((
char *) astream);
2549 unsigned int width=
vid_stream->mb_width * 16;
2550 unsigned int height=
vid_stream->mb_height * 16;
2563 if(!temp_sz) temp_sz = 1;
2564 if(temp_sz == 3) temp_sz = 4;
2567 new->display = (
unsigned char *) malloc(width * height * temp_sz *
2570 new->luminance = (
unsigned char *) malloc(width * height);
2571 new->Cr = (
unsigned char *) malloc(width * height / 4);
2572 new->Cb = (
unsigned char *) malloc(width * height / 4);
2601DestroyPictImage(apictimage)
2604 if (apictimage->luminance != NULL) {
2605 free(apictimage->luminance);
2607 if (apictimage->Cr != NULL) {
2608 free(apictimage->Cr);
2610 if (apictimage->Cb != NULL) {
2611 free(apictimage->Cb);
2613 if (apictimage->display != NULL) {
2614 free(apictimage->display);
2649 TimeStamp time_stamp;
2676 if (data != SEQ_START_CODE) {
2677 printf(
"This is not an MPEG video stream. (%x)\n",data);
2714 case SEQ_START_CODE:
2721 case GOP_START_CODE:
2728 case PICTURE_START_CODE:
2731 status = ParsePicture(
vid_stream, time_stamp);
2733 if (status == SKIP_PICTURE) {
2735 while (!next_bits(32, PICTURE_START_CODE,
vid_stream)) {
2736 if (next_bits(32, GOP_START_CODE,
vid_stream))
2738 else if (next_bits(32, SEQ_END_CODE,
vid_stream))
2744 }
else if (status != PARSE_OK)
2752 case SEQUENCE_ERROR_CODE:
2761 if ((data >= SLICE_MIN_START_CODE) && (data <= SLICE_MAX_START_CODE)) {
2773 for (i = 0; i < MB_QUANTUM; i++) {
2777 if (!next_bits(23, 0x00000000,
vid_stream)) {
2796 if (((data < SLICE_MIN_START_CODE) || (data > SLICE_MAX_START_CODE)) &&
2797 (data != SEQUENCE_ERROR_CODE)) {
2809 if ((data < SLICE_MIN_START_CODE) || (data > SLICE_MAX_START_CODE)) {
2881 for (i = 0; i < RING_BUF_SIZE; i++) {
2889 vid_stream->aspect_ratio = (
unsigned char) data;
2894 vid_stream->picture_rate = (
unsigned char) data;
2924 for (i = 0; i < 64; i++) {
2927 vid_stream->intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] =
2928 (
unsigned char) data;
2938 for (i = 0; i < 64; i++) {
2941 vid_stream->non_intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] =
2942 (
unsigned char) data;
2953 if (next_bits(32, EXT_START_CODE,
vid_stream)) {
2963 if (next_bits(32, USER_START_CODE,
vid_stream)) {
3058 if (next_bits(32, EXT_START_CODE,
vid_stream)) {
3068 if (next_bits(32, USER_START_CODE,
vid_stream)) {
3101 TimeStamp time_stamp;
3117 if ((
vid_stream->picture.code_type == B_TYPE) &&
3122 return SKIP_PICTURE;
3124 if ((
vid_stream->picture.code_type == P_TYPE) &&
3126 return SKIP_PICTURE;
3134 if ((
vid_stream->picture.code_type == P_TYPE) ||
3140 vid_stream->picture.full_pel_forw_vector = TRUE;
3142 vid_stream->picture.full_pel_forw_vector = FALSE;
3155 if (
vid_stream->picture.code_type == B_TYPE) {
3160 vid_stream->picture.full_pel_back_vector = TRUE;
3162 vid_stream->picture.full_pel_back_vector = FALSE;
3174 if (
vid_stream->picture.extra_info != NULL) {
3185 if (next_bits(32, EXT_START_CODE,
vid_stream)) {
3196 if (next_bits(32, USER_START_CODE,
vid_stream)) {
3210 if (++i >= RING_BUF_SIZE) {
3211 perror(
"Fatal error. Ring buffer full.");
3285 vid_stream->mblock.recon_right_back_prev = 0;
3296 vid_stream->block.dct_dc_cr_past = 1024 << 3;
3297 vid_stream->block.dct_dc_cb_past = 1024 << 3;
3328 int mask, i, recon_right_for, recon_down_for, recon_right_back,
3330 int zero_block_flag;
3331 int mb_quant = 0, mb_motion_forw = 0, mb_motion_back = 0,
3340 DecodeMBAddrInc(addr_incr);
3341 if (mb_addr_inc[ind].num_bits==0) {
3344 if (addr_incr == MB_ESCAPE) {
3346 addr_incr = MB_STUFFING;
3348 }
while (addr_incr == MB_STUFFING);
3352 return SKIP_TO_START_CODE;
3361 else if (
vid_stream->picture.code_type == B_TYPE)
3370 DecodeMBTypeI(mb_quant, mb_motion_forw, mb_motion_back, mb_pattern,
3375 DecodeMBTypeP(mb_quant, mb_motion_forw, mb_motion_back, mb_pattern,
3380 DecodeMBTypeB(mb_quant, mb_motion_forw, mb_motion_back, mb_pattern,
3384 printf(
"ERROR: MPEG-1 Streams with D-frames are not supported\n");
3390 if (mb_quant == TRUE) {
3395 if (mb_motion_forw == TRUE) {
3398 DecodeMotionVectors(
vid_stream->mblock.motion_h_forw_code);
3403 (
vid_stream->mblock.motion_h_forw_code != 0)) {
3404 get_bitsn(
vid_stream->picture.forw_r_size, data);
3408 DecodeMotionVectors(
vid_stream->mblock.motion_v_forw_code);
3413 (
vid_stream->mblock.motion_v_forw_code != 0)) {
3414 get_bitsn(
vid_stream->picture.forw_r_size, data);
3419 if (mb_motion_back == TRUE) {
3422 DecodeMotionVectors(
vid_stream->mblock.motion_h_back_code);
3427 (
vid_stream->mblock.motion_h_back_code != 0)) {
3428 get_bitsn(
vid_stream->picture.back_r_size, data);
3432 DecodeMotionVectors(
vid_stream->mblock.motion_v_back_code);
3437 (
vid_stream->mblock.motion_v_back_code != 0)) {
3438 get_bitsn(
vid_stream->picture.back_r_size, data);
3444 if (mb_pattern == TRUE) {
3452 if (
vid_stream->picture.code_type == P_TYPE) {
3458 if (!mb_motion_forw) {
3459 recon_right_for = 0;
3468 ComputeForwVector(&recon_right_for, &recon_down_for,
vid_stream);
3471 if (
vid_stream->picture.code_type == B_TYPE) {
3478 vid_stream->mblock.recon_right_back_prev = 0;
3484 if (!mb_motion_forw) {
3485 recon_right_for =
vid_stream->mblock.recon_right_for_prev;
3486 recon_down_for =
vid_stream->mblock.recon_down_for_prev;
3491 ComputeForwVector(&recon_right_for, &recon_down_for,
vid_stream);
3496 if (!mb_motion_back) {
3497 recon_right_back =
vid_stream->mblock.recon_right_back_prev;
3498 recon_down_back =
vid_stream->mblock.recon_down_back_prev;
3501 ComputeBackVector(&recon_right_back, &recon_down_back,
vid_stream);
3508 vid_stream->mblock.bpict_past_forw = mb_motion_forw;
3509 vid_stream->mblock.bpict_past_back = mb_motion_back;
3513 for (mask = 32, i = 0; i < 6; mask >>= 1, i++) {
3517 zero_block_flag = 0;
3520 zero_block_flag = 1;
3526 }
else if (mb_motion_forw && mb_motion_back) {
3527 ReconBiMBlock(
vid_stream, i, recon_right_for, recon_down_for,
3528 recon_right_back, recon_down_back, zero_block_flag);
3529 }
else if (mb_motion_forw || (
vid_stream->picture.code_type == P_TYPE)) {
3530 ReconPMBlock(
vid_stream, i, recon_right_for, recon_down_for,
3532 }
else if (mb_motion_back) {
3533 ReconBMBlock(
vid_stream, i, recon_right_back, recon_down_back,
3568#define myassert(x,expression)\
3569 if (!(expression)) {\
3570 fprintf (stderr,"Bad crop value (%d) at line %d\n", x, __LINE__);\
3571 next_start_code(vid_stream); return;}
3572#define assertCrop(x) myassert(x,((x) >= -MAX_NEG_CROP) && \
3573 ((x) <= 2048+MAX_NEG_CROP))
3575#define assertCrop(x)
3580 int mb_row, mb_col, row, col, row_size, rr;
3581 unsigned char *dest;
3609 }
else if (bnum == 5) {
3648 short *sp = &
vid_stream->block.dct_recon[0][0];
3649 unsigned char *cm = cropTbl + MAX_NEG_CROP;
3650 dest += row * row_size + col;
3651 for (rr = 0; rr < 4; rr++, sp += 16, dest += row_size) {
3652 dest[0] = cm[sp[0]];
3654 dest[1] = cm[sp[1]];
3656 dest[2] = cm[sp[2]];
3658 dest[3] = cm[sp[3]];
3660 dest[4] = cm[sp[4]];
3662 dest[5] = cm[sp[5]];
3664 dest[6] = cm[sp[6]];
3666 dest[7] = cm[sp[7]];
3670 dest[0] = cm[sp[8]];
3672 dest[1] = cm[sp[9]];
3674 dest[2] = cm[sp[10]];
3676 dest[3] = cm[sp[11]];
3678 dest[4] = cm[sp[12]];
3680 dest[5] = cm[sp[13]];
3682 dest[6] = cm[sp[14]];
3684 dest[7] = cm[sp[15]];
3710 int mb_row, mb_col, row, col, row_size, rr;
3711 unsigned char *dest = NULL, *past = NULL;
3712 unsigned char *rindex1, *rindex2;
3713 unsigned char *index;
3714 short int *blockvals;
3725 vid_stream->right_for = recon_right_for >> 1;
3727 vid_stream->right_half_for = recon_right_for & 0x1;
3728 vid_stream->down_half_for = recon_down_for & 0x1;
3734 if (
vid_stream->picture.code_type == B_TYPE) {
3762 recon_right_for /= 2;
3763 recon_down_for /= 2;
3764 vid_stream->right_for = recon_right_for >> 1;
3766 vid_stream->right_half_for = recon_right_for & 0x1;
3767 vid_stream->down_half_for = recon_down_for & 0x1;
3787 if (
vid_stream->picture.code_type == B_TYPE) {
3801 if (
vid_stream->picture.code_type == B_TYPE) {
3812 index = dest + (row * row_size) + col;
3813 rindex1 = past + (row +
vid_stream->down_for) * row_size
3816 blockvals = &(
vid_stream->block.dct_recon[0][0]);
3824 unsigned char *cm = cropTbl + MAX_NEG_CROP;
3826 for (rr = 0; rr < 4; rr++) {
3827 index[0] = cm[(int) rindex1[0] + (
int) blockvals[0]];
3828 index[1] = cm[(int) rindex1[1] + (
int) blockvals[1]];
3829 index[2] = cm[(int) rindex1[2] + (
int) blockvals[2]];
3830 index[3] = cm[(int) rindex1[3] + (
int) blockvals[3]];
3831 index[4] = cm[(int) rindex1[4] + (
int) blockvals[4]];
3832 index[5] = cm[(int) rindex1[5] + (
int) blockvals[5]];
3833 index[6] = cm[(int) rindex1[6] + (
int) blockvals[6]];
3834 index[7] = cm[(int) rindex1[7] + (
int) blockvals[7]];
3836 rindex1 += row_size;
3838 index[0] = cm[(int) rindex1[0] + (
int) blockvals[8]];
3839 index[1] = cm[(int) rindex1[1] + (
int) blockvals[9]];
3840 index[2] = cm[(int) rindex1[2] + (
int) blockvals[10]];
3841 index[3] = cm[(int) rindex1[3] + (
int) blockvals[11]];
3842 index[4] = cm[(int) rindex1[4] + (
int) blockvals[12]];
3843 index[5] = cm[(int) rindex1[5] + (
int) blockvals[13]];
3844 index[6] = cm[(int) rindex1[6] + (
int) blockvals[14]];
3845 index[7] = cm[(int) rindex1[7] + (
int) blockvals[15]];
3848 rindex1 += row_size;
3853 for (rr = 0; rr < 4; rr++) {
3854 index[0] = rindex1[0];
3855 index[1] = rindex1[1];
3856 index[2] = rindex1[2];
3857 index[3] = rindex1[3];
3858 index[4] = rindex1[4];
3859 index[5] = rindex1[5];
3860 index[6] = rindex1[6];
3861 index[7] = rindex1[7];
3863 rindex1 += row_size;
3865 index[0] = rindex1[0];
3866 index[1] = rindex1[1];
3867 index[2] = rindex1[2];
3868 index[3] = rindex1[3];
3869 index[4] = rindex1[4];
3870 index[5] = rindex1[5];
3871 index[6] = rindex1[6];
3872 index[7] = rindex1[7];
3874 rindex1 += row_size;
3878 short *src = (
short *)rindex1;
3879 short *dest = (
short *)index;
3881 for (rr = 0; rr < 4; rr++) {
3898 int *src = (
int *)rindex1;
3899 int *dest = (
int *)index;
3901 for (rr = 0; rr < 4; rr++) {
3915 unsigned char *cm = cropTbl + MAX_NEG_CROP;
3916 rindex2 = rindex1 +
vid_stream->right_half_for
3922 for (rr = 0; rr < 4; rr++) {
3923 index[0] = cm[((int) (rindex1[0] + rindex2[0] + 1) >> 1) + blockvals[0]];
3924 index[1] = cm[((int) (rindex1[1] + rindex2[1] + 1) >> 1) + blockvals[1]];
3925 index[2] = cm[((int) (rindex1[2] + rindex2[2] + 1) >> 1) + blockvals[2]];
3926 index[3] = cm[((int) (rindex1[3] + rindex2[3] + 1) >> 1) + blockvals[3]];
3927 index[4] = cm[((int) (rindex1[4] + rindex2[4] + 1) >> 1) + blockvals[4]];
3928 index[5] = cm[((int) (rindex1[5] + rindex2[5] + 1) >> 1) + blockvals[5]];
3929 index[6] = cm[((int) (rindex1[6] + rindex2[6] + 1) >> 1) + blockvals[6]];
3930 index[7] = cm[((int) (rindex1[7] + rindex2[7] + 1) >> 1) + blockvals[7]];
3932 rindex1 += row_size;
3933 rindex2 += row_size;
3935 index[0] = cm[((int) (rindex1[0] + rindex2[0] + 1) >> 1) + blockvals[8]];
3936 index[1] = cm[((int) (rindex1[1] + rindex2[1] + 1) >> 1) + blockvals[9]];
3937 index[2] = cm[((int) (rindex1[2] + rindex2[2] + 1) >> 1) + blockvals[10]];
3938 index[3] = cm[((int) (rindex1[3] + rindex2[3] + 1) >> 1) + blockvals[11]];
3939 index[4] = cm[((int) (rindex1[4] + rindex2[4] + 1) >> 1) + blockvals[12]];
3940 index[5] = cm[((int) (rindex1[5] + rindex2[5] + 1) >> 1) + blockvals[13]];
3941 index[6] = cm[((int) (rindex1[6] + rindex2[6] + 1) >> 1) + blockvals[14]];
3942 index[7] = cm[((int) (rindex1[7] + rindex2[7] + 1) >> 1) + blockvals[15]];
3945 rindex1 += row_size;
3946 rindex2 += row_size;
3949 for (rr = 0; rr < 8; rr++) {
3950 index[0] = (int) (rindex1[0] + rindex2[0] + 1) >> 1;
3951 index[1] = (int) (rindex1[1] + rindex2[1] + 1) >> 1;
3952 index[2] = (int) (rindex1[2] + rindex2[2] + 1) >> 1;
3953 index[3] = (int) (rindex1[3] + rindex2[3] + 1) >> 1;
3954 index[4] = (int) (rindex1[4] + rindex2[4] + 1) >> 1;
3955 index[5] = (int) (rindex1[5] + rindex2[5] + 1) >> 1;
3956 index[6] = (int) (rindex1[6] + rindex2[6] + 1) >> 1;
3957 index[7] = (int) (rindex1[7] + rindex2[7] + 1) >> 1;
3959 rindex1 += row_size;
3960 rindex2 += row_size;
3985ReconBMBlock(
vid_stream, bnum, recon_right_back, recon_down_back, zflag)
3987 int bnum, recon_right_back, recon_down_back, zflag;
3989 int mb_row, mb_col, row, col, row_size, rr;
3990 unsigned char *dest, *future;
3991 int right_back, down_back, right_half_back, down_half_back;
3992 unsigned char *rindex1, *rindex2;
3993 unsigned char *index;
3994 short int *blockvals;
4008 right_back = recon_right_back >> 1;
4009 down_back = recon_down_back >> 1;
4010 right_half_back = recon_right_back & 0x1;
4011 down_half_back = recon_down_back & 0x1;
4044 recon_right_back /= 2;
4045 recon_down_back /= 2;
4046 right_back = recon_right_back >> 1;
4047 down_back = recon_down_back >> 1;
4048 right_half_back = recon_right_back & 0x1;
4049 down_half_back = recon_down_back & 0x1;
4095 index = dest + (row * row_size) + col;
4096 rindex1 = future + (row + down_back) * row_size + col + right_back;
4098 blockvals = &(
vid_stream->block.dct_recon[0][0]);
4100 if ((!right_half_back) && (!down_half_back)) {
4101 unsigned char *cm = cropTbl + MAX_NEG_CROP;
4103 for (rr = 0; rr < 4; rr++) {
4104 index[0] = cm[(int) rindex1[0] + (
int) blockvals[0]];
4105 index[1] = cm[(int) rindex1[1] + (
int) blockvals[1]];
4106 index[2] = cm[(int) rindex1[2] + (
int) blockvals[2]];
4107 index[3] = cm[(int) rindex1[3] + (
int) blockvals[3]];
4108 index[4] = cm[(int) rindex1[4] + (
int) blockvals[4]];
4109 index[5] = cm[(int) rindex1[5] + (
int) blockvals[5]];
4110 index[6] = cm[(int) rindex1[6] + (
int) blockvals[6]];
4111 index[7] = cm[(int) rindex1[7] + (
int) blockvals[7]];
4113 rindex1 += row_size;
4115 index[0] = cm[(int) rindex1[0] + (
int) blockvals[8]];
4116 index[1] = cm[(int) rindex1[1] + (
int) blockvals[9]];
4117 index[2] = cm[(int) rindex1[2] + (
int) blockvals[10]];
4118 index[3] = cm[(int) rindex1[3] + (
int) blockvals[11]];
4119 index[4] = cm[(int) rindex1[4] + (
int) blockvals[12]];
4120 index[5] = cm[(int) rindex1[5] + (
int) blockvals[13]];
4121 index[6] = cm[(int) rindex1[6] + (
int) blockvals[14]];
4122 index[7] = cm[(int) rindex1[7] + (
int) blockvals[15]];
4125 rindex1 += row_size;
4128 if (right_back & 0x1) {
4130 for (rr = 0; rr < 4; rr++) {
4131 index[0] = rindex1[0];
4132 index[1] = rindex1[1];
4133 index[2] = rindex1[2];
4134 index[3] = rindex1[3];
4135 index[4] = rindex1[4];
4136 index[5] = rindex1[5];
4137 index[6] = rindex1[6];
4138 index[7] = rindex1[7];
4140 rindex1 += row_size;
4142 index[0] = rindex1[0];
4143 index[1] = rindex1[1];
4144 index[2] = rindex1[2];
4145 index[3] = rindex1[3];
4146 index[4] = rindex1[4];
4147 index[5] = rindex1[5];
4148 index[6] = rindex1[6];
4149 index[7] = rindex1[7];
4151 rindex1 += row_size;
4153 }
else if (right_back & 0x2) {
4155 short *src = (
short *)rindex1;
4156 short *dest = (
short *)index;
4158 for (rr = 0; rr < 4; rr++) {
4175 int *src = (
int *)rindex1;
4176 int *dest = (
int *)index;
4178 for (rr = 0; rr < 4; rr++) {
4192 unsigned char *cm = cropTbl + MAX_NEG_CROP;
4193 rindex2 = rindex1 + right_half_back + (down_half_back * row_size);
4195 for (rr = 0; rr < 4; rr++) {
4196 index[0] = cm[((int) (rindex1[0] + rindex2[0] + 1) >> 1) + blockvals[0]];
4197 index[1] = cm[((int) (rindex1[1] + rindex2[1] + 1) >> 1) + blockvals[1]];
4198 index[2] = cm[((int) (rindex1[2] + rindex2[2] + 1) >> 1) + blockvals[2]];
4199 index[3] = cm[((int) (rindex1[3] + rindex2[3] + 1) >> 1) + blockvals[3]];
4200 index[4] = cm[((int) (rindex1[4] + rindex2[4] + 1) >> 1) + blockvals[4]];
4201 index[5] = cm[((int) (rindex1[5] + rindex2[5] + 1) >> 1) + blockvals[5]];
4202 index[6] = cm[((int) (rindex1[6] + rindex2[6] + 1) >> 1) + blockvals[6]];
4203 index[7] = cm[((int) (rindex1[7] + rindex2[7] + 1) >> 1) + blockvals[7]];
4205 rindex1 += row_size;
4206 rindex2 += row_size;
4208 index[0] = cm[((int) (rindex1[0] + rindex2[0] + 1) >> 1) + blockvals[8]];
4209 index[1] = cm[((int) (rindex1[1] + rindex2[1] + 1) >> 1) + blockvals[9]];
4210 index[2] = cm[((int) (rindex1[2] + rindex2[2] + 1) >> 1) + blockvals[10]];
4211 index[3] = cm[((int) (rindex1[3] + rindex2[3] + 1) >> 1) + blockvals[11]];
4212 index[4] = cm[((int) (rindex1[4] + rindex2[4] + 1) >> 1) + blockvals[12]];
4213 index[5] = cm[((int) (rindex1[5] + rindex2[5] + 1) >> 1) + blockvals[13]];
4214 index[6] = cm[((int) (rindex1[6] + rindex2[6] + 1) >> 1) + blockvals[14]];
4215 index[7] = cm[((int) (rindex1[7] + rindex2[7] + 1) >> 1) + blockvals[15]];
4218 rindex1 += row_size;
4219 rindex2 += row_size;
4222 for (rr = 0; rr < 8; rr++) {
4223 index[0] = (int) (rindex1[0] + rindex2[0] + 1) >> 1;
4224 index[1] = (int) (rindex1[1] + rindex2[1] + 1) >> 1;
4225 index[2] = (int) (rindex1[2] + rindex2[2] + 1) >> 1;
4226 index[3] = (int) (rindex1[3] + rindex2[3] + 1) >> 1;
4227 index[4] = (int) (rindex1[4] + rindex2[4] + 1) >> 1;
4228 index[5] = (int) (rindex1[5] + rindex2[5] + 1) >> 1;
4229 index[6] = (int) (rindex1[6] + rindex2[6] + 1) >> 1;
4230 index[7] = (int) (rindex1[7] + rindex2[7] + 1) >> 1;
4232 rindex1 += row_size;
4233 rindex2 += row_size;
4257ReconBiMBlock(
vid_stream, bnum, recon_right_for, recon_down_for,
4258 recon_right_back, recon_down_back, zflag)
4260 int bnum, recon_right_for, recon_down_for, recon_right_back, recon_down_back;
4263 int mb_row, mb_col, row, col, row_size, rr;
4264 unsigned char *dest, *past=NULL, *future=NULL;
4265 int right_for, down_for, right_half_for, down_half_for;
4266 int right_back, down_back, right_half_back, down_half_back;
4267 unsigned char *index, *rindex1, *bindex1;
4268 short int *blockvals;
4269 int forw_row_start, back_row_start, forw_col_start, back_col_start;
4286 right_for = recon_right_for >> 1;
4287 down_for = recon_down_for >> 1;
4288 right_half_for = recon_right_for & 0x1;
4289 down_half_for = recon_down_for & 0x1;
4291 right_back = recon_right_back >> 1;
4292 down_back = recon_down_back >> 1;
4293 right_half_back = recon_right_back & 0x1;
4294 down_half_back = recon_down_back & 0x1;
4318 row = (mb_row << 4);
4319 col = (mb_col << 4);
4325 forw_col_start = col + right_for;
4326 forw_row_start = row + down_for;
4328 back_col_start = col + right_back;
4329 back_row_start = row + down_back;
4338 recon_right_for /= 2;
4339 recon_down_for /= 2;
4340 right_for = recon_right_for >> 1;
4341 down_for = recon_down_for >> 1;
4342 right_half_for = recon_right_for & 0x1;
4343 down_half_for = recon_down_for & 0x1;
4345 recon_right_back /= 2;
4346 recon_down_back /= 2;
4347 right_back = recon_right_back >> 1;
4348 down_back = recon_down_back >> 1;
4349 right_half_back = recon_right_back & 0x1;
4350 down_half_back = recon_down_back & 0x1;
4358 row = (mb_row << 3);
4359 col = (mb_col << 3);
4361 forw_col_start = col + right_for;
4362 forw_row_start = row + down_for;
4364 back_col_start = col + right_back;
4365 back_row_start = row + down_back;
4412 index = dest + (row * row_size) + col;
4414 rindex1 = past + forw_row_start * row_size + forw_col_start;
4416 bindex1 = future + back_row_start * row_size + back_col_start;
4418 blockvals = (
short int *) &(
vid_stream->block.dct_recon[0][0]);
4421 unsigned char *cm = cropTbl + MAX_NEG_CROP;
4423 for (rr = 0; rr < 4; rr++) {
4424 index[0] = cm[((int) (rindex1[0] + bindex1[0]) >> 1) + blockvals[0]];
4425 index[1] = cm[((int) (rindex1[1] + bindex1[1]) >> 1) + blockvals[1]];
4426 index[2] = cm[((int) (rindex1[2] + bindex1[2]) >> 1) + blockvals[2]];
4427 index[3] = cm[((int) (rindex1[3] + bindex1[3]) >> 1) + blockvals[3]];
4428 index[4] = cm[((int) (rindex1[4] + bindex1[4]) >> 1) + blockvals[4]];
4429 index[5] = cm[((int) (rindex1[5] + bindex1[5]) >> 1) + blockvals[5]];
4430 index[6] = cm[((int) (rindex1[6] + bindex1[6]) >> 1) + blockvals[6]];
4431 index[7] = cm[((int) (rindex1[7] + bindex1[7]) >> 1) + blockvals[7]];
4433 rindex1 += row_size;
4434 bindex1 += row_size;
4436 index[0] = cm[((int) (rindex1[0] + bindex1[0]) >> 1) + blockvals[8]];
4437 index[1] = cm[((int) (rindex1[1] + bindex1[1]) >> 1) + blockvals[9]];
4438 index[2] = cm[((int) (rindex1[2] + bindex1[2]) >> 1) + blockvals[10]];
4439 index[3] = cm[((int) (rindex1[3] + bindex1[3]) >> 1) + blockvals[11]];
4440 index[4] = cm[((int) (rindex1[4] + bindex1[4]) >> 1) + blockvals[12]];
4441 index[5] = cm[((int) (rindex1[5] + bindex1[5]) >> 1) + blockvals[13]];
4442 index[6] = cm[((int) (rindex1[6] + bindex1[6]) >> 1) + blockvals[14]];
4443 index[7] = cm[((int) (rindex1[7] + bindex1[7]) >> 1) + blockvals[15]];
4446 rindex1 += row_size;
4447 bindex1 += row_size;
4451 for (rr = 0; rr < 4; rr++) {
4452 index[0] = (int) (rindex1[0] + bindex1[0]) >> 1;
4453 index[1] = (int) (rindex1[1] + bindex1[1]) >> 1;
4454 index[2] = (int) (rindex1[2] + bindex1[2]) >> 1;
4455 index[3] = (int) (rindex1[3] + bindex1[3]) >> 1;
4456 index[4] = (int) (rindex1[4] + bindex1[4]) >> 1;
4457 index[5] = (int) (rindex1[5] + bindex1[5]) >> 1;
4458 index[6] = (int) (rindex1[6] + bindex1[6]) >> 1;
4459 index[7] = (int) (rindex1[7] + bindex1[7]) >> 1;
4461 rindex1 += row_size;
4462 bindex1 += row_size;
4464 index[0] = (int) (rindex1[0] + bindex1[0]) >> 1;
4465 index[1] = (int) (rindex1[1] + bindex1[1]) >> 1;
4466 index[2] = (int) (rindex1[2] + bindex1[2]) >> 1;
4467 index[3] = (int) (rindex1[3] + bindex1[3]) >> 1;
4468 index[4] = (int) (rindex1[4] + bindex1[4]) >> 1;
4469 index[5] = (int) (rindex1[5] + bindex1[5]) >> 1;
4470 index[6] = (int) (rindex1[6] + bindex1[6]) >> 1;
4471 index[7] = (int) (rindex1[7] + bindex1[7]) >> 1;
4473 rindex1 += row_size;
4474 bindex1 += row_size;
4501 int row_size, half_row, mb_row, mb_col, row, col, rr;
4502 int addr, row_incr, half_row_incr, crow, ccol;
4503 int *dest, *src, *dest1, *src1;
4508 half_row = (row_size >> 1);
4509 row_incr = row_size >> 2;
4510 half_row_incr = half_row >> 2;
4514 for (addr =
vid_stream->mblock.past_mb_addr + 1;
4515 addr <
vid_stream->mblock.mb_address; addr++) {
4530 dest = (
int *)(
vid_stream->current->luminance + (row * row_size) + col);
4531 src = (
int *)(
vid_stream->future->luminance + (row * row_size) + col);
4533 for (rr = 0; rr < 8; rr++) {
4562 dest = (
int *)(
vid_stream->current->Cr + (crow * half_row) + ccol);
4563 src = (
int *)(
vid_stream->future->Cr + (crow * half_row) + ccol);
4564 dest1 = (
int *)(
vid_stream->current->Cb + (crow * half_row) + ccol);
4565 src1 = (
int *)(
vid_stream->future->Cb + (crow * half_row) + ccol);
4567 for (rr = 0; rr < 4; rr++) {
4577 dest += half_row_incr;
4578 src += half_row_incr;
4579 dest1 += half_row_incr;
4580 src1 += half_row_incr;
4588 dest += half_row_incr;
4589 src += half_row_incr;
4590 dest1 += half_row_incr;
4591 src1 += half_row_incr;
4625 int row_size, half_row, mb_row, mb_col, row, col, rr;
4626 int right_half_for = 0, down_half_for = 0;
4627 int c_right_half_for = 0, c_down_half_for = 0;
4628 int right_half_back = 0, down_half_back = 0;
4629 int c_right_half_back = 0, c_down_half_back = 0;
4630 int addr, right_for = 0, down_for = 0;
4631 int recon_right_for, recon_down_for;
4632 int recon_right_back, recon_down_back;
4633 int right_back = 0, down_back = 0;
4634 int c_right_for = 0, c_down_for = 0;
4635 int c_right_back = 0, c_down_back = 0;
4636 unsigned char forw_lum[256];
4637 unsigned char forw_cr[64], forw_cb[64];
4638 unsigned char back_lum[256], back_cr[64], back_cb[64];
4639 int row_incr, half_row_incr;
4645 half_row = (row_size >> 1);
4646 row_incr = row_size >> 2;
4647 half_row_incr = half_row >> 2;
4651 if (
vid_stream->picture.full_pel_forw_vector) {
4652 recon_right_for =
vid_stream->mblock.recon_right_for_prev << 1;
4653 recon_down_for =
vid_stream->mblock.recon_down_for_prev << 1;
4655 recon_right_for =
vid_stream->mblock.recon_right_for_prev;
4656 recon_down_for =
vid_stream->mblock.recon_down_for_prev;
4659 if (
vid_stream->picture.full_pel_back_vector) {
4660 recon_right_back =
vid_stream->mblock.recon_right_back_prev << 1;
4661 recon_down_back =
vid_stream->mblock.recon_down_back_prev << 1;
4663 recon_right_back =
vid_stream->mblock.recon_right_back_prev;
4664 recon_down_back =
vid_stream->mblock.recon_down_back_prev;
4675 right_for = recon_right_for >> 1;
4676 down_for = recon_down_for >> 1;
4677 right_half_for = recon_right_for & 0x1;
4678 down_half_for = recon_down_for & 0x1;
4680 recon_right_for /= 2;
4681 recon_down_for /= 2;
4682 c_right_for = recon_right_for >> 1;
4683 c_down_for = recon_down_for >> 1;
4684 c_right_half_for = recon_right_for & 0x1;
4685 c_down_half_for = recon_down_for & 0x1;
4689 right_back = recon_right_back >> 1;
4690 down_back = recon_down_back >> 1;
4691 right_half_back = recon_right_back & 0x1;
4692 down_half_back = recon_down_back & 0x1;
4694 recon_right_back /= 2;
4695 recon_down_back /= 2;
4696 c_right_back = recon_right_back >> 1;
4697 c_down_back = recon_down_back >> 1;
4698 c_right_half_back = recon_right_back & 0x1;
4699 c_down_half_back = recon_down_back & 0x1;
4704 for (addr =
vid_stream->mblock.past_mb_addr + 1;
4705 addr <
vid_stream->mblock.mb_address; addr++) {
4723 ReconSkippedBlock(
vid_stream->past->luminance, forw_lum,
4724 row, col, row_size, right_for, down_for,
4725 right_half_for, down_half_for, 16);
4726 ReconSkippedBlock(
vid_stream->past->Cr, forw_cr, crow,
4728 c_right_for, c_down_for, c_right_half_for, c_down_half_for, 8);
4729 ReconSkippedBlock(
vid_stream->past->Cb, forw_cb, crow,
4731 c_right_for, c_down_for, c_right_half_for, c_down_half_for, 8);
4736 ReconSkippedBlock(
vid_stream->future->luminance, back_lum,
4737 row, col, row_size, right_back, down_back,
4738 right_half_back, down_half_back, 16);
4739 ReconSkippedBlock(
vid_stream->future->Cr, back_cr, crow,
4741 c_right_back, c_down_back,
4742 c_right_half_back, c_down_half_back, 8);
4743 ReconSkippedBlock(
vid_stream->future->Cb, back_cb, crow,
4745 c_right_back, c_down_back,
4746 c_right_half_back, c_down_half_back, 8);
4753 dest = (
int *)(
vid_stream->current->luminance + (row * row_size) + col);
4754 src = (
int *)forw_lum;
4756 for (rr = 0; rr < 16; rr++) {
4767 dest = (
int *)(
vid_stream->current->Cr + (crow * half_row) + ccol);
4768 dest1 = (
int *)(
vid_stream->current->Cb + (crow * half_row) + ccol);
4769 src = (
int *)forw_cr;
4770 src1 = (
int *)forw_cb;
4772 for (rr = 0; rr < 8; rr++) {
4784 dest += half_row_incr;
4785 dest1 += half_row_incr;
4789 }
else if (
vid_stream->mblock.bpict_past_back &&
4794 dest = (
int *)(
vid_stream->current->luminance + (row * row_size) + col);
4795 src = (
int *)back_lum;
4797 for (rr = 0; rr < 16; rr++) {
4807 dest = (
int *)(
vid_stream->current->Cr + (crow * half_row) + ccol);
4808 dest1 = (
int *)(
vid_stream->current->Cb + (crow * half_row) + ccol);
4809 src = (
int *)back_cr;
4810 src1 = (
int *)back_cb;
4812 for (rr = 0; rr < 8; rr++) {
4824 dest += half_row_incr;
4825 dest1 += half_row_incr;
4831 unsigned char *src1, *src2, *src1a, *src2a;
4832 unsigned char *dest, *dest1;
4833 dest =
vid_stream->current->luminance + (row * row_size) + col;
4837 for (rr = 0; rr < 16; rr++) {
4838 dest[0] = (int) (src1[0] + src2[0]) >> 1;
4839 dest[1] = (int) (src1[1] + src2[1]) >> 1;
4840 dest[2] = (int) (src1[2] + src2[2]) >> 1;
4841 dest[3] = (int) (src1[3] + src2[3]) >> 1;
4842 dest[4] = (int) (src1[4] + src2[4]) >> 1;
4843 dest[5] = (int) (src1[5] + src2[5]) >> 1;
4844 dest[6] = (int) (src1[6] + src2[6]) >> 1;
4845 dest[7] = (int) (src1[7] + src2[7]) >> 1;
4846 dest[8] = (int) (src1[8] + src2[8]) >> 1;
4847 dest[9] = (int) (src1[9] + src2[9]) >> 1;
4848 dest[10] = (int) (src1[10] + src2[10]) >> 1;
4849 dest[11] = (int) (src1[11] + src2[11]) >> 1;
4850 dest[12] = (int) (src1[12] + src2[12]) >> 1;
4851 dest[13] = (int) (src1[13] + src2[13]) >> 1;
4852 dest[14] = (int) (src1[14] + src2[14]) >> 1;
4853 dest[15] = (int) (src1[15] + src2[15]) >> 1;
4860 dest =
vid_stream->current->Cr + (crow * half_row) + ccol;
4861 dest1 =
vid_stream->current->Cb + (crow * half_row) + ccol;
4867 for (rr = 0; rr < 8; rr++) {
4868 dest[0] = (int) (src1[0] + src2[0]) >> 1;
4869 dest[1] = (int) (src1[1] + src2[1]) >> 1;
4870 dest[2] = (int) (src1[2] + src2[2]) >> 1;
4871 dest[3] = (int) (src1[3] + src2[3]) >> 1;
4872 dest[4] = (int) (src1[4] + src2[4]) >> 1;
4873 dest[5] = (int) (src1[5] + src2[5]) >> 1;
4874 dest[6] = (int) (src1[6] + src2[6]) >> 1;
4875 dest[7] = (int) (src1[7] + src2[7]) >> 1;
4880 dest1[0] = (int) (src1a[0] + src2a[0]) >> 1;
4881 dest1[1] = (int) (src1a[1] + src2a[1]) >> 1;
4882 dest1[2] = (int) (src1a[2] + src2a[2]) >> 1;
4883 dest1[3] = (int) (src1a[3] + src2a[3]) >> 1;
4884 dest1[4] = (int) (src1a[4] + src2a[4]) >> 1;
4885 dest1[5] = (int) (src1a[5] + src2a[5]) >> 1;
4886 dest1[6] = (int) (src1a[6] + src2a[6]) >> 1;
4887 dest1[7] = (int) (src1a[7] + src2a[7]) >> 1;
4919ReconSkippedBlock(source, dest, row, col, row_size,
4920 right, down, right_half, down_half, width)
4921 unsigned char *source;
4922 unsigned char *dest;
4923 int row, col, row_size, right, down, right_half, down_half, width;
4926 unsigned char *source2;
4928 source += ((row + down) * row_size) + col + right;
4931 if ((!right_half) && (!down_half)) {
4934 for (rr = 0; rr < 16; rr++) {
4935 dest[0] = source[0];
4936 dest[1] = source[1];
4937 dest[2] = source[2];
4938 dest[3] = source[3];
4939 dest[4] = source[4];
4940 dest[5] = source[5];
4941 dest[6] = source[6];
4942 dest[7] = source[7];
4943 dest[8] = source[8];
4944 dest[9] = source[9];
4945 dest[10] = source[10];
4946 dest[11] = source[11];
4947 dest[12] = source[12];
4948 dest[13] = source[13];
4949 dest[14] = source[14];
4950 dest[15] = source[15];
4954 }
else if (right & 0x2) {
4956 short *src = (
short *)source;
4957 short *d = (
short *)dest;
4959 for (rr = 0; rr < 16; rr++) {
4973 int *src = (
int *)source;
4974 int *d = (
int *)dest;
4976 for (rr = 0; rr < 16; rr++) {
4986 source2 = source + right_half + (row_size * down_half);
4987 for (rr = 0; rr < width; rr++) {
4988 dest[0] = (int) (source[0] + source2[0]) >> 1;
4989 dest[1] = (int) (source[1] + source2[1]) >> 1;
4990 dest[2] = (int) (source[2] + source2[2]) >> 1;
4991 dest[3] = (int) (source[3] + source2[3]) >> 1;
4992 dest[4] = (int) (source[4] + source2[4]) >> 1;
4993 dest[5] = (int) (source[5] + source2[5]) >> 1;
4994 dest[6] = (int) (source[6] + source2[6]) >> 1;
4995 dest[7] = (int) (source[7] + source2[7]) >> 1;
4996 dest[8] = (int) (source[8] + source2[8]) >> 1;
4997 dest[9] = (int) (source[9] + source2[9]) >> 1;
4998 dest[10] = (int) (source[10] + source2[10]) >> 1;
4999 dest[11] = (int) (source[11] + source2[11]) >> 1;
5000 dest[12] = (int) (source[12] + source2[12]) >> 1;
5001 dest[13] = (int) (source[13] + source2[13]) >> 1;
5002 dest[14] = (int) (source[14] + source2[14]) >> 1;
5003 dest[15] = (int) (source[15] + source2[15]) >> 1;
5006 source2 += row_size;
5011 if ((!right_half) && (!down_half)) {
5013 for (rr = 0; rr < width; rr++) {
5014 dest[0] = source[0];
5015 dest[1] = source[1];
5016 dest[2] = source[2];
5017 dest[3] = source[3];
5018 dest[4] = source[4];
5019 dest[5] = source[5];
5020 dest[6] = source[6];
5021 dest[7] = source[7];
5025 }
else if (right & 0x02) {
5026 short *d = (
short *)dest;
5027 short *src = (
short *)source;
5029 for (rr = 0; rr < width; rr++) {
5038 int *d = (
int *)dest;
5039 int *src = (
int *)source;
5041 for (rr = 0; rr < width; rr++) {
5049 source2 = source + right_half + (row_size * down_half);
5050 for (rr = 0; rr < width; rr++) {
5051 dest[0] = (int) (source[0] + source2[0]) >> 1;
5052 dest[1] = (int) (source[1] + source2[1]) >> 1;
5053 dest[2] = (int) (source[2] + source2[2]) >> 1;
5054 dest[3] = (int) (source[3] + source2[3]) >> 1;
5055 dest[4] = (int) (source[4] + source2[4]) >> 1;
5056 dest[5] = (int) (source[5] + source2[5]) >> 1;
5057 dest[6] = (int) (source[6] + source2[6]) >> 1;
5058 dest[7] = (int) (source[7] + source2[7]) >> 1;
5061 source2 += row_size;
5094 if (No_B_Flag && (
vid_stream->picture.code_type == B_TYPE))
return;
5097 Color32DitherImage(
vid_stream->current->luminance,
5144#ifdef RIGHT_SHIFT_IS_UNSIGNED
5145#define SHIFT_TEMPS int shift_temp;
5146#define RIGHT_SHIFT(x,shft) \
5147 ((shift_temp = (x)) < 0 ? \
5148 (shift_temp >> (shft)) | ((~((int) 0)) << (32-(shft))) : \
5149 (shift_temp >> (shft)))
5152#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
5160 Sorry,
this code only copes with 8x8 DCTs.
5200#ifdef EIGHT_BIT_SAMPLES
5206#define ONE ((int) 1)
5208#define CONST_SCALE (ONE << CONST_BITS)
5216#define FIX(x) ((int) ((x) * CONST_SCALE + 0.5))
5219#define FIX2(x) ((int) ((x) * CONST_SCALE))
5226#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
5239#ifdef EIGHT_BIT_SAMPLES
5240#ifdef SHORTxSHORT_32
5241#define MULTIPLY(var,const) (((INT16) (var)) * ((INT16) (const)))
5243#ifdef SHORTxLCONST_32
5244#define MULTIPLY(var,const) (((INT16) (var)) * ((int) (const)))
5248#define MULTIPLY(var,const) ((var) * (const))
5250#define SPARSE_SCALE_FACTOR 8
5254static DCTELEM PreIDCT[64][64];
5276 for (i=0; i<64; i++) {
5277 memset((
char *) PreIDCT[i], 0, 64*
sizeof(DCTELEM));
5278 PreIDCT[i][i] = 1 << SPARSE_SCALE_FACTOR;
5279 j_rev_dct(PreIDCT[i]);
5301j_rev_dct_sparse (data, pos)
5311 register DCTELEM *dataptr;
5314 DCTBLOCK tmpdata, tmp2data;
5315 DCTELEM *tmpdataptr, *tmp2dataptr;
5330 val += (quant >> 1);
5335 val = (v + (quant >> 1)) / quant;
5338 v = ((val & 0xffff) | (val << 16));
5340 dp[0] = v; dp[1] = v; dp[2] = v; dp[3] = v;
5341 dp[4] = v; dp[5] = v; dp[6] = v; dp[7] = v;
5342 dp[8] = v; dp[9] = v; dp[10] = v; dp[11] = v;
5343 dp[12] = v; dp[13] = v; dp[14] = v; dp[15] = v;
5344 dp[16] = v; dp[17] = v; dp[18] = v; dp[19] = v;
5345 dp[20] = v; dp[21] = v; dp[22] = v; dp[23] = v;
5346 dp[24] = v; dp[25] = v; dp[26] = v; dp[27] = v;
5347 dp[28] = v; dp[29] = v; dp[30] = v; dp[31] = v;
5355 dataptr = (DCTELEM *)data;
5356 coeff = dataptr[pos];
5357 ndataptr = PreIDCT[pos];
5360 printf (
"COEFFICIENT = %3d, POSITION = %2d\n", coeff, pos);
5362 for (v=0; v<64; v++) {
5363 memcpy((
char *) tmpdata, data, 64*
sizeof(DCTELEM));
5365 tmpdataptr = (DCTELEM *)tmpdata;
5367 for (v=0; v<64; v++) {
5368 memcpy((
char *) tmp2data, data, 64*
sizeof(DCTELEM));
5370 tmp2dataptr = (DCTELEM *)tmp2data;
5372 for (rr=0; rr<4; rr++) {
5373 dataptr[0] = (ndataptr[0] * coeff) >> SPARSE_SCALE_FACTOR;
5374 dataptr[1] = (ndataptr[1] * coeff) >> SPARSE_SCALE_FACTOR;
5375 dataptr[2] = (ndataptr[2] * coeff) >> SPARSE_SCALE_FACTOR;
5376 dataptr[3] = (ndataptr[3] * coeff) >> SPARSE_SCALE_FACTOR;
5377 dataptr[4] = (ndataptr[4] * coeff) >> SPARSE_SCALE_FACTOR;
5378 dataptr[5] = (ndataptr[5] * coeff) >> SPARSE_SCALE_FACTOR;
5379 dataptr[6] = (ndataptr[6] * coeff) >> SPARSE_SCALE_FACTOR;
5380 dataptr[7] = (ndataptr[7] * coeff) >> SPARSE_SCALE_FACTOR;
5381 dataptr[8] = (ndataptr[8] * coeff) >> SPARSE_SCALE_FACTOR;
5382 dataptr[9] = (ndataptr[9] * coeff) >> SPARSE_SCALE_FACTOR;
5383 dataptr[10] = (ndataptr[10] * coeff) >> SPARSE_SCALE_FACTOR;
5384 dataptr[11] = (ndataptr[11] * coeff) >> SPARSE_SCALE_FACTOR;
5385 dataptr[12] = (ndataptr[12] * coeff) >> SPARSE_SCALE_FACTOR;
5386 dataptr[13] = (ndataptr[13] * coeff) >> SPARSE_SCALE_FACTOR;
5387 dataptr[14] = (ndataptr[14] * coeff) >> SPARSE_SCALE_FACTOR;
5388 dataptr[15] = (ndataptr[15] * coeff) >> SPARSE_SCALE_FACTOR;
5393 dataptr = (DCTELEM *) data;
5427 int tmp0, tmp1, tmp2, tmp3;
5428 int tmp10, tmp11, tmp12, tmp13;
5429 int z1, z2, z3, z4, z5;
5430 int d0, d1, d2, d3, d4, d5, d6, d7;
5431 register DCTELEM *dataptr;
5441 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
5451 register int *idataptr = (
int*)dataptr;
5454 if ((d1 == 0) && (idataptr[1] | idataptr[2] | idataptr[3]) == 0) {
5458 DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
5459 register int v = (dcval & 0xffff) | (dcval << 16);
5484 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5485 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5486 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5488 tmp0 = (d0 + d4) << CONST_BITS;
5489 tmp1 = (d0 - d4) << CONST_BITS;
5491 tmp10 = tmp0 + tmp3;
5492 tmp13 = tmp0 - tmp3;
5493 tmp11 = tmp1 + tmp2;
5494 tmp12 = tmp1 - tmp2;
5497 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5498 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5499 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5501 tmp0 = d4 << CONST_BITS;
5503 tmp10 = tmp0 + tmp3;
5504 tmp13 = tmp0 - tmp3;
5505 tmp11 = tmp2 - tmp0;
5506 tmp12 = -(tmp0 + tmp2);
5511 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
5512 tmp3 = MULTIPLY(d6, FIX(0.541196100));
5514 tmp0 = (d0 + d4) << CONST_BITS;
5515 tmp1 = (d0 - d4) << CONST_BITS;
5517 tmp10 = tmp0 + tmp3;
5518 tmp13 = tmp0 - tmp3;
5519 tmp11 = tmp1 + tmp2;
5520 tmp12 = tmp1 - tmp2;
5523 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
5524 tmp3 = MULTIPLY(d6, FIX(0.541196100));
5526 tmp0 = d4 << CONST_BITS;
5528 tmp10 = tmp0 + tmp3;
5529 tmp13 = tmp0 - tmp3;
5530 tmp11 = tmp2 - tmp0;
5531 tmp12 = -(tmp0 + tmp2);
5538 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5539 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5540 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5542 tmp0 = d0 << CONST_BITS;
5544 tmp10 = tmp0 + tmp3;
5545 tmp13 = tmp0 - tmp3;
5546 tmp11 = tmp0 + tmp2;
5547 tmp12 = tmp0 - tmp2;
5550 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5551 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5552 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5562 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
5563 tmp3 = MULTIPLY(d6, FIX(0.541196100));
5565 tmp0 = d0 << CONST_BITS;
5567 tmp10 = tmp0 + tmp3;
5568 tmp13 = tmp0 - tmp3;
5569 tmp11 = tmp0 + tmp2;
5570 tmp12 = tmp0 - tmp2;
5573 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
5574 tmp3 = MULTIPLY(d6, FIX(0.541196100));
5588 tmp2 = MULTIPLY(d2, FIX(0.541196100));
5589 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
5591 tmp0 = (d0 + d4) << CONST_BITS;
5592 tmp1 = (d0 - d4) << CONST_BITS;
5594 tmp10 = tmp0 + tmp3;
5595 tmp13 = tmp0 - tmp3;
5596 tmp11 = tmp1 + tmp2;
5597 tmp12 = tmp1 - tmp2;
5600 tmp2 = MULTIPLY(d2, FIX(0.541196100));
5601 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
5603 tmp0 = d4 << CONST_BITS;
5605 tmp10 = tmp0 + tmp3;
5606 tmp13 = tmp0 - tmp3;
5607 tmp11 = tmp2 - tmp0;
5608 tmp12 = -(tmp0 + tmp2);
5613 tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
5614 tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
5617 tmp10 = tmp13 = d4 << CONST_BITS;
5618 tmp11 = tmp12 = -tmp10;
5625 tmp2 = MULTIPLY(d2, FIX(0.541196100));
5626 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
5628 tmp0 = d0 << CONST_BITS;
5630 tmp10 = tmp0 + tmp3;
5631 tmp13 = tmp0 - tmp3;
5632 tmp11 = tmp0 + tmp2;
5633 tmp12 = tmp0 - tmp2;
5636 tmp2 = MULTIPLY(d2, FIX(0.541196100));
5637 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
5647 tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
5650 tmp10 = tmp13 = tmp11 = tmp12 = 0;
5670 z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
5672 tmp0 = MULTIPLY(d7, FIX(0.298631336));
5673 tmp1 = MULTIPLY(d5, FIX(2.053119869));
5674 tmp2 = MULTIPLY(d3, FIX(3.072711026));
5675 tmp3 = MULTIPLY(d1, FIX(1.501321110));
5676 z1 = MULTIPLY(z1, - FIX(0.899976223));
5677 z2 = MULTIPLY(z2, - FIX(2.562915447));
5678 z3 = MULTIPLY(z3, - FIX(1.961570560));
5679 z4 = MULTIPLY(z4, - FIX(0.390180644));
5692 z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
5694 tmp0 = MULTIPLY(d7, FIX(0.298631336));
5695 tmp1 = MULTIPLY(d5, FIX(2.053119869));
5696 tmp2 = MULTIPLY(d3, FIX(3.072711026));
5697 z1 = MULTIPLY(d7, - FIX(0.899976223));
5698 z2 = MULTIPLY(z2, - FIX(2.562915447));
5699 z3 = MULTIPLY(z3, - FIX(1.961570560));
5700 z4 = MULTIPLY(d5, - FIX(0.390180644));
5715 z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
5717 tmp0 = MULTIPLY(d7, FIX(0.298631336));
5718 tmp1 = MULTIPLY(d5, FIX(2.053119869));
5719 tmp3 = MULTIPLY(d1, FIX(1.501321110));
5720 z1 = MULTIPLY(z1, - FIX(0.899976223));
5721 z2 = MULTIPLY(d5, - FIX(2.562915447));
5722 z3 = MULTIPLY(d7, - FIX(1.961570560));
5723 z4 = MULTIPLY(z4, - FIX(0.390180644));
5734 z5 = MULTIPLY(d7 + d5, FIX(1.175875602));
5736 tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
5737 tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
5738 z1 = MULTIPLY(d7, - FIX(0.899976223));
5739 z3 = MULTIPLY(d7, - FIX(1.961570560));
5740 z2 = MULTIPLY(d5, - FIX(2.562915447));
5741 z4 = MULTIPLY(d5, - FIX(0.390180644));
5758 z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
5760 tmp0 = MULTIPLY(d7, FIX(0.298631336));
5761 tmp2 = MULTIPLY(d3, FIX(3.072711026));
5762 tmp3 = MULTIPLY(d1, FIX(1.501321110));
5763 z1 = MULTIPLY(z1, - FIX(0.899976223));
5764 z2 = MULTIPLY(d3, - FIX(2.562915447));
5765 z3 = MULTIPLY(z3, - FIX(1.961570560));
5766 z4 = MULTIPLY(d1, - FIX(0.390180644));
5778 z5 = MULTIPLY(z3, FIX(1.175875602));
5780 tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
5781 tmp2 = MULTIPLY(d3, FIX(0.509795579));
5782 z1 = MULTIPLY(d7, - FIX(0.899976223));
5783 z2 = MULTIPLY(d3, - FIX(2.562915447));
5784 z3 = MULTIPLY(z3, - FIX2(0.785694958));
5795 z5 = MULTIPLY(z1, FIX(1.175875602));
5797 tmp0 = MULTIPLY(d7, - FIX2(1.662939224));
5798 tmp3 = MULTIPLY(d1, FIX2(1.111140466));
5799 z1 = MULTIPLY(z1, FIX2(0.275899379));
5800 z3 = MULTIPLY(d7, - FIX(1.961570560));
5801 z4 = MULTIPLY(d1, - FIX(0.390180644));
5809 tmp0 = MULTIPLY(d7, - FIX2(1.387039845));
5810 tmp1 = MULTIPLY(d7, FIX(1.175875602));
5811 tmp2 = MULTIPLY(d7, - FIX2(0.785694958));
5812 tmp3 = MULTIPLY(d7, FIX2(0.275899379));
5823 z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
5825 tmp1 = MULTIPLY(d5, FIX(2.053119869));
5826 tmp2 = MULTIPLY(d3, FIX(3.072711026));
5827 tmp3 = MULTIPLY(d1, FIX(1.501321110));
5828 z1 = MULTIPLY(d1, - FIX(0.899976223));
5829 z2 = MULTIPLY(z2, - FIX(2.562915447));
5830 z3 = MULTIPLY(d3, - FIX(1.961570560));
5831 z4 = MULTIPLY(z4, - FIX(0.390180644));
5843 z5 = MULTIPLY(z2, FIX(1.175875602));
5845 tmp1 = MULTIPLY(d5, FIX2(1.662939225));
5846 tmp2 = MULTIPLY(d3, FIX2(1.111140466));
5847 z2 = MULTIPLY(z2, - FIX2(1.387039845));
5848 z3 = MULTIPLY(d3, - FIX(1.961570560));
5849 z4 = MULTIPLY(d5, - FIX(0.390180644));
5860 z5 = MULTIPLY(z4, FIX(1.175875602));
5862 tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
5863 tmp3 = MULTIPLY(d1, FIX2(0.601344887));
5864 z1 = MULTIPLY(d1, - FIX(0.899976223));
5865 z2 = MULTIPLY(d5, - FIX(2.562915447));
5866 z4 = MULTIPLY(z4, FIX2(0.785694958));
5874 tmp0 = MULTIPLY(d5, FIX(1.175875602));
5875 tmp1 = MULTIPLY(d5, FIX2(0.275899380));
5876 tmp2 = MULTIPLY(d5, - FIX2(1.387039845));
5877 tmp3 = MULTIPLY(d5, FIX2(0.785694958));
5886 tmp2 = MULTIPLY(d3, - FIX(1.451774981));
5887 tmp3 = MULTIPLY(d1, (FIX(0.211164243) - 1));
5888 z1 = MULTIPLY(d1, FIX(1.061594337));
5889 z2 = MULTIPLY(d3, - FIX(2.172734803));
5890 z4 = MULTIPLY(z5, FIX(0.785694958));
5891 z5 = MULTIPLY(z5, FIX(1.175875602));
5899 tmp0 = MULTIPLY(d3, - FIX2(0.785694958));
5900 tmp1 = MULTIPLY(d3, - FIX2(1.387039845));
5901 tmp2 = MULTIPLY(d3, - FIX2(0.275899379));
5902 tmp3 = MULTIPLY(d3, FIX(1.175875602));
5907 tmp0 = MULTIPLY(d1, FIX2(0.275899379));
5908 tmp1 = MULTIPLY(d1, FIX2(0.785694958));
5909 tmp2 = MULTIPLY(d1, FIX(1.175875602));
5910 tmp3 = MULTIPLY(d1, FIX2(1.387039845));
5913 tmp0 = tmp1 = tmp2 = tmp3 = 0;
5921 dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
5922 dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
5923 dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
5924 dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
5925 dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
5926 dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
5927 dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
5928 dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
5938 for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
5947 d0 = dataptr[DCTSIZE*0];
5948 d1 = dataptr[DCTSIZE*1];
5949 d2 = dataptr[DCTSIZE*2];
5950 d3 = dataptr[DCTSIZE*3];
5951 d4 = dataptr[DCTSIZE*4];
5952 d5 = dataptr[DCTSIZE*5];
5953 d6 = dataptr[DCTSIZE*6];
5954 d7 = dataptr[DCTSIZE*7];
5963 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5964 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5965 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5967 tmp0 = (d0 + d4) << CONST_BITS;
5968 tmp1 = (d0 - d4) << CONST_BITS;
5970 tmp10 = tmp0 + tmp3;
5971 tmp13 = tmp0 - tmp3;
5972 tmp11 = tmp1 + tmp2;
5973 tmp12 = tmp1 - tmp2;
5976 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
5977 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
5978 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
5980 tmp0 = d4 << CONST_BITS;
5982 tmp10 = tmp0 + tmp3;
5983 tmp13 = tmp0 - tmp3;
5984 tmp11 = tmp2 - tmp0;
5985 tmp12 = -(tmp0 + tmp2);
5990 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
5991 tmp3 = MULTIPLY(d6, FIX(0.541196100));
5993 tmp0 = (d0 + d4) << CONST_BITS;
5994 tmp1 = (d0 - d4) << CONST_BITS;
5996 tmp10 = tmp0 + tmp3;
5997 tmp13 = tmp0 - tmp3;
5998 tmp11 = tmp1 + tmp2;
5999 tmp12 = tmp1 - tmp2;
6002 tmp2 = MULTIPLY(d6, -FIX2(1.306562965));
6003 tmp3 = MULTIPLY(d6, FIX(0.541196100));
6005 tmp0 = d4 << CONST_BITS;
6007 tmp10 = tmp0 + tmp3;
6008 tmp13 = tmp0 - tmp3;
6009 tmp11 = tmp2 - tmp0;
6010 tmp12 = -(tmp0 + tmp2);
6017 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
6018 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
6019 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
6021 tmp0 = d0 << CONST_BITS;
6023 tmp10 = tmp0 + tmp3;
6024 tmp13 = tmp0 - tmp3;
6025 tmp11 = tmp0 + tmp2;
6026 tmp12 = tmp0 - tmp2;
6029 z1 = MULTIPLY(d2 + d6, FIX(0.541196100));
6030 tmp2 = z1 + MULTIPLY(d6, - FIX(1.847759065));
6031 tmp3 = z1 + MULTIPLY(d2, FIX(0.765366865));
6041 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
6042 tmp3 = MULTIPLY(d6, FIX(0.541196100));
6044 tmp0 = d0 << CONST_BITS;
6046 tmp10 = tmp0 + tmp3;
6047 tmp13 = tmp0 - tmp3;
6048 tmp11 = tmp0 + tmp2;
6049 tmp12 = tmp0 - tmp2;
6052 tmp2 = MULTIPLY(d6, - FIX2(1.306562965));
6053 tmp3 = MULTIPLY(d6, FIX(0.541196100));
6067 tmp2 = MULTIPLY(d2, FIX(0.541196100));
6068 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
6070 tmp0 = (d0 + d4) << CONST_BITS;
6071 tmp1 = (d0 - d4) << CONST_BITS;
6073 tmp10 = tmp0 + tmp3;
6074 tmp13 = tmp0 - tmp3;
6075 tmp11 = tmp1 + tmp2;
6076 tmp12 = tmp1 - tmp2;
6079 tmp2 = MULTIPLY(d2, FIX(0.541196100));
6080 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
6082 tmp0 = d4 << CONST_BITS;
6084 tmp10 = tmp0 + tmp3;
6085 tmp13 = tmp0 - tmp3;
6086 tmp11 = tmp2 - tmp0;
6087 tmp12 = -(tmp0 + tmp2);
6092 tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
6093 tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
6096 tmp10 = tmp13 = d4 << CONST_BITS;
6097 tmp11 = tmp12 = -tmp10;
6104 tmp2 = MULTIPLY(d2, FIX(0.541196100));
6105 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
6107 tmp0 = d0 << CONST_BITS;
6109 tmp10 = tmp0 + tmp3;
6110 tmp13 = tmp0 - tmp3;
6111 tmp11 = tmp0 + tmp2;
6112 tmp12 = tmp0 - tmp2;
6115 tmp2 = MULTIPLY(d2, FIX(0.541196100));
6116 tmp3 = MULTIPLY(d2, (FIX(1.306562965) + .5));
6126 tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
6129 tmp10 = tmp13 = tmp11 = tmp12 = 0;
6147 z5 = MULTIPLY(z3 + z4, FIX(1.175875602));
6149 tmp0 = MULTIPLY(d7, FIX(0.298631336));
6150 tmp1 = MULTIPLY(d5, FIX(2.053119869));
6151 tmp2 = MULTIPLY(d3, FIX(3.072711026));
6152 tmp3 = MULTIPLY(d1, FIX(1.501321110));
6153 z1 = MULTIPLY(z1, - FIX(0.899976223));
6154 z2 = MULTIPLY(z2, - FIX(2.562915447));
6155 z3 = MULTIPLY(z3, - FIX(1.961570560));
6156 z4 = MULTIPLY(z4, - FIX(0.390180644));
6169 z5 = MULTIPLY(z3 + d5, FIX(1.175875602));
6171 tmp0 = MULTIPLY(d7, FIX(0.298631336));
6172 tmp1 = MULTIPLY(d5, FIX(2.053119869));
6173 tmp2 = MULTIPLY(d3, FIX(3.072711026));
6174 z1 = MULTIPLY(d7, - FIX(0.899976223));
6175 z2 = MULTIPLY(z2, - FIX(2.562915447));
6176 z3 = MULTIPLY(z3, - FIX(1.961570560));
6177 z4 = MULTIPLY(d5, - FIX(0.390180644));
6192 z5 = MULTIPLY(d7 + z4, FIX(1.175875602));
6194 tmp0 = MULTIPLY(d7, FIX(0.298631336));
6195 tmp1 = MULTIPLY(d5, FIX(2.053119869));
6196 tmp3 = MULTIPLY(d1, FIX(1.501321110));
6197 z1 = MULTIPLY(z1, - FIX(0.899976223));
6198 z2 = MULTIPLY(d5, - FIX(2.562915447));
6199 z3 = MULTIPLY(d7, - FIX(1.961570560));
6200 z4 = MULTIPLY(z4, - FIX(0.390180644));
6211 z5 = MULTIPLY(d5 + d7, FIX(1.175875602));
6213 tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
6214 tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
6215 z1 = MULTIPLY(d7, - FIX(0.899976223));
6216 z3 = MULTIPLY(d7, - FIX(1.961570560));
6217 z2 = MULTIPLY(d5, - FIX(2.562915447));
6218 z4 = MULTIPLY(d5, - FIX(0.390180644));
6235 z5 = MULTIPLY(z3 + d1, FIX(1.175875602));
6237 tmp0 = MULTIPLY(d7, FIX(0.298631336));
6238 tmp2 = MULTIPLY(d3, FIX(3.072711026));
6239 tmp3 = MULTIPLY(d1, FIX(1.501321110));
6240 z1 = MULTIPLY(z1, - FIX(0.899976223));
6241 z2 = MULTIPLY(d3, - FIX(2.562915447));
6242 z3 = MULTIPLY(z3, - FIX(1.961570560));
6243 z4 = MULTIPLY(d1, - FIX(0.390180644));
6255 z5 = MULTIPLY(z3, FIX(1.175875602));
6257 tmp0 = MULTIPLY(d7, - FIX2(0.601344887));
6258 z1 = MULTIPLY(d7, - FIX(0.899976223));
6259 tmp2 = MULTIPLY(d3, FIX(0.509795579));
6260 z2 = MULTIPLY(d3, - FIX(2.562915447));
6261 z3 = MULTIPLY(z3, - FIX2(0.785694958));
6272 z5 = MULTIPLY(z1, FIX(1.175875602));
6274 tmp0 = MULTIPLY(d7, - FIX2(1.662939224));
6275 tmp3 = MULTIPLY(d1, FIX2(1.111140466));
6276 z1 = MULTIPLY(z1, FIX2(0.275899379));
6277 z3 = MULTIPLY(d7, - FIX(1.961570560));
6278 z4 = MULTIPLY(d1, - FIX(0.390180644));
6286 tmp0 = MULTIPLY(d7, - FIX2(1.387039845));
6287 tmp1 = MULTIPLY(d7, FIX(1.175875602));
6288 tmp2 = MULTIPLY(d7, - FIX2(0.785694958));
6289 tmp3 = MULTIPLY(d7, FIX2(0.275899379));
6300 z5 = MULTIPLY(d3 + z4, FIX(1.175875602));
6302 tmp1 = MULTIPLY(d5, FIX(2.053119869));
6303 tmp2 = MULTIPLY(d3, FIX(3.072711026));
6304 tmp3 = MULTIPLY(d1, FIX(1.501321110));
6305 z1 = MULTIPLY(d1, - FIX(0.899976223));
6306 z2 = MULTIPLY(z2, - FIX(2.562915447));
6307 z3 = MULTIPLY(d3, - FIX(1.961570560));
6308 z4 = MULTIPLY(z4, - FIX(0.390180644));
6320 z5 = MULTIPLY(z2, FIX(1.175875602));
6322 tmp1 = MULTIPLY(d5, FIX2(1.662939225));
6323 tmp2 = MULTIPLY(d3, FIX2(1.111140466));
6324 z2 = MULTIPLY(z2, - FIX2(1.387039845));
6325 z3 = MULTIPLY(d3, - FIX(1.961570560));
6326 z4 = MULTIPLY(d5, - FIX(0.390180644));
6337 z5 = MULTIPLY(z4, FIX(1.175875602));
6339 tmp1 = MULTIPLY(d5, - FIX2(0.509795578));
6340 tmp3 = MULTIPLY(d1, FIX2(0.601344887));
6341 z1 = MULTIPLY(d1, - FIX(0.899976223));
6342 z2 = MULTIPLY(d5, - FIX(2.562915447));
6343 z4 = MULTIPLY(z4, FIX2(0.785694958));
6351 tmp0 = MULTIPLY(d5, FIX(1.175875602));
6352 tmp1 = MULTIPLY(d5, FIX2(0.275899380));
6353 tmp2 = MULTIPLY(d5, - FIX2(1.387039845));
6354 tmp3 = MULTIPLY(d5, FIX2(0.785694958));
6363 tmp2 = MULTIPLY(d3, - FIX(1.451774981));
6364 tmp3 = MULTIPLY(d1, (FIX(0.211164243) - 1));
6365 z1 = MULTIPLY(d1, FIX(1.061594337));
6366 z2 = MULTIPLY(d3, - FIX(2.172734803));
6367 z4 = MULTIPLY(z5, FIX(0.785694958));
6368 z5 = MULTIPLY(z5, FIX(1.175875602));
6376 tmp0 = MULTIPLY(d3, - FIX2(0.785694958));
6377 tmp1 = MULTIPLY(d3, - FIX2(1.387039845));
6378 tmp2 = MULTIPLY(d3, - FIX2(0.275899379));
6379 tmp3 = MULTIPLY(d3, FIX(1.175875602));
6384 tmp0 = MULTIPLY(d1, FIX2(0.275899379));
6385 tmp1 = MULTIPLY(d1, FIX2(0.785694958));
6386 tmp2 = MULTIPLY(d1, FIX(1.175875602));
6387 tmp3 = MULTIPLY(d1, FIX2(1.387039845));
6390 tmp0 = tmp1 = tmp2 = tmp3 = 0;
6398 dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
6399 CONST_BITS+PASS1_BITS+3);
6400 dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
6401 CONST_BITS+PASS1_BITS+3);
6402 dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
6403 CONST_BITS+PASS1_BITS+3);
6404 dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
6405 CONST_BITS+PASS1_BITS+3);
6406 dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
6407 CONST_BITS+PASS1_BITS+3);
6408 dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
6409 CONST_BITS+PASS1_BITS+3);
6410 dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
6411 CONST_BITS+PASS1_BITS+3);
6412 dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
6413 CONST_BITS+PASS1_BITS+3);
6439#define ComputeVector(recon_right_ptr, recon_down_ptr, recon_right_prev, recon_down_prev, f, full_pel_vector, motion_h_code, motion_v_code, motion_h_r, motion_v_r) \
6442 int comp_h_r, comp_v_r; \
6443 int right_little, right_big, down_little, down_big; \
6444 int max, min, new_vector; \
6451 if (f == 1 || motion_h_code == 0) \
6454 comp_h_r = f - 1 - motion_h_r; \
6456 if (f == 1 || motion_v_code == 0) \
6459 comp_v_r = f - 1 - motion_v_r; \
6461 right_little = motion_h_code * f; \
6462 if (right_little == 0) \
6465 if (right_little > 0) { \
6466 right_little = right_little - comp_h_r; \
6467 right_big = right_little - 32 * f; \
6470 right_little = right_little + comp_h_r; \
6471 right_big = right_little + 32 * f; \
6475 down_little = motion_v_code * f; \
6476 if (down_little == 0) \
6479 if (down_little > 0) { \
6480 down_little = down_little - comp_v_r; \
6481 down_big = down_little - 32 * f; \
6484 down_little = down_little + comp_v_r; \
6485 down_big = down_little + 32 * f; \
6492 new_vector = recon_right_prev + right_little; \
6494 if (new_vector <= max && new_vector >= min) \
6495 *recon_right_ptr = recon_right_prev + right_little; \
6498 *recon_right_ptr = recon_right_prev + right_big; \
6499 recon_right_prev = *recon_right_ptr; \
6500 if (full_pel_vector) \
6501 *recon_right_ptr = *recon_right_ptr << 1; \
6503 new_vector = recon_down_prev + down_little; \
6504 if (new_vector <= max && new_vector >= min) \
6505 *recon_down_ptr = recon_down_prev + down_little; \
6508 *recon_down_ptr = recon_down_prev + down_big; \
6509 recon_down_prev = *recon_down_ptr; \
6510 if (full_pel_vector) \
6511 *recon_down_ptr = *recon_down_ptr << 1; \
6534ComputeForwVector(recon_right_for_ptr, recon_down_for_ptr, the_stream)
6535 int *recon_right_for_ptr;
6536 int *recon_down_for_ptr;
6543 picture = &(the_stream->picture);
6544 mblock = &(the_stream->mblock);
6546 ComputeVector(recon_right_for_ptr, recon_down_for_ptr,
6547 mblock->recon_right_for_prev,
6548 mblock->recon_down_for_prev,
6549 (
int) picture->forw_f,
6550 picture->full_pel_forw_vector,
6551 mblock->motion_h_forw_code, mblock->motion_v_forw_code,
6552 mblock->motion_h_forw_r, mblock->motion_v_forw_r);
6575ComputeBackVector(recon_right_back_ptr, recon_down_back_ptr, the_stream)
6576 int *recon_right_back_ptr;
6577 int *recon_down_back_ptr;
6583 picture = &(the_stream->picture);
6584 mblock = &(the_stream->mblock);
6586 ComputeVector(recon_right_back_ptr, recon_down_back_ptr,
6587 mblock->recon_right_back_prev,
6588 mblock->recon_down_back_prev,
6589 (
int) picture->back_f,
6590 picture->full_pel_back_vector,
6591 mblock->motion_h_back_code, mblock->motion_v_back_code,
6592 mblock->motion_h_back_r, mblock->motion_v_back_r);
6599#define PACK_START_CODE ((unsigned int)0x000001ba)
6600#define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb)
6601#define PACKET_START_CODE_MASK ((unsigned int)0xffffff00)
6602#define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100)
6603#define ISO_11172_END_CODE ((unsigned int)0x000001b9)
6605#define PACK_HEADER_SIZE 8
6607#define STD_AUDIO_STREAM_ID ((unsigned char) 0xb8)
6608#define STD_VIDEO_STREAM_ID ((unsigned char) 0xb9)
6609#define MIN_STREAM_ID_ID ((unsigned char) 0xbc)
6610#define RESERVED_STREAM_ID ((unsigned char) 0xbc)
6611#define PRIVATE_STREAM_1_ID ((unsigned char) 0xbd)
6612#define PADDING_STREAM_ID ((unsigned char) 0xbe)
6613#define PRIVATE_STREAM_2_ID ((unsigned char) 0xbf)
6615#define STD_SYSTEM_CLOCK_FREQ (unsigned long)90000
6616#define MUX_RATE_SCALE_FACTOR 50
6617#define MAX_STREAMS 8
6618#define NOT_PACKET_ID ((unsigned char) 0xff)
6619#define KILL_BUFFER ((unsigned char) 0xfe)
6643 unsigned int **bs_ptr=&
vid_stream->buf_start;
6647 int ioBytes, data, result;
6652 if (sys_layer == 0) {
6653 return pure_get_more_data(*bs_ptr,
6660 if (sys_layer == -1) {
6664 ioBytes = fread(&data, 1, 4,
vid_stream->input);
6670 data = fw_ntohl(data);
6671 if ( (data == PACK_START_CODE) || (data == SYSTEM_HEADER_START_CODE) ) {
6678 result = read_sys(
vid_stream,(
unsigned int) data);
6680 }
else if (data == SEQ_START_CODE) {
6687 result = pure_get_more_data(*bs_ptr, *max_length,
6694 fprintf(stderr,
"Junk at start of stream, searching for start code\n");
6697 if ((ioBytes = fread(&
byte, 1, 1,
vid_stream->input)) != 1)
return 0;
6699 if (state < 2) state++;
6700 }
else if ((
byte == 1) && (state == 2)) {
6706 if ((ioBytes = fread(&
byte, 1, 1,
vid_stream->input)) != 1)
return 0;
6707 data = ((
unsigned int)
byte + 0x100);
6709 case SEQ_START_CODE:
6711 case PACK_START_CODE:
6712 case SYSTEM_HEADER_START_CODE:
6767pure_get_more_data(buf_start, max_length, length_ptr, buf_ptr,
vid_stream)
6768 unsigned int *buf_start;
6771 unsigned int **buf_ptr;
6775 int length, num_read, i;
6776 unsigned int request;
6777 unsigned char *buffer, *mark;
6778 unsigned int *lmark;
6783 length = *length_ptr;
6784 buffer = (
unsigned char *) *buf_ptr;
6789 if (((
unsigned char *)buf_start) != buffer) {
6790 memcpy((
unsigned char *) buf_start, buffer, (
unsigned int) (length*4));
6792 mark = ((
unsigned char *) (buf_start + length));
6795 mark = (
unsigned char *) buf_start;
6799 request = (max_length-length)*4;
6802 num_read = fread(mark, 1, request,
vid_stream->input);
6806 int num_read_rounded;
6807 unsigned char *index;
6809 num_read_rounded = 4*(num_read/4);
6812 if ( num_read_rounded < num_read ) {
6813 num_read_rounded = 4*( num_read/4+1 );
6816 for( index=mark+num_read; index<mark+num_read_rounded; *(index++)=0 );
6819 num_read = num_read_rounded;
6825 }
else if (num_read == 0) {
6826 *buf_ptr = buf_start;
6834 *(buf_start + length) = 0x0;
6835 *(buf_start + length+1) = SEQ_END_CODE;
6841 lmark = (
unsigned int *) mark;
6843 num_read = num_read/4;
6846 for (i = 0; i < num_read; i++) {
6847 *lmark = fw_htonl(*lmark);
6852 *buf_ptr = buf_start;
6853 *length_ptr = length + num_read;
6881 unsigned int startCode;
6882 int errorCode, PacketReply;
6883 unsigned char packetID;
6884 double systemClockTime;
6885 unsigned long muxRate;
6890 errorCode = ReadStartCode(&startCode,
vid_stream);
6892 if (errorCode != 0) {
6893 fprintf(stderr,
"Unable to read initial pack start code\n");
6903 if (startCode == PACK_START_CODE) {
6905 errorCode = ReadPackHeader( &systemClockTime, &muxRate,
vid_stream);
6906 if (errorCode != 0) {
6907 fprintf(stderr,
"Error in reading pack header\n");
6910 errorCode = ReadStartCode( &startCode,
vid_stream );
6911 if (errorCode != 0) {
6912 fprintf(stderr,
"Error in reading start code\n");
6916 if (startCode == SYSTEM_HEADER_START_CODE) {
6919 if (errorCode != 0) {
6920 fprintf(stderr,
"Error in reading system header\n");
6923 errorCode = ReadStartCode( &startCode,
vid_stream );
6924 if (errorCode != 0) {
6925 fprintf(stderr,
"Error in reading start code after system header\n");
6929 packetID = startCode & 0xff;
6930 while (((startCode & PACKET_START_CODE_MASK) == PACKET_START_CODE_PREFIX) &&
6931 (packetID >= 0xbc)) {
6933 packetID = startCode & 0xff;
6934 PacketReply = ReadPacket(packetID,
vid_stream);
6935 switch (PacketReply) {
6943 errorCode = ReadStartCode( &startCode,
vid_stream );
6944 if (errorCode != 0) {
6945 fprintf(stderr,
"Error in start code after packet\n");
6948 if (startCode == PACK_START_CODE || startCode == ISO_11172_END_CODE) {
6953 if (startCode == ISO_11172_END_CODE) {
6965 fprintf(stderr,
"\nNo match found for start code %08x in system layer, skipping\n",startCode);
6966 startCode = find_start_code(
vid_stream->input);
6967 if (startCode == EOF) {
6989 unsigned int *startCode;
6994 numRead = fread((
unsigned char *)startCode, 1, 4,
vid_stream->input);
6995 *startCode = fw_htonl(*startCode);
7002 if ((*startCode&0xfffffe00) != 0) {
7003 fprintf(stderr,
"Problem with system layer parse, skipping to start code\n");
7004 *startCode = find_start_code(
vid_stream->input);
7005 if (*startCode == EOF) {
7027int find_start_code(input)
7031 switch(fgetc(input)) {
7032 case 0:
goto ONE_ZERO;
7033 case EOF:
goto EOF_FOUND;
7034 default:
goto NO_ZEROS;
7038 switch(fgetc(input)) {
7039 case 0:
goto TWO_ZEROS;
7040 case EOF:
goto EOF_FOUND;
7041 default:
goto NO_ZEROS;
7045 switch(fgetc(input)) {
7046 case 0x01:
goto CODE_FOUND;
7047 case 0x00:
goto TWO_ZEROS;
7048 case EOF:
goto EOF_FOUND;
7049 default:
goto NO_ZEROS;
7053 return 0x00000100+fgetc(input);
7073int ReadPackHeader(systemClockTime,muxRate,
vid_stream)
7074 double *systemClockTime;
7075 unsigned long *muxRate;
7079 unsigned char inputBuffer[PACK_HEADER_SIZE];
7080 unsigned long systemClockRef;
7081 unsigned char systemClockRefHiBit;
7084 numRead = fread(inputBuffer, 1, PACK_HEADER_SIZE,
vid_stream->input);
7085 if (numRead < PACK_HEADER_SIZE) {
7089 ReadTimeStamp(inputBuffer, &systemClockRefHiBit, &systemClockRef);
7090 errorCode = MakeFloatClockTime(systemClockRefHiBit, systemClockRef,
7092 ReadRate(&inputBuffer[5], muxRate);
7093 *muxRate *= MUX_RATE_SCALE_FACTOR;
7113 unsigned char *inputBuffer = NULL;
7116 unsigned short headerSize;
7117 unsigned char streamID;
7119 numRead = fread((
char *)&headerSize, 1, 2,
vid_stream->input);
7120 headerSize = fw_ntohs(headerSize);
7125 inputBuffer = (
unsigned char *) malloc((
unsigned int) headerSize+1);
7126 if (inputBuffer == NULL) {
7129 inputBuffer[headerSize]=0;
7130 numRead = fread(inputBuffer, 1, headerSize,
vid_stream->input);
7132 if (numRead < (
int) headerSize) {
7138 while ((inputBuffer[pos] & 0x80) == 0x80) {
7139 streamID = inputBuffer[pos];
7141 case STD_VIDEO_STREAM_ID:
7143 case STD_AUDIO_STREAM_ID:
7145 case RESERVED_STREAM_ID:
7147 case PADDING_STREAM_ID:
7149 case PRIVATE_STREAM_1_ID:
7151 case PRIVATE_STREAM_2_ID:
7154 if (streamID < MIN_STREAM_ID_ID) {
7157 switch (streamID >> 4) {
7178 if (inputBuffer != NULL)
7208 unsigned char packetID;
7218 unsigned int **bs_ptr=&
vid_stream->buf_start;
7219 int *max_length = &
vid_stream->max_buf_length;
7223 unsigned char nextByte;
7224 unsigned short packetLength;
7225 unsigned char *packetBuffer = NULL;
7227 int numStuffBytes = 0;
7228 unsigned int packetDataLength;
7230 unsigned char scratch[10];
7233 if (packetID == NOT_PACKET_ID) {
7237 *(*buf_ptr+*length_ptr) =
vid_stream->leftover_bytes;
7238 *(*buf_ptr+*length_ptr+1) = ISO_11172_END_CODE;
7241 *(*buf_ptr+*length_ptr) = ISO_11172_END_CODE;
7245 }
else if (packetID==KILL_BUFFER) {
7251 ioBytes = fread(&packetLength, 1, 2,
vid_stream->input);
7252 packetLength = fw_htons(packetLength);
7256 if (packetID ==
vid_stream->gAudioStreamID) {
7258 else if (packetID ==
vid_stream->gVideoStreamID) {
7262 case PADDING_STREAM_ID:
7263 case RESERVED_STREAM_ID:
7264 case PRIVATE_STREAM_1_ID:
7265 case PRIVATE_STREAM_2_ID:
7268 fprintf(stderr,
"\nUnknown packet type encountered. P'bly audio? (%x) at %d\n",
7271 if (packetID !=
vid_stream->gVideoStreamID) {
7279 while (nextByte & 0x80) {
7284 if ((nextByte >> 6) == 0x01) {
7289 if ((nextByte >> 4) == 0x02) {
7290 scratch[0] = nextByte;
7295 else if ((nextByte >> 4) == 0x03) {
7296 scratch[0] = nextByte;
7306printf (
"buf_ptr %p\n",*buf_ptr);
7307printf (
"length_ptr %p\n",length_ptr);
7308 if (*bs_ptr + *max_length < *buf_ptr+ packetLength/4 + *length_ptr) {
7310 if (*max_length - *length_ptr < (
int) packetLength/4) {
7314 unsigned int *old = *bs_ptr;
7315 *max_length = *length_ptr + packetLength/2;
7316 *bs_ptr=(
unsigned int *)malloc(*max_length*4);
7317 if (*bs_ptr == NULL) {
7320 memcpy((
unsigned char *)*bs_ptr, *buf_ptr, (
unsigned int) *length_ptr*4);
7324 memcpy((
unsigned char *)*bs_ptr, *buf_ptr, (
unsigned int) *length_ptr*4);
7327 byte_length = *length_ptr*4;
7331 *(*buf_ptr+*length_ptr) =
vid_stream->leftover_bytes;
7333 packetBuffer=((
unsigned char *)*buf_ptr)+byte_length;
7334 packetDataLength = packetLength - pos;
7335 *packetBuffer++ = nextByte;
7337 if (packetID ==
vid_stream->gVideoStreamID) {
7338 ioBytes = fread(packetBuffer, 1, packetDataLength-1,
vid_stream->input);
7339 if (ioBytes != packetDataLength-1) {
7343 if (1 != fw_ntohl(1)) {
7344 unsigned int *mark = *buf_ptr+*length_ptr;
7347 for (i=0; i < ((packetDataLength+
7349 *mark=fw_ntohl(*mark);
7353 byte_length = byte_length + packetDataLength;
7355 *length_ptr = byte_length / 4;
7356 vid_stream->leftover_bytes = *(*buf_ptr + *length_ptr);
7359 else if (packetID ==
vid_stream->gAudioStreamID) {
7360 packetBuffer = (
unsigned char *)(*buf_ptr + *length_ptr + 1);
7361 fread(packetBuffer, 1, packetDataLength - 1,
vid_stream->input);
7365 packetBuffer = (
unsigned char *)(*buf_ptr + *length_ptr + 1);
7366 fread(packetBuffer, 1, packetDataLength - 1,
vid_stream->input);
7375void ReadTimeStamp(inputBuffer,hiBit,low4Bytes)
7376 unsigned char *inputBuffer, *hiBit;
7377 unsigned long *low4Bytes;
7379 *hiBit = ((
unsigned long)inputBuffer[0] >> 3) & 0x01;
7380 *low4Bytes = (((
unsigned long)inputBuffer[0] >> 1) & 0x03) << 30;
7381 *low4Bytes |= (
unsigned long)inputBuffer[1] << 22;
7382 *low4Bytes |= ((
unsigned long)inputBuffer[2] >> 1) << 15;
7383 *low4Bytes |= (
unsigned long)inputBuffer[3] << 7;
7384 *low4Bytes |= ((
unsigned long)inputBuffer[4]) >> 1;
7387void ReadSTD(inputBuffer,stdBufferScale,stdBufferSize)
7388unsigned char *inputBuffer;
7389unsigned char *stdBufferScale;
7390unsigned long *stdBufferSize;
7393 *stdBufferScale = ((int)(inputBuffer[0] & 0x20) >> 5);
7394 *stdBufferSize = ((
unsigned long)inputBuffer[0] & 0x1f) << 8;
7395 *stdBufferSize |= (
unsigned long)inputBuffer[1];
7399void ReadRate(inputBuffer,rate)
7400 unsigned char *inputBuffer;
7401 unsigned long *rate;
7403 *rate = (inputBuffer[0] & 0x7f) << 15;
7404 *rate |= inputBuffer[1] << 7;
7406 *rate |= (int) (inputBuffer[2] & 0xfe) >> 1;
7409#define FLOAT_0x10000 (double)((unsigned long)1 << 16)
7412int MakeFloatClockTime(
unsigned char hiBit,
unsigned long low4Bytes,
7413 double * floatClockTime)
7415int MakeFloatClockTime(hiBit,low4Bytes,floatClockTime)
7416 unsigned char hiBit;
7417 unsigned long low4Bytes;
7418 double *floatClockTime;
7421 if (hiBit != 0 && hiBit != 1) {
7422 *floatClockTime = 0.0;
7426 = (double)hiBit*FLOAT_0x10000*FLOAT_0x10000 + (
double)low4Bytes;
7427 *floatClockTime /= (double)STD_SYSTEM_CLOCK_FREQ;
7434#define BUF_LENGTH 80000
7437void int_handler P((
void ));
7438void bad_handler P((
void ));
7460void mpg_main(
char *fname,
int *x,
int *y,
int *depth,
int *fc,
char **ptr) {
7463 int ppm_width = -1, ppm_height = -1, ppm_modulus = -1;
7476 mpegfile=fopen(fname,
"r");
7478 if (mpegfile == NULL) {
7479 printf(
"Could not open MovieTexture file %s\n", fname);
7489 theStream = mpg_NewVidStream((
unsigned int) BUF_LENGTH);
7490 theStream->ppm_width = ppm_width;
7491 theStream->ppm_height = ppm_height;
7492 theStream->ppm_modulus = ppm_modulus;
7493 theStream->input = mpegfile;
7494 theStream->filename = fname;
7495 theStream->matched_depth = 24;
7497 if (mpegVidRsrc(0, theStream, 1)==NULL) {
7499 printf(
"Skipping movie \"%s\" - not an MPEG stream\n",
7501 if (theStream!=NULL) {
7502 printf (
"theStream != NULL, destroying, part1\n");
7503 Destroympeg_VidStream(theStream);
7508 if (theStream != NULL) theStream->realTimeStart = ReadSysClock();
7509 if (theStream != NULL) {
7510 while (theStream->film_has_ended == FALSE) {
7511 mpegVidRsrc(0, theStream, 0);
7517 free ((
int *)Cr_r_tab);
7519 free ((
int *)Cr_g_tab);
7521 free ((
int *)Cb_g_tab);
7523 free ((
int *)Cb_b_tab);
7525 if (r_2_pix_alloc!=NULL)
7526 free ((
long *) r_2_pix_alloc);
7527 if (g_2_pix_alloc!=NULL)
7528 free ((
long *) g_2_pix_alloc);
7529 if (b_2_pix_alloc!=NULL)
7530 free ((
long *) b_2_pix_alloc);
7533 L_tab = NULL; Cr_r_tab = NULL; Cr_g_tab = NULL; Cb_g_tab = NULL;Cb_b_tab = NULL;
7534 r_2_pix_alloc = NULL; g_2_pix_alloc= NULL;b_2_pix_alloc = NULL;
7538 *fc = (*frameCount)--;