[svn] / branches / dev-api-4 / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/utils/mbtransquant.c

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

trunk/xvidcore/src/utils/mbtransquant.c revision 118, Sat Apr 13 16:30:02 2002 UTC branches/dev-api-4/xvidcore/src/utils/mbtransquant.c revision 982, Thu Apr 10 13:05:54 2003 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
2    *                                                                            *   *
3    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *   *  XVID MPEG-4 VIDEO CODEC
4    *                                                                            *   *  - MB Transfert/Quantization functions -
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    *   *  Copyright(C) 2001-2003  Peter Ross <pross@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *               2001-2003  Michael Militzer <isibaar@xvid.org>
8    *  use may infringe existing patents or copyrights, and any such use         *   *               2003       Edouard Gomez <ed.gomez@free.fr>
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     *   *  This program is free software ; you can redistribute it and/or modify
11    *  companies, will have no liability for use of this software or             *   *  it under the terms of the GNU General Public License as published by
12    *  modifications or derivatives thereof.                                     *   *  the Free Software Foundation ; either version 2 of the License, or
13    *                                                                            *   *  (at your option) any later version.
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         *   *  This program is distributed in the hope that it will be useful,
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
17    *  (at your option) any later version.                                       *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    *                                                                            *   *  GNU General Public License for more details.
19    *  XviD is distributed in the hope that it will be useful, but               *   *
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  You should have received a copy of the GNU General Public License
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *  along with this program ; if not, write to the Free Software
22    *  GNU General Public License for more details.                              *   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23    *                                                                            *   *
24    *  You should have received a copy of the GNU General Public License         *   * $Id: mbtransquant.c,v 1.21.2.7 2003-04-10 13:05:54 edgomez Exp $
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  *   ****************************************************************************/
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  mbtransquant.c                                                            *  
   *                                                                            *  
   *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *  
   *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>                  *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  29.03.2002 interlacing speedup - used transfer strides instead of  
   *             manual field-to-frame conversion  
   *  26.03.2002 interlacing support - moved transfers outside loops  
   *  22.12.2001 get_dc_scaler() moved to common.h  
   *  19.11.2001 introduced coefficient thresholding (Isibaar)                  *  
   *  17.11.2001 initial version                                                *  
   *                                                                            *  
   ******************************************************************************/  
27    
28  #include <string.h>  #include <string.h>
29    #include <stdlib.h>
30    
31  #include "../portab.h"  #include "../portab.h"
32  #include "mbfunctions.h"  #include "mbfunctions.h"
# Line 65  Line 40 
40  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
41  #include "../encoder.h"  #include "../encoder.h"
42    
43  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #include "../image/reduced.h"
 #define MAX(X, Y) ((X)>(Y)?(X):(Y))  
44    
45  #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */  MBFIELDTEST_PTR MBFieldTest;
46    
47  /* this isnt pretty, but its better than 20 ifdefs */  /*
48     * Skip blocks having a coefficient sum below this value. This value will be
49     * corrected according to the MB quantizer to avoid artifacts for quant==1
50     */
51    #define PVOP_TOOSMALL_LIMIT 1
52    #define BVOP_TOOSMALL_LIMIT 3
53    
54  void MBTransQuantIntra(const MBParam *pParam,  /*****************************************************************************
55                         MACROBLOCK * pMB,   * Local functions
56                         const uint32_t x_pos,   ****************************************************************************/
                        const uint32_t y_pos,  
                        int16_t data[6*64],  
                        int16_t qcoeff[6*64],  
                        IMAGE * const pCurrent)  
