1 |
/****************************************************************************** |
/***************************************************************************** |
2 |
* * |
* |
3 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder * |
* XVID MPEG-4 VIDEO CODEC |
4 |
* * |
* - MB Transfert/Quantization functions - |
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) 2001-2003 Peter Ross <pross@xvid.org> |
7 |
* software module in hardware or software products are advised that its * |
* 2001-2003 Michael Militzer <isibaar@xvid.org> |
8 |
* use may infringe existing patents or copyrights, and any such use * |
* 2003 Edouard Gomez <ed.gomez@free.fr> |
9 |
* would be at such party's own risk. The original developer of this * |
* |
10 |
* software module and his/her company, and subsequent editors and their * |
* This program is free software ; you can redistribute it and/or modify |
11 |
* companies, will have no liability for use of this software or * |
* it under the terms of the GNU General Public License as published by |
12 |
* modifications or derivatives thereof. * |
* the Free Software Foundation ; either version 2 of the License, or |
13 |
* * |
* (at your option) any later version. |
14 |
* XviD is free software; you can redistribute it and/or modify it * |
* |
15 |
* under the terms of the GNU General Public License as published by * |
* This program is distributed in the hope that it will be useful, |
16 |
* the Free Software Foundation; either version 2 of the License, or * |
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
17 |
* (at your option) any later version. * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* * |
* GNU General Public License for more details. |
19 |
* XviD is distributed in the hope that it will be useful, but * |
* |
20 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
* You should have received a copy of the GNU General Public License |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* along with this program ; if not, write to the Free Software |
22 |
* GNU General Public License for more details. * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* * |
* |
24 |
* You should have received a copy of the GNU General Public License * |
* $Id: mbtransquant.c,v 1.21.2.8 2003-04-13 16:18:09 syskin Exp $ |
25 |
* along with this program; if not, write to the Free Software * |
* |
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
****************************************************************************/ |
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
|
/****************************************************************************** |
|
|
* * |
|
|
* mbtransquant.c * |
|
|
* * |
|
|
* Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> * |
|
|
* Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> * |
|
|
* * |
|
|
* 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 * |
|
|
* * |
|
|
******************************************************************************/ |
|
27 |
|
|
28 |
#include <string.h> |
#include <string.h> |
29 |
|
#include <stdlib.h> |
30 |
|
|
31 |
#include "../portab.h" |
#include "../portab.h" |
32 |
#include "mbfunctions.h" |
#include "mbfunctions.h" |
40 |
#include "../quant/quant_h263.h" |
#include "../quant/quant_h263.h" |
41 |
#include "../encoder.h" |
#include "../encoder.h" |
42 |
|
|
43 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#include "../image/reduced.h" |
|
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
|
44 |
|
|
45 |
#define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */ |
MBFIELDTEST_PTR MBFieldTest; |
46 |
|
|
47 |
/* this isnt pretty, but its better than 20 ifdefs */ |
/* |
48 |
|
* Skip blocks having a coefficient sum below this value. This value will be |
49 |
|
* corrected according to the MB quantizer to avoid artifacts for quant==1 |
50 |
|
*/ |
51 |
|
#define PVOP_TOOSMALL_LIMIT 1 |
52 |
|
#define BVOP_TOOSMALL_LIMIT 3 |
53 |
|
|
54 |
void MBTransQuantIntra(const MBParam *pParam, |
/***************************************************************************** |
55 |
FRAMEINFO * frame, |
* Local functions |
56 |
MACROBLOCK * pMB, |
****************************************************************************/ |
|
const uint32_t x_pos, |
|
|
const uint32_t y_pos, |
|
|
int16_t data[6*64], |
|
|
int16_t qcoeff[6*64]) |
|
57 |
|
|
58 |
|
/* permute block and return field dct choice */ |
59 |
|
static __inline uint32_t |
60 |
|
MBDecideFieldDCT(int16_t data[6 * 64]) |
61 |
{ |
{ |
62 |
|
uint32_t field = MBFieldTest(data); |
63 |
|
|
64 |
uint32_t stride = pParam->edged_width; |
if (field) |
65 |
uint32_t stride2 = stride / 2; |
MBFrameToField(data); |
|
uint32_t next_block = stride * 8; |
|
|
uint32_t i; |
|
|
uint32_t iQuant = frame->quant; |
|
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
|
|
IMAGE * pCurrent = &frame->image; |
|
|
|
|
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
|
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
|
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
|
66 |
|
|
67 |
start_timer(); |
return field; |
68 |
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
} |
|
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
|
|
transfer_8to16copy(&data[2*64], pY_Cur + next_block, stride); |
|
|
transfer_8to16copy(&data[3*64], pY_Cur + next_block + 8,stride); |
|
|
transfer_8to16copy(&data[4*64], pU_Cur, stride2); |
|
|
transfer_8to16copy(&data[5*64], pV_Cur, stride2); |
|
|
stop_transfer_timer(); |
|
69 |
|
|
70 |
|
/* Performs Forward DCT on all blocks */ |
71 |
|
static __inline void |
72 |
|
MBfDCT(const MBParam * const pParam, |
73 |
|
const FRAMEINFO * const frame, |
74 |
|
MACROBLOCK * const pMB, |
75 |
|
uint32_t x_pos, |
76 |
|
uint32_t y_pos, |
77 |
|
int16_t data[6 * 64]) |
78 |
|
{ |
79 |
|
/* Handles interlacing */ |
80 |
start_timer(); |
start_timer(); |
81 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
82 |
if ((frame->global_flags & XVID_INTERLACING)) |
if ((frame->vol_flags & XVID_VOL_INTERLACING) && |
83 |
{ |
(x_pos>0) && (x_pos<pParam->mb_width-1) && |
84 |
|
(y_pos>0) && (y_pos<pParam->mb_height-1)) { |
85 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
86 |
} |
} |
87 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
88 |
|
|
89 |
for(i = 0; i < 6; i++) |
/* Perform DCT */ |
|
{ |
|
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
|
|
|
|
90 |
start_timer(); |
start_timer(); |
91 |
fdct(&data[i*64]); |
fdct(&data[0 * 64]); |
92 |
|
fdct(&data[1 * 64]); |
93 |
|
fdct(&data[2 * 64]); |
94 |
|
fdct(&data[3 * 64]); |
95 |
|
fdct(&data[4 * 64]); |
96 |
|
fdct(&data[5 * 64]); |
97 |
stop_dct_timer(); |
stop_dct_timer(); |
98 |
|
} |
99 |
|
|
100 |
if (pParam->m_quant_type == H263_QUANT) |
/* Performs Inverse DCT on all blocks */ |
101 |
|
static __inline void |
102 |
|
MBiDCT(int16_t data[6 * 64], |
103 |
|
const uint8_t cbp) |
104 |
{ |
{ |
105 |
start_timer(); |
start_timer(); |
106 |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]); |
107 |
|
if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]); |
108 |
|
if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]); |
109 |
|
if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]); |
110 |
|
if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]); |
111 |
|
if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]); |
112 |
|
stop_idct_timer(); |
113 |
|
} |
114 |
|
|
115 |
|
/* Quantize all blocks -- Intra mode */ |
116 |
|
static __inline void |
117 |
|
MBQuantIntra(const MBParam * pParam, |
118 |
|
const MACROBLOCK * pMB, |
119 |
|
int16_t qcoeff[6 * 64], |
120 |
|
int16_t data[6*64]) |
121 |
|
{ |
122 |
|
int i; |
123 |
|
|
124 |
|
for (i = 0; i < 6; i++) { |
125 |
|
uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4); |
126 |
|
|
127 |
|
/* Quantize the block */ |
128 |
|
start_timer(); |
129 |
|
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
130 |
|
quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
131 |
|
else |
132 |
|
quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
133 |
stop_quant_timer(); |
stop_quant_timer(); |
134 |
|
} |
135 |
|
} |
136 |
|
|
137 |
|
/* DeQuantize all blocks -- Intra mode */ |
138 |
|
static __inline void |
139 |
|
MBDeQuantIntra(const MBParam * pParam, |
140 |
|
const int iQuant, |
141 |
|
int16_t qcoeff[6 * 64], |
142 |
|
int16_t data[6*64]) |
143 |
|
{ |
144 |
|
int i; |
145 |
|
|
146 |
|
for (i = 0; i < 6; i++) { |
147 |
|
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
148 |
|
|
149 |
start_timer(); |
start_timer(); |
150 |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
151 |
|
dequant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
152 |
|
else |
153 |
|
dequant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
154 |
stop_iquant_timer(); |
stop_iquant_timer(); |
155 |
} |
} |
156 |
else |
} |
157 |
|
|
158 |
|
/* Quantize all blocks -- Inter mode */ |
159 |
|
static __inline uint8_t |
160 |
|
MBQuantInter(const MBParam * pParam, |
161 |
|
const MACROBLOCK * pMB, |
162 |
|
int16_t data[6 * 64], |
163 |
|
int16_t qcoeff[6 * 64], |
164 |
|
int bvop, |
165 |
|
int limit) |
166 |
{ |
{ |
167 |
|
|
168 |
|
int i; |
169 |
|
uint8_t cbp = 0; |
170 |
|
int sum; |
171 |
|
int code_block; |
172 |
|
|
173 |
|
for (i = 0; i < 6; i++) { |
174 |
|
|
175 |
|
/* Quantize the block */ |
176 |
start_timer(); |
start_timer(); |
177 |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
178 |
|
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
179 |
|
else |
180 |
|
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
181 |
stop_quant_timer(); |
stop_quant_timer(); |
182 |
|
|
183 |
start_timer(); |
/* |
184 |
dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
* We code the block if the sum is higher than the limit and if the first |
185 |
stop_iquant_timer(); |
* two AC coefficients in zig zag order are not zero. |
186 |
|
*/ |
187 |
|
code_block = 0; |
188 |
|
if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) { |
189 |
|
code_block = 1; |
190 |
|
} else { |
191 |
|
|
192 |
|
if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) { |
193 |
|
/* dark blocks prevention for direct mode */ |
194 |
|
if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0)) |
195 |
|
code_block = 1; |
196 |
|
} else { |
197 |
|
/* not direct mode */ |
198 |
|
if (qcoeff[i*64] != 0) |
199 |
|
code_block = 1; |
200 |
|
} |
201 |
} |
} |
202 |
|
|
203 |
start_timer(); |
/* Set the corresponding cbp bit */ |
204 |
idct(&data[i*64]); |
cbp |= code_block << (5 - i); |
205 |
stop_idct_timer(); |
|
206 |
} |
} |
207 |
|
|
208 |
if (pMB->field_dct) |
return(cbp); |
|
{ |
|
|
next_block = stride; |
|
|
stride *= 2; |
|
209 |
} |
} |
210 |
|
|
211 |
start_timer(); |
/* DeQuantize all blocks -- Inter mode */ |
212 |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
static __inline void |
213 |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
MBDeQuantInter(const MBParam * pParam, |
214 |
transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
const int iQuant, |
215 |
transfer_16to8copy(pY_Cur + next_block + 8, &data[3*64], stride); |
int16_t data[6 * 64], |
216 |
transfer_16to8copy(pU_Cur, &data[4*64], stride2); |
int16_t qcoeff[6 * 64], |
217 |
transfer_16to8copy(pV_Cur, &data[5*64], stride2); |
const uint8_t cbp) |
218 |
stop_transfer_timer(); |
{ |
219 |
|
int i; |
220 |
|
|
221 |
|
for (i = 0; i < 6; i++) { |
222 |
|
if (cbp & (1 << (5 - i))) { |
223 |
|
start_timer(); |
224 |
|
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
225 |
|
dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
226 |
|
else |
227 |
|
dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
228 |
|
stop_iquant_timer(); |
229 |
|
} |
230 |
|
} |
231 |
} |
} |
232 |
|
|
233 |
|
typedef void (transfer_operation_8to16_t) (int16_t *Dst, const uint8_t *Src, int BpS); |
234 |
|
typedef void (transfer_operation_16to8_t) (uint8_t *Dst, const int16_t *Src, int BpS); |
235 |
|
|
|
uint8_t MBTransQuantInter(const MBParam *pParam, |
|
|
FRAMEINFO * frame, |
|
|
MACROBLOCK * pMB, |
|
|
const uint32_t x_pos, const uint32_t y_pos, |
|
|
int16_t data[6*64], |
|
|
int16_t qcoeff[6*64]) |
|
236 |
|
|
237 |
|
static __inline void |
238 |
|
MBTrans8to16(const MBParam * const pParam, |
239 |
|
const FRAMEINFO * const frame, |
240 |
|
const MACROBLOCK * const pMB, |
241 |
|
const uint32_t x_pos, |
242 |
|
const uint32_t y_pos, |
243 |
|
int16_t data[6 * 64]) |
244 |
{ |
{ |
|
|
|
245 |
uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
246 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
247 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
248 |
uint32_t i; |
int32_t cst; |
|
uint32_t iQuant = frame->quant; |
|
249 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
250 |
uint8_t cbp = 0; |
const IMAGE * const pCurrent = &frame->image; |
251 |
uint32_t sum; |
transfer_operation_8to16_t *transfer_op = NULL; |
252 |
IMAGE * pCurrent = &frame->image; |
|
253 |
|
if ((frame->vop_flags & XVID_VOP_REDUCED)) { |
254 |
|
|
255 |
|
/* Image pointers */ |
256 |
|
pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5); |
257 |
|
pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4); |
258 |
|
pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4); |
259 |
|
|
260 |
|
/* Block size */ |
261 |
|
cst = 16; |
262 |
|
|
263 |
|
/* Operation function */ |
264 |
|
transfer_op = (transfer_operation_8to16_t*)filter_18x18_to_8x8; |
265 |
|
} else { |
266 |
|
|
267 |
|
/* Image pointers */ |
268 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
269 |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
270 |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
271 |
|
|
272 |
start_timer(); |
/* Block size */ |
273 |
pMB->field_dct = 0; |
cst = 8; |
274 |
if ((frame->global_flags & XVID_INTERLACING)) |
|
275 |
{ |
/* Operation function */ |
276 |
pMB->field_dct = MBDecideFieldDCT(data); |
transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy; |
277 |
} |
} |
|
stop_interlacing_timer(); |
|
278 |
|
|
279 |
for(i = 0; i < 6; i++) |
/* Do the transfer */ |
|
{ |
|
|
/* |
|
|
* no need to transfer 8->16-bit |
|
|
* (this is performed already in motion compensation) |
|
|
*/ |
|
280 |
start_timer(); |
start_timer(); |
281 |
fdct(&data[i*64]); |
transfer_op(&data[0 * 64], pY_Cur, stride); |
282 |
stop_dct_timer(); |
transfer_op(&data[1 * 64], pY_Cur + cst, stride); |
283 |
|
transfer_op(&data[2 * 64], pY_Cur + next_block, stride); |
284 |
|
transfer_op(&data[3 * 64], pY_Cur + next_block + cst, stride); |
285 |
|
transfer_op(&data[4 * 64], pU_Cur, stride2); |
286 |
|
transfer_op(&data[5 * 64], pV_Cur, stride2); |
287 |
|
stop_transfer_timer(); |
288 |
|
} |
289 |
|
|
290 |
if (pParam->m_quant_type == 0) |
static __inline void |
291 |
|
MBTrans16to8(const MBParam * const pParam, |
292 |
|
const FRAMEINFO * const frame, |
293 |
|
const MACROBLOCK * const pMB, |
294 |
|
const uint32_t x_pos, |
295 |
|
const uint32_t y_pos, |
296 |
|
int16_t data[6 * 64], |
297 |
|
const uint32_t add, |
298 |
|
const uint8_t cbp) |
299 |
{ |
{ |
300 |
start_timer(); |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
301 |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
uint32_t stride = pParam->edged_width; |
302 |
stop_quant_timer(); |
uint32_t stride2 = stride / 2; |
303 |
|
uint32_t next_block = stride * 8; |
304 |
|
uint32_t cst; |
305 |
|
const IMAGE * const pCurrent = &frame->image; |
306 |
|
transfer_operation_16to8_t *transfer_op = NULL; |
307 |
|
|
308 |
|
if (pMB->field_dct) { |
309 |
|
next_block = stride; |
310 |
|
stride *= 2; |
311 |
} |
} |
312 |
|
|
313 |
|
if ((frame->vop_flags & XVID_VOP_REDUCED)) { |
314 |
|
|
315 |
|
/* Image pointers */ |
316 |
|
pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5); |
317 |
|
pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4); |
318 |
|
pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4); |
319 |
|
|
320 |
|
/* Block size */ |
321 |
|
cst = 16; |
322 |
|
|
323 |
|
/* Operation function */ |
324 |
|
if(add) |
325 |
|
transfer_op = (transfer_operation_16to8_t*)add_upsampled_8x8_16to8; |
326 |
else |
else |
327 |
{ |
transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8; |
328 |
start_timer(); |
} else { |
|
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
|
|
stop_quant_timer(); |
|
|
} |
|
329 |
|
|
330 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
/* Image pointers */ |
331 |
|
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
332 |
|
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
333 |
|
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
334 |
|
|
335 |
if (pParam->m_quant_type == H263_QUANT) |
/* Block size */ |
336 |
{ |
cst = 8; |
337 |
start_timer(); |
|
338 |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
/* Operation function */ |
339 |
stop_iquant_timer(); |
if(add) |
340 |
} |
transfer_op = (transfer_operation_16to8_t*)transfer_16to8add; |
341 |
else |
else |
342 |
{ |
transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy; |
|
start_timer(); |
|
|
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
|
|
stop_iquant_timer(); |
|
343 |
} |
} |
344 |
|
|
345 |
cbp |= 1 << (5 - i); |
/* Do the operation */ |
|
|
|
346 |
start_timer(); |
start_timer(); |
347 |
idct(&data[i*64]); |
if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride); |
348 |
stop_idct_timer(); |
if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride); |
349 |
} |
if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride); |
350 |
|
if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride); |
351 |
|
if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2); |
352 |
|
if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2); |
353 |
|
stop_transfer_timer(); |
354 |
} |
} |
355 |
|
|
356 |
if (pMB->field_dct) |
/***************************************************************************** |
357 |
|
* Module functions |
358 |
|
****************************************************************************/ |
359 |
|
|
360 |
|
void |
361 |
|
MBTransQuantIntra(const MBParam * const pParam, |
362 |
|
const FRAMEINFO * const frame, |
363 |
|
MACROBLOCK * const 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 |
{ |
{ |
|
next_block = stride; |
|
|
stride *= 2; |
|
|
} |
|
369 |
|
|
370 |
start_timer(); |
/* Transfer data */ |
371 |
if (cbp & 32) |
MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data); |
372 |
transfer_16to8add(pY_Cur, &data[0*64], stride); |
|
373 |
if (cbp & 16) |
/* Perform DCT (and field decision) */ |
374 |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); |
|
if (cbp & 8) |
|
|
transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
|
|
if (cbp & 4) |
|
|
transfer_16to8add(pY_Cur + next_block + 8, &data[3*64], stride); |
|
|
if (cbp & 2) |
|
|
transfer_16to8add(pU_Cur, &data[4*64], stride2); |
|
|
if (cbp & 1) |
|
|
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
|
|
stop_transfer_timer(); |
|
375 |
|
|
376 |
return cbp; |
/* Quantize the block */ |
377 |
|
MBQuantIntra(pParam, pMB, data, qcoeff); |
378 |
|
|
379 |
|
/* DeQuantize the block */ |
380 |
|
MBDeQuantIntra(pParam, pMB->quant, data, qcoeff); |
381 |
|
|
382 |
|
/* Perform inverse DCT*/ |
383 |
|
MBiDCT(data, 0x3F); |
384 |
|
|
385 |
|
/* Transfer back the data -- Don't add data */ |
386 |
|
MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F); |
387 |
} |
} |
388 |
|
|
389 |
|
|
390 |
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
uint8_t |
391 |
|
MBTransQuantInter(const MBParam * const pParam, |
392 |
|
const FRAMEINFO * const frame, |
393 |
|
MACROBLOCK * const pMB, |
394 |
|
const uint32_t x_pos, |
395 |
|
const uint32_t y_pos, |
396 |
|
int16_t data[6 * 64], |
397 |
|
int16_t qcoeff[6 * 64]) |
398 |
|
{ |
399 |
|
uint8_t cbp; |
400 |
|
uint32_t limit; |
401 |
|
|
402 |
|
/* |
403 |
|
* There is no MBTrans8to16 for Inter block, that's done in motion compensation |
404 |
|
* already |
405 |
|
*/ |
406 |
|
|
407 |
|
/* Perform DCT (and field decision) */ |
408 |
|
MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); |
409 |
|
|
410 |
|
/* Set the limit threshold */ |
411 |
|
limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0); |
412 |
|
|
413 |
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
/* Quantize the block */ |
414 |
|
cbp = MBQuantInter(pParam, pMB, data, qcoeff, 0, limit); |
415 |
|
|
416 |
|
/* DeQuantize the block */ |
417 |
|
MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp); |
418 |
|
|
419 |
|
/* Perform inverse DCT*/ |
420 |
|
MBiDCT(data, cbp); |
421 |
|
|
422 |
|
/* Transfer back the data -- Add the data */ |
423 |
|
MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp); |
424 |
|
|
425 |
|
return(cbp); |
426 |
|
} |
427 |
|
|
428 |
|
uint8_t |
429 |
|
MBTransQuantInterBVOP(const MBParam * pParam, |
430 |
|
FRAMEINFO * frame, |
431 |
|
MACROBLOCK * pMB, |
432 |
|
const uint32_t x_pos, |
433 |
|
const uint32_t y_pos, |
434 |
|
int16_t data[6 * 64], |
435 |
|
int16_t qcoeff[6 * 64]) |
436 |
{ |
{ |
437 |
|
uint8_t cbp; |
438 |
|
uint32_t limit; |
439 |
|
|
440 |
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
/* |
441 |
|
* There is no MBTrans8to16 for Inter block, that's done in motion compensation |
442 |
|
* already |
443 |
|
*/ |
444 |
|
|
445 |
|
/* Perform DCT (and field decision) */ |
446 |
|
MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); |
447 |
|
|
448 |
|
/* Set the limit threshold */ |
449 |
|
limit = BVOP_TOOSMALL_LIMIT; |
450 |
|
|
451 |
|
/* Quantize the block */ |
452 |
|
cbp = MBQuantInter(pParam, pMB, data, qcoeff, 1, limit); |
453 |
|
|
454 |
|
/* |
455 |
|
* History comment: |
456 |
|
* We don't have to DeQuant, iDCT and Transfer back data for B-frames. |
457 |
|
* |
458 |
|
* BUT some plugins require the original frame to be passed so we have |
459 |
|
* to take care of that here |
460 |
|
*/ |
461 |
|
if((pParam->plugin_flags & XVID_REQORIGINAL)) { |
462 |
|
|
463 |
|
/* DeQuantize the block */ |
464 |
|
MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp); |
465 |
|
|
466 |
|
/* Perform inverse DCT*/ |
467 |
|
MBiDCT(data, cbp); |
468 |
|
|
469 |
|
/* Transfer back the data -- Add the data */ |
470 |
|
MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp); |
471 |
|
} |
472 |
|
|
473 |
|
return(cbp); |
474 |
|
} |
475 |
|
|
476 |
|
/* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ |
477 |
|
uint32_t |
478 |
|
MBFieldTest_c(int16_t data[6 * 64]) |
479 |
|
{ |
480 |
|
const uint8_t blocks[] = |
481 |
|
{ 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; |
482 |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
483 |
|
|
484 |
int frame = 0, field = 0; |
int frame = 0, field = 0; |
485 |
int i, j; |
int i, j; |
486 |
|
|
487 |
for (i=0 ; i<7 ; ++i) |
for (i = 0; i < 7; ++i) { |
488 |
{ |
for (j = 0; j < 8; ++j) { |
489 |
for (j=0 ; j<8 ; ++j) |
frame += |
490 |
{ |
abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
491 |
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
frame += |
492 |
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]); |
493 |
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
frame += |
494 |
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]); |
495 |
|
frame += |
496 |
|
abs(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
497 |
|
|
498 |
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
field += |
499 |
|
abs(data[blocks[i + 1] + lines[i + 1] + j] - |
500 |
data[blocks[i ] + lines[i ] + j]); |
data[blocks[i ] + lines[i ] + j]); |
501 |
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
field += |
502 |
|
abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
503 |
data[blocks[i ] + lines[i ] + 8 + j]); |
data[blocks[i ] + lines[i ] + 8 + j]); |
504 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
field += |
505 |
|
abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
506 |
data[blocks[i ] + 64 + lines[i ] + j]); |
data[blocks[i ] + 64 + lines[i ] + j]); |
507 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
field += |
508 |
|
abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
509 |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
510 |
} |
} |
511 |
} |
} |
512 |
|
|
513 |
if (frame > field) |
return (frame >= (field + 350)); |
|
{ |
|
|
MBFrameToField(data); |
|
|
} |
|
|
|
|
|
return (frame > field); |
|
514 |
} |
} |
515 |
|
|
516 |
|
|
519 |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
520 |
#define LINE(X,Y) &data[X*64 + Y*8] |
#define LINE(X,Y) &data[X*64 + Y*8] |
521 |
|
|
522 |
void MBFrameToField(int16_t data[6*64]) |
void |
523 |
|
MBFrameToField(int16_t data[6 * 64]) |
524 |
{ |
{ |
525 |
int16_t tmp[8]; |
int16_t tmp[8]; |
526 |
|
|