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