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 |
|
|
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, |
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[][64], |
int16_t data[6 * 64], |
82 |
int16_t qcoeff[][64], |
int16_t qcoeff[6 * 64]) |
|
IMAGE * const pCurrent) |
|
|
|
|
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 = 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); |
|
|
|
|
for(i = 0; i < 6; i++) { |
|
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
|
96 |
|
|
97 |
start_timer(); |
start_timer(); |
98 |
|
transfer_8to16copy(&data[0 * 64], pY_Cur, stride); |
99 |
|
transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); |
100 |
|
transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); |
101 |
|
transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); |
102 |
|
transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); |
103 |
|
transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); |
104 |
|
stop_transfer_timer(); |
105 |
|
|
106 |
switch(i) { |
start_timer(); |
107 |
case 0 : |
pMB->field_dct = 0; |
108 |
transfer_8to16copy(data[0], pY_Cur, stride); |
if ((frame->global_flags & XVID_INTERLACING)) { |
109 |
break; |
pMB->field_dct = MBDecideFieldDCT(data); |
|
case 1 : |
|
|
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 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
115 |
|
|
116 |
start_timer(); |
start_timer(); |
117 |
fdct(data[i]); |
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], data[i], iQuant, iDcScaler); |
quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
123 |
stop_quant_timer(); |
stop_quant_timer(); |
124 |
|
|
125 |
start_timer(); |
start_timer(); |
126 |
dequant_intra(data[i], qcoeff[i], 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], 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(); |
if (pMB->field_dct) { |
144 |
|
next_block = stride; |
145 |
switch(i) { |
stride *= 2; |
|
case 0: |
|
|
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; |
|
146 |
} |
} |
147 |
|
|
148 |
|
start_timer(); |
149 |
|
transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
150 |
|
transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); |
151 |
|
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
152 |
|
transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride); |
153 |
|
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
154 |
|
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
155 |
stop_transfer_timer(); |
stop_transfer_timer(); |
|
} |
|
|
} |
|
156 |
|
|
157 |
|
} |
158 |
|
|
|
uint8_t MBTransQuantInter(const MBParam *pParam, |
|
|
const uint32_t x_pos, const uint32_t y_pos, |
|
|
int16_t data[][64], |
|
|
int16_t qcoeff[][64], |
|
|
IMAGE * const pCurrent) |
|
159 |
|
|
160 |
|
uint8_t |
161 |
|
MBTransQuantInter(const MBParam * pParam, |
162 |
|
FRAMEINFO * frame, |
163 |
|
MACROBLOCK * pMB, |
164 |
|
const uint32_t x_pos, |
165 |
|
const uint32_t y_pos, |
166 |
|
int16_t data[6 * 64], |
167 |
|
int16_t qcoeff[6 * 64]) |
168 |
{ |
{ |
169 |
const uint32_t stride = pParam->edged_width; |
|
170 |
uint8_t i; |
uint32_t stride = pParam->edged_width; |
171 |
uint8_t iQuant = pParam->quant; |
uint32_t stride2 = stride / 2; |
172 |
|
uint32_t next_block = stride * 8; |
173 |
|
uint32_t i; |
174 |
|
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(); |
185 |
|
pMB->field_dct = 0; |
186 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
187 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
188 |
|
} |
189 |
|
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) |
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->m_quant_type == 0) { |
|
{ |
|
201 |
start_timer(); |
start_timer(); |
202 |
sum = quant_inter(qcoeff[i], data[i], iQuant); |
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
203 |
stop_quant_timer(); |
stop_quant_timer(); |
204 |
} |
} else { |
|
else |
|
|
{ |
|
205 |
start_timer(); |
start_timer(); |
206 |
sum = quant4_inter(qcoeff[i], data[i], iQuant); |
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
207 |
stop_quant_timer(); |
stop_quant_timer(); |
208 |
} |
} |
209 |
|
|
210 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
211 |
|
|
212 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) { |
|
{ |
|
213 |
start_timer(); |
start_timer(); |
214 |
dequant_inter(data[i], qcoeff[i], iQuant); |
dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
215 |
stop_iquant_timer(); |
stop_iquant_timer(); |
216 |
} |
} else { |
|
else |
|
|
{ |
|
217 |
start_timer(); |
start_timer(); |
218 |
dequant4_inter(data[i], qcoeff[i], iQuant); |
dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
219 |
stop_iquant_timer(); |
stop_iquant_timer(); |
220 |
} |
} |
221 |
|
|
222 |
cbp |= 1 << (5 - i); |
cbp |= 1 << (5 - i); |
223 |
|
|
224 |
start_timer(); |
start_timer(); |
225 |
idct(data[i]); |
idct(&data[i * 64]); |
226 |
stop_idct_timer(); |
stop_idct_timer(); |
227 |
|
} |
228 |
|
} |
229 |
|
|
230 |
|
if (pMB->field_dct) { |
231 |
|
next_block = stride; |
232 |
|
stride *= 2; |
233 |
|
} |
234 |
|
|
235 |
start_timer(); |
start_timer(); |
236 |
|
if (cbp & 32) |
237 |
|
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
238 |
|
if (cbp & 16) |
239 |
|
transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
240 |
|
if (cbp & 8) |
241 |
|
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
242 |
|
if (cbp & 4) |
243 |
|
transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); |
244 |
|
if (cbp & 2) |
245 |
|
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
246 |
|
if (cbp & 1) |
247 |
|
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
248 |
|
stop_transfer_timer(); |
249 |
|
|
250 |
|
return cbp; |
251 |
|
|
|
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; |
|
252 |
} |
} |
253 |
stop_transfer_timer(); |
|
254 |
|
|
255 |
|
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
256 |
|
|
257 |
|
|
258 |
|
uint32_t |
259 |
|
MBDecideFieldDCT(int16_t data[6 * 64]) |
260 |
|
{ |
261 |
|
|
262 |
|
const uint8_t blocks[] = |
263 |
|
{ 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; |
264 |
|
const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 }; |
265 |
|
|
266 |
|
int frame = 0, field = 0; |
267 |
|
int i, j; |
268 |
|
|
269 |
|
for (i = 0; i < 7; ++i) { |
270 |
|
for (j = 0; j < 8; ++j) { |
271 |
|
frame += |
272 |
|
ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
273 |
|
frame += |
274 |
|
ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); |
275 |
|
frame += |
276 |
|
ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); |
277 |
|
frame += |
278 |
|
ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
279 |
|
|
280 |
|
field += |
281 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + j] - |
282 |
|
data[blocks[i] + lines[i] + j]); |
283 |
|
field += |
284 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
285 |
|
data[blocks[i] + lines[i] + 8 + j]); |
286 |
|
field += |
287 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
288 |
|
data[blocks[i] + 64 + lines[i] + j]); |
289 |
|
field += |
290 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
291 |
|
data[blocks[i] + 64 + lines[i] + 8 + j]); |
292 |
} |
} |
293 |
} |
} |
294 |
return cbp; |
|
295 |
|
if (frame > field) { |
296 |
|
MBFrameToField(data); |
297 |
|
} |
298 |
|
|
299 |
|
return (frame > field); |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
/* deinterlace Y blocks vertically */ |
304 |
|
|
305 |
|
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
306 |
|
#define LINE(X,Y) &data[X*64 + Y*8] |
307 |
|
|
308 |
|
void |
309 |
|
MBFrameToField(int16_t data[6 * 64]) |
310 |
|
{ |
311 |
|
int16_t tmp[8]; |
312 |
|
|
313 |
|
/* left blocks */ |
314 |
|
|
315 |
|
// 1=2, 2=4, 4=8, 8=1 |
316 |
|
MOVLINE(tmp, LINE(0, 1)); |
317 |
|
MOVLINE(LINE(0, 1), LINE(0, 2)); |
318 |
|
MOVLINE(LINE(0, 2), LINE(0, 4)); |
319 |
|
MOVLINE(LINE(0, 4), LINE(2, 0)); |
320 |
|
MOVLINE(LINE(2, 0), tmp); |
321 |
|
|
322 |
|
// 3=6, 6=12, 12=9, 9=3 |
323 |
|
MOVLINE(tmp, LINE(0, 3)); |
324 |
|
MOVLINE(LINE(0, 3), LINE(0, 6)); |
325 |
|
MOVLINE(LINE(0, 6), LINE(2, 4)); |
326 |
|
MOVLINE(LINE(2, 4), LINE(2, 1)); |
327 |
|
MOVLINE(LINE(2, 1), tmp); |
328 |
|
|
329 |
|
// 5=10, 10=5 |
330 |
|
MOVLINE(tmp, LINE(0, 5)); |
331 |
|
MOVLINE(LINE(0, 5), LINE(2, 2)); |
332 |
|
MOVLINE(LINE(2, 2), tmp); |
333 |
|
|
334 |
|
// 7=14, 14=13, 13=11, 11=7 |
335 |
|
MOVLINE(tmp, LINE(0, 7)); |
336 |
|
MOVLINE(LINE(0, 7), LINE(2, 6)); |
337 |
|
MOVLINE(LINE(2, 6), LINE(2, 5)); |
338 |
|
MOVLINE(LINE(2, 5), LINE(2, 3)); |
339 |
|
MOVLINE(LINE(2, 3), tmp); |
340 |
|
|
341 |
|
/* right blocks */ |
342 |
|
|
343 |
|
// 1=2, 2=4, 4=8, 8=1 |
344 |
|
MOVLINE(tmp, LINE(1, 1)); |
345 |
|
MOVLINE(LINE(1, 1), LINE(1, 2)); |
346 |
|
MOVLINE(LINE(1, 2), LINE(1, 4)); |
347 |
|
MOVLINE(LINE(1, 4), LINE(3, 0)); |
348 |
|
MOVLINE(LINE(3, 0), tmp); |
349 |
|
|
350 |
|
// 3=6, 6=12, 12=9, 9=3 |
351 |
|
MOVLINE(tmp, LINE(1, 3)); |
352 |
|
MOVLINE(LINE(1, 3), LINE(1, 6)); |
353 |
|
MOVLINE(LINE(1, 6), LINE(3, 4)); |
354 |
|
MOVLINE(LINE(3, 4), LINE(3, 1)); |
355 |
|
MOVLINE(LINE(3, 1), tmp); |
356 |
|
|
357 |
|
// 5=10, 10=5 |
358 |
|
MOVLINE(tmp, LINE(1, 5)); |
359 |
|
MOVLINE(LINE(1, 5), LINE(3, 2)); |
360 |
|
MOVLINE(LINE(3, 2), tmp); |
361 |
|
|
362 |
|
// 7=14, 14=13, 13=11, 11=7 |
363 |
|
MOVLINE(tmp, LINE(1, 7)); |
364 |
|
MOVLINE(LINE(1, 7), LINE(3, 6)); |
365 |
|
MOVLINE(LINE(3, 6), LINE(3, 5)); |
366 |
|
MOVLINE(LINE(3, 5), LINE(3, 3)); |
367 |
|
MOVLINE(LINE(3, 3), tmp); |
368 |
} |
} |