[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 69, Tue Mar 26 11:16:08 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  *   ****************************************************************************/
27    *                                                                            *  
28    ******************************************************************************/  #include <string.h>
29    #include <stdlib.h>
  /******************************************************************************  
   *                                                                            *  
   *  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                                                *  
   *                                                                            *  
   ******************************************************************************/  
30    
31  #include "../portab.h"  #include "../portab.h"
32  #include "mbfunctions.h"  #include "mbfunctions.h"
# Line 55  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[][64],  
                            int16_t qcoeff[][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          const uint32_t stride = pParam->edged_width;          uint32_t field = MBFieldTest(data);
         uint32_t i;  
         uint32_t iQuant = pParam->quant;  
         uint8_t *pY_Cur, *pU_Cur, *pV_Cur;  
64    
65      pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          if (field)
66      pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);                  MBFrameToField(data);
     pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);  
67    
68          start_timer();          return field;
69          transfer_8to16copy(data[0], pY_Cur, stride);  }
         transfer_8to16copy(data[1], pY_Cur + 8, stride);  
     transfer_8to16copy(data[2], pY_Cur + 8 * stride, stride);  
         transfer_8to16copy(data[3], pY_Cur + 8 * stride + 8, stride);  
         transfer_8to16copy(data[4], pU_Cur, stride / 2);  
         transfer_8to16copy(data[5], 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]);          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], data[i], iQuant, iDcScaler);          if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);
108            if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]);
109            if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]);
110            if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]);
111            if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]);
112            if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]);
113            stop_idct_timer();
114    }
115    
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            int i;
125    
126            for (i = 0; i < 6; i++) {
127                    uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4);
128    
129                    /* Quantize the block */
130                    start_timer();
131                    if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
132                            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();                          stop_quant_timer();
137            }
138    }
139    
140    /* DeQuantize all blocks -- Intra mode */
141    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            int i;
148    
149            for (i = 0; i < 6; i++) {
150                    uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
151    
152                          start_timer();                          start_timer();
153                          dequant_intra(data[i], qcoeff[i], iQuant, iDcScaler);                  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();                          stop_iquant_timer();
158                  }                  }
159                  else  }
160    
161    /* Quantize all blocks -- Inter mode */
162    static __inline uint8_t
163    MBQuantInter(const MBParam * pParam,
164                             const FRAMEINFO * const frame,
165                             const MACROBLOCK * pMB,
166                             int16_t data[6 * 64],
167                             int16_t qcoeff[6 * 64],
168                             int bvop,
169                             int limit)
170                  {                  {
171    
172            int i;
173            uint8_t cbp = 0;
174            int sum;
175            int code_block;
176    
177            for (i = 0; i < 6; i++) {
178    
179                    /* Quantize the block */
180                          start_timer();                          start_timer();
181                          quant4_intra(qcoeff[i], data[i], iQuant, iDcScaler);                  if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
182                            sum = quant_inter(&qcoeff[i*64], &data[i*64], pMB->quant);
183                            if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) {
184                                    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_quant_timer();                          stop_quant_timer();
193    
194                          start_timer();                  /*
195                          dequant4_intra(data[i], qcoeff[i], iQuant, iDcScaler);                   * We code the block if the sum is higher than the limit and if the first
196                          stop_iquant_timer();                   * two AC coefficients in zig zag order are not zero.
197                     */
198                    code_block = 0;
199                    if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
200                            code_block = 1;
201                    } else {
202    
203                            if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) {
204                                    /* dark blocks prevention for direct mode */
205                                    if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0))
206                                            code_block = 1;
207                            } else {
208                                    /* not direct mode */
209                                    if (qcoeff[i*64] != 0)
210                                            code_block = 1;
211                            }
212                  }                  }
213    
214                  start_timer();                  /* Set the corresponding cbp bit */
215                  idct(data[i]);                  cbp |= code_block << (5 - i);
                 stop_idct_timer();  