57    
58    /* permute block and return field dct choice */
59    static __inline uint32_t
60    MBDecideFieldDCT(int16_t data[6 * 64])
61  {  {
62            uint32_t field = MBFieldTest(data);
63    
64          uint32_t stride = pParam->edged_width;          if (field)
65          uint32_t stride2 = stride / 2;                  MBFrameToField(data);
         uint32_t next_block = stride * 8;  
         uint32_t i;  
         uint32_t iQuant = pParam->quant;  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
   
         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);  
66    
67          start_timer();          return field;
68          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();  
69    
70    /* Performs Forward DCT on all blocks */
71    static __inline void
72    MBfDCT(const MBParam * pParam,
73               FRAMEINFO * frame,
74               MACROBLOCK * pMB,
75               uint32_t x_pos,
76               uint32_t y_pos,
77               int16_t data[6 * 64])
78    {
79            /* Handles interlacing */
80          start_timer();          start_timer();
81          pMB->field_dct = 0;          pMB->field_dct = 0;
82          if (pParam->global_flags & XVID_INTERLACING)          if ((frame->vol_flags & XVID_VOL_INTERLACING) &&
83          {                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
84                    (y_pos>0) && (y_pos<pParam->mb_height-1)) {
85                  pMB->field_dct = MBDecideFieldDCT(data);                  pMB->field_dct = MBDecideFieldDCT(data);
86          }          }
87          stop_interlacing_timer();          stop_interlacing_timer();
88    
89          for(i = 0; i < 6; i++)          /* Perform DCT */
         {  
                 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  
   
90                  start_timer();                  start_timer();
91                  fdct(&data[i*64]);          fdct(&data[0 * 64]);
92            fdct(&data[1 * 64]);
93            fdct(&data[2 * 64]);
94            fdct(&data[3 * 64]);
95            fdct(&data[4 * 64]);
96            fdct(&data[5 * 64]);
97                  stop_dct_timer();                  stop_dct_timer();
98    }
99    
100                  if (pParam->quant_type == H263_QUANT)  /* Performs Inverse DCT on all blocks */
101    static __inline void
102    MBiDCT(int16_t data[6 * 64],
103               const uint8_t cbp)
104                  {                  {
105                          start_timer();                          start_timer();
106                          quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);          if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);
107                          stop_quant_timer();          if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]);
108            if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]);
109                          start_timer();          if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]);
110                          dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);          if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]);
111                          stop_iquant_timer();          if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]);
112            stop_idct_timer();
113                  }                  }
114                  else  
115    /* Quantize all blocks -- Intra mode */
116    static __inline void
117    MBQuantIntra(const MBParam * pParam,
118                             const MACROBLOCK * pMB,
119                         int16_t qcoeff[6 * 64],
120                             int16_t data[6*64])
121                  {                  {
122                          start_timer();          int i;
                         quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);  
                         stop_quant_timer();  
123    
124                          start_timer();          for (i = 0; i < 6; i++) {
125                          dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);                  uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4);
                         stop_iquant_timer();  
                 }  
126    
127                    /* Quantize the block */
128                  start_timer();                  start_timer();
129                  idct(&data[i*64]);                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
130                  stop_idct_timer();                          quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
131                    else
132                            quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
133                    stop_quant_timer();
134            }
135          }          }
136    
137          if (pMB->field_dct)  /* DeQuantize all blocks -- Intra mode */
138    static __inline void
139    MBDeQuantIntra(const MBParam * pParam,
140                               const int iQuant,
141                               int16_t qcoeff[6 * 64],
142                               int16_t data[6*64])
143          {          {
144                  next_block = stride;          int i;
                 stride *= 2;  
         }  
145    
146          start_timer();          for (i = 0; i < 6; i++) {
147          transfer_16to8copy(pY_Cur,                  &data[0*64], stride);                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
         transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);  
         transfer_16to8copy(pY_Cur + next_block,     &data[2*64], stride);  
         transfer_16to8copy(pY_Cur + next_block + 8, &data[3*64], stride);  
         transfer_16to8copy(pU_Cur,                  &data[4*64], stride2);  
         transfer_16to8copy(pV_Cur,                  &data[5*64], stride2);  
         stop_transfer_timer();  
148    
149                    start_timer();
150                    if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
151                            dequant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
152                    else
153                            dequant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
154                    stop_iquant_timer();
155            }
156  }  }
157    
158    /* Quantize all blocks -- Inter mode */
159  uint8_t MBTransQuantInter(const MBParam *pParam,  static __inline uint8_t
160                            MACROBLOCK * pMB,  MBQuantInter(const MBParam * pParam,
161                            const uint32_t x_pos, const uint32_t y_pos,                           const MACROBLOCK * pMB,
162                            int16_t data[6*64],                            int16_t data[6*64],
163                            int16_t qcoeff[6*64],                            int16_t qcoeff[6*64],
164                            IMAGE * const pCurrent)                           int bvop,
165                             int limit)
166  {  {
167    
168          uint32_t stride = pParam->edged_width;          int i;
         uint32_t stride2 = stride / 2;  
         uint32_t next_block = stride * 8;  
         uint32_t i;  
         uint32_t iQuant = pParam->quant;  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
169          uint8_t cbp = 0;          uint8_t cbp = 0;
170          uint32_t sum;          int sum;
171            int code_block;
172    
173          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          for (i = 0; i < 6; i++) {
         pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);  
         pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);  
174    
175                    /* Quantize the block */
176          start_timer();          start_timer();
177          pMB->field_dct = 0;                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
178          if (pParam->global_flags & XVID_INTERLACING)                          sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);
179          {                  else
180                  pMB->field_dct = MBDecideFieldDCT(data);                          sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);
181          }                  stop_quant_timer();
         stop_interlacing_timer();  
