42 |
* * |
* * |
43 |
* Revision history: * |
* Revision history: * |
44 |
* * |
* * |
45 |
|
* 26.03.2002 interlacing support - moved transfers outside loops |
46 |
* 22.12.2001 get_dc_scaler() moved to common.h |
* 22.12.2001 get_dc_scaler() moved to common.h |
47 |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
48 |
* 17.11.2001 initial version * |
* 17.11.2001 initial version * |
49 |
* * |
* * |
50 |
******************************************************************************/ |
******************************************************************************/ |
51 |
|
|
52 |
|
#include <string.h> |
53 |
|
|
54 |
#include "../portab.h" |
#include "../portab.h" |
55 |
#include "mbfunctions.h" |
#include "mbfunctions.h" |
56 |
|
|
71 |
/* this isnt pretty, but its better than 20 ifdefs */ |
/* this isnt pretty, but its better than 20 ifdefs */ |
72 |
|
|
73 |
void MBTransQuantIntra(const MBParam *pParam, |
void MBTransQuantIntra(const MBParam *pParam, |
74 |
|
MACROBLOCK * pMB, |
75 |
const uint32_t x_pos, |
const uint32_t x_pos, |
76 |
const uint32_t y_pos, |
const uint32_t y_pos, |
77 |
int16_t data[][64], |
int16_t data[6*64], |
78 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64], |
79 |
IMAGE * const pCurrent) |
IMAGE * const pCurrent) |
80 |
|
|
81 |
{ |
{ |
82 |
|
|
83 |
const uint32_t stride = pParam->edged_width; |
const uint32_t stride = pParam->edged_width; |
84 |
uint32_t i; |
uint32_t i; |
85 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = pParam->quant; |
89 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
90 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
91 |
|
|
|
for(i = 0; i < 6; i++) { |
|
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
|
|
|
|
92 |
start_timer(); |
start_timer(); |
93 |
|
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
94 |
|
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
95 |
|
transfer_8to16copy(&data[2*64], pY_Cur + 8 * stride, stride); |
96 |
|
transfer_8to16copy(&data[3*64], pY_Cur + 8 * stride + 8, stride); |
97 |
|
transfer_8to16copy(&data[4*64], pU_Cur, stride / 2); |
98 |
|
transfer_8to16copy(&data[5*64], pV_Cur, stride / 2); |
99 |
|
stop_transfer_timer(); |
100 |
|
|
101 |
switch(i) { |
start_timer(); |
102 |
case 0 : |
pMB->field_dct = 0; |
103 |
transfer_8to16copy(data[0], pY_Cur, stride); |
if (pParam->global_flags & XVID_INTERLACING) |
104 |
break; |
{ |
105 |
case 1 : |
pMB->field_dct = MBDecideFieldDCT(data); |
|
transfer_8to16copy(data[1], pY_Cur + 8, stride); |
|
|
break; |
|
|
case 2 : |
|
|
transfer_8to16copy(data[2], pY_Cur + 8 * stride, stride); |
|
|
break; |
|
|
case 3 : |
|
|
transfer_8to16copy(data[3], pY_Cur + 8 * stride + 8, stride); |
|
|
break; |
|
|
case 4 : |
|
|
transfer_8to16copy(data[4], pU_Cur, stride / 2); |
|
|
break; |
|
|
case 5 : |
|
|
transfer_8to16copy(data[5], pV_Cur, stride / 2); |
|
|
break; |
|
106 |
} |
} |
107 |
stop_transfer_timer(); |
stop_interlacing_timer(); |
108 |
|
|
109 |
|
for(i = 0; i < 6; i++) |
110 |
|
{ |
111 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
112 |
|
|
113 |
start_timer(); |
start_timer(); |
114 |
fdct(data[i]); |
fdct(&data[i*64]); |
115 |
stop_dct_timer(); |
stop_dct_timer(); |
116 |
|
|
117 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->quant_type == H263_QUANT) |
118 |
{ |
{ |
119 |
start_timer(); |
start_timer(); |
120 |
quant_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
121 |
stop_quant_timer(); |
stop_quant_timer(); |
122 |
|
|
123 |
start_timer(); |
start_timer(); |
124 |
dequant_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
125 |
stop_iquant_timer(); |
stop_iquant_timer(); |
126 |
} |
} |
127 |
else |
else |
128 |
{ |
{ |
129 |
start_timer(); |
start_timer(); |
130 |
quant4_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
131 |
stop_quant_timer(); |
stop_quant_timer(); |
132 |
|
|
133 |
start_timer(); |
start_timer(); |
134 |
dequant4_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
135 |
stop_iquant_timer(); |
stop_iquant_timer(); |
136 |
} |
} |
137 |
|
|
138 |
start_timer(); |
start_timer(); |
139 |
idct(data[i]); |
idct(&data[i*64]); |
140 |
stop_idct_timer(); |
stop_idct_timer(); |
141 |
|
} |
142 |
|
|
143 |
start_timer(); |
start_timer(); |
144 |
|
if (pMB->field_dct) |
145 |
switch(i) { |
{ |
146 |
case 0: |
MBFieldToFrame(data); |
|
transfer_16to8copy(pY_Cur, data[0], stride); |
|
|
break; |
|
|
case 1: |
|
|
transfer_16to8copy(pY_Cur + 8, data[1], stride); |
|
|
break; |
|
|
case 2: |
|
|
transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride); |
|
|
break; |
|
|
case 3: |
|
|
transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride); |
|
|
break; |
|
|
case 4: |
|
|
transfer_16to8copy(pU_Cur, data[4], stride / 2); |
|
|
break; |
|
|
case 5: |
|
|
transfer_16to8copy(pV_Cur, data[5], stride / 2); |
|
|
break; |
|
147 |
} |
} |
148 |
|
stop_interlacing_timer(); |
149 |
|
|
150 |
|
start_timer(); |
151 |
|
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
152 |
|
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
153 |
|
transfer_16to8copy(pY_Cur + 8 * stride, &data[2*64], stride); |
154 |
|
transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
155 |
|
transfer_16to8copy(pU_Cur, &data[4*64], stride / 2); |
156 |
|
transfer_16to8copy(pV_Cur, &data[5*64], stride / 2); |
157 |
stop_transfer_timer(); |
stop_transfer_timer(); |
158 |
} |
|
159 |
} |
} |
160 |
|
|
161 |
|
|
162 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t MBTransQuantInter(const MBParam *pParam, |
163 |
|
MACROBLOCK * pMB, |
164 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, const uint32_t y_pos, |
165 |
int16_t data[][64], |
int16_t data[6*64], |
166 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64], |
167 |
IMAGE * const pCurrent) |
IMAGE * const pCurrent) |
168 |
|
|
169 |
{ |
{ |
170 |
|
|
171 |
const uint32_t stride = pParam->edged_width; |
const uint32_t stride = pParam->edged_width; |
172 |
uint8_t i; |
uint32_t i; |
173 |
uint8_t iQuant = pParam->quant; |
uint32_t iQuant = pParam->quant; |
174 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
175 |
uint8_t cbp = 0; |
uint8_t cbp = 0; |
176 |
uint32_t sum; |
uint32_t sum; |
179 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
180 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
181 |
|
|
182 |
for(i = 0; i < 6; i++) { |
start_timer(); |
183 |
|
pMB->field_dct = 0; |
184 |
|
if (pParam->global_flags & XVID_INTERLACING) |
185 |
|
{ |
186 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
187 |
|
} |
188 |
|
stop_interlacing_timer(); |
189 |
|
|
190 |
|
for(i = 0; i < 6; i++) |
191 |
|
{ |
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) |
195 |
*/ |
*/ |
196 |
start_timer(); |
start_timer(); |
197 |
fdct(data[i]); |
fdct(&data[i*64]); |
198 |
stop_dct_timer(); |
stop_dct_timer(); |
199 |
|
|
200 |
if (pParam->quant_type == 0) |
if (pParam->quant_type == 0) |
201 |
{ |
{ |
202 |
start_timer(); |
start_timer(); |
203 |
sum = quant_inter(qcoeff[i], data[i], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
204 |
stop_quant_timer(); |
stop_quant_timer(); |
205 |
} |
} |
206 |
else |
else |
207 |
{ |
{ |
208 |
start_timer(); |
start_timer(); |
209 |
sum = quant4_inter(qcoeff[i], data[i], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
210 |
stop_quant_timer(); |
stop_quant_timer(); |
211 |
} |
} |
212 |
|
|
215 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->quant_type == H263_QUANT) |
216 |
{ |
{ |
217 |
start_timer(); |
start_timer(); |
218 |
dequant_inter(data[i], qcoeff[i], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
219 |
stop_iquant_timer(); |
stop_iquant_timer(); |
220 |
} |
} |
221 |
else |
else |
222 |
{ |
{ |
223 |
start_timer(); |
start_timer(); |
224 |
dequant4_inter(data[i], qcoeff[i], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
225 |
stop_iquant_timer(); |
stop_iquant_timer(); |
226 |
} |
} |
227 |
|
|
228 |
cbp |= 1 << (5 - i); |
cbp |= 1 << (5 - i); |
229 |
|
|
230 |
start_timer(); |
start_timer(); |
231 |
idct(data[i]); |
idct(&data[i*64]); |
232 |
stop_idct_timer(); |
stop_idct_timer(); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
start_timer(); |
start_timer(); |
237 |
|
if (pMB->field_dct) |
238 |
switch(i) { |
{ |
239 |
case 0: |
MBFieldToFrame(data); |
|
transfer_16to8add(pY_Cur, data[0], stride); |
|
|
break; |
|
|
case 1: |
|
|
transfer_16to8add(pY_Cur + 8, data[1], stride); |
|
|
break; |
|
|
case 2: |
|
|
transfer_16to8add(pY_Cur + 8 * stride, data[2], stride); |
|
|
break; |
|
|
case 3: |
|
|
transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride); |
|
|
break; |
|
|
case 4: |
|
|
transfer_16to8add(pU_Cur, data[4], stride / 2); |
|
|
break; |
|
|
case 5: |
|
|
transfer_16to8add(pV_Cur, data[5], stride / 2); |
|
|
break; |
|
240 |
} |
} |
241 |
|
stop_interlacing_timer(); |
242 |
|
|
243 |
|
start_timer(); |
244 |
|
if (cbp & 32) |
245 |
|
transfer_16to8add(pY_Cur, &data[0*64], stride); |
246 |
|
if (cbp & 16) |
247 |
|
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
248 |
|
if (cbp & 8) |
249 |
|
transfer_16to8add(pY_Cur + 8 * stride, &data[2*64], stride); |
250 |
|
if (cbp & 4) |
251 |
|
transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
252 |
|
if (cbp & 2) |
253 |
|
transfer_16to8add(pU_Cur, &data[4*64], stride / 2); |
254 |
|
if (cbp & 1) |
255 |
|
transfer_16to8add(pV_Cur, &data[5*64], stride / 2); |
256 |
stop_transfer_timer(); |
stop_transfer_timer(); |
257 |
|
|
258 |
|
return cbp; |
259 |
|
|
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
|
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
264 |
|
|
265 |
|
#define ABS(X) (X)<0 ? -(X) : (X) |
266 |
|
|
267 |
|
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
268 |
|
{ |
269 |
|
|
270 |
|
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
271 |
|
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
272 |
|
|
273 |
|
int frame = 0, field = 0; |
274 |
|
int i, j; |
275 |
|
|
276 |
|
for (i=0 ; i<7 ; ++i) |
277 |
|
{ |
278 |
|
for (j=0 ; j<8 ; ++j) |
279 |
|
{ |
280 |
|
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
281 |
|
frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]); |
282 |
|
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
283 |
|
frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]); |
284 |
|
|
285 |
|
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
286 |
|
data[blocks[i ] + lines[i ] + j]); |
287 |
|
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
288 |
|
data[blocks[i ] + lines[i ] + 8 + j]); |
289 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
290 |
|
data[blocks[i ] + 64 + lines[i ] + j]); |
291 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
292 |
|
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
293 |
} |
} |
294 |
return cbp; |
} |
295 |
|
|
296 |
|
if (frame > field) |
297 |
|
{ |
298 |
|
MBFrameToField(data); |
299 |
|
} |
300 |
|
|
301 |
|
return (frame > field); |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
/* deinterlace Y blocks vertically */ |
306 |
|
|
307 |
|
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
308 |
|
#define LINE(X,Y) &data[X*64 + Y*8] |
309 |
|
|
310 |
|
void MBFrameToField(int16_t data[6*64]) |
311 |
|
{ |
312 |
|
int16_t tmp[8]; |
313 |
|
|
314 |
|
/* left blocks */ |
315 |
|
|
316 |
|
// 1=2, 2=4, 4=8, 8=1 |
317 |
|
MOVLINE(tmp, LINE(0,1)); |
318 |
|
MOVLINE(LINE(0,1), LINE(0,2)); |
319 |
|
MOVLINE(LINE(0,2), LINE(0,4)); |
320 |
|
MOVLINE(LINE(0,4), LINE(2,0)); |
321 |
|
MOVLINE(LINE(2,0), tmp); |
322 |
|
|
323 |
|
// 3=6, 6=12, 12=9, 9=3 |
324 |
|
MOVLINE(tmp, LINE(0,3)); |
325 |
|
MOVLINE(LINE(0,3), LINE(0,6)); |
326 |
|
MOVLINE(LINE(0,6), LINE(2,4)); |
327 |
|
MOVLINE(LINE(2,4), LINE(2,1)); |
328 |
|
MOVLINE(LINE(2,1), tmp); |
329 |
|
|
330 |
|
// 5=10, 10=5 |
331 |
|
MOVLINE(tmp, LINE(0,5)); |
332 |
|
MOVLINE(LINE(0,5), LINE(2,2)); |
333 |
|
MOVLINE(LINE(2,2), tmp); |
334 |
|
|
335 |
|
// 7=14, 14=13, 13=11, 11=7 |
336 |
|
MOVLINE(tmp, LINE(0,7)); |
337 |
|
MOVLINE(LINE(0,7), LINE(2,6)); |
338 |
|
MOVLINE(LINE(2,6), LINE(2,5)); |
339 |
|
MOVLINE(LINE(2,5), LINE(2,3)); |
340 |
|
MOVLINE(LINE(2,3), tmp); |
341 |
|
|
342 |
|
/* right blocks */ |
343 |
|
|
344 |
|
// 1=2, 2=4, 4=8, 8=1 |
345 |
|
MOVLINE(tmp, LINE(1,1)); |
346 |
|
MOVLINE(LINE(1,1), LINE(1,2)); |
347 |
|
MOVLINE(LINE(1,2), LINE(1,4)); |
348 |
|
MOVLINE(LINE(1,4), LINE(3,0)); |
349 |
|
MOVLINE(LINE(3,0), tmp); |
350 |
|
|
351 |
|
// 3=6, 6=12, 12=9, 9=3 |
352 |
|
MOVLINE(tmp, LINE(1,3)); |
353 |
|
MOVLINE(LINE(1,3), LINE(1,6)); |
354 |
|
MOVLINE(LINE(1,6), LINE(3,4)); |
355 |
|
MOVLINE(LINE(3,4), LINE(3,1)); |
356 |
|
MOVLINE(LINE(3,1), tmp); |
357 |
|
|
358 |
|
// 5=10, 10=5 |
359 |
|
MOVLINE(tmp, LINE(1,5)); |
360 |
|
MOVLINE(LINE(1,5), LINE(3,2)); |
361 |
|
MOVLINE(LINE(3,2), tmp); |
362 |
|
|
363 |
|
// 7=14, 14=13, 13=11, 11=7 |
364 |
|
MOVLINE(tmp, LINE(1,7)); |
365 |
|
MOVLINE(LINE(1,7), LINE(3,6)); |
366 |
|
MOVLINE(LINE(3,6), LINE(3,5)); |
367 |
|
MOVLINE(LINE(3,5), LINE(3,3)); |
368 |
|
MOVLINE(LINE(3,3), tmp); |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
|
/* interlace Y blocks vertically */ |
373 |
|
|
374 |
|
void MBFieldToFrame(int16_t data[6*64]) |
375 |
|
{ |
376 |
|
uint16_t tmp[8]; |
377 |
|
|
378 |
|
/* left blocks */ |
379 |
|
|
380 |
|
// 1=8, 8=4, 4=2, 2=1 |
381 |
|
MOVLINE(tmp, LINE(0,1)); |
382 |
|
MOVLINE(LINE(0,1), LINE(2,0)); |
383 |
|
MOVLINE(LINE(2,0), LINE(0,4)); |
384 |
|
MOVLINE(LINE(0,4), LINE(0,2)); |
385 |
|
MOVLINE(LINE(0,2), tmp); |
386 |
|
|
387 |
|
// 3=9, 9=12, 12=6, 6=3 |
388 |
|
MOVLINE(tmp, LINE(0,3)); |
389 |
|
MOVLINE(LINE(0,3), LINE(2,1)); |
390 |
|
MOVLINE(LINE(2,1), LINE(2,4)); |
391 |
|
MOVLINE(LINE(2,4), LINE(0,6)); |
392 |
|
MOVLINE(LINE(0,6), tmp); |
393 |
|
|
394 |
|
// 5=10, 10=5 |
395 |
|
MOVLINE(tmp, LINE(0,5)); |
396 |
|
MOVLINE(LINE(0,5), LINE(2,2)); |
397 |
|
MOVLINE(LINE(2,2), tmp); |
398 |
|
|
399 |
|
// 7=11, 11=13, 13=14, 14=7 |
400 |
|
MOVLINE(tmp, LINE(0,7)); |
401 |
|
MOVLINE(LINE(0,7), LINE(2,3)); |
402 |
|
MOVLINE(LINE(2,3), LINE(2,5)); |
403 |
|
MOVLINE(LINE(2,5), LINE(2,6)); |
404 |
|
MOVLINE(LINE(2,6), tmp); |
405 |
|
|
406 |
|
/* right blocks */ |
407 |
|
|
408 |
|
// 1=8, 8=4, 4=2, 2=1 |
409 |
|
MOVLINE(tmp, LINE(1,1)); |
410 |
|
MOVLINE(LINE(1,1), LINE(3,0)); |
411 |
|
MOVLINE(LINE(3,0), LINE(1,4)); |
412 |
|
MOVLINE(LINE(1,4), LINE(1,2)); |
413 |
|
MOVLINE(LINE(1,2), tmp); |
414 |
|
|
415 |
|
// 3=9, 9=12, 12=6, 6=3 |
416 |
|
MOVLINE(tmp, LINE(1,3)); |
417 |
|
MOVLINE(LINE(1,3), LINE(3,1)); |
418 |
|
MOVLINE(LINE(3,1), LINE(3,4)); |
419 |
|
MOVLINE(LINE(3,4), LINE(1,6)); |
420 |
|
MOVLINE(LINE(1,6), tmp); |
421 |
|
|
422 |
|
// 5=10, 10=5 |
423 |
|
MOVLINE(tmp, LINE(1,5)); |
424 |
|
MOVLINE(LINE(1,5), LINE(3,2)); |
425 |
|
MOVLINE(LINE(3,2), tmp); |
426 |
|
|
427 |
|
// 7=11, 11=13, 13=14, 14=7 |
428 |
|
MOVLINE(tmp, LINE(1,7)); |
429 |
|
MOVLINE(LINE(1,7), LINE(3,3)); |
430 |
|
MOVLINE(LINE(3,3), LINE(3,5)); |
431 |
|
MOVLINE(LINE(3,5), LINE(3,6)); |
432 |
|
MOVLINE(LINE(3,6), tmp); |
433 |
} |
} |