[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.21.2.6, Sun Mar 30 13:16:41 2003 UTC revision 1.22.2.1, Sun May 4 15:15:59 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   *  - MB Transfert/Quantization functions -    *                                                                            *
5   *    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *
6   *  Copyright(C) 2001-2003  Peter Ross <pross@xvid.org>    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
7   *               2001-2003  Michael Militzer <isibaar@xvid.org>    *  software module in hardware or software products are advised that its     *
8   *               2003       Edouard Gomez <ed.gomez@free.fr>    *  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   *  This program is free software ; you can redistribute it and/or modify    *  software module and his/her company, and subsequent editors and their     *
11   *  it under the terms of the GNU General Public License as published by    *  companies, will have no liability for use of this software or             *
12   *  the Free Software Foundation ; either version 2 of the License, or    *  modifications or derivatives thereof.                                     *
13   *  (at your option) any later version.    *                                                                            *
14   *    *  XviD is free software; you can redistribute it and/or modify it           *
15   *  This program is distributed in the hope that it will be useful,    *  under the terms of the GNU General Public License as published by         *
16   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of    *  the Free Software Foundation; either version 2 of the License, or         *
17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *  (at your option) any later version.                                       *
18   *  GNU General Public License for more details.    *                                                                            *
19   *    *  XviD is distributed in the hope that it will be useful, but               *
20   *  You should have received a copy of the GNU General Public License    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
21   *  along with this program ; if not, write to the Free Software    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    *  GNU General Public License for more details.                              *
23   *    *                                                                            *
24   * $Id$    *  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      *  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 43  Line 69 
69    
70  MBFIELDTEST_PTR MBFieldTest;  MBFIELDTEST_PTR MBFieldTest;
71    
72  /*  #define TOOSMALL_LIMIT  1       /* skip blocks having a coefficient sum below this value */
  * Skip blocks having a coefficient sum below this value. This value will be  
  * corrected according to the MB quantizer to avoid artifacts for quant==1  
  */  
 #define PVOP_TOOSMALL_LIMIT 1  
 #define BVOP_TOOSMALL_LIMIT 3  
   
 /*****************************************************************************  
  * Local functions  
  ****************************************************************************/  
   
 /* permute block and return field dct choice */  
 static __inline uint32_t  
 MBDecideFieldDCT(int16_t data[6 * 64])  
 {  
         uint32_t field = MBFieldTest(data);  
   
         if (field)  
                 MBFrameToField(data);  
73    
         return field;  
 }  
   
 /* Performs Forward DCT on all blocks */  
74  static __inline void  static __inline void
75  MBfDCT(const MBParam * pParam,  MBfDCT(int16_t data[6 * 64])
            FRAMEINFO * frame,  
            MACROBLOCK * pMB,  
            uint32_t x_pos,  
            uint32_t y_pos,  
            int16_t data[6 * 64])  
76  {  {
         /* Handles interlacing */  
         start_timer();  
         pMB->field_dct = 0;  
         if ((frame->vol_flags & XVID_VOL_INTERLACING) &&  
                 (x_pos>0) && (x_pos<pParam->mb_width-1) &&  
                 (y_pos>0) && (y_pos<pParam->mb_height-1)) {  
                 pMB->field_dct = MBDecideFieldDCT(data);  
         }  
         stop_interlacing_timer();  
   
         /* Perform DCT */  
77          start_timer();          start_timer();
78          fdct(&data[0 * 64]);          fdct(&data[0 * 64]);
79          fdct(&data[1 * 64]);          fdct(&data[1 * 64]);
# Line 96  Line 84 
84          stop_dct_timer();          stop_dct_timer();
85  }  }
86    
 /* Performs Inverse DCT on all blocks */  
 static __inline void  
 MBiDCT(int16_t data[6 * 64],  
            const uint8_t cbp)  
 {  
         start_timer();  
         if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);  
         if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]);  
         if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]);  
         if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]);  
         if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]);  
         if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]);  
         stop_idct_timer();  
 }  
