[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 78, Thu Mar 28 20:57:25 2002 UTC branches/dev-api-4/xvidcore/src/utils/mbtransquant.c revision 995, Sun Apr 27 19:47:48 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.9 2003-04-27 19:47:48 chl 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:                                                         *  
   *                                                                            *  
   *  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 57  Line 34 
34  #include "../global.h"  #include "../global.h"
35  #include "mem_transfer.h"  #include "mem_transfer.h"
36  #include "timer.h"  #include "timer.h"
37    #include "../bitstream/mbcoding.h"
38  #include "../dct/fdct.h"  #include "../dct/fdct.h"
39  #include "../dct/idct.h"  #include "../dct/idct.h"
40  #include "../quant/quant_mpeg4.h"  #include "../quant/quant_mpeg4.h"
41  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
42  #include "../encoder.h"  #include "../encoder.h"
43    
44  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #include "../image/reduced.h"
 #define MAX(X, Y) ((X)>(Y)?(X):(Y))  
45    
46  #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */  MBFIELDTEST_PTR MBFieldTest;
47    
48  /* this isnt pretty, but its better than 20 ifdefs */  /*
49     * Skip blocks having a coefficient sum below this value. This value will be
50     * corrected according to the MB quantizer to avoid artifacts for quant==1
51     */
52    #define PVOP_TOOSMALL_LIMIT 1
53    #define BVOP_TOOSMALL_LIMIT 3
54    
55  void MBTransQuantIntra(const MBParam *pParam,  /*****************************************************************************
56                         MACROBLOCK * pMB,   * Local functions
57                         const uint32_t x_pos,   ****************************************************************************/
                        const uint32_t y_pos,  
                        int16_t data[6*64],  
                        int16_t qcoeff[6*64],  
                        IMAGE * const pCurrent)  
58    
59    /* permute block and return field dct choice */
60    static __inline uint32_t
61    MBDecideFieldDCT(int16_t data[6 * 64])
62  {  {
63            uint32_t field = MBFieldTest(data);
64    
65          const uint32_t stride = pParam->edged_width;          if (field)
66          uint32_t i;                  MBFrameToField(data);
         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) * (stride >> 1) + (x_pos << 3);  
         pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);  
67    
68          start_timer();          return field;
69          transfer_8to16copy(&data[0*64], pY_Cur, stride);  }
         transfer_8to16copy(&data[1*64], pY_Cur + 8, stride);  
         transfer_8to16copy(&data[2*64], pY_Cur + 8 * stride, stride);  
         transfer_8to16copy(&data[3*64], pY_Cur + 8 * stride + 8, stride);  
         transfer_8to16copy(&data[4*64], pU_Cur, stride / 2);  
         transfer_8to16copy(&data[5*64], pV_Cur, stride / 2);  
         stop_transfer_timer();  
