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