216      }      }
217    
218          start_timer();          return(cbp);
         if (pMB->field_dct)  
         {  
                 MBFieldToFrame(data);  
219          }          }
         stop_interlacing_timer();  
220    
221    /* 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          transfer_16to8copy(pY_Cur, data[0], stride);                          if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
235          transfer_16to8copy(pY_Cur + 8, data[1], stride);                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
236          transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride);                          else
237          transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride);                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
238          transfer_16to8copy(pU_Cur, data[4], stride / 2);                          stop_iquant_timer();
239          transfer_16to8copy(pV_Cur, data[5], stride / 2);                  }
240          stop_transfer_timer();          }
241  }  }
242    
243    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    
 uint8_t MBTransQuantInter(const MBParam *pParam,  
                                         MACROBLOCK * pMB,  
                                         const uint32_t x_pos, const uint32_t y_pos,  
                                         int16_t data[][64],  
                                         int16_t qcoeff[][64],  
                                         IMAGE * const pCurrent)  
246    
247    static __inline void
248    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          const uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
256      uint32_t i;          uint32_t stride2 = stride / 2;
257      uint32_t iQuant = pParam->quant;          uint32_t next_block = stride * 8;
258            int32_t cst;
259          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
260      uint8_t cbp = 0;          const IMAGE * const pCurrent = &frame->image;
261          uint32_t sum;          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);      pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
279      pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);                  pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
280      pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);                  pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
281    
282          start_timer();                  /* Block size */
283          pMB->field_dct = 0;                  cst = 8;
284          if (pParam->global_flags & XVID_INTERLACING)  
285          {                  /* Operation function */
286                  pMB->field_dct = MBDecideFieldDCT(data);                  transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;
287          }          }
         stop_interlacing_timer();  
288    
289      for(i = 0; i < 6; i++)          /* Do the transfer */
         {  
                 /*  
                 no need to transfer 8->16-bit  
                 (this is performed already in motion compensation)  
                 */  
290                  start_timer();                  start_timer();
291                  fdct(data[i]);          transfer_op(&data[0 * 64], pY_Cur, stride);
292                  stop_dct_timer();          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                  if (pParam->quant_type == 0)  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                          start_timer();          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
311                          sum = quant_inter(qcoeff[i], data[i], iQuant);          uint32_t stride = pParam->edged_width;
312                          stop_quant_timer();          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                  else
337                  {                          transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8;
338                          start_timer();          } else {
                         sum = quant4_inter(qcoeff[i], data[i], iQuant);  
                         stop_quant_timer();  
                 }  
339    
340                  if(sum >= TOOSMALL_LIMIT) { // skip block ?                  /* 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                          if (pParam->quant_type == H263_QUANT)                  /* Block size */
346                          {                  cst = 8;
347                                  start_timer();  
348                                  dequant_inter(data[i], qcoeff[i], iQuant);                  /* Operation function */
349                                  stop_iquant_timer();                  if(add)
350                          }                          transfer_op = (transfer_operation_16to8_t*)transfer_16to8add;
351                          else                          else
352                          {                          transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy;
                                 start_timer();  
                                 dequant4_inter(data[i], qcoeff[i], iQuant);  
                                 stop_iquant_timer();  
353                          }                          }
354    
355                          cbp |= 1 << (5 - i);          /* Do the operation */
   
356                          start_timer();                          start_timer();
357                          idct(data[i]);          if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);
358                          stop_idct_timer();          if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride);
359                  }          if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride);
360            if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride);
361            if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2);
362            if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2);
363            stop_transfer_timer();
364          }          }
365    
366          start_timer();  /*****************************************************************************
367          if (pMB->field_dct)   * 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          {          {
                 MBFieldToFrame(data);  
         }  
         stop_interlacing_timer();  
379    
380          start_timer();          /* Transfer data */
381          if (cbp & 32)          MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data);
                 transfer_16to8add(pY_Cur, data[0], stride);  
         if (cbp & 16)  
                 transfer_16to8add(pY_Cur + 8, data[1], stride);  
         if (cbp & 8)  
                 transfer_16to8add(pY_Cur + 8 * stride, data[2], stride);  
         if (cbp & 4)  
                 transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride);  
         if (cbp & 2)  
                 transfer_16to8add(pU_Cur, data[4], stride / 2);  
         if (cbp & 1)  
                 transfer_16to8add(pV_Cur, data[5], stride / 2);  
         stop_transfer_timer();  
