42 |
* * |
* * |
43 |
* Revision history: * |
* Revision history: * |
44 |
* * |
* * |
45 |
|
* 29.03.2002 interlacing speedup - used transfer strides instead of |
46 |
|
* 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 |
* 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 |
* * |
* * |
52 |
******************************************************************************/ |
******************************************************************************/ |
53 |
|
|
54 |
|
#include <string.h> |
55 |
|
|
56 |
#include "../portab.h" |
#include "../portab.h" |
57 |
#include "mbfunctions.h" |
#include "mbfunctions.h" |
58 |
|
|
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 MBTransQuantIntra(const MBParam *pParam, |
76 |
|
MACROBLOCK * pMB, |
77 |
const uint32_t x_pos, |
const uint32_t x_pos, |
78 |
const uint32_t y_pos, |
const uint32_t y_pos, |
79 |
int16_t data[][64], |
int16_t data[6*64], |
80 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64], |
81 |
IMAGE * const pCurrent) |
IMAGE * const pCurrent) |
82 |
|
|
83 |
{ |
{ |
84 |
const uint32_t stride = pParam->edged_width; |
|
85 |
|
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 = pParam->quant; |
90 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
91 |
|
|
92 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
93 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
94 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
|
|
|
|
for(i = 0; i < 6; i++) { |
|
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
|
95 |
|
|
96 |
start_timer(); |
start_timer(); |
97 |
|
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
98 |
|
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
99 |
|
transfer_8to16copy(&data[2*64], pY_Cur + next_block, stride); |
100 |
|
transfer_8to16copy(&data[3*64], pY_Cur + next_block + 8,stride); |
101 |
|
transfer_8to16copy(&data[4*64], pU_Cur, stride2); |
102 |
|
transfer_8to16copy(&data[5*64], pV_Cur, stride2); |
103 |
|
stop_transfer_timer(); |
104 |
|
|
105 |
switch(i) { |
start_timer(); |
106 |
case 0 : |
pMB->field_dct = 0; |
107 |
transfer_8to16copy(data[0], pY_Cur, stride); |
if (pParam->global_flags & XVID_INTERLACING) |
108 |
break; |
{ |
109 |
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; |
|
110 |
} |
} |
111 |
stop_transfer_timer(); |
stop_interlacing_timer(); |
112 |
|
|
113 |
|
for(i = 0; i < 6; i++) |
114 |
|
{ |
115 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
116 |
|
|
117 |
start_timer(); |
start_timer(); |
118 |
fdct(data[i]); |
fdct(&data[i*64]); |
119 |
stop_dct_timer(); |
stop_dct_timer(); |
120 |
|
|
121 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->quant_type == H263_QUANT) |
122 |
{ |
{ |
123 |
start_timer(); |
start_timer(); |
124 |
quant_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
125 |
stop_quant_timer(); |
stop_quant_timer(); |
126 |
|
|
127 |
start_timer(); |
start_timer(); |
128 |
dequant_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
129 |
stop_iquant_timer(); |
stop_iquant_timer(); |
130 |
} |
} |
131 |
else |
else |
132 |
{ |
{ |
133 |
start_timer(); |
start_timer(); |
134 |
quant4_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
135 |
stop_quant_timer(); |
stop_quant_timer(); |
136 |
|
|
137 |
start_timer(); |
start_timer(); |
138 |
dequant4_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
139 |
stop_iquant_timer(); |
stop_iquant_timer(); |
140 |
} |
} |
141 |
|
|
142 |
start_timer(); |
start_timer(); |
143 |
idct(data[i]); |
idct(&data[i*64]); |
144 |
stop_idct_timer(); |
stop_idct_timer(); |
145 |
|
} |
146 |
|
|
147 |
start_timer(); |
if (pMB->field_dct) |
148 |
|
{ |
149 |
switch(i) { |
next_block = stride; |
150 |
case 0: |
stride *= 2; |
|
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; |
|
151 |
} |
} |
152 |
|
|
153 |
|
start_timer(); |
154 |
|
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
155 |
|
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
156 |
|
transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
157 |
|
transfer_16to8copy(pY_Cur + next_block + 8, &data[3*64], stride); |
158 |
|
transfer_16to8copy(pU_Cur, &data[4*64], stride2); |
159 |
|
transfer_16to8copy(pV_Cur, &data[5*64], stride2); |
160 |
stop_transfer_timer(); |
stop_transfer_timer(); |
161 |
} |
|
162 |
} |
} |
163 |
|
|
164 |
|
|
165 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t MBTransQuantInter(const MBParam *pParam, |
166 |
|
MACROBLOCK * pMB, |
167 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, const uint32_t y_pos, |
168 |
int16_t data[][64], |
int16_t data[6*64], |
169 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64], |
170 |
IMAGE * const pCurrent) |
IMAGE * const pCurrent) |
171 |
|
|
172 |
{ |
{ |
173 |
const uint32_t stride = pParam->edged_width; |
|
174 |
uint8_t i; |
uint32_t stride = pParam->edged_width; |
175 |
uint8_t iQuant = pParam->quant; |
uint32_t stride2 = stride / 2; |
176 |
|
uint32_t next_block = stride * 8; |
177 |
|
uint32_t i; |
178 |
|
uint32_t iQuant = pParam->quant; |
179 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
180 |
uint8_t cbp = 0; |
uint8_t cbp = 0; |
181 |
uint32_t sum; |
uint32_t sum; |
182 |
|
|
183 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
184 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
185 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
186 |
|
|
187 |
for(i = 0; i < 6; i++) { |
start_timer(); |
188 |
|
pMB->field_dct = 0; |
189 |
|
if (pParam->global_flags & XVID_INTERLACING) |
190 |
|
{ |
191 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
192 |
|
} |
193 |
|
stop_interlacing_timer(); |
194 |
|
|
195 |
|
for(i = 0; i < 6; i++) |
196 |
|
{ |
197 |
/* |
/* |
198 |
no need to transfer 8->16-bit |
* no need to transfer 8->16-bit |
199 |
(this is performed already in motion compensation) |
* (this is performed already in motion compensation) |
200 |
*/ |
*/ |
201 |
start_timer(); |
start_timer(); |
202 |
fdct(data[i]); |
fdct(&data[i*64]); |
203 |
stop_dct_timer(); |
stop_dct_timer(); |
204 |
|
|
205 |
if (pParam->quant_type == 0) |
if (pParam->quant_type == 0) |
206 |
{ |
{ |
207 |
start_timer(); |
start_timer(); |
208 |
sum = quant_inter(qcoeff[i], data[i], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
209 |
stop_quant_timer(); |
stop_quant_timer(); |
210 |
} |
} |
211 |
else |
else |
212 |
{ |
{ |
213 |
start_timer(); |
start_timer(); |
214 |
sum = quant4_inter(qcoeff[i], data[i], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
215 |
stop_quant_timer(); |
stop_quant_timer(); |
216 |
} |
} |
217 |
|
|
220 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->quant_type == H263_QUANT) |
221 |
{ |
{ |
222 |
start_timer(); |
start_timer(); |
223 |
dequant_inter(data[i], qcoeff[i], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
224 |
stop_iquant_timer(); |
stop_iquant_timer(); |
225 |
} |
} |
226 |
else |
else |
227 |
{ |
{ |
228 |
start_timer(); |
start_timer(); |
229 |
dequant4_inter(data[i], qcoeff[i], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
230 |
stop_iquant_timer(); |
stop_iquant_timer(); |
231 |
} |
} |
232 |
|
|
233 |
cbp |= 1 << (5 - i); |
cbp |= 1 << (5 - i); |
234 |
|
|
235 |
start_timer(); |
start_timer(); |
236 |
idct(data[i]); |
idct(&data[i*64]); |
237 |
stop_idct_timer(); |
stop_idct_timer(); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
if (pMB->field_dct) |
242 |
|
{ |
243 |
|
next_block = stride; |
244 |
|
stride *= 2; |
245 |
|
} |
246 |
|
|
247 |
start_timer(); |
start_timer(); |
248 |
|
if (cbp & 32) |
249 |
|
transfer_16to8add(pY_Cur, &data[0*64], stride); |
250 |
|
if (cbp & 16) |
251 |
|
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
252 |
|
if (cbp & 8) |
253 |
|
transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
254 |
|
if (cbp & 4) |
255 |
|
transfer_16to8add(pY_Cur + next_block + 8, &data[3*64], stride); |
256 |
|
if (cbp & 2) |
257 |
|
transfer_16to8add(pU_Cur, &data[4*64], stride2); |
258 |
|
if (cbp & 1) |
259 |
|
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
260 |
|
stop_transfer_timer(); |
261 |
|
|
262 |
|
return cbp; |
263 |
|
|
|
switch(i) { |
|
|
case 0: |
|
|
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; |
|
264 |
} |
} |
265 |
stop_transfer_timer(); |
|
266 |
|
|
267 |
|
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
268 |
|
|
269 |
|
|
270 |
|
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
271 |
|
{ |
272 |
|
|
273 |
|
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
274 |
|
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
275 |
|
|
276 |
|
int frame = 0, field = 0; |
277 |
|
int i, j; |
278 |
|
|
279 |
|
for (i=0 ; i<7 ; ++i) |
280 |
|
{ |
281 |
|
for (j=0 ; j<8 ; ++j) |
282 |
|
{ |
283 |
|
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
284 |
|
frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]); |
285 |
|
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
286 |
|
frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]); |
287 |
|
|
288 |
|
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
289 |
|
data[blocks[i ] + lines[i ] + j]); |
290 |
|
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
291 |
|
data[blocks[i ] + lines[i ] + 8 + j]); |
292 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
293 |
|
data[blocks[i ] + 64 + lines[i ] + j]); |
294 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
295 |
|
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
296 |
} |
} |
297 |
} |
} |
298 |
return cbp; |
|
299 |
|
if (frame > field) |
300 |
|
{ |
301 |
|
MBFrameToField(data); |
302 |
|
} |
303 |
|
|
304 |
|
return (frame > field); |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
/* deinterlace Y blocks vertically */ |
309 |
|
|
310 |
|
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
311 |
|
#define LINE(X,Y) &data[X*64 + Y*8] |
312 |
|
|
313 |
|
void MBFrameToField(int16_t data[6*64]) |
314 |
|
{ |
315 |
|
int16_t tmp[8]; |
316 |
|
|
317 |
|
/* left blocks */ |
318 |
|
|
319 |
|
// 1=2, 2=4, 4=8, 8=1 |
320 |
|
MOVLINE(tmp, LINE(0,1)); |
321 |
|
MOVLINE(LINE(0,1), LINE(0,2)); |
322 |
|
MOVLINE(LINE(0,2), LINE(0,4)); |
323 |
|
MOVLINE(LINE(0,4), LINE(2,0)); |
324 |
|
MOVLINE(LINE(2,0), tmp); |
325 |
|
|
326 |
|
// 3=6, 6=12, 12=9, 9=3 |
327 |
|
MOVLINE(tmp, LINE(0,3)); |
328 |
|
MOVLINE(LINE(0,3), LINE(0,6)); |
329 |
|
MOVLINE(LINE(0,6), LINE(2,4)); |
330 |
|
MOVLINE(LINE(2,4), LINE(2,1)); |
331 |
|
MOVLINE(LINE(2,1), tmp); |
332 |
|
|
333 |
|
// 5=10, 10=5 |
334 |
|
MOVLINE(tmp, LINE(0,5)); |
335 |
|
MOVLINE(LINE(0,5), LINE(2,2)); |
336 |
|
MOVLINE(LINE(2,2), tmp); |
337 |
|
|
338 |
|
// 7=14, 14=13, 13=11, 11=7 |
339 |
|
MOVLINE(tmp, LINE(0,7)); |
340 |
|
MOVLINE(LINE(0,7), LINE(2,6)); |
341 |
|
MOVLINE(LINE(2,6), LINE(2,5)); |
342 |
|
MOVLINE(LINE(2,5), LINE(2,3)); |
343 |
|
MOVLINE(LINE(2,3), tmp); |
344 |
|
|
345 |
|
/* right blocks */ |
346 |
|
|
347 |
|
// 1=2, 2=4, 4=8, 8=1 |
348 |
|
MOVLINE(tmp, LINE(1,1)); |
349 |
|
MOVLINE(LINE(1,1), LINE(1,2)); |
350 |
|
MOVLINE(LINE(1,2), LINE(1,4)); |
351 |
|
MOVLINE(LINE(1,4), LINE(3,0)); |
352 |
|
MOVLINE(LINE(3,0), tmp); |
353 |
|
|
354 |
|
// 3=6, 6=12, 12=9, 9=3 |
355 |
|
MOVLINE(tmp, LINE(1,3)); |
356 |
|
MOVLINE(LINE(1,3), LINE(1,6)); |
357 |
|
MOVLINE(LINE(1,6), LINE(3,4)); |
358 |
|
MOVLINE(LINE(3,4), LINE(3,1)); |
359 |
|
MOVLINE(LINE(3,1), tmp); |
360 |
|
|
361 |
|
// 5=10, 10=5 |
362 |
|
MOVLINE(tmp, LINE(1,5)); |
363 |
|
MOVLINE(LINE(1,5), LINE(3,2)); |
364 |
|
MOVLINE(LINE(3,2), tmp); |
365 |
|
|
366 |
|
// 7=14, 14=13, 13=11, 11=7 |
367 |
|
MOVLINE(tmp, LINE(1,7)); |
368 |
|
MOVLINE(LINE(1,7), LINE(3,6)); |
369 |
|
MOVLINE(LINE(3,6), LINE(3,5)); |
370 |
|
MOVLINE(LINE(3,5), LINE(3,3)); |
371 |
|
MOVLINE(LINE(3,3), tmp); |
372 |
} |
} |