87    
88  /* Quantize all blocks -- Intra mode */  static __inline uint32_t
89  static __inline void  QuantizeInterBlock(     int16_t qcoeff[64],
90  MBQuantIntra(const MBParam * pParam,                                          const int16_t data[64],
91                           const MACROBLOCK * pMB,                                          const uint32_t iQuant,
92                       int16_t qcoeff[6 * 64],                                          const uint32_t quant_type)
                          int16_t data[6*64])  
93  {  {
94          int i;          uint32_t sum;
95    
         for (i = 0; i < 6; i++) {  
                 uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4);  
   
                 /* Quantize the block */  
96                  start_timer();                  start_timer();
97                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))          if (quant_type == H263_QUANT)
98                          quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);                  sum = quant_inter(qcoeff, data, iQuant);
99                  else                  else
100                          quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);                  sum = quant4_inter(qcoeff, data, iQuant);
101    
102                  stop_quant_timer();                  stop_quant_timer();
103          }          return sum;
104  }  }
105    
106  /* DeQuantize all blocks -- Intra mode */  void
107  static __inline void  MBTransQuantIntra(const MBParam * const pParam,
108  MBDeQuantIntra(const MBParam * pParam,                                  FRAMEINFO * const frame,
109                             const int iQuant,                                  MACROBLOCK * const pMB,
110                             int16_t qcoeff[6 * 64],                                  const uint32_t x_pos,
111                             int16_t data[6*64])                                  const uint32_t y_pos,
112                                    int16_t data[6 * 64],
113                                    int16_t qcoeff[6 * 64])
114  {  {
         int i;  
115    
116          for (i = 0; i < 6; i++) {          uint32_t stride = pParam->edged_width;
117                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);          const uint32_t stride2 = stride / 2;
118            uint32_t next_block = stride * ((frame->global_flags & XVID_REDUCED)?16:8);
119            int i;
120            const uint32_t iQuant = pMB->quant;
121            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
122            const IMAGE * const pCurrent = &frame->image;
123    
124                  start_timer();                  start_timer();
125                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))          if ((frame->global_flags & XVID_REDUCED))
126                          dequant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);          {
127                  else                  pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
128                          dequant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);                  pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
129                  stop_iquant_timer();                  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);
139                    pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
140                    pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
141    
142                    transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
143                    transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
144                    transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
145                    transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
146                    transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
147                    transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
148  }  }
149            stop_transfer_timer();
150    
151  /* Quantize all blocks -- Inter mode */          /* XXX: rrv+interlacing is buggy */
152  static __inline uint8_t          start_timer();
153  MBQuantInter(const MBParam * pParam,          pMB->field_dct = 0;
154                           const MACROBLOCK * pMB,          if ((frame->global_flags & XVID_INTERLACING) &&
155                           int16_t data[6 * 64],                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
156                           int16_t qcoeff[6 * 64],                  (y_pos>0) && (y_pos<pParam->mb_height-1)) {
157                           int bvop,                  pMB->field_dct = MBDecideFieldDCT(data);
158                           int limit)          }
159  {          stop_interlacing_timer();
160    
161          int i;          MBfDCT(data);
         uint8_t cbp = 0;  
         int sum;  
         int code_block;  
162    
163          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
164                    const uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
165    
                 /* Quantize the block */  
166                  start_timer();                  start_timer();
167                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))                  if (pParam->m_quant_type == H263_QUANT)
168                          sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);                          quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
169                  else                  else
170                          sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);                          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                   * We code the block if the sum is higher than the limit and if the first                  if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
175                   * two AC coefficients in zig zag order are not zero.                  {
176                   */                          start_timer();
177                  code_block = 0;                          if (pParam->m_quant_type == H263_QUANT)
178                  if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {                                  dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
179                          code_block = 1;                          else
180                  } else {                                  dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
181                            stop_iquant_timer();
182    
183                          if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) {                          start_timer();
184                                  /* dark blocks prevention for direct mode */                          idct(&data[i * 64]);
185                                  if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0))                          stop_idct_timer();
                                         code_block = 1;  
                         } else {  
                                 /* not direct mode */  
                                 if (qcoeff[i*64] != 0)  
                                         code_block = 1;  
186                          }                          }
187                  }                  }
188    
189                  /* Set the corresponding cbp bit */          /* speedup: dont decode when encoding only ivops */
190                  cbp |= code_block << (5 - i);          if (pParam->iMaxKeyInterval != 1 || pParam->max_bframes > 0)
191            {
         }  