382    
383      return cbp;          /* Perform DCT (and field decision) */
384  }          MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
385    
386            /* Quantize the block */
387            MBQuantIntra(pParam, frame, pMB, data, qcoeff);
388    
389  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */          /* DeQuantize the block */
390            MBDeQuantIntra(pParam, pMB->quant, data, qcoeff);
391    
392  #define ABS(X) (X)<0 ? -(X) : (X)          /* Perform inverse DCT*/
393            MBiDCT(data, 0x3F);
394    
395  uint32_t MBDecideFieldDCT(int16_t data[][64])          /* Transfer back the data -- Don't add data */
396  {          MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F);
397          const uint8_t blocks[] = {0, 0, 0, 0, 2, 2, 2, 2};  }
         const uint8_t lines[] = {0, 16, 32, 48, 0, 16, 32, 48};  
398    
         int frame = 0, field = 0;  
         int i, j;  
399    
400          for (i=0 ; i<7 ; ++i)  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                  for (j=0 ; j<8 ; ++j)          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            /* Transfer back the data -- Add the data */
433            MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
434    
435            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                          frame += ABS(data[0][(i+1)*8 + j] - data[0][i*8 + j]);          uint8_t cbp;
448                          frame += ABS(data[1][(i+1)*8 + j] - data[1][i*8 + j]);          uint32_t limit;
449                          frame += ABS(data[2][(i+1)*8 + j] - data[2][i*8 + j]);  
450                          frame += ABS(data[3][(i+1)*8 + j] - data[3][i*8 + j]);          /*
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                          field += ABS(data[blocks[i+1]][lines[i+1] + j] - data[blocks[i]][lines[i] + j]);          /*
465                          field += ABS(data[blocks[i+1]][lines[i+1] + 8 + j] - data[blocks[i]][lines[i] + 8 + j]);           * History comment:
466                          field += ABS(data[blocks[i+1]+1][lines[i+1] + j] - data[blocks[i]+1][lines[i] + j]);           * We don't have to DeQuant, iDCT and Transfer back data for B-frames.
467                          field += ABS(data[blocks[i+1]+1][lines[i+1] + 8 + j] - data[blocks[i]+1][lines[i] + 8 + j]);           *
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 (frame > field)  /* 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                  MBFrameToField(data);          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 };
493    
494            int frame = 0, field = 0;
495            int i, j;
496    
497            for (i = 0; i < 7; ++i) {
498                    for (j = 0; j < 8; ++j) {
499                            frame +=
500                                    abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
501                            frame +=
502                                    abs(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
503                            frame +=
504                                    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 +=
509                                    abs(data[blocks[i + 1] + lines[i + 1] + j] -
510                                            data[blocks[i] + lines[i] + j]);
511                            field +=
512                                    abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
513                                            data[blocks[i] + lines[i] + 8 + j]);
514                            field +=
515                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
516                                            data[blocks[i] + 64 + lines[i] + j]);
517                            field +=
518                                    abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
519                                            data[blocks[i] + 64 + lines[i] + 8 + j]);
520                    }
521          }          }
522    
523          return (frame > field);          return (frame >= (field + 350));
524  }  }
525    
526    
527  /* deinterlace Y blocks vertically */  /* deinterlace Y blocks vertically */
528    
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][Y*8]  #define LINE(X,Y)       &data[X*64 + Y*8]
531    
532  void MBFrameToField(int16_t data[][64])  void
533    MBFrameToField(int16_t data[6 * 64])
534  {  {
535          int16_t tmp[8];          int16_t tmp[8];
536    
# Line 356  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[][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.69  
changed lines
  Added in v.995

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