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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16, Wed Oct 9 22:51:42 2002 UTC revision 1.22, Sat Mar 22 14:04:48 2003 UTC
# Line 1  Line 1 
1  /*****************************************************************************   /******************************************************************************
2   *    *                                                                            *
3   *  XVID MPEG-4 VIDEO CODEC    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *
4   *  - MacroBlock transfer and quantization -    *                                                                            *
5   *    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *
6   *  Copyright(C) 2002-2001 Michael Militzer <isibaar@xvid.org>    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
7   *               2002-2001 Peter Ross <pross@xvid.org>    *  software module in hardware or software products are advised that its     *
8   *    *  use may infringe existing patents or copyrights, and any such use         *
9   *  This program is an implementation of a part of one or more MPEG-4    *  would be at such party's own risk.  The original developer of this        *
10   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending    *  software module and his/her company, and subsequent editors and their     *
11   *  to use this software module in hardware or software products are    *  companies, will have no liability for use of this software or             *
12   *  advised that its use may infringe existing patents or copyrights, and    *  modifications or derivatives thereof.                                     *
13   *  any such use would be at such party's own risk.  The original    *                                                                            *
14   *  developer of this software module and his/her company, and subsequent    *  XviD is free software; you can redistribute it and/or modify it           *
15   *  editors and their companies, will have no liability for use of this    *  under the terms of the GNU General Public License as published by         *
16   *  software or modifications or derivatives thereof.    *  the Free Software Foundation; either version 2 of the License, or         *
17   *    *  (at your option) any later version.                                       *
18   *  This program is free software; you can redistribute it and/or modify    *                                                                            *
19   *  it under the terms of the GNU General Public License as published by    *  XviD is distributed in the hope that it will be useful, but               *
20   *  the Free Software Foundation; either version 2 of the License, or    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
21   *  (at your option) any later version.    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22   *    *  GNU General Public License for more details.                              *
23   *  This program is distributed in the hope that it will be useful,    *                                                                            *
24   *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *  You should have received a copy of the GNU General Public License         *
25   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *  along with this program; if not, write to the Free Software               *
26   *  GNU General Public License for more details.    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
27   *    *                                                                            *
28   *  You should have received a copy of the GNU General Public License    ******************************************************************************/
29   *  along with this program; if not, write to the Free Software  
30   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   /******************************************************************************
31   *    *                                                                            *
32   * $Id$    *  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      *  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      *  19.11.2001 introduced coefficient thresholding (Isibaar)                  *
50      *  17.11.2001 initial version                                                *
51      *                                                                            *
52      ******************************************************************************/
53    
54  #include <string.h>  #include <string.h>
55    
# Line 47  Line 65 
65  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
66  #include "../encoder.h"  #include "../encoder.h"
67    
68  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #include "../image/reduced.h"
 #define MAX(X, Y) ((X)>(Y)?(X):(Y))  