192    
193          return(cbp);                  if (pMB->field_dct) {
194                            next_block = stride;
195                            stride *= 2;
196  }  }
197    
 /* DeQuantize all blocks -- Inter mode */  
 static __inline 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))) {  
198                          start_timer();                          start_timer();
199                          if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))                  if ((frame->global_flags & XVID_REDUCED)) {
200                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);                          copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
201                          else                          copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
202                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);                          copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
203                          stop_iquant_timer();                          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);
208                            transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
209                            transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
210                            transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
211                            transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
212                            transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
213          }          }
214                    stop_transfer_timer();
215  }  }
216    
217  typedef void (transfer_operation_8to16_t) (int16_t *Dst, const uint8_t *Src, int BpS);  }
 typedef void (transfer_operation_16to8_t) (uint8_t *Dst, const int16_t *Src, int BpS);  
   
218    
219  static __inline void  uint8_t
220  MBTrans8to16(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])
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          int32_t cst;          int i;
232            const uint32_t iQuant = pMB->quant;
233          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
234          IMAGE *pCurrent = &frame->image;          int cbp = 0;
235          transfer_operation_8to16_t *transfer_op = NULL;          uint32_t sum;
236            const IMAGE * const pCurrent = &frame->image;
237    
238          if ((frame->vop_flags & XVID_VOP_REDUCED)) {          if ((frame->global_flags & XVID_REDUCED)) {
   
                 /* Image pointers */  
239                  pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);                  pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);
240                  pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);                  pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
241                  pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);                  pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
   
                 /* Block size */  
                 cst = 16;  
   
                 /* Operation function */  
                 transfer_op = (transfer_operation_8to16_t*)filter_18x18_to_8x8;  
242          } else {          } else {
   
                 /* Image pointers */  
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);
   
                 /* Block size */  
                 cst = 8;  
   
                 /* Operation function */  
                 transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;  
246          }          }
247    
         /* Do the transfer */  
