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