182    
         for(i = 0; i < 6; i++)  
         {  
183                  /*                  /*
184                   *  no need to transfer 8->16-bit                   * We code the block if the sum is higher than the limit and if the first
185                   * (this is performed already in motion compensation)                   * two AC coefficients in zig zag order are not zero.
186                   */                   */
187                  start_timer();                  code_block = 0;
188                  fdct(&data[i*64]);                  if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
189                  stop_dct_timer();                          code_block = 1;
190                    } else {
191    
192                  if (pParam->quant_type == 0)                          if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) {
193                  {                                  /* dark blocks prevention for direct mode */
194                          start_timer();                                  if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0))
195                          sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant);                                          code_block = 1;
196                          stop_quant_timer();                          } else {
197                                    /* not direct mode */
198                                    if (qcoeff[i*64] != 0)
199                                            code_block = 1;
200                  }                  }
                 else  
                 {  
                         start_timer();  
                         sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant);  
                         stop_quant_timer();  
201                  }                  }
202    
203                  if(sum >= TOOSMALL_LIMIT) { // skip block ?                  /* Set the corresponding cbp bit */
204                    cbp |= code_block << (5 - i);
205    
206            }
207    
208            return(cbp);
209    }
210    
211                          if (pParam->quant_type == H263_QUANT)  /* DeQuantize all blocks -- Inter mode */
212    static __inline void
213    MBDeQuantInter(const MBParam * pParam,
214                               const int iQuant,
215                               int16_t data[6 * 64],
216                               int16_t qcoeff[6 * 64],
217                               const uint8_t cbp)
218                          {                          {
219            int i;
220    
221            for (i = 0; i < 6; i++) {
222                    if (cbp & (1 << (5 - i))) {
223                                  start_timer();                                  start_timer();
224                            if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
225                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);
                                 stop_iquant_timer();  
                         }  
226                          else                          else
                         {  
                                 start_timer();  
227                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);
228                                  stop_iquant_timer();                                  stop_iquant_timer();
229                          }                          }
230            }
231    }
232    
233                          cbp |= 1 << (5 - i);  typedef void (transfer_operation_8to16_t) (int16_t *Dst, const uint8_t *Src, int BpS);
234    typedef void (transfer_operation_16to8_t) (uint8_t *Dst, const int16_t *Src, int BpS);
235    
236                          start_timer();  
237                          idct(&data[i*64]);  static __inline void
238                          stop_idct_timer();  MBTrans8to16(const MBParam * pParam,
239                             FRAMEINFO * frame,
240                             MACROBLOCK * pMB,
241                             const uint32_t x_pos,
242                             const uint32_t y_pos,
243                             int16_t data[6 * 64])
244    {
245            uint32_t stride = pParam->edged_width;
246            uint32_t stride2 = stride / 2;
247            uint32_t next_block = stride * 8;
248            int32_t cst;
249            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
250            IMAGE *pCurrent = &frame->image;
251            transfer_operation_8to16_t *transfer_op = NULL;
252    
253            if ((frame->vop_flags & XVID_VOP_REDUCED)) {
254    
255                    /* Image pointers */
256                    pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);
257                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
258                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
259    
260                    /* Block size */
261                    cst = 16;
262    
263                    /* Operation function */
264                    transfer_op = (transfer_operation_8to16_t*)filter_18x18_to_8x8;
265            } else {
266    
267                    /* Image pointers */
268                    pY_Cur = pCurrent->y + (y_pos << 4) * stride  + (x_pos << 4);
269                    pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
270                    pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
271    
272                    /* Block size */
273                    cst = 8;
274    
275                    /* Operation function */
276                    transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;
277                  }                  }
278    
279            /* Do the transfer */
280            start_timer();
281            transfer_op(&data[0 * 64], pY_Cur, stride);
282            transfer_op(&data[1 * 64], pY_Cur + cst, stride);
283            transfer_op(&data[2 * 64], pY_Cur + next_block, stride);
284            transfer_op(&data[3 * 64], pY_Cur + next_block + cst, stride);
285            transfer_op(&data[4 * 64], pU_Cur, stride2);
286            transfer_op(&data[5 * 64], pV_Cur, stride2);
287            stop_transfer_timer();
288          }          }
289    
290          if (pMB->field_dct)  static __inline void
291    MBTrans16to8(const MBParam * pParam,
292                             FRAMEINFO * frame,
293                             MACROBLOCK * pMB,
294                             const uint32_t x_pos,
295                             const uint32_t y_pos,
296                             int16_t data[6 * 64],
297                             const uint32_t add,
298                             const uint8_t cbp)
299          {          {
300            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
301            uint32_t stride = pParam->edged_width;
302            uint32_t stride2 = stride / 2;
303            uint32_t next_block = stride * 8;
304            uint32_t cst;
305            IMAGE *pCurrent = &frame->image;
306            transfer_operation_16to8_t *transfer_op = NULL;
307    
308            if (pMB->field_dct) {
309                  next_block = stride;                  next_block = stride;
310                  stride *= 2;                  stride *= 2;
311          }          }
312    
313            if ((frame->vop_flags & XVID_VOP_REDUCED)) {
314    
315                    /* Image pointers */
316                    pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);
317                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
318                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
319    
320                    /* Block size */
321                    cst = 16;
322    
323                    /* Operation function */
324                    if(add)
325                            transfer_op = (transfer_operation_16to8_t*)add_upsampled_8x8_16to8;
326                    else
327                            transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8;
328            } else {
329    
330                    /* Image pointers */
331                    pY_Cur = pCurrent->y + (y_pos << 4) * stride  + (x_pos << 4);
332                    pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
333                    pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
334    
335                    /* Block size */
336                    cst = 8;
337    
338                    /* Operation function */
339                    if(add)
340                            transfer_op = (transfer_operation_16to8_t*)transfer_16to8add;
341                    else
342                            transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy;
343            }
344    
345            /* Do the operation */
346          start_timer();          start_timer();
347          if (cbp & 32)          if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);
348                  transfer_16to8add(pY_Cur,                  &data[0*64], stride);          if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride);
349          if (cbp & 16)          if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride);
350                  transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);          if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride);
351          if (cbp & 8)          if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2);
352                  transfer_16to8add(pY_Cur + next_block,     &data[2*64], stride);          if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2);
         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);  