69    
70  #define TOOSMALL_LIMIT 3                /* skip blocks having a coefficient sum below this value */  MBFIELDTEST_PTR MBFieldTest;
71    
72  /* this isnt pretty, but its better than 20 ifdefs */  #define TOOSMALL_LIMIT  1       /* skip blocks having a coefficient sum below this value */
73    
74    static __inline void
75    MBfDCT(int16_t data[6 * 64])
76    {
77            start_timer();
78            fdct(&data[0 * 64]);
79            fdct(&data[1 * 64]);
80            fdct(&data[2 * 64]);
81            fdct(&data[3 * 64]);
82            fdct(&data[4 * 64]);
83            fdct(&data[5 * 64]);
84            stop_dct_timer();
85    }
86    
87    
88    static __inline uint32_t
89    QuantizeInterBlock(     int16_t qcoeff[64],
90                                            const int16_t data[64],
91                                            const uint32_t iQuant,
92                                            const uint32_t quant_type)
93    {
94            uint32_t sum;
95    
96            start_timer();
97            if (quant_type == H263_QUANT)
98                    sum = quant_inter(qcoeff, data, iQuant);
99            else
100                    sum = quant4_inter(qcoeff, data, iQuant);
101    
102            stop_quant_timer();
103            return sum;
104    }
105    
106  void  void
107  MBTransQuantIntra(const MBParam * pParam,  MBTransQuantIntra(const MBParam * const pParam,
108                                    FRAMEINFO * frame,                                  FRAMEINFO * const frame,
109                                    MACROBLOCK * pMB,                                  MACROBLOCK * const pMB,
110                                    const uint32_t x_pos,                                    const uint32_t x_pos,
111                                    const uint32_t y_pos,                                    const uint32_t y_pos,
112                                    int16_t data[6 * 64],                                    int16_t data[6 * 64],
# Line 65  Line 114 
114  {  {
115    
116          uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
117          uint32_t stride2 = stride / 2;          const uint32_t stride2 = stride / 2;
118          uint32_t next_block = stride * 8;          uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
119          uint32_t i;          int i;
120          uint32_t iQuant = frame->quant;          const uint32_t iQuant = pMB->quant;
121          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
122          IMAGE *pCurrent = &frame->image;          const IMAGE * const pCurrent = &frame->image;
123    
124            start_timer();
125            if ((frame->global_flags & XVID_REDUCED))
126            {
127                    pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
128                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
129                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
130    
131                    filter_18x18_to_8x8(&data[0 * 64], pY_Cur, stride);
132                    filter_18x18_to_8x8(&data[1 * 64], pY_Cur + 16, stride);
133                    filter_18x18_to_8x8(&data[2 * 64], pY_Cur + next_block, stride);
134                    filter_18x18_to_8x8(&data[3 * 64], pY_Cur + next_block + 16, stride);
135                    filter_18x18_to_8x8(&data[4 * 64], pU_Cur, stride2);
136                    filter_18x18_to_8x8(&data[5 * 64], pV_Cur, stride2);
137            } else {
138          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
139          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
140          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
141    
         start_timer();  
142          transfer_8to16copy(&data[0 * 64], pY_Cur, stride);          transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
143          transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);          transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
144          transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);          transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
145          transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);          transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
146          transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);          transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
147          transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);          transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
148            }
149          stop_transfer_timer();          stop_transfer_timer();
150    
151            /* XXX: rrv+interlacing is buggy */
152          start_timer();          start_timer();
153          pMB->field_dct = 0;          pMB->field_dct = 0;
154          if ((frame->global_flags & XVID_INTERLACING) &&          if ((frame->global_flags & XVID_INTERLACING) &&
# Line 94  Line 158 
158          }          }
159          stop_interlacing_timer();          stop_interlacing_timer();
160    
161          for (i = 0; i < 6; i++) {          MBfDCT(data);
                 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  
162    
163                  start_timer();          for (i = 0; i < 6; i++) {
164                  fdct(&data[i * 64]);                  const uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
                 stop_dct_timer();  
165    
                 if (pParam->m_quant_type == H263_QUANT) {  
166                          start_timer();                          start_timer();
167                    if (pParam->m_quant_type == H263_QUANT)
168                          quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);                          quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
169                          stop_quant_timer();                  else
   
                         start_timer();  
                         dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
                 } else {  
                         start_timer();  
170                          quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);                          quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
171                          stop_quant_timer();                          stop_quant_timer();
172    
173                    /* speedup: dont decode when encoding only ivops */
174                    if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
175                    {
176                          start_timer();                          start_timer();
177                            if (pParam->m_quant_type == H263_QUANT)
178                                    dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
179                            else
180                          dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);                          dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
181                          stop_iquant_timer();                          stop_iquant_timer();
                 }  
182    
183                  start_timer();                  start_timer();
184                  idct(&data[i * 64]);                  idct(&data[i * 64]);
185                  stop_idct_timer();                  stop_idct_timer();
186          }          }
187            }
188    
189            /* speedup: dont decode when encoding only ivops */
190            if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
191            {
192    
193          if (pMB->field_dct) {          if (pMB->field_dct) {
194                  next_block = stride;                  next_block = stride;
# Line 130  Line 196 
196          }          }
197    
198          start_timer();          start_timer();
199                    if ((frame->global_flags & XVID_REDUCED)) {
200                            copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
201                            copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
202                            copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
203                            copy_upsampled_8x8_16to8(pY_Cur + next_block + 16, &data[3 * 64], stride);
204                            copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
205                            copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
206                    } else {
207          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);          transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
208          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);          transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
209          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
210          transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);          transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
211          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
212          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
213                    }
214          stop_transfer_timer();          stop_transfer_timer();
   
