[cvs] / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/utils/mbtransquant.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11.2.6 - (view) (download)

1 : Isibaar 1.1 /******************************************************************************
2 :     * *
3 :     * This file is part of XviD, a free MPEG-4 video encoder/decoder *
4 :     * *
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 *
7 :     * software module in hardware or software products are advised that its *
8 :     * use may infringe existing patents or copyrights, and any such use *
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 *
11 :     * companies, will have no liability for use of this software or *
12 :     * modifications or derivatives thereof. *
13 :     * *
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 *
16 :     * the Free Software Foundation; either version 2 of the License, or *
17 :     * (at your option) any later version. *
18 :     * *
19 :     * XviD is distributed in the hope that it will be useful, but *
20 :     * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 :     * GNU General Public License for more details. *
23 :     * *
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 *
26 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
27 :     * *
28 :     ******************************************************************************/
29 :    
30 :     /******************************************************************************
31 :     * *
32 :     * mbtransquant.c *
33 :     * *
34 :     * Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> *
35 :     * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> *
36 :     * *
37 :     * For more information visit the XviD homepage: http://www.xvid.org *
38 :     * *
39 :     ******************************************************************************/
40 :    
41 :     /******************************************************************************
42 :     * *
43 :     * Revision history: *
44 :     * *
45 : Isibaar 1.9 * 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 *
48 :     * 22.12.2001 get_dc_scaler() moved to common.h *
49 : Isibaar 1.1 * 19.11.2001 introduced coefficient thresholding (Isibaar) *
50 :     * 17.11.2001 initial version *
51 :     * *
52 :     ******************************************************************************/
53 :    
54 : edgomez 1.3 #include <string.h>
55 :    
56 : Isibaar 1.1 #include "../portab.h"
57 :     #include "mbfunctions.h"
58 :    
59 :     #include "../global.h"
60 :     #include "mem_transfer.h"
61 :     #include "timer.h"
62 :     #include "../dct/fdct.h"
63 :     #include "../dct/idct.h"
64 :     #include "../quant/quant_mpeg4.h"
65 :     #include "../quant/quant_h263.h"
66 :     #include "../encoder.h"
67 :    
68 : suxen_drol 1.11.2.6 #include "../image/reduced.h"
69 :    
70 : h 1.11.2.2 MBFIELDTEST_PTR MBFieldTest;
71 :    
72 : Isibaar 1.1 #define MIN(X, Y) ((X)<(Y)?(X):(Y))
73 :     #define MAX(X, Y) ((X)>(Y)?(X):(Y))
74 :    
75 : syskin 1.11.2.4 #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */
76 : Isibaar 1.1
77 : edgomez 1.7 void
78 :     MBTransQuantIntra(const MBParam * pParam,
79 :     FRAMEINFO * frame,
80 :     MACROBLOCK * pMB,
81 :     const uint32_t x_pos,
82 :     const uint32_t y_pos,
83 :     int16_t data[6 * 64],
84 :     int16_t qcoeff[6 * 64])
85 : Isibaar 1.1 {
86 : edgomez 1.3
87 : h 1.4 uint32_t stride = pParam->edged_width;
88 :     uint32_t stride2 = stride / 2;
89 : suxen_drol 1.11.2.6 uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
90 : Isibaar 1.1 uint32_t i;
91 : suxen_drol 1.6 uint32_t iQuant = frame->quant;
92 : Isibaar 1.1 uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
93 : edgomez 1.7 IMAGE *pCurrent = &frame->image;
94 : Isibaar 1.1
95 : h 1.2 start_timer();
96 : suxen_drol 1.11.2.6 if ((frame->global_flags & XVID_REDUCED))
97 :     {
98 :     pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
99 :     pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
100 :     pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
101 :    
102 :     filter_18x18_to_8x8(&data[0 * 64], pY_Cur, stride);
103 :     filter_18x18_to_8x8(&data[1 * 64], pY_Cur + 16, stride);
104 :     filter_18x18_to_8x8(&data[2 * 64], pY_Cur + next_block, stride);
105 :     filter_18x18_to_8x8(&data[3 * 64], pY_Cur + next_block + 16, stride);
106 :     filter_18x18_to_8x8(&data[4 * 64], pU_Cur, stride2);
107 :     filter_18x18_to_8x8(&data[5 * 64], pV_Cur, stride2);
108 :     }else{
109 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
110 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
111 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
112 :    
113 :     transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
114 :     transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
115 :     transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
116 :     transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
117 :     transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
118 :     transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
119 :     }
120 : h 1.2 stop_transfer_timer();
121 :    
122 : suxen_drol 1.11.2.6 /* XXX: rrv+interlacing is buggy */
123 : h 1.2 start_timer();
124 :     pMB->field_dct = 0;
125 : h 1.11 if ((frame->global_flags & XVID_INTERLACING) &&
126 :     (x_pos>0) && (x_pos<pParam->mb_width-1) &&
127 :     (y_pos>0) && (y_pos<pParam->mb_height-1)) {
128 : h 1.2 pMB->field_dct = MBDecideFieldDCT(data);
129 :     }
130 :     stop_interlacing_timer();
131 :    
132 : edgomez 1.7 for (i = 0; i < 6; i++) {
133 : Isibaar 1.1 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
134 :    
135 :     start_timer();
136 : edgomez 1.7 fdct(&data[i * 64]);
137 : Isibaar 1.1 stop_dct_timer();
138 :    
139 : edgomez 1.7 if (pParam->m_quant_type == H263_QUANT) {
140 : Isibaar 1.1 start_timer();
141 : edgomez 1.7 quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
142 : Isibaar 1.1 stop_quant_timer();
143 : edgomez 1.7 } else {
144 : Isibaar 1.1 start_timer();
145 : edgomez 1.7 quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
146 : Isibaar 1.1 stop_quant_timer();
147 : suxen_drol 1.11.2.6 }
148 :    
149 :     /* speedup: dont decode when encoding only ivops */
150 :     if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
151 :     {
152 :     if (pParam->m_quant_type == H263_QUANT) {
153 :     start_timer();
154 :     dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
155 :     stop_iquant_timer();
156 :     } else {
157 :     start_timer();
158 :     dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
159 :     stop_iquant_timer();
160 :     }
161 : Isibaar 1.1
162 :     start_timer();
163 : suxen_drol 1.11.2.6 idct(&data[i * 64]);
164 :     stop_idct_timer();
165 : Isibaar 1.1 }
166 : edgomez 1.3 }
167 : h 1.2
168 : suxen_drol 1.11.2.6 /* speedup: dont decode when encoding only ivops */
169 :     if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
170 :     {
171 :    
172 :     if (pMB->field_dct) {
173 :     next_block = stride;
174 :     stride *= 2;
175 :     }
176 : Isibaar 1.1
177 : suxen_drol 1.11.2.6 start_timer();
178 :     if ((frame->global_flags & XVID_REDUCED))
179 :     {
180 :     copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
181 :     copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
182 :     copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
183 :     copy_upsampled_8x8_16to8(pY_Cur + next_block + 16, &data[3 * 64], stride);
184 :     copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
185 :     copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
186 :    
187 :     }else{
188 :     transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
189 :     transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
190 :     transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
191 :     transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
192 :     transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
193 :     transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
194 :     }
195 :     stop_transfer_timer();
196 :     }
197 : edgomez 1.3
198 : Isibaar 1.1 }
199 :    
200 :    
201 : edgomez 1.7 uint8_t
202 :     MBTransQuantInter(const MBParam * pParam,
203 :     FRAMEINFO * frame,
204 :     MACROBLOCK * pMB,
205 :     const uint32_t x_pos,
206 :     const uint32_t y_pos,
207 :     int16_t data[6 * 64],
208 :     int16_t qcoeff[6 * 64])
209 : Isibaar 1.1 {
210 : edgomez 1.3
211 : h 1.4 uint32_t stride = pParam->edged_width;
212 :     uint32_t stride2 = stride / 2;
213 : suxen_drol 1.11.2.6 uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
214 : edgomez 1.3 uint32_t i;
215 : suxen_drol 1.6 uint32_t iQuant = frame->quant;
216 : Isibaar 1.1 uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
217 : edgomez 1.3 uint8_t cbp = 0;
218 : Isibaar 1.1 uint32_t sum;
219 : edgomez 1.7 IMAGE *pCurrent = &frame->image;
220 :    
221 : suxen_drol 1.11.2.6 if ((frame->global_flags & XVID_REDUCED))
222 :     {
223 :     pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
224 :     pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
225 :     pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
226 :     }else{
227 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
228 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
229 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
230 :     }
231 : Isibaar 1.1
232 : h 1.2 start_timer();
233 :     pMB->field_dct = 0;
234 : h 1.11 if ((frame->global_flags & XVID_INTERLACING) &&
235 :     (x_pos>0) && (x_pos<pParam->mb_width-1) &&
236 :     (y_pos>0) && (y_pos<pParam->mb_height-1)) {
237 : h 1.2 pMB->field_dct = MBDecideFieldDCT(data);
238 :     }
239 :     stop_interlacing_timer();
240 :    
241 : edgomez 1.7 for (i = 0; i < 6; i++) {
242 : Isibaar 1.11.2.5 uint32_t increase_limit = (iQuant == 1) ? 1 : 0;
243 :    
244 : Isibaar 1.1 /*
245 : edgomez 1.3 * no need to transfer 8->16-bit
246 :     * (this is performed already in motion compensation)
247 :     */
248 : Isibaar 1.1 start_timer();
249 : edgomez 1.7 fdct(&data[i * 64]);
250 : Isibaar 1.1 stop_dct_timer();
251 :    
252 : edgomez 1.7 if (pParam->m_quant_type == 0) {
253 : Isibaar 1.1 start_timer();
254 : edgomez 1.7 sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
255 : Isibaar 1.1 stop_quant_timer();
256 : edgomez 1.7 } else {
257 : Isibaar 1.1 start_timer();
258 : edgomez 1.7 sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
259 : Isibaar 1.1 stop_quant_timer();
260 :     }
261 :    
262 : Isibaar 1.11.2.5 if ((sum >= TOOSMALL_LIMIT + increase_limit) || (qcoeff[i*64] != 0) ||
263 : Isibaar 1.9 (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
264 : Isibaar 1.1
265 : edgomez 1.7 if (pParam->m_quant_type == H263_QUANT) {
266 : Isibaar 1.1 start_timer();
267 : edgomez 1.7 dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
268 : Isibaar 1.1 stop_iquant_timer();
269 : edgomez 1.7 } else {
270 : Isibaar 1.1 start_timer();
271 : edgomez 1.7 dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
272 : Isibaar 1.1 stop_iquant_timer();
273 :     }
274 :    
275 :     cbp |= 1 << (5 - i);
276 :    
277 :     start_timer();
278 : edgomez 1.7 idct(&data[i * 64]);
279 : Isibaar 1.1 stop_idct_timer();
280 : h 1.2 }
281 :     }
282 :    
283 : edgomez 1.7 if (pMB->field_dct) {
284 : h 1.4 next_block = stride;
285 :     stride *= 2;
286 : h 1.2 }
287 :    
288 :     start_timer();
289 : suxen_drol 1.11.2.6 if ((frame->global_flags & XVID_REDUCED))
290 :     {
291 :     if (cbp & 32)
292 :     add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
293 :     if (cbp & 16)
294 :     add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
295 :     if (cbp & 8)
296 :     add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
297 :     if (cbp & 4)
298 :     add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
299 :     if (cbp & 2)
300 :     add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
301 :     if (cbp & 1)
302 :     add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
303 :     }else{
304 :     if (cbp & 32)
305 :     transfer_16to8add(pY_Cur, &data[0 * 64], stride);
306 :     if (cbp & 16)
307 :     transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
308 :     if (cbp & 8)
309 :     transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
310 :     if (cbp & 4)
311 :     transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
312 :     if (cbp & 2)
313 :     transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
314 :     if (cbp & 1)
315 :     transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
316 :     }
317 : h 1.2 stop_transfer_timer();
318 :    
319 : edgomez 1.3 return cbp;
320 :    
321 : h 1.2 }
322 :    
323 : chl 1.8 void
324 :     MBTransQuantIntra2(const MBParam * pParam,
325 :     FRAMEINFO * frame,
326 :     MACROBLOCK * pMB,
327 :     const uint32_t x_pos,
328 :     const uint32_t y_pos,
329 :     int16_t data[6 * 64],
330 :     int16_t qcoeff[6 * 64])
331 :     {
332 :     MBTrans(pParam,frame,pMB,x_pos,y_pos,data);
333 :     MBfDCT(pParam,frame,pMB,data);
334 :     MBQuantIntra(pParam,frame,pMB,data,qcoeff);
335 :     MBDeQuantIntra(pParam,frame->quant,data,qcoeff);
336 :     MBiDCT(data,0x3F);
337 :     MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F);
338 :     }
339 :    
340 :    
341 :     uint8_t
342 :     MBTransQuantInter2(const MBParam * pParam,
343 :     FRAMEINFO * frame,
344 :     MACROBLOCK * pMB,
345 :     const uint32_t x_pos,
346 :     const uint32_t y_pos,
347 :     int16_t data[6 * 64],
348 :     int16_t qcoeff[6 * 64])
349 :     {
350 :     uint8_t cbp;
351 :    
352 :     /* there is no MBTrans for Inter block, that's done in motion compensation already */
353 :    
354 :     MBfDCT(pParam,frame,pMB,data);
355 :     cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);
356 :     MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp);
357 :     MBiDCT(data,cbp);
358 :     MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp);
359 :    
360 :     return cbp;
361 :     }
362 :    
363 :     uint8_t
364 :     MBTransQuantInterBVOP(const MBParam * pParam,
365 :     FRAMEINFO * frame,
366 :     MACROBLOCK * pMB,
367 :     int16_t data[6 * 64],
368 :     int16_t qcoeff[6 * 64])
369 :     {
370 :     uint8_t cbp;
371 :    
372 :     /* there is no MBTrans for Inter block, that's done in motion compensation already */
373 :    
374 :     MBfDCT(pParam,frame,pMB,data);
375 :     cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);
376 :    
377 :     /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */
378 :    
379 :     return cbp;
380 :     }
381 :    
382 :    
383 :     void
384 :     MBfDCT(const MBParam * pParam,
385 :     FRAMEINFO * frame,
386 :     MACROBLOCK * pMB,
387 :     int16_t data[6 * 64])
388 :     {
389 :     int i;
390 :    
391 :     start_timer();
392 :     pMB->field_dct = 0;
393 :     if ((frame->global_flags & XVID_INTERLACING)) {
394 :     pMB->field_dct = MBDecideFieldDCT(data);
395 :     }
396 :     stop_interlacing_timer();
397 :    
398 :     for (i = 0; i < 6; i++) {
399 :     start_timer();
400 :     fdct(&data[i * 64]);
401 :     stop_dct_timer();
402 :     }
403 :     }
404 :    
405 :     void
406 :     MBQuantDeQuantIntra(const MBParam * pParam,
407 :     FRAMEINFO * frame,
408 :     MACROBLOCK * pMB,
409 :     int16_t qcoeff[6 * 64],
410 :     int16_t data[6*64])
411 :     {
412 :     int i;
413 :     int iQuant = frame->quant;
414 :    
415 :     start_timer();
416 :     pMB->field_dct = 0;
417 :     if ((frame->global_flags & XVID_INTERLACING)) {
418 :     pMB->field_dct = MBDecideFieldDCT(data);
419 :     }
420 :     stop_interlacing_timer();
421 :    
422 :     for (i = 0; i < 6; i++) {
423 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
424 :    
425 :     if (pParam->m_quant_type == H263_QUANT) {
426 :     start_timer();
427 :     quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
428 :     stop_quant_timer();
429 :    
430 :     start_timer();
431 :     dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
432 :     stop_iquant_timer();
433 :     } else {
434 :     start_timer();
435 :     quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
436 :     stop_quant_timer();
437 :    
438 :     start_timer();
439 :     dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
440 :     stop_iquant_timer();
441 :     }
442 :     }
443 :     }
444 :    
445 :     void
446 :     MBQuantIntra(const MBParam * pParam,
447 :     FRAMEINFO * frame,
448 :     MACROBLOCK *pMB,
449 :     int16_t qcoeff[6 * 64],
450 :     int16_t data[6*64])
451 :     {
452 :     int i;
453 :     int iQuant = frame->quant;
454 :    
455 :     start_timer();
456 :     pMB->field_dct = 0;
457 :     if ((frame->global_flags & XVID_INTERLACING)) {
458 :     pMB->field_dct = MBDecideFieldDCT(data);
459 :     }
460 :     stop_interlacing_timer();
461 :    
462 :     for (i = 0; i < 6; i++) {
463 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
464 :    
465 :     if (pParam->m_quant_type == H263_QUANT) {
466 :     start_timer();
467 :     quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
468 :     stop_quant_timer();
469 :     } else {
470 :     start_timer();
471 :     quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
472 :     stop_quant_timer();
473 :     }
474 :     }
475 :     }
476 :    
477 :     void
478 :     MBDeQuantIntra(const MBParam * pParam,
479 :     const int iQuant,
480 :     int16_t qcoeff[6 * 64],
481 :     int16_t data[6*64])
482 :     {
483 :     int i;
484 :    
485 :     for (i = 0; i < 6; i++) {
486 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
487 :    
488 :     if (pParam->m_quant_type == H263_QUANT) {
489 :     start_timer();
490 :     dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
491 :     stop_iquant_timer();
492 :     } else {
493 :     start_timer();
494 :     dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
495 :     stop_iquant_timer();
496 :     }
497 :     }
498 :     }
499 :    
500 :     uint8_t
501 :     MBQuantInter(const MBParam * pParam,
502 :     const int iQuant,
503 :     int16_t data[6 * 64],
504 :     int16_t qcoeff[6 * 64])
505 :     {
506 :    
507 :     int i;
508 :     uint8_t cbp = 0;
509 :     int sum;
510 :    
511 :     for (i = 0; i < 6; i++) {
512 :    
513 :     if (pParam->m_quant_type == 0) {
514 :     start_timer();
515 :     sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
516 :     stop_quant_timer();
517 :     } else {
518 :     start_timer();
519 :     sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
520 :     stop_quant_timer();
521 :     }
522 :    
523 :     if (sum >= TOOSMALL_LIMIT) { // skip block ?
524 :     cbp |= 1 << (5 - i);
525 :     }
526 :     }
527 :     return cbp;
528 :     }
529 :    
530 :     void
531 :     MBDeQuantInter( const MBParam * pParam,
532 :     const int iQuant,
533 :     int16_t data[6 * 64],
534 :     int16_t qcoeff[6 * 64],
535 :     const uint8_t cbp)
536 :     {
537 :     int i;
538 :    
539 :     for (i = 0; i < 6; i++) {
540 :     if (cbp & (1 << (5 - i)))
541 :     {
542 :     if (pParam->m_quant_type == H263_QUANT) {
543 :     start_timer();
544 :     dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
545 :     stop_iquant_timer();
546 :     } else {
547 :     start_timer();
548 :     dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
549 :     stop_iquant_timer();
550 :     }
551 :     }
552 :     }
553 :     }
554 :    
555 :     void
556 :     MBiDCT( int16_t data[6 * 64],
557 :     const uint8_t cbp)
558 :     {
559 :     int i;
560 :    
561 :     for (i = 0; i < 6; i++) {
562 :     if (cbp & (1 << (5 - i)))
563 :     {
564 :     start_timer();
565 :     idct(&data[i * 64]);
566 :     stop_idct_timer();
567 :    
568 :     }
569 :     }
570 :     }
571 :    
572 :    
573 :     void
574 :     MBTrans(const MBParam * pParam,
575 :     FRAMEINFO * frame,
576 :     MACROBLOCK * pMB,
577 :     const uint32_t x_pos,
578 :     const uint32_t y_pos,
579 :     int16_t data[6 * 64])
580 :     {
581 :     uint32_t stride = pParam->edged_width;
582 :     uint32_t stride2 = stride / 2;
583 :     uint32_t next_block = stride * 8;
584 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
585 :     IMAGE *pCurrent = &frame->image;
586 :    
587 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
588 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
589 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
590 :    
591 :     start_timer();
592 :     transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
593 :     transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
594 :     transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
595 :     transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
596 :     transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
597 :     transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
598 :     stop_transfer_timer();
599 :     }
600 :    
601 :     void
602 :     MBTransAdd(const MBParam * pParam,
603 :     FRAMEINFO * frame,
604 :     MACROBLOCK * pMB,
605 :     const uint32_t x_pos,
606 :     const uint32_t y_pos,
607 :     int16_t data[6 * 64],
608 :     const uint8_t cbp)
609 :     {
610 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
611 :     uint32_t stride = pParam->edged_width;
612 :     uint32_t stride2 = stride / 2;
613 :     uint32_t next_block = stride * 8;
614 :     IMAGE *pCurrent = &frame->image;
615 :    
616 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
617 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
618 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
619 :    
620 :     if (pMB->field_dct) {
621 :     next_block = stride;
622 :     stride *= 2;
623 :     }
624 :    
625 :     start_timer();
626 :     if (cbp & 32)
627 :     transfer_16to8add(pY_Cur, &data[0 * 64], stride);
628 :     if (cbp & 16)
629 :     transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
630 :     if (cbp & 8)
631 :     transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
632 :     if (cbp & 4)
633 :     transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
634 :     if (cbp & 2)
635 :     transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
636 :     if (cbp & 1)
637 :     transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
638 :     stop_transfer_timer();
639 :     }
640 :    
641 :    
642 : h 1.2
643 : h 1.11.2.2 /* permute block and return field dct choice */
644 : h 1.2
645 : Isibaar 1.1
646 : edgomez 1.7 uint32_t
647 :     MBDecideFieldDCT(int16_t data[6 * 64])
648 : h 1.2 {
649 : h 1.11.2.2 uint32_t field = MBFieldTest(data);
650 :    
651 :     if (field) {
652 :     MBFrameToField(data);
653 :     }
654 :    
655 :     return field;
656 :     }
657 :    
658 : edgomez 1.3
659 : h 1.11.2.2 /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
660 :    
661 :     uint32_t
662 :     MBFieldTest_c(int16_t data[6 * 64])
663 :     {
664 : edgomez 1.7 const uint8_t blocks[] =
665 :     { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
666 :     const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
667 : h 1.2
668 :     int frame = 0, field = 0;
669 :     int i, j;
670 :    
671 : edgomez 1.7 for (i = 0; i < 7; ++i) {
672 :     for (j = 0; j < 8; ++j) {
673 :     frame +=
674 :     ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
675 :     frame +=
676 :     ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
677 :     frame +=
678 :     ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]);
679 :     frame +=
680 :     ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
681 :    
682 :     field +=
683 :     ABS(data[blocks[i + 1] + lines[i + 1] + j] -
684 :     data[blocks[i] + lines[i] + j]);
685 :     field +=
686 :     ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
687 :     data[blocks[i] + lines[i] + 8 + j]);
688 :     field +=
689 :     ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
690 :     data[blocks[i] + 64 + lines[i] + j]);
691 :     field +=
692 :     ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
693 :     data[blocks[i] + 64 + lines[i] + 8 + j]);
694 : Isibaar 1.1 }
695 :     }
696 : h 1.2
697 : h 1.11.2.3 return (frame >= (field + 350));
698 : h 1.2 }
699 :    
700 :    
701 :     /* deinterlace Y blocks vertically */
702 :    
703 :     #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
704 : edgomez 1.3 #define LINE(X,Y) &data[X*64 + Y*8]
705 : h 1.2
706 : edgomez 1.7 void
707 :     MBFrameToField(int16_t data[6 * 64])
708 : h 1.2 {
709 :     int16_t tmp[8];
710 :    
711 :     /* left blocks */
712 :    
713 :     // 1=2, 2=4, 4=8, 8=1
714 : edgomez 1.7 MOVLINE(tmp, LINE(0, 1));
715 :     MOVLINE(LINE(0, 1), LINE(0, 2));
716 :     MOVLINE(LINE(0, 2), LINE(0, 4));
717 :     MOVLINE(LINE(0, 4), LINE(2, 0));
718 :     MOVLINE(LINE(2, 0), tmp);
719 : h 1.2
720 :     // 3=6, 6=12, 12=9, 9=3
721 : edgomez 1.7 MOVLINE(tmp, LINE(0, 3));
722 :     MOVLINE(LINE(0, 3), LINE(0, 6));
723 :     MOVLINE(LINE(0, 6), LINE(2, 4));
724 :     MOVLINE(LINE(2, 4), LINE(2, 1));
725 :     MOVLINE(LINE(2, 1), tmp);
726 : h 1.2
727 :     // 5=10, 10=5
728 : edgomez 1.7 MOVLINE(tmp, LINE(0, 5));
729 :     MOVLINE(LINE(0, 5), LINE(2, 2));
730 :     MOVLINE(LINE(2, 2), tmp);
731 : h 1.2
732 :     // 7=14, 14=13, 13=11, 11=7
733 : edgomez 1.7 MOVLINE(tmp, LINE(0, 7));
734 :     MOVLINE(LINE(0, 7), LINE(2, 6));
735 :     MOVLINE(LINE(2, 6), LINE(2, 5));
736 :     MOVLINE(LINE(2, 5), LINE(2, 3));
737 :     MOVLINE(LINE(2, 3), tmp);
738 : h 1.2
739 :     /* right blocks */
740 :    
741 :     // 1=2, 2=4, 4=8, 8=1
742 : edgomez 1.7 MOVLINE(tmp, LINE(1, 1));
743 :     MOVLINE(LINE(1, 1), LINE(1, 2));
744 :     MOVLINE(LINE(1, 2), LINE(1, 4));
745 :     MOVLINE(LINE(1, 4), LINE(3, 0));
746 :     MOVLINE(LINE(3, 0), tmp);
747 : h 1.2
748 :     // 3=6, 6=12, 12=9, 9=3
749 : edgomez 1.7 MOVLINE(tmp, LINE(1, 3));
750 :     MOVLINE(LINE(1, 3), LINE(1, 6));
751 :     MOVLINE(LINE(1, 6), LINE(3, 4));
752 :     MOVLINE(LINE(3, 4), LINE(3, 1));
753 :     MOVLINE(LINE(3, 1), tmp);
754 : h 1.2
755 :     // 5=10, 10=5
756 : edgomez 1.7 MOVLINE(tmp, LINE(1, 5));
757 :     MOVLINE(LINE(1, 5), LINE(3, 2));
758 :     MOVLINE(LINE(3, 2), tmp);
759 : h 1.2
760 :     // 7=14, 14=13, 13=11, 11=7
761 : edgomez 1.7 MOVLINE(tmp, LINE(1, 7));
762 :     MOVLINE(LINE(1, 7), LINE(3, 6));
763 :     MOVLINE(LINE(3, 6), LINE(3, 5));
764 :     MOVLINE(LINE(3, 5), LINE(3, 3));
765 :     MOVLINE(LINE(3, 3), tmp);
766 : Isibaar 1.1 }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4