70    
71    /* Performs Forward DCT on all blocks */
72    static __inline void
73    MBfDCT(const MBParam * const pParam,
74               const FRAMEINFO * const frame,
75               MACROBLOCK * const pMB,
76               uint32_t x_pos,
77               uint32_t y_pos,
78               int16_t data[6 * 64])
79    {
80            /* Handles interlacing */
81          start_timer();          start_timer();
82          pMB->field_dct = 0;          pMB->field_dct = 0;
83          if (pParam->global_flags & XVID_INTERLACING)          if ((frame->vol_flags & XVID_VOL_INTERLACING) &&
84          {                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
85                    (y_pos>0) && (y_pos<pParam->mb_height-1)) {
86                  pMB->field_dct = MBDecideFieldDCT(data);                  pMB->field_dct = MBDecideFieldDCT(data);
87          }          }
88          stop_interlacing_timer();          stop_interlacing_timer();
89    
90          for(i = 0; i < 6; i++)          /* Perform DCT */
         {  
                 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  
   
91                  start_timer();                  start_timer();
92                  fdct(&data[i*64]);          fdct(&data[0 * 64]);
93            fdct(&data[1 * 64]);
94            fdct(&data[2 * 64]);
95            fdct(&data[3 * 64]);
96            fdct(&data[4 * 64]);
97            fdct(&data[5 * 64]);
98                  stop_dct_timer();                  stop_dct_timer();
99    }
100    
101                  if (pParam->quant_type == H263_QUANT)  /* Performs Inverse DCT on all blocks */
102    static __inline void
103    MBiDCT(int16_t data[6 * 64],
104               const uint8_t cbp)
105                  {                  {
106                          start_timer();                          start_timer();
107                          quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);          if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);
108                          stop_quant_timer();          if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]);
109            if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]);
110                          start_timer();          if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]);
111                          dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);          if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]);
112                          stop_iquant_timer();          if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]);
113            stop_idct_timer();
114                  }                  }
115                  else  
116    /* Quantize all blocks -- Intra mode */
117    static __inline void
118    MBQuantIntra(const MBParam * pParam,
119                             const FRAMEINFO * const frame,
120                             const MACROBLOCK * pMB,
121                             int16_t qcoeff[6 * 64],
122                             int16_t data[6*64])
123                  {                  {
124                          start_timer();          int i;
                         quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);  
                         stop_quant_timer();  
125    
126                          start_timer();          for (i = 0; i < 6; i++) {
127                          dequant4_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);                  uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4);
                         stop_iquant_timer();  
                 }  
128    
129                    /* Quantize the block */
130                  start_timer();                  start_timer();
131                  idct(&data[i*64]);                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
132                  stop_idct_timer();                          quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
133                    } else {
134                            quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
135                    }
136                    stop_quant_timer();
137            }
138          }          }
139    
140          start_timer();  /* DeQuantize all blocks -- Intra mode */
141          if (pMB->field_dct)  static __inline void
142    MBDeQuantIntra(const MBParam * pParam,
143                               const int iQuant,
144                               int16_t qcoeff[6 * 64],
145                               int16_t data[6*64])
146          {          {
147                  MBFieldToFrame(data);          int i;
         }  
         stop_interlacing_timer();  
148    
149          start_timer();          for (i = 0; i < 6; i++) {
150          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 + 8 * stride,     &data[2*64], stride);  
         transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride);  
         transfer_16to8copy(pU_Cur,                  &data[4*64], stride / 2);  
         transfer_16to8copy(pV_Cur,                  &data[5*64], stride / 2);  
         stop_transfer_timer();  
151    
152                    start_timer();
153                    if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
154                            dequant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
155                    else
156                            dequant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
157                    stop_iquant_timer();
158            }
159  }  }
160    
161    /* Quantize all blocks -- Inter mode */
162  uint8_t MBTransQuantInter(const MBParam *pParam,  static __inline uint8_t
163                            MACROBLOCK * pMB,  MBQuantInter(const MBParam * pParam,
164                            const uint32_t x_pos, const uint32_t y_pos,                           const FRAMEINFO * const frame,
165                             const MACROBLOCK * pMB,
166                            int16_t data[6*64],                            int16_t data[6*64],
167                            int16_t qcoeff[6*64],                            int16_t qcoeff[6*64],
168                            IMAGE * const pCurrent)                           int bvop,
169                             int limit)
170  {  {
171    
172          const uint32_t stride = pParam->edged_width;          int i;
         uint32_t i;  
         uint32_t iQuant = pParam->quant;  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
173          uint8_t cbp = 0;          uint8_t cbp = 0;
174          uint32_t sum;          int sum;
175            int code_block;
176    
177          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          for (i = 0; i < 6; i++) {
         pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);  
         pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);  
178    
179                    /* Quantize the block */
180          start_timer();          start_timer();
181          pMB->field_dct = 0;                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
182          if (pParam->global_flags & XVID_INTERLACING)                          sum = quant_inter(&qcoeff[i*64], &data[i*64], pMB->quant);
183          {                          if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) {
184                  pMB->field_dct = MBDecideFieldDCT(data);                                  sum = dct_quantize_trellis_inter_h263_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1;
185                                    limit = 1;
186                            }
187                    } else {
188                            sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);
189    //                      if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) )
190    //                              sum = dct_quantize_trellis_inter_mpeg_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1;
191          }          }
192          stop_interlacing_timer();                  stop_quant_timer();
193    
         for(i = 0; i < 6; i++)  
         {  
194                  /*                  /*
195                   *  no need to transfer 8->16-bit                   * We code the block if the sum is higher than the limit and if the first
196                   * (this is performed already in motion compensation)                   * two AC coefficients in zig zag order are not zero.
197                   */                   */
198                  start_timer();                  code_block = 0;
199                  fdct(&data[i*64]);                  if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
200                  stop_dct_timer();                          code_block = 1;
201                    } else {
202    
203                  if (pParam->quant_type == 0)                          if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) {
204                  {                                  /* dark blocks prevention for direct mode */
205                          start_timer();                                  if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0))
206                          sum = quant_inter(&qcoeff[i*64], &data[i*64], iQuant);                                          code_block = 1;
207                          stop_quant_timer();                          } else {
208                                    /* not direct mode */
209                                    if (qcoeff[i*64] != 0)
210                                            code_block = 1;
211                  }                  }
                 else  
                 {  
                         start_timer();  
                         sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant);  
                         stop_quant_timer();  