215  }  }
216    
217    }
218    
219  uint8_t  uint8_t
220  MBTransQuantInter(const MBParam * pParam,  MBTransQuantInter(const MBParam * const pParam,
221                                    FRAMEINFO * frame,                                  FRAMEINFO * const frame,
222                                    MACROBLOCK * pMB,                                  MACROBLOCK * const pMB,
223                                    const uint32_t x_pos,                                    const uint32_t x_pos,
224                                    const uint32_t y_pos,                                    const uint32_t y_pos,
225                                    int16_t data[6 * 64],                                    int16_t data[6 * 64],
226                                    int16_t qcoeff[6 * 64])                                    int16_t qcoeff[6 * 64])
227  {  {
   
228          uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
229          uint32_t stride2 = stride / 2;          const uint32_t stride2 = stride / 2;
230          uint32_t next_block = stride * 8;          uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
231          uint32_t i;          int i;
232          uint32_t iQuant = frame->quant;          const uint32_t iQuant = pMB->quant;
233          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
234          uint8_t cbp = 0;          int cbp = 0;
235          uint32_t sum;          uint32_t sum;
236          IMAGE *pCurrent = &frame->image;          const IMAGE * const pCurrent = &frame->image;
237    
238            if ((frame->global_flags & XVID_REDUCED)) {
239                    pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
240                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
241                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
242            } else {
243          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
244          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
245          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
246            }
247    
248          start_timer();          start_timer();
249          pMB->field_dct = 0;          pMB->field_dct = 0;
# Line 174  Line 254 
254          }          }
255          stop_interlacing_timer();          stop_interlacing_timer();
256    
257            MBfDCT(data);
258    
259          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
260                    const uint32_t limit = TOOSMALL_LIMIT + ((iQuant == 1) ? 1 : 0);
261                  /*                  /*
262                   *  no need to transfer 8->16-bit                   *  no need to transfer 8->16-bit
263                   * (this is performed already in motion compensation)                   * (this is performed already in motion compensation)
264                   */                   */
                 start_timer();  
                 fdct(&data[i * 64]);  
                 stop_dct_timer();  
265    
266                  if (pParam->m_quant_type == 0) {                  sum = QuantizeInterBlock(&qcoeff[i * 64], &data[i * 64], iQuant, pParam->m_quant_type);
                         start_timer();  
                         sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);  
                         stop_quant_timer();  
                 } else {  
                         start_timer();  
                         sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);  
                         stop_quant_timer();  
                 }  
267    
268                  if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) ||                  if (sum >= limit) {
                         (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {  
269    
                         if (pParam->m_quant_type == H263_QUANT) {  
270                                  start_timer();                                  start_timer();
271                            if (pParam->m_quant_type == H263_QUANT)
272                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
273                                  stop_iquant_timer();                          else
                         } else {  
                                 start_timer();  
274                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
275                                  stop_iquant_timer();                                  stop_iquant_timer();
                         }  
276    
277                          cbp |= 1 << (5 - i);                          cbp |= 1 << (5 - i);
278    
# Line 220  Line 288 
288          }          }
289    
290          start_timer();          start_timer();
291            if ((frame->global_flags & XVID_REDUCED)) {
292                    if (cbp & 32)
293                            add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
294                    if (cbp & 16)
295                            add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
296                    if (cbp & 8)
297                            add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
298                    if (cbp & 4)
299                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
300                    if (cbp & 2)
301                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
302                    if (cbp & 1)
303                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
304            } else {
305          if (cbp & 32)          if (cbp & 32)
306                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);                  transfer_16to8add(pY_Cur, &data[0 * 64], stride);
307          if (cbp & 16)          if (cbp & 16)
# Line 232  Line 314 
314                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
315          if (cbp & 1)          if (cbp & 1)
316                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
         stop_transfer_timer();  
   
         return cbp;  
   
 }  
   
 void  
 MBTransQuantIntra2(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])  
 {  
         MBTrans(pParam,frame,pMB,x_pos,y_pos,data);  
         MBfDCT(pParam,frame,pMB,data);  
         MBQuantIntra(pParam,frame,pMB,data,qcoeff);  
         MBDeQuantIntra(pParam,frame->quant,data,qcoeff);  
         MBiDCT(data,0x3F);  
         MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F);  
