42 |
* * |
* * |
43 |
* Revision history: * |
* Revision history: * |
44 |
* * |
* * |
45 |
|
* 29.03.2002 interlacing speedup - used transfer strides instead of |
46 |
|
* manual field-to-frame conversion |
47 |
* 26.03.2002 interlacing support - moved transfers outside loops |
* 26.03.2002 interlacing support - moved transfers outside loops |
48 |
* 22.12.2001 get_dc_scaler() moved to common.h |
* 22.12.2001 get_dc_scaler() moved to common.h |
49 |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
* 19.11.2001 introduced coefficient thresholding (Isibaar) * |
51 |
* * |
* * |
52 |
******************************************************************************/ |
******************************************************************************/ |
53 |
|
|
54 |
|
#include <string.h> |
55 |
|
|
56 |
#include "../portab.h" |
#include "../portab.h" |
57 |
#include "mbfunctions.h" |
#include "mbfunctions.h" |
58 |
|
|
73 |
/* this isnt pretty, but its better than 20 ifdefs */ |
/* this isnt pretty, but its better than 20 ifdefs */ |
74 |
|
|
75 |
void MBTransQuantIntra(const MBParam *pParam, |
void 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[][64], |
int16_t data[6*64], |
81 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64]) |
|
IMAGE * const pCurrent) |
|
82 |
|
|
83 |
{ |
{ |
84 |
const uint32_t stride = pParam->edged_width; |
|
85 |
|
uint32_t stride = pParam->edged_width; |
86 |
|
uint32_t stride2 = stride / 2; |
87 |
|
uint32_t next_block = stride * 8; |
88 |
uint32_t i; |
uint32_t i; |
89 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
90 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
91 |
|
IMAGE * pCurrent = &frame->image; |
92 |
|
|
93 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
94 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
95 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
96 |
|
|
97 |
start_timer(); |
start_timer(); |
98 |
transfer_8to16copy(data[0], pY_Cur, stride); |
transfer_8to16copy(&data[0*64], pY_Cur, stride); |
99 |
transfer_8to16copy(data[1], pY_Cur + 8, stride); |
transfer_8to16copy(&data[1*64], pY_Cur + 8, stride); |
100 |
transfer_8to16copy(data[2], pY_Cur + 8 * stride, stride); |
transfer_8to16copy(&data[2*64], pY_Cur + next_block, stride); |
101 |
transfer_8to16copy(data[3], pY_Cur + 8 * stride + 8, stride); |
transfer_8to16copy(&data[3*64], pY_Cur + next_block + 8,stride); |
102 |
transfer_8to16copy(data[4], pU_Cur, stride / 2); |
transfer_8to16copy(&data[4*64], pU_Cur, stride2); |
103 |
transfer_8to16copy(data[5], pV_Cur, stride / 2); |
transfer_8to16copy(&data[5*64], pV_Cur, stride2); |
104 |
stop_transfer_timer(); |
stop_transfer_timer(); |
105 |
|
|
106 |
start_timer(); |
start_timer(); |
107 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
108 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING)) |
109 |
{ |
{ |
110 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
111 |
} |
} |
116 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
117 |
|
|
118 |
start_timer(); |
start_timer(); |
119 |
fdct(data[i]); |
fdct(&data[i*64]); |
120 |
stop_dct_timer(); |
stop_dct_timer(); |
121 |
|
|
122 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) |
123 |
{ |
{ |
124 |
start_timer(); |
start_timer(); |
125 |
quant_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
126 |
stop_quant_timer(); |
stop_quant_timer(); |
127 |
|
|
128 |
start_timer(); |
start_timer(); |
129 |
dequant_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
130 |
stop_iquant_timer(); |
stop_iquant_timer(); |
131 |
} |
} |
132 |
else |
else |
133 |
{ |
{ |
134 |
start_timer(); |
start_timer(); |
135 |
quant4_intra(qcoeff[i], data[i], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
136 |
stop_quant_timer(); |
stop_quant_timer(); |
137 |
|
|
138 |
start_timer(); |
start_timer(); |
139 |
dequant4_intra(data[i], qcoeff[i], iQuant, iDcScaler); |
dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
140 |
stop_iquant_timer(); |
stop_iquant_timer(); |
141 |
} |
} |
142 |
|
|
143 |
start_timer(); |
start_timer(); |
144 |
idct(data[i]); |
idct(&data[i*64]); |
145 |
stop_idct_timer(); |
stop_idct_timer(); |
146 |
} |
} |
147 |
|
|
|
start_timer(); |
|
148 |
if (pMB->field_dct) |
if (pMB->field_dct) |
149 |
{ |
{ |
150 |
MBFieldToFrame(data); |
next_block = stride; |
151 |
|
stride *= 2; |
152 |
} |
} |
|
stop_interlacing_timer(); |
|
153 |
|
|
154 |
start_timer(); |
start_timer(); |
155 |
transfer_16to8copy(pY_Cur, data[0], stride); |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
156 |
transfer_16to8copy(pY_Cur + 8, data[1], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
157 |
transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
158 |
transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride); |
transfer_16to8copy(pY_Cur + next_block + 8, &data[3*64], stride); |
159 |
transfer_16to8copy(pU_Cur, data[4], stride / 2); |
transfer_16to8copy(pU_Cur, &data[4*64], stride2); |
160 |
transfer_16to8copy(pV_Cur, data[5], stride / 2); |
transfer_16to8copy(pV_Cur, &data[5*64], stride2); |
161 |
stop_transfer_timer(); |
stop_transfer_timer(); |
162 |
|
|
163 |
} |
} |
164 |
|
|
165 |
|
|
166 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t MBTransQuantInter(const MBParam *pParam, |
167 |
|
FRAMEINFO * frame, |
168 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
169 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, const uint32_t y_pos, |
170 |
int16_t data[][64], |
int16_t data[6*64], |
171 |
int16_t qcoeff[][64], |
int16_t qcoeff[6*64]) |
|
IMAGE * const pCurrent) |
|
172 |
|
|
173 |
{ |
{ |
174 |
const uint32_t stride = pParam->edged_width; |
|
175 |
|
uint32_t stride = pParam->edged_width; |
176 |
|
uint32_t stride2 = stride / 2; |
177 |
|
uint32_t next_block = stride * 8; |
178 |
uint32_t i; |
uint32_t i; |
179 |
uint32_t iQuant = pParam->quant; |
uint32_t iQuant = frame->quant; |
180 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
181 |
uint8_t cbp = 0; |
uint8_t cbp = 0; |
182 |
uint32_t sum; |
uint32_t sum; |
183 |
|
IMAGE * pCurrent = &frame->image; |
184 |
|
|
185 |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
186 |
pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
187 |
pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); |
188 |
|
|
189 |
start_timer(); |
start_timer(); |
190 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
191 |
if (pParam->global_flags & XVID_INTERLACING) |
if ((frame->global_flags & XVID_INTERLACING)) |
192 |
{ |
{ |
193 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
194 |
} |
} |
197 |
for(i = 0; i < 6; i++) |
for(i = 0; i < 6; i++) |
198 |
{ |
{ |
199 |
/* |
/* |
200 |
no need to transfer 8->16-bit |
* no need to transfer 8->16-bit |
201 |
(this is performed already in motion compensation) |
* (this is performed already in motion compensation) |
202 |
*/ |
*/ |
203 |
start_timer(); |
start_timer(); |
204 |
fdct(data[i]); |
fdct(&data[i*64]); |
205 |
stop_dct_timer(); |
stop_dct_timer(); |
206 |
|
|
207 |
if (pParam->quant_type == 0) |
if (pParam->m_quant_type == 0) |
208 |
{ |
{ |
209 |
start_timer(); |
start_timer(); |
210 |
sum = quant_inter(qcoeff[i], data[i], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
211 |
stop_quant_timer(); |
stop_quant_timer(); |
212 |
} |
} |
213 |
else |
else |
214 |
{ |
{ |
215 |
start_timer(); |
start_timer(); |
216 |
sum = quant4_inter(qcoeff[i], data[i], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
217 |
stop_quant_timer(); |
stop_quant_timer(); |
218 |
} |
} |
219 |
|
|
220 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
221 |
|
|
222 |
if (pParam->quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) |
223 |
{ |
{ |
224 |
start_timer(); |
start_timer(); |
225 |
dequant_inter(data[i], qcoeff[i], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
226 |
stop_iquant_timer(); |
stop_iquant_timer(); |
227 |
} |
} |
228 |
else |
else |
229 |
{ |
{ |
230 |
start_timer(); |
start_timer(); |
231 |
dequant4_inter(data[i], qcoeff[i], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
232 |
stop_iquant_timer(); |
stop_iquant_timer(); |
233 |
} |
} |
234 |
|
|
235 |
cbp |= 1 << (5 - i); |
cbp |= 1 << (5 - i); |
236 |
|
|
237 |
start_timer(); |
start_timer(); |
238 |
idct(data[i]); |
idct(&data[i*64]); |
239 |
stop_idct_timer(); |
stop_idct_timer(); |
240 |
} |
} |
241 |
} |
} |
242 |
|
|
|
start_timer(); |
|
243 |
if (pMB->field_dct) |
if (pMB->field_dct) |
244 |
{ |
{ |
245 |
MBFieldToFrame(data); |
next_block = stride; |
246 |
|
stride *= 2; |
247 |
} |
} |
|
stop_interlacing_timer(); |
|
248 |
|
|
249 |
start_timer(); |
start_timer(); |
250 |
if (cbp & 32) |
if (cbp & 32) |
251 |
transfer_16to8add(pY_Cur, data[0], stride); |
transfer_16to8add(pY_Cur, &data[0*64], stride); |
252 |
if (cbp & 16) |
if (cbp & 16) |
253 |
transfer_16to8add(pY_Cur + 8, data[1], stride); |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
254 |
if (cbp & 8) |
if (cbp & 8) |
255 |
transfer_16to8add(pY_Cur + 8 * stride, data[2], stride); |
transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
256 |
if (cbp & 4) |
if (cbp & 4) |
257 |
transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride); |
transfer_16to8add(pY_Cur + next_block + 8, &data[3*64], stride); |
258 |
if (cbp & 2) |
if (cbp & 2) |
259 |
transfer_16to8add(pU_Cur, data[4], stride / 2); |
transfer_16to8add(pU_Cur, &data[4*64], stride2); |
260 |
if (cbp & 1) |
if (cbp & 1) |
261 |
transfer_16to8add(pV_Cur, data[5], stride / 2); |
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
262 |
stop_transfer_timer(); |
stop_transfer_timer(); |
263 |
|
|
264 |
return cbp; |
return cbp; |
265 |
|
|
266 |
} |
} |
267 |
|
|
268 |
|
|
269 |
/* 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 */ |
270 |
|
|
|
#define ABS(X) (X)<0 ? -(X) : (X) |
|
271 |
|
|
272 |
uint32_t MBDecideFieldDCT(int16_t data[][64]) |
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
273 |
{ |
{ |
274 |
const uint8_t blocks[] = {0, 0, 0, 0, 2, 2, 2, 2}; |
|
275 |
|
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
276 |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
277 |
|
|
278 |
int frame = 0, field = 0; |
int frame = 0, field = 0; |
282 |
{ |
{ |
283 |
for (j=0 ; j<8 ; ++j) |
for (j=0 ; j<8 ; ++j) |
284 |
{ |
{ |
285 |
frame += ABS(data[0][(i+1)*8 + j] - data[0][i*8 + j]); |
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
286 |
frame += ABS(data[1][(i+1)*8 + j] - data[1][i*8 + j]); |
frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]); |
287 |
frame += ABS(data[2][(i+1)*8 + j] - data[2][i*8 + j]); |
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
288 |
frame += ABS(data[3][(i+1)*8 + j] - data[3][i*8 + j]); |
frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]); |
289 |
|
|
290 |
field += ABS(data[blocks[i+1]][lines[i+1] + j] - data[blocks[i]][lines[i] + j]); |
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
291 |
field += ABS(data[blocks[i+1]][lines[i+1] + 8 + j] - data[blocks[i]][lines[i] + 8 + j]); |
data[blocks[i ] + lines[i ] + j]); |
292 |
field += ABS(data[blocks[i+1]+1][lines[i+1] + j] - data[blocks[i]+1][lines[i] + j]); |
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
293 |
field += ABS(data[blocks[i+1]+1][lines[i+1] + 8 + j] - data[blocks[i]+1][lines[i] + 8 + j]); |
data[blocks[i ] + lines[i ] + 8 + j]); |
294 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
295 |
|
data[blocks[i ] + 64 + lines[i ] + j]); |
296 |
|
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
297 |
|
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
298 |
} |
} |
299 |
} |
} |
300 |
|
|
310 |
/* deinterlace Y blocks vertically */ |
/* deinterlace Y blocks vertically */ |
311 |
|
|
312 |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
313 |
#define LINE(X,Y) &data[X][Y*8] |
#define LINE(X,Y) &data[X*64 + Y*8] |
314 |
|
|
315 |
void MBFrameToField(int16_t data[][64]) |
void MBFrameToField(int16_t data[6*64]) |
316 |
{ |
{ |
317 |
int16_t tmp[8]; |
int16_t tmp[8]; |
318 |
|
|
372 |
MOVLINE(LINE(3,5), LINE(3,3)); |
MOVLINE(LINE(3,5), LINE(3,3)); |
373 |
MOVLINE(LINE(3,3), tmp); |
MOVLINE(LINE(3,3), tmp); |
374 |
} |
} |
|
|
|
|
|
|
|
/* interlace Y blocks vertically */ |
|
|
|
|
|
void MBFieldToFrame(int16_t data[][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); |
|
|
} |
|