212                  }                  }
213    
214                  if(sum >= TOOSMALL_LIMIT) { // skip block ?                  /* Set the corresponding cbp bit */
215                    cbp |= code_block << (5 - i);
216            }
217    
218            return(cbp);
219    }
220    
221                          if (pParam->quant_type == H263_QUANT)  /* DeQuantize all blocks -- Inter mode */
222    static __inline void
223    MBDeQuantInter(const MBParam * pParam,
224                               const int iQuant,
225                               int16_t data[6 * 64],
226                               int16_t qcoeff[6 * 64],
227                               const uint8_t cbp)
228                          {                          {
229            int i;
230    
231            for (i = 0; i < 6; i++) {
232                    if (cbp & (1 << (5 - i))) {
233                                  start_timer();                                  start_timer();
234                            if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
235                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);
                                 stop_iquant_timer();  
                         }  
236                          else                          else
                         {  
                                 start_timer();  
237                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);
238                                  stop_iquant_timer();                                  stop_iquant_timer();
239                          }                          }
240            }
241    }
242    
243                          cbp |= 1 << (5 - i);  typedef void (transfer_operation_8to16_t) (int16_t *Dst, const uint8_t *Src, int BpS);
244    typedef void (transfer_operation_16to8_t) (uint8_t *Dst, const int16_t *Src, int BpS);
245    
246                          start_timer();  
247                          idct(&data[i*64]);  static __inline void
248                          stop_idct_timer();  MBTrans8to16(const MBParam * const pParam,
249                  }                           const FRAMEINFO * const frame,
250                             const MACROBLOCK * const pMB,
251                             const uint32_t x_pos,
252                             const uint32_t y_pos,
253                             int16_t data[6 * 64])
254    {
255            uint32_t stride = pParam->edged_width;
256            uint32_t stride2 = stride / 2;
257            uint32_t next_block = stride * 8;
258            int32_t cst;
259            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
260            const IMAGE * const pCurrent = &frame->image;
261            transfer_operation_8to16_t *transfer_op = NULL;
262    
263            if ((frame->vop_flags & XVID_VOP_REDUCED)) {
264    
265                    /* Image pointers */
266                    pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);
267                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
268                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
269    
270                    /* Block size */
271                    cst = 16;
272    
273                    /* Operation function */
274                    transfer_op = (transfer_operation_8to16_t*)filter_18x18_to_8x8;
275            } else {
276    
277                    /* Image pointers */
278                    pY_Cur = pCurrent->y + (y_pos << 4) * stride  + (x_pos << 4);
279                    pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
280                    pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
281    
282                    /* Block size */
283                    cst = 8;
284    
285                    /* Operation function */
286                    transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;
287          }          }
288    
289            /* Do the transfer */
290          start_timer();          start_timer();
291          if (pMB->field_dct)          transfer_op(&data[0 * 64], pY_Cur, stride);
292            transfer_op(&data[1 * 64], pY_Cur + cst, stride);
293            transfer_op(&data[2 * 64], pY_Cur + next_block, stride);
294            transfer_op(&data[3 * 64], pY_Cur + next_block + cst, stride);
295            transfer_op(&data[4 * 64], pU_Cur, stride2);
296            transfer_op(&data[5 * 64], pV_Cur, stride2);
297            stop_transfer_timer();
298    }
299    
300    static __inline void
301    MBTrans16to8(const MBParam * const pParam,
302                             const FRAMEINFO * const frame,
303                             const MACROBLOCK * const pMB,
304                             const uint32_t x_pos,
305                             const uint32_t y_pos,
306                             int16_t data[6 * 64],
307                             const uint32_t add,
308                             const uint8_t cbp)
309          {          {
310                  MBFieldToFrame(data);          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
311            uint32_t stride = pParam->edged_width;
312            uint32_t stride2 = stride / 2;
313            uint32_t next_block = stride * 8;
314            uint32_t cst;
315            const IMAGE * const pCurrent = &frame->image;
316            transfer_operation_16to8_t *transfer_op = NULL;
317    
318            if (pMB->field_dct) {
319                    next_block = stride;
320                    stride *= 2;
321            }
322    
323            if ((frame->vop_flags & XVID_VOP_REDUCED)) {
324    
325                    /* Image pointers */
326                    pY_Cur = pCurrent->y + (y_pos << 5) * stride  + (x_pos << 5);
327                    pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
328                    pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
329    
330                    /* Block size */
331                    cst = 16;
332    
333                    /* Operation function */
334                    if(add)
335                            transfer_op = (transfer_operation_16to8_t*)add_upsampled_8x8_16to8;
336                    else
337                            transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8;
338            } else {
339    
340                    /* Image pointers */
341                    pY_Cur = pCurrent->y + (y_pos << 4) * stride  + (x_pos << 4);
342                    pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
343                    pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
344    
345                    /* Block size */
346                    cst = 8;
347    
348                    /* Operation function */
349                    if(add)
350                            transfer_op = (transfer_operation_16to8_t*)transfer_16to8add;
351                    else
352                            transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy;
353          }          }
         stop_interlacing_timer();  
354    
355            /* Do the operation */
356          start_timer();          start_timer();
357          if (cbp & 32)          if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);
358                  transfer_16to8add(pY_Cur,                  &data[0*64], stride);          if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride);
359          if (cbp & 16)          if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride);
360                  transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);          if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride);
361          if (cbp & 8)          if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2);
362                  transfer_16to8add(pY_Cur + 8 * stride,     &data[2*64], stride);          if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2);
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur,                  &data[4*64], stride / 2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur,                  &data[5*64], stride / 2);  
363          stop_transfer_timer();          stop_transfer_timer();
364    }
365    
366    /*****************************************************************************
367     * Module functions
368     ****************************************************************************/
369    
370    void
371    MBTransQuantIntra(const MBParam * const pParam,
372                                      const FRAMEINFO * const frame,
373                                      MACROBLOCK * const pMB,
374                                      const uint32_t x_pos,
375                                      const uint32_t y_pos,
376                                      int16_t data[6 * 64],
377                                      int16_t qcoeff[6 * 64])
378    {
379    
380            /* Transfer data */
381            MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data);
382    
383            /* Perform DCT (and field decision) */
384            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
385    
386          return cbp;          /* Quantize the block */
387            MBQuantIntra(pParam, frame, pMB, data, qcoeff);
388    
389            /* DeQuantize the block */
390            MBDeQuantIntra(pParam, pMB->quant, data, qcoeff);
391    
392            /* Perform inverse DCT*/
393            MBiDCT(data, 0x3F);
394    
395            /* Transfer back the data -- Don't add data */
396            MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F);
397  }  }
398    
399    
400  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */  uint8_t
401    MBTransQuantInter(const MBParam * const pParam,
402                                      const FRAMEINFO * const frame,
403                                      MACROBLOCK * const pMB,
404                                      const uint32_t x_pos,
405                                      const uint32_t y_pos,
406                                      int16_t data[6 * 64],
407                                      int16_t qcoeff[6 * 64])
408    {
409            uint8_t cbp;
410            uint32_t limit;
411    
412            /*
413             * There is no MBTrans8to16 for Inter block, that's done in motion compensation
414             * already
415             */
416    
417            /* Perform DCT (and field decision) */
418            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
419    
420            /* Set the limit threshold */
421            limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0);
422    
423            /* Quantize the block */
424            cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 0, limit);
425    
426            /* DeQuantize the block */
427            MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
428    
429            /* Perform inverse DCT*/
430            MBiDCT(data, cbp);
431    
432  #define ABS(X) (X)<0 ? -(X) : (X)          /* Transfer back the data -- Add the data */
433            MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
434    
435  uint32_t MBDecideFieldDCT(int16_t data[6*64])          return(cbp);
436    }
437    
438    uint8_t
439    MBTransQuantInterBVOP(const MBParam * pParam,
440                                      FRAMEINFO * frame,
441                                      MACROBLOCK * pMB,
442                                      const uint32_t x_pos,
443                                      const uint32_t y_pos,
444                                      int16_t data[6 * 64],
445                                      int16_t qcoeff[6 * 64])
446  {  {
447            uint8_t cbp;
448            uint32_t limit;
449    
450            /*
451             * There is no MBTrans8to16 for Inter block, that's done in motion compensation
452             * already
453             */
454    
455            /* Perform DCT (and field decision) */
456            MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
457    
458            /* Set the limit threshold */
459            limit = BVOP_TOOSMALL_LIMIT;
460    
461            /* Quantize the block */
462            cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 1, limit);
463    
464          const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64};          /*
465             * History comment:
466             * We don't have to DeQuant, iDCT and Transfer back data for B-frames.
467             *
468             * BUT some plugins require the original frame to be passed so we have
469             * to take care of that here
470             */
471            if((pParam->plugin_flags & XVID_REQORIGINAL)) {
472    
473                    /* DeQuantize the block */
474                    MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
475    
476                    /* Perform inverse DCT*/
477                    MBiDCT(data, cbp);
478    
479                    /* Transfer back the data -- Add the data */
480                    MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
481            }
482    
483            return(cbp);
484    }
485    
486    /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
487    uint32_t
488    MBFieldTest_c(int16_t data[6 * 64])
489    {
490            const uint8_t blocks[] =
491                    { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
492          const uint8_t lines[]  = {0, 16, 32, 48, 0, 16, 32, 48};          const uint8_t lines[]  = {0, 16, 32, 48, 0, 16, 32, 48};
493    
494          int frame = 0, field = 0;          int frame = 0, field = 0;
495          int i, j;          int i, j;
496    
497          for (i=0 ; i<7 ; ++i)          for (i = 0; i < 7; ++i) {
498          {                  for (j = 0; j < 8; ++j) {
499                  for (j=0 ; j<8 ; ++j)                          frame +=
500                  {                                  abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
501                          frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]);                          frame +=
502                          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]);
503                          frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]);                          frame +=
504                          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]);
505                            frame +=
506                                    abs(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
507    
508                          field += ABS(data[blocks[i+1] + lines[i+1] + j] -\                          field +=
509                                    abs(data[blocks[i + 1] + lines[i + 1] + j] -
510                                       data[blocks[i  ] + lines[i  ] + j]);                                       data[blocks[i  ] + lines[i  ] + j]);
511                          field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\                          field +=
512                                    abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
513                                       data[blocks[i  ] + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + lines[i  ] + 8 + j]);
514                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\                          field +=
515                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
516                                       data[blocks[i  ] + 64 + lines[i  ] + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + j]);
517                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\                          field +=
518                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
519                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);
520                  }                  }
521          }          }
522    
523          if (frame > field)          return (frame >= (field + 350));
         {  
                 MBFrameToField(data);  
         }  
   
         return (frame > field);  
