42 |
* * |
* * |
43 |
* Revision history: * |
* Revision history: * |
44 |
* * |
* * |
45 |
* 26.03.2002 interlacing support - moved transfers outside loops |
* 29.03.2002 interlacing speedup - used transfer strides instead of * |
46 |
* 22.12.2001 get_dc_scaler() moved to common.h |
* manual field-to-frame conversion * |
47 |
|
* 26.03.2002 interlacing support - moved transfers outside loops * |
48 |
|
* 22.12.2001 get_dc_scaler() moved to common.h * |
49 |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
50 |
* 17.11.2001 initial version * |
* 17.11.2001 initial version * |
51 |
* * |
* * |
68 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
69 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
70 |
|
|
71 |
#define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */ |
#define TOOSMALL_LIMIT 3 /* skip blocks having a coefficient sum below this value */ |
72 |
|
|
73 |
/* this isnt pretty, but its better than 20 ifdefs */ |
/* this isnt pretty, but its better than 20 ifdefs */ |
74 |
|
|
75 |
void MBTransQuantIntra(const MBParam *pParam, |
void |
76 |
|
MBTransQuantIntra(const MBParam * pParam, |
77 |
|
FRAMEINFO * frame, |
78 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
79 |
const uint32_t x_pos, |
const uint32_t x_pos, |
80 |
const uint32_t y_pos, |
const uint32_t y_pos, |
81 |
int16_t data[6*64], |
int16_t data[6*64], |
82 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6 * 64]) |
|
IMAGE * const pCurrent) |
|
|
|
|
83 |
{ |
{ |
84 |
|
|
85 |
const uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
86 |
|
uint32_t stride2 = stride / 2; |
87 |
|
uint32_t next_block = stride * 8; |
88 |
uint32_t i; |
uint32_t i; |
89 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
90 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
91 |
|
IMAGE *pCurrent = &frame->image; |
92 |
|
|
93 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
94 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
95 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
96 |
|
|
97 |
start_timer(); |
start_timer(); |
98 |
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
99 |
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
100 |
transfer_8to16copy(&data[2*64], pY_Cur + 8 * stride, stride); |
transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); |
101 |
transfer_8to16copy(&data[3*64], pY_Cur + 8 * stride + 8, stride); |
transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); |
102 |
transfer_8to16copy(&data[4*64], pU_Cur, stride / 2); |
transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); |
103 |
transfer_8to16copy(&data[5*64], pV_Cur, stride / 2); |
transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); |
104 |
stop_transfer_timer(); |
stop_transfer_timer(); |
105 |
|
|
106 |
start_timer(); |
start_timer(); |
107 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
108 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING) && |
109 |
{ |
(x_pos>0) && (x_pos<pParam->mb_width-1) && |
110 |
|
(y_pos>0) && (y_pos<pParam->mb_height-1)) { |
111 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
112 |
} |
} |
113 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
114 |
|
|
115 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
116 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
117 |
|
|
118 |
start_timer(); |
start_timer(); |
119 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
120 |
stop_dct_timer(); |
stop_dct_timer(); |
121 |
|
|
122 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) { |
|
{ |
|
123 |
start_timer(); |
start_timer(); |
124 |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
125 |
stop_quant_timer(); |
stop_quant_timer(); |
127 |
start_timer(); |
start_timer(); |
128 |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
129 |
stop_iquant_timer(); |
stop_iquant_timer(); |
130 |
} |
} else { |
|
else |
|
|
{ |
|
131 |
start_timer(); |
start_timer(); |
132 |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
133 |
stop_quant_timer(); |
stop_quant_timer(); |
142 |
stop_idct_timer(); |
stop_idct_timer(); |
143 |
} |
} |
144 |
|
|
145 |
start_timer(); |
if (pMB->field_dct) { |
146 |
if (pMB->field_dct) |
next_block = stride; |
147 |
{ |
stride *= 2; |
|
MBFieldToFrame(data); |
|
148 |
} |
} |
|
stop_interlacing_timer(); |
|
149 |
|
|
150 |
start_timer(); |
start_timer(); |
151 |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
152 |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
153 |
transfer_16to8copy(pY_Cur + 8 * stride, &data[2*64], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
154 |
transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride); |
155 |
transfer_16to8copy(pU_Cur, &data[4*64], stride / 2); |
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
156 |
transfer_16to8copy(pV_Cur, &data[5*64], stride / 2); |
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
157 |
stop_transfer_timer(); |
stop_transfer_timer(); |
158 |
|
|
159 |
} |
} |
160 |
|
|
161 |
|
|
162 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t |
163 |
|
MBTransQuantInter(const MBParam * pParam, |
164 |
|
FRAMEINFO * frame, |
165 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
166 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, |
167 |
|
const uint32_t y_pos, |
168 |
int16_t data[6*64], |
int16_t data[6*64], |
169 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6 * 64]) |
|
IMAGE * const pCurrent) |
|
|
|
|
170 |
{ |
{ |
171 |
|
|
172 |
const uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
173 |
|
uint32_t stride2 = stride / 2; |
174 |
|
uint32_t next_block = stride * 8; |
175 |
uint32_t i; |
uint32_t i; |
176 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
177 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
178 |
uint8_t cbp = 0; |
uint8_t cbp = 0; |
179 |
uint32_t sum; |
uint32_t sum; |
180 |
|
IMAGE *pCurrent = &frame->image; |
181 |
|
|
182 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
183 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
184 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
185 |
|
|
186 |
start_timer(); |
start_timer(); |
187 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
188 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING) && |
189 |
{ |
(x_pos>0) && (x_pos<pParam->mb_width-1) && |
190 |
|
(y_pos>0) && (y_pos<pParam->mb_height-1)) { |
191 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
192 |
} |
} |
193 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
194 |
|
|
195 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
196 |
/* |
/* |
197 |
* no need to transfer 8->16-bit |
* no need to transfer 8->16-bit |
198 |
* (this is performed already in motion compensation) |
* (this is performed already in motion compensation) |
201 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
202 |
stop_dct_timer(); |
stop_dct_timer(); |
203 |
|
|
204 |
if (pParam->quant_type == 0) |
if (pParam->m_quant_type == 0) { |
|
{ |
|
205 |
start_timer(); |
start_timer(); |
206 |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
207 |
stop_quant_timer(); |
stop_quant_timer(); |
208 |
|
} else { |
209 |
|
start_timer(); |
210 |
|
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
211 |
|
stop_quant_timer(); |
212 |
|
} |
213 |
|
|
214 |
|
if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) || |
215 |
|
(qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) { |
216 |
|
|
217 |
|
if (pParam->m_quant_type == H263_QUANT) { |
218 |
|
start_timer(); |
219 |
|
dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
220 |
|
stop_iquant_timer(); |
221 |
|
} else { |
222 |
|
start_timer(); |
223 |
|
dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
224 |
|
stop_iquant_timer(); |
225 |
|
} |
226 |
|
|
227 |
|
cbp |= 1 << (5 - i); |
228 |
|
|
229 |
|
start_timer(); |
230 |
|
idct(&data[i * 64]); |
231 |
|
stop_idct_timer(); |
232 |
|
} |
233 |
|
} |
234 |
|
|
235 |
|
if (pMB->field_dct) { |
236 |
|
next_block = stride; |
237 |
|
stride *= 2; |
238 |
|
} |
239 |
|
|
240 |
|
start_timer(); |
241 |
|
if (cbp & 32) |
242 |
|
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
243 |
|
if (cbp & 16) |
244 |
|
transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
245 |
|
if (cbp & 8) |
246 |
|
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
247 |
|
if (cbp & 4) |
248 |
|
transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); |
249 |
|
if (cbp & 2) |
250 |
|
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
251 |
|
if (cbp & 1) |
252 |
|
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
253 |
|
stop_transfer_timer(); |
254 |
|
|
255 |
|
return cbp; |
256 |
|
|
257 |
|
} |
258 |
|
|
259 |
|
void |
260 |
|
MBTransQuantIntra2(const MBParam * pParam, |
261 |
|
FRAMEINFO * frame, |
262 |
|
MACROBLOCK * pMB, |
263 |
|
const uint32_t x_pos, |
264 |
|
const uint32_t y_pos, |
265 |
|
int16_t data[6 * 64], |
266 |
|
int16_t qcoeff[6 * 64]) |
267 |
|
{ |
268 |
|
MBTrans(pParam,frame,pMB,x_pos,y_pos,data); |
269 |
|
MBfDCT(pParam,frame,pMB,data); |
270 |
|
MBQuantIntra(pParam,frame,pMB,data,qcoeff); |
271 |
|
MBDeQuantIntra(pParam,frame->quant,data,qcoeff); |
272 |
|
MBiDCT(data,0x3F); |
273 |
|
MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F); |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
|
uint8_t |
278 |
|
MBTransQuantInter2(const MBParam * pParam, |
279 |
|
FRAMEINFO * frame, |
280 |
|
MACROBLOCK * pMB, |
281 |
|
const uint32_t x_pos, |
282 |
|
const uint32_t y_pos, |
283 |
|
int16_t data[6 * 64], |
284 |
|
int16_t qcoeff[6 * 64]) |
285 |
|
{ |
286 |
|
uint8_t cbp; |
287 |
|
|
288 |
|
/* there is no MBTrans for Inter block, that's done in motion compensation already */ |
289 |
|
|
290 |
|
MBfDCT(pParam,frame,pMB,data); |
291 |
|
cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); |
292 |
|
MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp); |
293 |
|
MBiDCT(data,cbp); |
294 |
|
MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp); |
295 |
|
|
296 |
|
return cbp; |
297 |
|
} |
298 |
|
|
299 |
|
uint8_t |
300 |
|
MBTransQuantInterBVOP(const MBParam * pParam, |
301 |
|
FRAMEINFO * frame, |
302 |
|
MACROBLOCK * pMB, |
303 |
|
int16_t data[6 * 64], |
304 |
|
int16_t qcoeff[6 * 64]) |
305 |
|
{ |
306 |
|
uint8_t cbp; |
307 |
|
|
308 |
|
/* there is no MBTrans for Inter block, that's done in motion compensation already */ |
309 |
|
|
310 |
|
MBfDCT(pParam,frame,pMB,data); |
311 |
|
cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); |
312 |
|
|
313 |
|
/* we don't have to DeQuant, iDCT and Transfer back data for B-frames */ |
314 |
|
|
315 |
|
return cbp; |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
void |
320 |
|
MBfDCT(const MBParam * pParam, |
321 |
|
FRAMEINFO * frame, |
322 |
|
MACROBLOCK * pMB, |
323 |
|
int16_t data[6 * 64]) |
324 |
|
{ |
325 |
|
int i; |
326 |
|
|
327 |
|
start_timer(); |
328 |
|
pMB->field_dct = 0; |
329 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
330 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
331 |
|
} |
332 |
|
stop_interlacing_timer(); |
333 |
|
|
334 |
|
for (i = 0; i < 6; i++) { |
335 |
|
start_timer(); |
336 |
|
fdct(&data[i * 64]); |
337 |
|
stop_dct_timer(); |
338 |
} |
} |
339 |
else |
} |
340 |
|
|
341 |
|
void |
342 |
|
MBQuantDeQuantIntra(const MBParam * pParam, |
343 |
|
FRAMEINFO * frame, |
344 |
|
MACROBLOCK * pMB, |
345 |
|
int16_t qcoeff[6 * 64], |
346 |
|
int16_t data[6*64]) |
347 |
{ |
{ |
348 |
|
int i; |
349 |
|
int iQuant = frame->quant; |
350 |
|
|
351 |
|
start_timer(); |
352 |
|
pMB->field_dct = 0; |
353 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
354 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
355 |
|
} |
356 |
|
stop_interlacing_timer(); |
357 |
|
|
358 |
|
for (i = 0; i < 6; i++) { |
359 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
360 |
|
|
361 |
|
if (pParam->m_quant_type == H263_QUANT) { |
362 |
|
start_timer(); |
363 |
|
quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
364 |
|
stop_quant_timer(); |
365 |
|
|
366 |
|
start_timer(); |
367 |
|
dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
368 |
|
stop_iquant_timer(); |
369 |
|
} else { |
370 |
|
start_timer(); |
371 |
|
quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
372 |
|
stop_quant_timer(); |
373 |
|
|
374 |
|
start_timer(); |
375 |
|
dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
376 |
|
stop_iquant_timer(); |
377 |
|
} |
378 |
|
} |
379 |
|
} |
380 |
|
|
381 |
|
void |
382 |
|
MBQuantIntra(const MBParam * pParam, |
383 |
|
FRAMEINFO * frame, |
384 |
|
MACROBLOCK *pMB, |
385 |
|
int16_t qcoeff[6 * 64], |
386 |
|
int16_t data[6*64]) |
387 |
|
{ |
388 |
|
int i; |
389 |
|
int iQuant = frame->quant; |
390 |
|
|
391 |
|
start_timer(); |
392 |
|
pMB->field_dct = 0; |
393 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
394 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
395 |
|
} |
396 |
|
stop_interlacing_timer(); |
397 |
|
|
398 |
|
for (i = 0; i < 6; i++) { |
399 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
400 |
|
|
401 |
|
if (pParam->m_quant_type == H263_QUANT) { |
402 |
|
start_timer(); |
403 |
|
quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
404 |
|
stop_quant_timer(); |
405 |
|
} else { |
406 |
|
start_timer(); |
407 |
|
quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
408 |
|
stop_quant_timer(); |
409 |
|
} |
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
|
void |
414 |
|
MBDeQuantIntra(const MBParam * pParam, |
415 |
|
const int iQuant, |
416 |
|
int16_t qcoeff[6 * 64], |
417 |
|
int16_t data[6*64]) |
418 |
|
{ |
419 |
|
int i; |
420 |
|
|
421 |
|
for (i = 0; i < 6; i++) { |
422 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
423 |
|
|
424 |
|
if (pParam->m_quant_type == H263_QUANT) { |
425 |
|
start_timer(); |
426 |
|
dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
427 |
|
stop_iquant_timer(); |
428 |
|
} else { |
429 |
|
start_timer(); |
430 |
|
dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
431 |
|
stop_iquant_timer(); |
432 |
|
} |
433 |
|
} |
434 |
|
} |
435 |
|
|
436 |
|
uint8_t |
437 |
|
MBQuantInter(const MBParam * pParam, |
438 |
|
const int iQuant, |
439 |
|
int16_t data[6 * 64], |
440 |
|
int16_t qcoeff[6 * 64]) |
441 |
|
{ |
442 |
|
|
443 |
|
int i; |
444 |
|
uint8_t cbp = 0; |
445 |
|
int sum; |
446 |
|
|
447 |
|
for (i = 0; i < 6; i++) { |
448 |
|
|
449 |
|
if (pParam->m_quant_type == 0) { |
450 |
|
start_timer(); |
451 |
|
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
452 |
|
stop_quant_timer(); |
453 |
|
} else { |
454 |
start_timer(); |
start_timer(); |
455 |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
456 |
stop_quant_timer(); |
stop_quant_timer(); |
457 |
} |
} |
458 |
|
|
459 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
460 |
|
cbp |= 1 << (5 - i); |
461 |
|
} |
462 |
|
} |
463 |
|
return cbp; |
464 |
|
} |
465 |
|
|
466 |
|
void |
467 |
|
MBDeQuantInter( const MBParam * pParam, |
468 |
|
const int iQuant, |
469 |
|
int16_t data[6 * 64], |
470 |
|
int16_t qcoeff[6 * 64], |
471 |
|
const uint8_t cbp) |
472 |
|
{ |
473 |
|
int i; |
474 |
|
|
475 |
if (pParam->quant_type == H263_QUANT) |
for (i = 0; i < 6; i++) { |
476 |
|
if (cbp & (1 << (5 - i))) |
477 |
{ |
{ |
478 |
|
if (pParam->m_quant_type == H263_QUANT) { |
479 |
start_timer(); |
start_timer(); |
480 |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
481 |
stop_iquant_timer(); |
stop_iquant_timer(); |
482 |
} |
} else { |
|
else |
|
|
{ |
|
483 |
start_timer(); |
start_timer(); |
484 |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
485 |
stop_iquant_timer(); |
stop_iquant_timer(); |
486 |
} |
} |
487 |
|
} |
488 |
|
} |
489 |
|
} |
490 |
|
|
491 |
cbp |= 1 << (5 - i); |
void |
492 |
|
MBiDCT( int16_t data[6 * 64], |
493 |
|
const uint8_t cbp) |
494 |
|
{ |
495 |
|
int i; |
496 |
|
|
497 |
|
for (i = 0; i < 6; i++) { |
498 |
|
if (cbp & (1 << (5 - i))) |
499 |
|
{ |
500 |
start_timer(); |
start_timer(); |
501 |
idct(&data[i*64]); |
idct(&data[i*64]); |
502 |
stop_idct_timer(); |
stop_idct_timer(); |
503 |
|
|
504 |
|
} |
505 |
} |
} |
506 |
} |
} |
507 |
|
|
508 |
|
|
509 |
|
void |
510 |
|
MBTrans(const MBParam * pParam, |
511 |
|
FRAMEINFO * frame, |
512 |
|
MACROBLOCK * pMB, |
513 |
|
const uint32_t x_pos, |
514 |
|
const uint32_t y_pos, |
515 |
|
int16_t data[6 * 64]) |
516 |
|
{ |
517 |
|
uint32_t stride = pParam->edged_width; |
518 |
|
uint32_t stride2 = stride / 2; |
519 |
|
uint32_t next_block = stride * 8; |
520 |
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
521 |
|
IMAGE *pCurrent = &frame->image; |
522 |
|
|
523 |
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
524 |
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
525 |
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
526 |
|
|
527 |
start_timer(); |
start_timer(); |
528 |
if (pMB->field_dct) |
transfer_8to16copy(&data[0 * 64], pY_Cur, stride); |
529 |
|
transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); |
530 |
|
transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); |
531 |
|
transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); |
532 |
|
transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); |
533 |
|
transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); |
534 |
|
stop_transfer_timer(); |
535 |
|
} |
536 |
|
|
537 |
|
void |
538 |
|
MBTransAdd(const MBParam * pParam, |
539 |
|
FRAMEINFO * frame, |
540 |
|
MACROBLOCK * pMB, |
541 |
|
const uint32_t x_pos, |
542 |
|
const uint32_t y_pos, |
543 |
|
int16_t data[6 * 64], |
544 |
|
const uint8_t cbp) |
545 |
{ |
{ |
546 |
MBFieldToFrame(data); |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
547 |
|
uint32_t stride = pParam->edged_width; |
548 |
|
uint32_t stride2 = stride / 2; |
549 |
|
uint32_t next_block = stride * 8; |
550 |
|
IMAGE *pCurrent = &frame->image; |
551 |
|
|
552 |
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
553 |
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
554 |
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
555 |
|
|
556 |
|
if (pMB->field_dct) { |
557 |
|
next_block = stride; |
558 |
|
stride *= 2; |
559 |
} |
} |
|
stop_interlacing_timer(); |
|
560 |
|
|
561 |
start_timer(); |
start_timer(); |
562 |
if (cbp & 32) |
if (cbp & 32) |
564 |
if (cbp & 16) |
if (cbp & 16) |
565 |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
566 |
if (cbp & 8) |
if (cbp & 8) |
567 |
transfer_16to8add(pY_Cur + 8 * stride, &data[2*64], stride); |
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
568 |
if (cbp & 4) |
if (cbp & 4) |
569 |
transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); |
570 |
if (cbp & 2) |
if (cbp & 2) |
571 |
transfer_16to8add(pU_Cur, &data[4*64], stride / 2); |
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
572 |
if (cbp & 1) |
if (cbp & 1) |
573 |
transfer_16to8add(pV_Cur, &data[5*64], stride / 2); |
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
574 |
stop_transfer_timer(); |
stop_transfer_timer(); |
|
|
|
|
return cbp; |
|
|
|
|
575 |
} |
} |
576 |
|
|
577 |
|
|
578 |
|
|
579 |
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
580 |
|
|
|
#define ABS(X) (X)<0 ? -(X) : (X) |
|
581 |
|
|
582 |
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
uint32_t |
583 |
|
MBDecideFieldDCT(int16_t data[6 * 64]) |
584 |
{ |
{ |
585 |
|
|
586 |
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
const uint8_t blocks[] = |
587 |
|
{ 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; |
588 |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
589 |
|
|
590 |
int frame = 0, field = 0; |
int frame = 0, field = 0; |
591 |
int i, j; |
int i, j; |
592 |
|
|
593 |
for (i=0 ; i<7 ; ++i) |
for (i = 0; i < 7; ++i) { |
594 |
{ |
for (j = 0; j < 8; ++j) { |
595 |
for (j=0 ; j<8 ; ++j) |
frame += |
596 |
{ |
ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
597 |
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
frame += |
598 |
frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]); |
ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); |
599 |
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
frame += |
600 |
frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]); |
ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); |
601 |
|
frame += |
602 |
|
ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
603 |
|
|
604 |
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
field += |
605 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + j] - |
606 |
data[blocks[i ] + lines[i ] + j]); |
data[blocks[i ] + lines[i ] + j]); |
607 |
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
field += |
608 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
609 |
data[blocks[i ] + lines[i ] + 8 + j]); |
data[blocks[i ] + lines[i ] + 8 + j]); |
610 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
field += |
611 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
612 |
data[blocks[i ] + 64 + lines[i ] + j]); |
data[blocks[i ] + 64 + lines[i ] + j]); |
613 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
field += |
614 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
615 |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
616 |
} |
} |
617 |
} |
} |
618 |
|
|
619 |
if (frame > field) |
if (frame > field) { |
|
{ |
|
620 |
MBFrameToField(data); |
MBFrameToField(data); |
621 |
} |
} |
622 |
|
|
629 |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
630 |
#define LINE(X,Y) &data[X*64 + Y*8] |
#define LINE(X,Y) &data[X*64 + Y*8] |
631 |
|
|
632 |
void MBFrameToField(int16_t data[6*64]) |
void |
633 |
|
MBFrameToField(int16_t data[6 * 64]) |
634 |
{ |
{ |
635 |
int16_t tmp[8]; |
int16_t tmp[8]; |
636 |
|
|
690 |
MOVLINE(LINE(3,5), LINE(3,3)); |
MOVLINE(LINE(3,5), LINE(3,3)); |
691 |
MOVLINE(LINE(3,3), tmp); |
MOVLINE(LINE(3,3), tmp); |
692 |
} |
} |
|
|
|
|
|
|
|
/* interlace Y blocks vertically */ |
|
|
|
|
|
void MBFieldToFrame(int16_t data[6*64]) |
|
|
{ |
|
|
uint16_t tmp[8]; |
|
|
|
|
|
/* left blocks */ |
|
|
|
|
|
// 1=8, 8=4, 4=2, 2=1 |
|
|
MOVLINE(tmp, LINE(0,1)); |
|
|
MOVLINE(LINE(0,1), LINE(2,0)); |
|
|
MOVLINE(LINE(2,0), LINE(0,4)); |
|
|
MOVLINE(LINE(0,4), LINE(0,2)); |
|
|
MOVLINE(LINE(0,2), tmp); |
|
|
|
|
|
// 3=9, 9=12, 12=6, 6=3 |
|
|
MOVLINE(tmp, LINE(0,3)); |
|
|
MOVLINE(LINE(0,3), LINE(2,1)); |
|
|
MOVLINE(LINE(2,1), LINE(2,4)); |
|
|
MOVLINE(LINE(2,4), LINE(0,6)); |
|
|
MOVLINE(LINE(0,6), tmp); |
|
|
|
|
|
// 5=10, 10=5 |
|
|
MOVLINE(tmp, LINE(0,5)); |
|
|
MOVLINE(LINE(0,5), LINE(2,2)); |
|
|
MOVLINE(LINE(2,2), tmp); |
|
|
|
|
|
// 7=11, 11=13, 13=14, 14=7 |
|
|
MOVLINE(tmp, LINE(0,7)); |
|
|
MOVLINE(LINE(0,7), LINE(2,3)); |
|
|
MOVLINE(LINE(2,3), LINE(2,5)); |
|
|
MOVLINE(LINE(2,5), LINE(2,6)); |
|
|
MOVLINE(LINE(2,6), tmp); |
|
|
|
|
|
/* right blocks */ |
|
|
|
|
|
// 1=8, 8=4, 4=2, 2=1 |
|
|
MOVLINE(tmp, LINE(1,1)); |
|
|
MOVLINE(LINE(1,1), LINE(3,0)); |
|
|
MOVLINE(LINE(3,0), LINE(1,4)); |
|
|
MOVLINE(LINE(1,4), LINE(1,2)); |
|
|
MOVLINE(LINE(1,2), tmp); |
|
|
|
|
|
// 3=9, 9=12, 12=6, 6=3 |
|
|
MOVLINE(tmp, LINE(1,3)); |
|
|
MOVLINE(LINE(1,3), LINE(3,1)); |
|
|
MOVLINE(LINE(3,1), LINE(3,4)); |
|
|
MOVLINE(LINE(3,4), LINE(1,6)); |
|
|
MOVLINE(LINE(1,6), tmp); |
|
|
|
|
|
// 5=10, 10=5 |
|
|
MOVLINE(tmp, LINE(1,5)); |
|
|
MOVLINE(LINE(1,5), LINE(3,2)); |
|
|
MOVLINE(LINE(3,2), tmp); |
|
|
|
|
|
// 7=11, 11=13, 13=14, 14=7 |
|
|
MOVLINE(tmp, LINE(1,7)); |
|
|
MOVLINE(LINE(1,7), LINE(3,3)); |
|
|
MOVLINE(LINE(3,3), LINE(3,5)); |
|
|
MOVLINE(LINE(3,5), LINE(3,6)); |
|
|
MOVLINE(LINE(3,6), tmp); |
|
|
} |
|