248          start_timer();          start_timer();
249          transfer_op(&data[0 * 64], pY_Cur, stride);          pMB->field_dct = 0;
250          transfer_op(&data[1 * 64], pY_Cur + cst, stride);          if ((frame->global_flags & XVID_INTERLACING) &&
251          transfer_op(&data[2 * 64], pY_Cur + next_block, stride);                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
252          transfer_op(&data[3 * 64], pY_Cur + next_block + cst, stride);                  (y_pos>0) && (y_pos<pParam->mb_height-1)) {
253          transfer_op(&data[4 * 64], pU_Cur, stride2);                  pMB->field_dct = MBDecideFieldDCT(data);
         transfer_op(&data[5 * 64], pV_Cur, stride2);  
         stop_transfer_timer();  
254  }  }
255            stop_interlacing_timer();
256    
257  static __inline void          MBfDCT(data);
 MBTrans16to8(const MBParam * pParam,  
                          FRAMEINFO * frame,  
                          MACROBLOCK * pMB,  
                          const uint32_t x_pos,  
                          const uint32_t y_pos,  
                          int16_t data[6 * 64],  
                          const uint32_t add,  
                          const uint8_t cbp)  
 {  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
         uint32_t stride = pParam->edged_width;  
         uint32_t stride2 = stride / 2;  
         uint32_t next_block = stride * 8;  
         uint32_t cst;  
         IMAGE *pCurrent = &frame->image;  
         transfer_operation_16to8_t *transfer_op = NULL;  
258    
259          if (pMB->field_dct) {          for (i = 0; i < 6; i++) {
260                  next_block = stride;                  const uint32_t limit = TOOSMALL_LIMIT + ((iQuant == 1) ? 1 : 0);
261                  stride *= 2;                  /*
262          }                   *  no need to transfer 8->16-bit
263                     * (this is performed already in motion compensation)
264                     */
265    
266          if ((frame->vop_flags & XVID_VOP_REDUCED)) {                  sum = QuantizeInterBlock(&qcoeff[i * 64], &data[i * 64], iQuant, pParam->m_quant_type);
267    
268                  /* Image pointers */                  if(frame->global_flags & XVID_CARTOON_MODE) {
269                  pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);                          limit *= 3;
270                  pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);                  }
                 pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);  
271    
272                  /* Block size */                  if (sum >= limit) {
                 cst = 16;  
273    
274                  /* Operation function */                          start_timer();
275                  if(add)                          if (pParam->m_quant_type == H263_QUANT)
276                          transfer_op = (transfer_operation_16to8_t*)add_upsampled_8x8_16to8;                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
277                  else                  else
278                          transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8;                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
279          } else {                          stop_iquant_timer();
280    
281                  /* Image pointers */                          cbp |= 1 << (5 - i);
                 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);  
282    
283                  /* Block size */                          start_timer();
284                  cst = 8;                          idct(&data[i * 64]);
285                            stop_idct_timer();
286                    }
287            }
288    
289                  /* Operation function */          if (pMB->field_dct) {
290                  if(add)                  next_block = stride;
291                          transfer_op = (transfer_operation_16to8_t*)transfer_16to8add;                  stride *= 2;
                 else  
                         transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy;  
292          }          }
293    
         /* Do the operation */  
294          start_timer();          start_timer();
295          if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);          if ((frame->global_flags & XVID_REDUCED)) {
296          if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride);                  if (cbp & 32)
297          if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride);                          add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
298          if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride);                  if (cbp & 16)
299          if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2);                          add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
300          if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2);                  if (cbp & 8)
301          stop_transfer_timer();                          add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
302                    if (cbp & 4)
303                            add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
304                    if (cbp & 2)
305                            add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
306                    if (cbp & 1)
307                            add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
308            } else {
309                    if (cbp & 32)
310                            transfer_16to8add(pY_Cur, &data[0 * 64], stride);
311                    if (cbp & 16)
312                            transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
313                    if (cbp & 8)
314                            transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
315                    if (cbp & 4)
316                            transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
317                    if (cbp & 2)
318                            transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
319                    if (cbp & 1)
320                            transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
321  }  }
322            stop_transfer_timer();
323    
324  /*****************************************************************************          return (uint8_t) cbp;
  * Module functions  
  ****************************************************************************/  
   
 void  
 MBTransQuantIntra(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])  
 {  
   
         /* Transfer data */  
         MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data);  
   
         /* Perform DCT (and field decision) */  
         MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);  
   
         /* Quantize the block */  
         MBQuantIntra(pParam, pMB, data, qcoeff);  
   
         /* DeQuantize the block */  
         MBDeQuantIntra(pParam, pMB->quant, data, qcoeff);  
   
         /* Perform inverse DCT*/  
         MBiDCT(data, 0x3F);  
   
         /* Transfer back the data -- Don't add data */  
         MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F);  
325  }  }
326    
   