524  }  }
525    
526    
# Line 307  Line 529 
529  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
530  #define LINE(X,Y)    &data[X*64 + Y*8]  #define LINE(X,Y)    &data[X*64 + Y*8]
531    
532  void MBFrameToField(int16_t data[6*64])  void
533    MBFrameToField(int16_t data[6 * 64])
534  {  {
535          int16_t tmp[8];          int16_t tmp[8];
536    
# Line 367  Line 590 
590          MOVLINE(LINE(3,5),      LINE(3,3));          MOVLINE(LINE(3,5),      LINE(3,3));
591          MOVLINE(LINE(3,3),      tmp);          MOVLINE(LINE(3,3),      tmp);
592  }  }
   
   
 /* interlace Y blocks vertically */  
   
 void MBFieldToFrame(int16_t data[6*64])  
 {  
         uint16_t tmp[8];  
   
         /* left blocks */  
   
         // 1=8, 8=4, 4=2, 2=1  
         MOVLINE(tmp,            LINE(0,1));  
         MOVLINE(LINE(0,1),      LINE(2,0));  
         MOVLINE(LINE(2,0),      LINE(0,4));  
         MOVLINE(LINE(0,4),      LINE(0,2));  
         MOVLINE(LINE(0,2),      tmp);  
   
         // 3=9, 9=12, 12=6, 6=3  
         MOVLINE(tmp,            LINE(0,3));  
         MOVLINE(LINE(0,3),      LINE(2,1));  
         MOVLINE(LINE(2,1),      LINE(2,4));  
         MOVLINE(LINE(2,4),      LINE(0,6));  
         MOVLINE(LINE(0,6),      tmp);  
   
         // 5=10, 10=5  
         MOVLINE(tmp,            LINE(0,5));  
         MOVLINE(LINE(0,5),      LINE(2,2));  
         MOVLINE(LINE(2,2),      tmp);  
   
         // 7=11, 11=13, 13=14, 14=7  
         MOVLINE(tmp,            LINE(0,7));  
         MOVLINE(LINE(0,7),      LINE(2,3));  
         MOVLINE(LINE(2,3),      LINE(2,5));  
         MOVLINE(LINE(2,5),      LINE(2,6));  
         MOVLINE(LINE(2,6),      tmp);  
   
         /* right blocks */  
   
         // 1=8, 8=4, 4=2, 2=1  
         MOVLINE(tmp,            LINE(1,1));  
         MOVLINE(LINE(1,1),      LINE(3,0));  
         MOVLINE(LINE(3,0),      LINE(1,4));  
         MOVLINE(LINE(1,4),      LINE(1,2));  
         MOVLINE(LINE(1,2),      tmp);  
   
         // 3=9, 9=12, 12=6, 6=3  
         MOVLINE(tmp,            LINE(1,3));  
         MOVLINE(LINE(1,3),      LINE(3,1));  
         MOVLINE(LINE(3,1),      LINE(3,4));  
         MOVLINE(LINE(3,4),      LINE(1,6));  
         MOVLINE(LINE(1,6),      tmp);  
   
         // 5=10, 10=5  
         MOVLINE(tmp,            LINE(1,5));  
         MOVLINE(LINE(1,5),      LINE(3,2));  
         MOVLINE(LINE(3,2),      tmp);  
   
         // 7=11, 11=13, 13=14, 14=7  
         MOVLINE(tmp,            LINE(1,7));  
         MOVLINE(LINE(1,7),      LINE(3,3));  
         MOVLINE(LINE(3,3),      LINE(3,5));  
         MOVLINE(LINE(3,5),      LINE(3,6));  
         MOVLINE(LINE(3,6),      tmp);  
 }  

Legend:
Removed from v.78  
changed lines
  Added in v.995

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