317  }  }
318            stop_transfer_timer();
319    
320            return (uint8_t) cbp;
 uint8_t  
 MBTransQuantInter2(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])  
 {  
         uint8_t cbp;  
   
 /* there is no MBTrans for Inter block, that's done in motion compensation already */  
   
         MBfDCT(pParam,frame,pMB,data);  
         cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);  
         MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp);  
         MBiDCT(data,cbp);  
         MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp);  
   
         return cbp;  
321  }  }
322    
323  uint8_t  uint8_t
# Line 285  Line 327 
327                                    int16_t data[6 * 64],                                    int16_t data[6 * 64],
328                                    int16_t qcoeff[6 * 64])                                    int16_t qcoeff[6 * 64])
329  {  {
330          uint8_t cbp;          int cbp = 0;
   
 /* there is no MBTrans for Inter block, that's done in motion compensation already */  
   
         MBfDCT(pParam,frame,pMB,data);  
         cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);  
   
 /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */  
   
         return cbp;  
 }  
   
   
 void  
 MBfDCT(const MBParam * pParam,  
                                   FRAMEINFO * frame,  
                                   MACROBLOCK * pMB,  
                                   int16_t data[6 * 64])  
 {  
331          int i;          int i;
332    
333          start_timer();  /* there is no MBTrans for Inter block, that's done in motion compensation already */
         pMB->field_dct = 0;  
         if ((frame->global_flags & XVID_INTERLACING)) {  
                 pMB->field_dct = MBDecideFieldDCT(data);  
         }  
         stop_interlacing_timer();  
   
         for (i = 0; i < 6; i++) {  
                 start_timer();  
                 fdct(&data[i * 64]);  
                 stop_dct_timer();  
         }  
 }  
   
 void  
 MBQuantDeQuantIntra(const MBParam * pParam,  
                                         FRAMEINFO * frame,  
                                         MACROBLOCK * pMB,  
                                         int16_t qcoeff[6 * 64],  
                                         int16_t data[6*64])  
 {  
         int i;  
         int iQuant = frame->quant;  
   
         start_timer();  
         pMB->field_dct = 0;  
         if ((frame->global_flags & XVID_INTERLACING)) {  
                 pMB->field_dct = MBDecideFieldDCT(data);  
         }  
         stop_interlacing_timer();  
   
         for (i = 0; i < 6; i++) {  
                 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  
   
                 if (pParam->m_quant_type == H263_QUANT) {  
                         start_timer();  
                         quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);  
                         stop_quant_timer();  
   
                         start_timer();  
                         dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
                 } else {  
                         start_timer();  
                         quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);  
                         stop_quant_timer();  
   
                         start_timer();  
                         dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
                 }  
         }  
 }  
   
 void  
 MBQuantIntra(const MBParam * pParam,  
                          FRAMEINFO * frame,  
                          MACROBLOCK *pMB,  
                          int16_t data[6 * 64],  
                      int16_t qcoeff[6 * 64])  
 {  
         int i;  
         int iQuant = frame->quant;  
334    
335          start_timer();          start_timer();
336          pMB->field_dct = 0;          pMB->field_dct = 0;
# Line 377  Line 339 
339          }          }
340          stop_interlacing_timer();          stop_interlacing_timer();
341    
342          for (i = 0; i < 6; i++) {          MBfDCT(data);
                 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  
   
                 if (pParam->m_quant_type == H263_QUANT) {  
                         start_timer();  
                         quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);  
                         stop_quant_timer();  
                 } else {  
                         start_timer();  
                         quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);  
                         stop_quant_timer();  
                 }  
         }  
 }  
   
 void  
 MBDeQuantIntra(const MBParam * pParam,  
                            const int iQuant,  
                                   int16_t qcoeff[6 * 64],  
                                   int16_t data[6*64])  
 {  
         int i;  
343    
344          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
345                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);                  int codedecision = 0;
346    
347                  if (pParam->m_quant_type == H263_QUANT) {                  int sum = QuantizeInterBlock(&qcoeff[i * 64], &data[i * 64], pMB->quant, pParam->m_quant_type);
                         start_timer();  
                         dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
                 } else {  
                         start_timer();  
                         dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);  
                         stop_iquant_timer();  
                 }  
         }  
 }  
   
 uint8_t  
 MBQuantInter(const MBParam * pParam,  
                          const int iQuant,  
                                   int16_t data[6 * 64],  
                                   int16_t qcoeff[6 * 64])  
 {  
348    
349          int i;                  if ((sum > 2) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0) ) codedecision = 1;
350          uint8_t cbp = 0;                  else {
351          int sum;                          if (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V) {
352                                    // dark blocks prevention for direct mode
353          for (i = 0; i < 6; i++) {                                  if ( (qcoeff[i*64] < -1) || (qcoeff[i*64] > 0) ) codedecision = 1;
354                            } else
355                  if (pParam->m_quant_type == 0) {                                  if (qcoeff[i*64] != 0) codedecision = 1; // not direct mode
                         start_timer();  
                         sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);  
                         stop_quant_timer();  
                 } else {  
                         start_timer();  
                         sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);  
                         stop_quant_timer();  
356                  }                  }
357    
358                  if (sum >= TOOSMALL_LIMIT) {    // skip block ?                  if (codedecision) cbp |= 1 << (5 - i);
                         cbp |= 1 << (5 - i);  
                 }  
         }  
         return cbp;  
 }  
   
 void  
 MBDeQuantInter( const MBParam * pParam,  
                                 const int iQuant,  
                                   int16_t data[6 * 64],  
                                   int16_t qcoeff[6 * 64],  
                                   const uint8_t cbp)  
 {  
         int i;  
   
         for (i = 0; i < 6; i++) {  
                 if (cbp & (1 << (5 - i)))  
                 {  
                         if (pParam->m_quant_type == H263_QUANT) {  
                                 start_timer();  
                                 dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);  
                                 stop_iquant_timer();  
                         } else {  
                                 start_timer();  
                                 dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);  
                                 stop_iquant_timer();  
                         }  
                 }  
