72 |
|
|
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 |
76 |
|
MBTransQuantIntra(const MBParam * pParam, |
77 |
FRAMEINFO * frame, |
FRAMEINFO * frame, |
78 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
79 |
const uint32_t x_pos, |
const uint32_t x_pos, |
80 |
const uint32_t y_pos, |
const uint32_t y_pos, |
81 |
int16_t data[6*64], |
int16_t data[6*64], |
82 |
int16_t qcoeff[6*64]) |
int16_t qcoeff[6*64]) |
|
|
|
83 |
{ |
{ |
84 |
|
|
85 |
uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
105 |
|
|
106 |
start_timer(); |
start_timer(); |
107 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
108 |
if ((frame->global_flags & XVID_INTERLACING)) |
if ((frame->global_flags & XVID_INTERLACING)) { |
|
{ |
|
109 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
110 |
} |
} |
111 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
112 |
|
|
113 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
114 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
115 |
|
|
116 |
start_timer(); |
start_timer(); |
117 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
118 |
stop_dct_timer(); |
stop_dct_timer(); |
119 |
|
|
120 |
if (pParam->m_quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) { |
|
{ |
|
121 |
start_timer(); |
start_timer(); |
122 |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
123 |
stop_quant_timer(); |
stop_quant_timer(); |
125 |
start_timer(); |
start_timer(); |
126 |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler); |
127 |
stop_iquant_timer(); |
stop_iquant_timer(); |
128 |
} |
} else { |
|
else |
|
|
{ |
|
129 |
start_timer(); |
start_timer(); |
130 |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler); |
131 |
stop_quant_timer(); |
stop_quant_timer(); |
140 |
stop_idct_timer(); |
stop_idct_timer(); |
141 |
} |
} |
142 |
|
|
143 |
if (pMB->field_dct) |
if (pMB->field_dct) { |
|
{ |
|
144 |
next_block = stride; |
next_block = stride; |
145 |
stride *= 2; |
stride *= 2; |
146 |
} |
} |
157 |
} |
} |
158 |
|
|
159 |
|
|
160 |
uint8_t MBTransQuantInter(const MBParam *pParam, |
uint8_t |
161 |
|
MBTransQuantInter(const MBParam * pParam, |
162 |
FRAMEINFO * frame, |
FRAMEINFO * frame, |
163 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
164 |
const uint32_t x_pos, const uint32_t y_pos, |
const uint32_t x_pos, |
165 |
|
const uint32_t y_pos, |
166 |
int16_t data[6*64], |
int16_t data[6*64], |
167 |
int16_t qcoeff[6*64]) |
int16_t qcoeff[6*64]) |
|
|
|
168 |
{ |
{ |
169 |
|
|
170 |
uint32_t stride = pParam->edged_width; |
uint32_t stride = pParam->edged_width; |
183 |
|
|
184 |
start_timer(); |
start_timer(); |
185 |
pMB->field_dct = 0; |
pMB->field_dct = 0; |
186 |
if ((frame->global_flags & XVID_INTERLACING)) |
if ((frame->global_flags & XVID_INTERLACING)) { |
|
{ |
|
187 |
pMB->field_dct = MBDecideFieldDCT(data); |
pMB->field_dct = MBDecideFieldDCT(data); |
188 |
} |
} |
189 |
stop_interlacing_timer(); |
stop_interlacing_timer(); |
190 |
|
|
191 |
for(i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) { |
|
{ |
|
192 |
/* |
/* |
193 |
* no need to transfer 8->16-bit |
* no need to transfer 8->16-bit |
194 |
* (this is performed already in motion compensation) |
* (this is performed already in motion compensation) |
197 |
fdct(&data[i*64]); |
fdct(&data[i*64]); |
198 |
stop_dct_timer(); |
stop_dct_timer(); |
199 |
|
|
200 |
if (pParam->m_quant_type == 0) |
if (pParam->m_quant_type == 0) { |
|
{ |
|
201 |
start_timer(); |
start_timer(); |
202 |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant); |
203 |
stop_quant_timer(); |
stop_quant_timer(); |
204 |
} |
} else { |
|
else |
|
|
{ |
|
205 |
start_timer(); |
start_timer(); |
206 |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant); |
207 |
stop_quant_timer(); |
stop_quant_timer(); |
209 |
|
|
210 |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
if(sum >= TOOSMALL_LIMIT) { // skip block ? |
211 |
|
|
212 |
if (pParam->m_quant_type == H263_QUANT) |
if (pParam->m_quant_type == H263_QUANT) { |
|
{ |
|
213 |
start_timer(); |
start_timer(); |
214 |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant_inter(&data[i*64], &qcoeff[i*64], iQuant); |
215 |
stop_iquant_timer(); |
stop_iquant_timer(); |
216 |
} |
} else { |
|
else |
|
|
{ |
|
217 |
start_timer(); |
start_timer(); |
218 |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant); |
219 |
stop_iquant_timer(); |
stop_iquant_timer(); |
227 |
} |
} |
228 |
} |
} |
229 |
|
|
230 |
if (pMB->field_dct) |
if (pMB->field_dct) { |
|
{ |
|
231 |
next_block = stride; |
next_block = stride; |
232 |
stride *= 2; |
stride *= 2; |
233 |
} |
} |
255 |
/* 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 */ |
256 |
|
|
257 |
|
|
258 |
uint32_t MBDecideFieldDCT(int16_t data[6*64]) |
uint32_t |
259 |
|
MBDecideFieldDCT(int16_t data[6 * 64]) |
260 |
{ |
{ |
261 |
|
|
262 |
const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64}; |
const uint8_t blocks[] = |
263 |
|
{ 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; |
264 |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48}; |
265 |
|
|
266 |
int frame = 0, field = 0; |
int frame = 0, field = 0; |
267 |
int i, j; |
int i, j; |
268 |
|
|
269 |
for (i=0 ; i<7 ; ++i) |
for (i = 0; i < 7; ++i) { |
270 |
{ |
for (j = 0; j < 8; ++j) { |
271 |
for (j=0 ; j<8 ; ++j) |
frame += |
272 |
{ |
ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
273 |
frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]); |
frame += |
274 |
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]); |
275 |
frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]); |
frame += |
276 |
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]); |
277 |
|
frame += |
278 |
|
ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
279 |
|
|
280 |
field += ABS(data[blocks[i+1] + lines[i+1] + j] -\ |
field += |
281 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + j] - |
282 |
data[blocks[i ] + lines[i ] + j]); |
data[blocks[i ] + lines[i ] + j]); |
283 |
field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\ |
field += |
284 |
|
ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
285 |
data[blocks[i ] + lines[i ] + 8 + j]); |
data[blocks[i ] + lines[i ] + 8 + j]); |
286 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\ |
field += |
287 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
288 |
data[blocks[i ] + 64 + lines[i ] + j]); |
data[blocks[i ] + 64 + lines[i ] + j]); |
289 |
field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\ |
field += |
290 |
|
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
291 |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
data[blocks[i ] + 64 + lines[i ] + 8 + j]); |
292 |
} |
} |
293 |
} |
} |
294 |
|
|
295 |
if (frame > field) |
if (frame > field) { |
|
{ |
|
296 |
MBFrameToField(data); |
MBFrameToField(data); |
297 |
} |
} |
298 |
|
|
305 |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
#define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) |
306 |
#define LINE(X,Y) &data[X*64 + Y*8] |
#define LINE(X,Y) &data[X*64 + Y*8] |
307 |
|
|
308 |
void MBFrameToField(int16_t data[6*64]) |
void |
309 |
|
MBFrameToField(int16_t data[6 * 64]) |
310 |
{ |
{ |
311 |
int16_t tmp[8]; |
int16_t tmp[8]; |
312 |
|
|