327  uint8_t  uint8_t
328  MBTransQuantInter(const MBParam * pParam,  MBTransQuantInterBVOP(const MBParam * pParam,
329                                    FRAMEINFO * frame,                                    FRAMEINFO * frame,
330                                    MACROBLOCK * pMB,                                    MACROBLOCK * pMB,
                                   const uint32_t x_pos,  
                                   const uint32_t y_pos,  
331                                    int16_t data[6 * 64],                                    int16_t data[6 * 64],
332                                    int16_t qcoeff[6 * 64])                                    int16_t qcoeff[6 * 64])
333  {  {
334          uint8_t cbp;          int cbp = 0;
335          uint32_t limit;          int i;
   
         /*  
          * There is no MBTrans8to16 for Inter block, that's done in motion compensation  
          * already  
          */  
   
         /* Perform DCT (and field decision) */  
         MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);  
   
         /* Set the limit threshold */  
         limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0);  
   
         /* Quantize the block */  
         cbp = MBQuantInter(pParam, pMB, data, qcoeff, 0, limit);  
   
         /* DeQuantize the block */  
         MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);  
   
         /* Perform inverse DCT*/  
         MBiDCT(data, cbp);  
336    
337          /* Transfer back the data -- Add the data */  /* there is no MBTrans for Inter block, that's done in motion compensation already */
         MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);  
338    
339          return(cbp);          start_timer();
340            pMB->field_dct = 0;
341            if ((frame->global_flags & XVID_INTERLACING)) {
342                    pMB->field_dct = MBDecideFieldDCT(data);
343  }  }
344            stop_interlacing_timer();
345    
346  uint8_t          MBfDCT(data);
 MBTransQuantInterBVOP(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;  
         uint32_t limit;  
347    
348          /*          for (i = 0; i < 6; i++) {
349           * There is no MBTrans8to16 for Inter block, that's done in motion compensation                  int codedecision = 0;
          * already  
          */  
350    
351          /* Perform DCT (and field decision) */                  int sum = QuantizeInterBlock(&qcoeff[i * 64], &data[i * 64], pMB->quant, pParam->m_quant_type);
         MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);  
352    
353          /* Set the limit threshold */                  if(frame->global_flags & XVID_CARTOON_MODE) {
354          limit = BVOP_TOOSMALL_LIMIT;                          limit *= 2;
355                    }
356    
357          /* Quantize the block */                  if ((sum > 2) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0) ) codedecision = 1;
358          cbp = MBQuantInter(pParam, pMB, data, qcoeff, 1, limit);                  else {
359                            if (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V) {
360                                    // dark blocks prevention for direct mode
361                                    if ( (qcoeff[i*64] < -1) || (qcoeff[i*64] > 0) ) codedecision = 1;
362                            } else
363                                    if (qcoeff[i*64] != 0) codedecision = 1; // not direct mode
364                    }
365    
366          /*                  if (codedecision) cbp |= 1 << (5 - i);
367           * History comment:          }
          * We don't have to DeQuant, iDCT and Transfer back data for B-frames.  
          *  
          * BUT some plugins require the original frame to be passed so we have  
          * to take care of that here  
          */  
         if((pParam->plugin_flags & XVID_REQORIGINAL)) {  
368    
369                  /* DeQuantize the block */  /* we don't have to DeQuant, iDCT and Transfer back data for B-frames if we don't reconstruct this frame */
370                  MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);  /* warning: reconstruction not supported yet */
371            return (uint8_t) cbp;
372    }
373    
374                  /* Perform inverse DCT*/  /* permute block and return field dct choice */
                 MBiDCT(data, cbp);  
375    
376                  /* Transfer back the data -- Add the data */  static uint32_t
377                  MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);  MBDecideFieldDCT(int16_t data[6 * 64])
378          }  {
379            const uint32_t field = MBFieldTest(data);
380            if (field) MBFrameToField(data);
381    
382          return(cbp);          return field;
383  }  }
384    
385  /* 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 */
386    
387  uint32_t  uint32_t
388  MBFieldTest_c(int16_t data[6 * 64])  MBFieldTest_c(int16_t data[6 * 64])
389  {  {

Legend:
Removed from v.1.21.2.6  
changed lines
  Added in v.1.22.2.1

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