359          }          }
 }  
   
 void  
 MBiDCT( int16_t data[6 * 64],  
                 const uint8_t cbp)  
 {  
         int i;  
360    
361          for (i = 0; i < 6; i++) {  /* we don't have to DeQuant, iDCT and Transfer back data for B-frames if we don't reconstruct this frame */
362                  if (cbp & (1 << (5 - i)))  /* warning: reconstruction not supported yet */
363                  {          return (uint8_t) cbp;
                         start_timer();  
                         idct(&data[i * 64]);  
                         stop_idct_timer();  
   
                 }  
         }  
364  }  }
365    
366    /* permute block and return field dct choice */
367    
368  void  static uint32_t
369  MBTrans(const MBParam * pParam,  MBDecideFieldDCT(int16_t data[6 * 64])
                                   FRAMEINFO * frame,  
                                   MACROBLOCK * pMB,  
                                   const uint32_t x_pos,  
                                   const uint32_t y_pos,  
                                   int16_t data[6 * 64])  
 {  
         uint32_t stride = pParam->edged_width;  
         uint32_t stride2 = stride / 2;  
         uint32_t next_block = stride * 8;  
         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);  
   
         start_timer();  
         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();  
 }  
   
 void  
 MBTransAdd(const MBParam * pParam,  
                                   FRAMEINFO * frame,  
                                   MACROBLOCK * pMB,  
                                   const uint32_t x_pos,  
                                   const uint32_t y_pos,  
                                   int16_t data[6 * 64],  
                                   const uint8_t cbp)  
370  {  {
371          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          const uint32_t field = MBFieldTest(data);
372          uint32_t stride = pParam->edged_width;          if (field) MBFrameToField(data);
         uint32_t stride2 = stride / 2;  
         uint32_t next_block = stride * 8;  
         IMAGE *pCurrent = &frame->image;  
373    
374          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          return field;
         pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);  
         pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);  
   
         if (pMB->field_dct) {  
                 next_block = stride;  
                 stride *= 2;  
375          }          }
376    
         start_timer();  
         if (cbp & 32)  
                 transfer_16to8add(pY_Cur, &data[0 * 64], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);  
         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();  
 }  
   
   
   
377  /* 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 */
378    
   
379  uint32_t  uint32_t
380  MBDecideFieldDCT(int16_t data[6 * 64])  MBFieldTest_c(int16_t data[6 * 64])
381  {  {
   
382          const uint8_t blocks[] =          const uint8_t blocks[] =
383                  { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };                  { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
384          const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };          const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
# Line 598  Line 412 
412                  }                  }
413          }          }
414    
415          if (frame > field) {          return (frame >= (field + 350));
                 MBFrameToField(data);  
         }  
   
         return (frame > (field + 350));  
416  }  }
417    
418    

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.22

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