1 |
/****************************************************************************** |
/***************************************************************************** |
2 |
* * |
* |
3 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder * |
* XVID MPEG-4 VIDEO CODEC |
4 |
* * |
* - MacroBlock transfer and quantization - |
5 |
* XviD is an implementation of a part of one or more MPEG-4 Video tools * |
* |
6 |
* as specified in ISO/IEC 14496-2 standard. Those intending to use this * |
* Copyright(C) 2002-2001 Christoph Lampert <gruel@web.de> |
7 |
* software module in hardware or software products are advised that its * |
* 2002-2001 Michael Militzer <isibaar@xvid.org> |
8 |
* use may infringe existing patents or copyrights, and any such use * |
* 2002-2001 Peter Ross <pross@xvid.org> |
9 |
* would be at such party's own risk. The original developer of this * |
* 2002 Daniel Smith <danielsmith@astroboymail.com> |
10 |
* software module and his/her company, and subsequent editors and their * |
* |
11 |
* companies, will have no liability for use of this software or * |
* This program is an implementation of a part of one or more MPEG-4 |
12 |
* modifications or derivatives thereof. * |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
13 |
* * |
* to use this software module in hardware or software products are |
14 |
* XviD is free software; you can redistribute it and/or modify it * |
* advised that its use may infringe existing patents or copyrights, and |
15 |
* under the terms of the GNU General Public License as published by * |
* any such use would be at such party's own risk. The original |
16 |
* the Free Software Foundation; either version 2 of the License, or * |
* developer of this software module and his/her company, and subsequent |
17 |
* (at your option) any later version. * |
* editors and their companies, will have no liability for use of this |
18 |
* * |
* software or modifications or derivatives thereof. |
19 |
* XviD is distributed in the hope that it will be useful, but * |
* |
20 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
* This program is free software; you can redistribute it and/or modify |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* it under the terms of the GNU General Public License as published by |
22 |
* GNU General Public License for more details. * |
* the Free Software Foundation; either version 2 of the License, or |
23 |
* * |
* (at your option) any later version. |
24 |
* You should have received a copy of the GNU General Public License * |
* |
25 |
* along with this program; if not, write to the Free Software * |
* This program is distributed in the hope that it will be useful, |
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
27 |
* * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
28 |
******************************************************************************/ |
* GNU General Public License for more details. |
29 |
|
* |
30 |
/****************************************************************************** |
* You should have received a copy of the GNU General Public License |
31 |
* * |
* along with this program; if not, write to the Free Software |
32 |
* mbtransquant.c * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
33 |
* * |
* |
34 |
* Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> * |
* $Id: mbtransquant.c,v 1.18 2002-10-19 12:20:33 edgomez Exp $ |
35 |
* Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> * |
* |
36 |
* * |
****************************************************************************/ |
|
* For more information visit the XviD homepage: http://www.xvid.org * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
|
/****************************************************************************** |
|
|
* * |
|
|
* Revision history: * |
|
|
* * |
|
|
* 29.03.2002 interlacing speedup - used transfer strides instead of |
|
|
* manual field-to-frame conversion |
|
|
* 26.03.2002 interlacing support - moved transfers outside loops |
|
|
* 22.12.2001 get_dc_scaler() moved to common.h |
|
|
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
|
|
* 17.11.2001 initial version * |
|
|
* * |
|
|
******************************************************************************/ |
|
37 |
|
|
38 |
#include <string.h> |
#include <string.h> |
39 |
|
|
52 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
53 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
54 |
|
|
55 |
#define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */ |
#define TOOSMALL_LIMIT 3 /* skip blocks having a coefficient sum below this value */ |
56 |
|
|
57 |
/* this isnt pretty, but its better than 20 ifdefs */ |
/* this isnt pretty, but its better than 20 ifdefs */ |
58 |
|
|
59 |
void MBTransQuantIntra(const MBParam *pParam, |
void |
60 |
|
MBTransQuantIntra(const MBParam * pParam, |
61 |
|
FRAMEINFO * frame, |
62 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
63 |
const uint32_t x_pos, |
const uint32_t x_pos, |
64 |
const uint32_t y_pos, |
const uint32_t y_pos, |
65 |
int16_t data[6*64], |
int16_t data[6*64], |
66 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6 * 64]) |
|
IMAGE * const pCurrent) |
|
|
|
|
67 |
{ |
{ |
68 |
|
|
69 |
uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
70 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
71 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
72 |
uint32_t i; |
uint32_t i; |
73 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
74 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
75 |
|
IMAGE *pCurrent = &frame->image; |
76 |
|
|
77 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
78 |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
89 |
|
|
90 |
start_timer(); |
start_timer(); |
91 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
92 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING) && |
93 |
{ |
(x_pos>0) && (x_pos<pParam->mb_width-1) && |
94 |
|
(y_pos>0) && (y_pos<pParam->mb_height-1)) { |
95 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
96 |
} |
} |
97 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
98 |
|
|
99 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
100 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
101 |
|
|
102 |
start_timer(); |
start_timer(); |
103 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
104 |
stop_dct_timer(); |
stop_dct_timer(); |
105 |
|
|
106 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) { |
|
{ |
|
107 |
start_timer(); |
start_timer(); |
108 |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
109 |
stop_quant_timer(); |
stop_quant_timer(); |
111 |
start_timer(); |
start_timer(); |
112 |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
113 |
stop_iquant_timer(); |
stop_iquant_timer(); |
114 |
} |
} else { |
|
else |
|
|
{ |
|
115 |
start_timer(); |
start_timer(); |
116 |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
117 |
stop_quant_timer(); |
stop_quant_timer(); |
126 |
stop_idct_timer(); |
stop_idct_timer(); |
127 |
} |
} |
128 |
|
|
129 |
if (pMB->field_dct) |
if (pMB->field_dct) { |
|
{ |
|
130 |
next_block = stride; |
next_block = stride; |
131 |
stride *= 2; |
stride *= 2; |
132 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t |
147 |
|
MBTransQuantInter(const MBParam * pParam, |
148 |
|
FRAMEINFO * frame, |
149 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
150 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, |
151 |
|
const uint32_t y_pos, |
152 |
int16_t data[6*64], |
int16_t data[6*64], |
153 |
int16_t qcoeff[6*64], |
int16_t qcoeff[6 * 64]) |
|
IMAGE * const pCurrent) |
|
|
|
|
154 |
{ |
{ |
155 |
|
|
156 |
uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
157 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
158 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
159 |
uint32_t i; |
uint32_t i; |
160 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
161 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
162 |
uint8_t cbp = 0; |
uint8_t cbp = 0; |
163 |
uint32_t sum; |
uint32_t sum; |
164 |
|
IMAGE *pCurrent = &frame->image; |
165 |
|
|
166 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
167 |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
169 |
|
|
170 |
start_timer(); |
start_timer(); |
171 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
172 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING) && |
173 |
{ |
(x_pos>0) && (x_pos<pParam->mb_width-1) && |
174 |
|
(y_pos>0) && (y_pos<pParam->mb_height-1)) { |
175 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
176 |
} |
} |
177 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
178 |
|
|
179 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
180 |
/* |
/* |
181 |
* no need to transfer 8->16-bit |
* no need to transfer 8->16-bit |
182 |
* (this is performed already in motion compensation) |
* (this is performed already in motion compensation) |
185 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
186 |
stop_dct_timer(); |
stop_dct_timer(); |
187 |
|
|
188 |
if (pParam->quant_type == 0) |
if (pParam->m_quant_type == 0) { |
|
{ |
|
189 |
start_timer(); |
start_timer(); |
190 |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
191 |
stop_quant_timer(); |
stop_quant_timer(); |
192 |
|
} else { |
193 |
|
start_timer(); |
194 |
|
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
195 |
|
stop_quant_timer(); |
196 |
|
} |
197 |
|
|
198 |
|
if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) || |
199 |
|
(qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) { |
200 |
|
|
201 |
|
if (pParam->m_quant_type == H263_QUANT) { |
202 |
|
start_timer(); |
203 |
|
dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
204 |
|
stop_iquant_timer(); |
205 |
|
} else { |
206 |
|
start_timer(); |
207 |
|
dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
208 |
|
stop_iquant_timer(); |
209 |
|
} |
210 |
|
|
211 |
|
cbp |= 1 << (5 - i); |
212 |
|
|
213 |
|
start_timer(); |
214 |
|
idct(&data[i * 64]); |
215 |
|
stop_idct_timer(); |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
|
if (pMB->field_dct) { |
220 |
|
next_block = stride; |
221 |
|
stride *= 2; |
222 |
|
} |
223 |
|
|
224 |
|
start_timer(); |
225 |
|
if (cbp & 32) |
226 |
|
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
227 |
|
if (cbp & 16) |
228 |
|
transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
229 |
|
if (cbp & 8) |
230 |
|
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
231 |
|
if (cbp & 4) |
232 |
|
transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); |
233 |
|
if (cbp & 2) |
234 |
|
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
235 |
|
if (cbp & 1) |
236 |
|
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
237 |
|
stop_transfer_timer(); |
238 |
|
|
239 |
|
return cbp; |
240 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
void |
244 |
|
MBTransQuantIntra2(const MBParam * pParam, |
245 |
|
FRAMEINFO * frame, |
246 |
|
MACROBLOCK * pMB, |
247 |
|
const uint32_t x_pos, |
248 |
|
const uint32_t y_pos, |
249 |
|
int16_t data[6 * 64], |
250 |
|
int16_t qcoeff[6 * 64]) |
251 |
|
{ |
252 |
|
MBTrans(pParam,frame,pMB,x_pos,y_pos,data); |
253 |
|
MBfDCT(pParam,frame,pMB,data); |
254 |
|
MBQuantIntra(pParam,frame,pMB,data,qcoeff); |
255 |
|
MBDeQuantIntra(pParam,frame->quant,data,qcoeff); |
256 |
|
MBiDCT(data,0x3F); |
257 |
|
MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
uint8_t |
262 |
|
MBTransQuantInter2(const MBParam * pParam, |
263 |
|
FRAMEINFO * frame, |
264 |
|
MACROBLOCK * pMB, |
265 |
|
const uint32_t x_pos, |
266 |
|
const uint32_t y_pos, |
267 |
|
int16_t data[6 * 64], |
268 |
|
int16_t qcoeff[6 * 64]) |
269 |
|
{ |
270 |
|
uint8_t cbp; |
271 |
|
|
272 |
|
/* there is no MBTrans for Inter block, that's done in motion compensation already */ |
273 |
|
|
274 |
|
MBfDCT(pParam,frame,pMB,data); |
275 |
|
cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); |
276 |
|
MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp); |
277 |
|
MBiDCT(data,cbp); |
278 |
|
MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp); |
279 |
|
|
280 |
|
return cbp; |
281 |
|
} |
282 |
|
|
283 |
|
uint8_t |
284 |
|
MBTransQuantInterBVOP(const MBParam * pParam, |
285 |
|
FRAMEINFO * frame, |
286 |
|
MACROBLOCK * pMB, |
287 |
|
int16_t data[6 * 64], |
288 |
|
int16_t qcoeff[6 * 64]) |
289 |
|
{ |
290 |
|
uint8_t cbp; |
291 |
|
|
292 |
|
/* there is no MBTrans for Inter block, that's done in motion compensation already */ |
293 |
|
|
294 |
|
MBfDCT(pParam,frame,pMB,data); |
295 |
|
cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); |
296 |
|
|
297 |
|
/* we don't have to DeQuant, iDCT and Transfer back data for B-frames */ |
298 |
|
|
299 |
|
return cbp; |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
void |
304 |
|
MBfDCT(const MBParam * pParam, |
305 |
|
FRAMEINFO * frame, |
306 |
|
MACROBLOCK * pMB, |
307 |
|
int16_t data[6 * 64]) |
308 |
|
{ |
309 |
|
int i; |
310 |
|
|
311 |
|
start_timer(); |
312 |
|
pMB->field_dct = 0; |
313 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
314 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
315 |
|
} |
316 |
|
stop_interlacing_timer(); |
317 |
|
|
318 |
|
for (i = 0; i < 6; i++) { |
319 |
|
start_timer(); |
320 |
|
fdct(&data[i * 64]); |
321 |
|
stop_dct_timer(); |
322 |
|
} |
323 |
|
} |
324 |
|
|
325 |
|
void |
326 |
|
MBQuantDeQuantIntra(const MBParam * pParam, |
327 |
|
FRAMEINFO * frame, |
328 |
|
MACROBLOCK * pMB, |
329 |
|
int16_t qcoeff[6 * 64], |
330 |
|
int16_t data[6*64]) |
331 |
|
{ |
332 |
|
int i; |
333 |
|
int iQuant = frame->quant; |
334 |
|
|
335 |
|
start_timer(); |
336 |
|
pMB->field_dct = 0; |
337 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
338 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
339 |
|
} |
340 |
|
stop_interlacing_timer(); |
341 |
|
|
342 |
|
for (i = 0; i < 6; i++) { |
343 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
344 |
|
|
345 |
|
if (pParam->m_quant_type == H263_QUANT) { |
346 |
|
start_timer(); |
347 |
|
quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
348 |
|
stop_quant_timer(); |
349 |
|
|
350 |
|
start_timer(); |
351 |
|
dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
352 |
|
stop_iquant_timer(); |
353 |
|
} else { |
354 |
|
start_timer(); |
355 |
|
quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
356 |
|
stop_quant_timer(); |
357 |
|
|
358 |
|
start_timer(); |
359 |
|
dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
360 |
|
stop_iquant_timer(); |
361 |
|
} |
362 |
|
} |
363 |
} |
} |
364 |
else |
|
365 |
|
void |
366 |
|
MBQuantIntra(const MBParam * pParam, |
367 |
|
FRAMEINFO * frame, |
368 |
|
MACROBLOCK *pMB, |
369 |
|
int16_t data[6 * 64], |
370 |
|
int16_t qcoeff[6 * 64]) |
371 |
{ |
{ |
372 |
|
int i; |
373 |
|
int iQuant = frame->quant; |
374 |
|
|
375 |
|
start_timer(); |
376 |
|
pMB->field_dct = 0; |
377 |
|
if ((frame->global_flags & XVID_INTERLACING)) { |
378 |
|
pMB->field_dct = MBDecideFieldDCT(data); |
379 |
|
} |
380 |
|
stop_interlacing_timer(); |
381 |
|
|
382 |
|
for (i = 0; i < 6; i++) { |
383 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
384 |
|
|
385 |
|
if (pParam->m_quant_type == H263_QUANT) { |
386 |
|
start_timer(); |
387 |
|
quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
388 |
|
stop_quant_timer(); |
389 |
|
} else { |
390 |
|
start_timer(); |
391 |
|
quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
392 |
|
stop_quant_timer(); |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
|
|
397 |
|
void |
398 |
|
MBDeQuantIntra(const MBParam * pParam, |
399 |
|
const int iQuant, |
400 |
|
int16_t qcoeff[6 * 64], |
401 |
|
int16_t data[6*64]) |
402 |
|
{ |
403 |
|
int i; |
404 |
|
|
405 |
|
for (i = 0; i < 6; i++) { |
406 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
407 |
|
|
408 |
|
if (pParam->m_quant_type == H263_QUANT) { |
409 |
|
start_timer(); |
410 |
|
dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
411 |
|
stop_iquant_timer(); |
412 |
|
} else { |
413 |
|
start_timer(); |
414 |
|
dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
415 |
|
stop_iquant_timer(); |
416 |
|
} |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
|
uint8_t |
421 |
|
MBQuantInter(const MBParam * pParam, |
422 |
|
const int iQuant, |
423 |
|
int16_t data[6 * 64], |
424 |
|
int16_t qcoeff[6 * 64]) |
425 |
|
{ |
426 |
|
|
427 |
|
int i; |
428 |
|
uint8_t cbp = 0; |
429 |
|
int sum; |
430 |
|
|
431 |
|
for (i = 0; i < 6; i++) { |
432 |
|
|
433 |
|
if (pParam->m_quant_type == 0) { |
434 |
|
start_timer(); |
435 |
|
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
436 |
|
stop_quant_timer(); |
437 |
|
} else { |
438 |
start_timer(); |
start_timer(); |
439 |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
440 |
stop_quant_timer(); |
stop_quant_timer(); |
441 |
} |
} |
442 |
|
|
443 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
444 |
|
cbp |= 1 << (5 - i); |
445 |
|
} |
446 |
|
} |
447 |
|
return cbp; |
448 |
|
} |
449 |
|
|
450 |
|
void |
451 |
|
MBDeQuantInter( const MBParam * pParam, |
452 |
|
const int iQuant, |
453 |
|
int16_t data[6 * 64], |
454 |
|
int16_t qcoeff[6 * 64], |
455 |
|
const uint8_t cbp) |
456 |
|
{ |
457 |
|
int i; |
458 |
|
|
459 |
if (pParam->quant_type == H263_QUANT) |
for (i = 0; i < 6; i++) { |
460 |
|
if (cbp & (1 << (5 - i))) |
461 |
{ |
{ |
462 |
|
if (pParam->m_quant_type == H263_QUANT) { |
463 |
start_timer(); |
start_timer(); |
464 |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
465 |
stop_iquant_timer(); |
stop_iquant_timer(); |
466 |
} |
} else { |
|
else |
|
|
{ |
|
467 |
start_timer(); |
start_timer(); |
468 |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
469 |
stop_iquant_timer(); |
stop_iquant_timer(); |
470 |
} |
} |
471 |
|
} |
472 |
|
} |
473 |
|
} |
474 |
|
|
475 |
cbp |= 1 << (5 - i); |
void |
476 |
|
MBiDCT( int16_t data[6 * 64], |
477 |
|
const uint8_t cbp) |
478 |
|
{ |
479 |
|
int i; |
480 |
|
|
481 |
|
for (i = 0; i < 6; i++) { |
482 |
|
if (cbp & (1 << (5 - i))) |
483 |
|
{ |
484 |
start_timer(); |
start_timer(); |
485 |
idct(&data[i*64]); |
idct(&data[i*64]); |
486 |
stop_idct_timer(); |
stop_idct_timer(); |
487 |
|
|
488 |
} |
} |
489 |
} |
} |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
void |
494 |
|
MBTrans(const MBParam * pParam, |
495 |
|
FRAMEINFO * frame, |
496 |
|
MACROBLOCK * pMB, |
497 |
|
const uint32_t x_pos, |
498 |
|
const uint32_t y_pos, |
499 |
|
int16_t data[6 * 64]) |
500 |
|
{ |
501 |
|
uint32_t stride = pParam->edged_width; |
502 |
|
uint32_t stride2 = stride / 2; |
503 |
|
uint32_t next_block = stride * 8; |
504 |
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
505 |
|
IMAGE *pCurrent = &frame->image; |
506 |
|
|
507 |
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
508 |
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
509 |
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
510 |
|
|
511 |
|
start_timer(); |
512 |
|
transfer_8to16copy(&data[0 * 64], pY_Cur, stride); |
513 |
|
transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); |
514 |
|
transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); |
515 |
|
transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); |
516 |
|
transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); |
517 |
|
transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); |
518 |
|
stop_transfer_timer(); |
519 |
|
} |
520 |
|
|
521 |
if (pMB->field_dct) |
void |
522 |
|
MBTransAdd(const MBParam * pParam, |
523 |
|
FRAMEINFO * frame, |
524 |
|
MACROBLOCK * pMB, |
525 |
|
const uint32_t x_pos, |
526 |
|
const uint32_t y_pos, |
527 |
|
int16_t data[6 * 64], |
528 |
|
const uint8_t cbp) |
529 |
{ |
{ |
530 |
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
531 |
|
uint32_t stride = pParam->edged_width; |
532 |
|
uint32_t stride2 = stride / 2; |
533 |
|
uint32_t next_block = stride * 8; |
534 |
|
IMAGE *pCurrent = &frame->image; |
535 |
|
|
536 |
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
537 |
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
538 |
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
539 |
|
|
540 |
|
if (pMB->field_dct) { |
541 |
next_block = stride; |
next_block = stride; |
542 |
stride *= 2; |
stride *= 2; |
543 |
} |
} |
556 |
if (cbp & 1) |
if (cbp & 1) |
557 |
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
558 |
stop_transfer_timer(); |
stop_transfer_timer(); |
|
|
|
|
return cbp; |
|
|
|
|
559 |
} |
} |
560 |
|
|
561 |
|
|
562 |
|
|
563 |
/* 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 */ |
564 |
|
|
565 |
|
|
566 |
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
uint32_t |
567 |
|
MBDecideFieldDCT(int16_t data[6 * 64]) |
568 |
{ |
{ |
569 |
|
|
570 |
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
const uint8_t blocks[] = |
571 |
|
{ 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; |
572 |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
573 |
|
|
574 |
int frame = 0, field = 0; |
int frame = 0, field = 0; |
575 |
int i, j; |
int i, j; |
576 |
|
|
577 |
for (i=0 ; i<7 ; ++i) |
for (i = 0; i < 7; ++i) { |
578 |
{ |
for (j = 0; j < 8; ++j) { |
579 |
for (j=0 ; j<8 ; ++j) |
frame += |
580 |
{ |
ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
581 |
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
frame += |
582 |
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]); |
583 |
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
frame += |
584 |
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]); |
585 |
|
frame += |
586 |
|
ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
587 |
|
|
588 |
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
field += |
589 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + j] - |
590 |
data[blocks[i ] + lines[i ] + j]); |
data[blocks[i ] + lines[i ] + j]); |
591 |
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
field += |
592 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
593 |
data[blocks[i ] + lines[i ] + 8 + j]); |
data[blocks[i ] + lines[i ] + 8 + j]); |
594 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
field += |
595 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
596 |
data[blocks[i ] + 64 + lines[i ] + j]); |
data[blocks[i ] + 64 + lines[i ] + j]); |
597 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
field += |
598 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
599 |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
600 |
} |
} |
601 |
} |
} |
602 |
|
|
603 |
if (frame > field) |
if (frame > (field + 350)) { |
|
{ |
|
604 |
MBFrameToField(data); |
MBFrameToField(data); |
605 |
} |
} |
606 |
|
|
607 |
return (frame > field); |
return (frame > (field + 350)); |
608 |
} |
} |
609 |
|
|
610 |
|
|
613 |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
614 |
#define LINE(X,Y) &data[X*64 + Y*8] |
#define LINE(X,Y) &data[X*64 + Y*8] |
615 |
|
|
616 |
void MBFrameToField(int16_t data[6*64]) |
void |
617 |
|
MBFrameToField(int16_t data[6 * 64]) |
618 |
{ |
{ |
619 |
int16_t tmp[8]; |
int16_t tmp[8]; |
620 |
|
|