353          stop_transfer_timer();          stop_transfer_timer();
354    }
355    
356    /*****************************************************************************
357     * Module functions
358     ****************************************************************************/
359    
360    void
361    MBTransQuantIntra(const MBParam * pParam,
362                                      FRAMEINFO * frame,
363                                      MACROBLOCK * pMB,
364                                      const uint32_t x_pos,
365                                      const uint32_t y_pos,
366                                      int16_t data[6 * 64],
367                                      int16_t qcoeff[6 * 64])
368    {
369    
370            /* Transfer data */
371            MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data);
372    
373            /* Perform DCT (and field decision) */
374            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
375    
376          return cbp;          /* Quantize the block */
377            MBQuantIntra(pParam, pMB, data, qcoeff);
378    
379            /* DeQuantize the block */
380            MBDeQuantIntra(pParam, pMB->quant, data, qcoeff);
381    
382            /* Perform inverse DCT*/
383            MBiDCT(data, 0x3F);
384    
385            /* Transfer back the data -- Don't add data */
386            MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F);
387  }  }
388    
389    
390  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */  uint8_t
391    MBTransQuantInter(const MBParam * pParam,
392                                      FRAMEINFO * frame,
393                                      MACROBLOCK * pMB,
394                                      const uint32_t x_pos,
395                                      const uint32_t y_pos,
396                                      int16_t data[6 * 64],
397                                      int16_t qcoeff[6 * 64])
398    {
399            uint8_t cbp;
400            uint32_t limit;
401    
402            /*
403             * There is no MBTrans8to16 for Inter block, that's done in motion compensation
404             * already
405             */
406    
407            /* Perform DCT (and field decision) */
408            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
409    
410            /* Set the limit threshold */
411            limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0);
412    
413            /* Quantize the block */
414            cbp = MBQuantInter(pParam, pMB, data, qcoeff, 0, limit);
415    
416            /* DeQuantize the block */
417            MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
418    
419            /* Perform inverse DCT*/
420            MBiDCT(data, cbp);
421    
422  uint32_t MBDecideFieldDCT(int16_t data[6*64])          /* Transfer back the data -- Add the data */
423            MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
424    
425            return(cbp);
426    }
427    
428    uint8_t
429    MBTransQuantInterBVOP(const MBParam * pParam,
430                                      FRAMEINFO * frame,
431                                      MACROBLOCK * pMB,
432                                      const uint32_t x_pos,
433                                      const uint32_t y_pos,
434                                      int16_t data[6 * 64],
435                                      int16_t qcoeff[6 * 64])
436  {  {
437            uint8_t cbp;
438            uint32_t limit;
439    
440            /*
441             * There is no MBTrans8to16 for Inter block, that's done in motion compensation
442             * already
443             */
444    
445            /* Perform DCT (and field decision) */
446            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
447    
448            /* Set the limit threshold */
449            limit = BVOP_TOOSMALL_LIMIT;
450    
451            /* Quantize the block */
452            cbp = MBQuantInter(pParam, pMB, data, qcoeff, 1, limit);
453    
454            /*
455             * History comment:
456             * We don't have to DeQuant, iDCT and Transfer back data for B-frames.
457             *
458             * BUT some plugins require the original frame to be passed so we have
459             * to take care of that here
460             */
461            if((pParam->plugin_flags & XVID_REQORIGINAL)) {
462    
463                    /* DeQuantize the block */
464                    MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
465    
466                    /* Perform inverse DCT*/
467                    MBiDCT(data, cbp);
468    
469          const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64};                  /* Transfer back the data -- Add the data */
470                    MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
471            }
472    
473            return(cbp);
474    }
475    
476    /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
477    uint32_t
478    MBFieldTest_c(int16_t data[6 * 64])
479    {
480            const uint8_t blocks[] =
481                    { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
482          const uint8_t lines[]  = {0, 16, 32, 48, 0, 16, 32, 48};          const uint8_t lines[]  = {0, 16, 32, 48, 0, 16, 32, 48};
483    
484          int frame = 0, field = 0;          int frame = 0, field = 0;
485          int i, j;          int i, j;
486    
487          for (i=0 ; i<7 ; ++i)          for (i = 0; i < 7; ++i) {
488          {                  for (j = 0; j < 8; ++j) {
489                  for (j=0 ; j<8 ; ++j)                          frame +=
490                  {                                  abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
491                          frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]);                          frame +=
492                          frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]);                                  abs(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
493                          frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]);                          frame +=
494                          frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]);                                  abs(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]);
495                            frame +=
496                                    abs(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
497    
498                          field += ABS(data[blocks[i+1] + lines[i+1] + j] -\                          field +=
499                                    abs(data[blocks[i + 1] + lines[i + 1] + j] -
500                                       data[blocks[i  ] + lines[i  ] + j]);                                       data[blocks[i  ] + lines[i  ] + j]);
501                          field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\                          field +=
502                                    abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
503                                       data[blocks[i  ] + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + lines[i  ] + 8 + j]);
504                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\                          field +=
505                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
506                                       data[blocks[i  ] + 64 + lines[i  ] + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + j]);
507                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\                          field +=
508                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
509                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);
510                  }                  }
511          }          }
512    
513          if (frame > field)          return (frame >= (field + 350));
         {  
                 MBFrameToField(data);  
         }  
   
         return (frame > field);  
514  }  }
515    
516    
# Line 310  Line 519 
519  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
520  #define LINE(X,Y)    &data[X*64 + Y*8]  #define LINE(X,Y)    &data[X*64 + Y*8]
521    
522  void MBFrameToField(int16_t data[6*64])  void
523    MBFrameToField(int16_t data[6 * 64])
524  {  {
525          int16_t tmp[8];          int16_t tmp[8];
526    

Legend:
Removed from v.118  
changed lines
  Added in v.982

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