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

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

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

revision 1.1.1.1, Fri Mar 8 02:44:58 2002 UTC revision 1.21.2.9, 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$
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:                                                         *  
   *                                                                            *  
   *  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 54  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))  
   
 #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */  
45    
46  /* this isnt pretty, but its better than 20 ifdefs */  MBFIELDTEST_PTR MBFieldTest;
47    
48  void MBTransQuantIntra(const MBParam *pParam,  /*
49                         const uint32_t x_pos,   * Skip blocks having a coefficient sum below this value. This value will be
50                         const uint32_t y_pos,   * corrected according to the MB quantizer to avoid artifacts for quant==1
51                         int16_t data[][64],   */
52                             int16_t qcoeff[][64],  #define PVOP_TOOSMALL_LIMIT 1
53                             IMAGE * const pCurrent)  #define BVOP_TOOSMALL_LIMIT 3
54    
55    /*****************************************************************************
56     * Local functions
57     ****************************************************************************/
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          for(i = 0; i < 6; i++) {          return field;
69                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);  }
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;
83                  switch(i) {          if ((frame->vol_flags & XVID_VOL_INTERLACING) &&
84                  case 0 :                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
85                          transfer_8to16copy(data[0], pY_Cur, stride);                  (y_pos>0) && (y_pos<pParam->mb_height-1)) {
86                          break;                  pMB->field_dct = MBDecideFieldDCT(data);
87                  case 1 :          }
88                          transfer_8to16copy(data[1], pY_Cur + 8, stride);          stop_interlacing_timer();
89                          break;  
90                  case 2 :          /* Perform DCT */
91                      transfer_8to16copy(data[2], pY_Cur + 8 * stride, stride);          start_timer();
92                          break;          fdct(&data[0 * 64]);
93                  case 3 :          fdct(&data[1 * 64]);
94                          transfer_8to16copy(data[3], pY_Cur + 8 * stride + 8, stride);          fdct(&data[2 * 64]);
95                          break;          fdct(&data[3 * 64]);
96                  case 4 :          fdct(&data[4 * 64]);
97                          transfer_8to16copy(data[4], pU_Cur, stride / 2);          fdct(&data[5 * 64]);
98                          break;          stop_dct_timer();
                 case 5 :  
                         transfer_8to16copy(data[5], pV_Cur, stride / 2);  
                         break;  
99                  }                  }
                 stop_transfer_timer();  
100    
101    /* 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                  fdct(data[i]);          if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);
108                  stop_dct_timer();          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                  if (pParam->quant_type == H263_QUANT)  /* 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();                          start_timer();
131                          quant_intra(qcoeff[i], data[i], iQuant, iDcScaler);                  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);
216                  stop_idct_timer();          }
217    
218                  start_timer();          return(cbp);
219    }
220    
221                  switch(i) {  /* DeQuantize all blocks -- Inter mode */
222                  case 0:  static __inline void
223                          transfer_16to8copy(pY_Cur, data[0], stride);  MBDeQuantInter(const MBParam * pParam,
224                          break;                             const int iQuant,
225                  case 1:                             int16_t data[6 * 64],
226                          transfer_16to8copy(pY_Cur + 8, data[1], stride);                             int16_t qcoeff[6 * 64],
227                          break;                             const uint8_t cbp)
228                  case 2:  {
229                          transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride);          int i;
230                          break;  
231                  case 3:          for (i = 0; i < 6; i++) {
232                          transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride);                  if (cbp & (1 << (5 - i))) {
233                          break;                          start_timer();
234                  case 4:                          if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
235                          transfer_16to8copy(pU_Cur, data[4], stride / 2);                                  dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
236                          break;                          else
237                  case 5:                                  dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
238                          transfer_16to8copy(pV_Cur, data[5], stride / 2);                          stop_iquant_timer();
                         break;  
239                  }                  }
                 stop_transfer_timer();  
240      }      }
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,  
                                         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      uint8_t i;          uint32_t stride2 = stride / 2;
257      uint8_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      for(i = 0; i < 6; i++) {                  /* Block size */
283                  /*                  cst = 8;
284                  no need to transfer 8->16-bit  
285                  (this is performed already in motion compensation)                  /* Operation function */
286                  */                  transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;
287            }
288    
289            /* Do the transfer */
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            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            }
354    
355            /* Do the operation */
356                          start_timer();                          start_timer();
357                          sum = quant_inter(qcoeff[i], data[i], iQuant);          if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);
358                          stop_quant_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                  else  
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                          start_timer();  
380                          sum = quant4_inter(qcoeff[i], data[i], iQuant);          /* Transfer data */
381                          stop_quant_timer();          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            /* 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    
                 if(sum >= TOOSMALL_LIMIT) { // skip block ?  
399    
400                          if (pParam->quant_type == H263_QUANT)  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                                  start_timer();          uint8_t cbp;
410                                  dequant_inter(data[i], qcoeff[i], iQuant);          uint32_t limit;
411                                  stop_iquant_timer();  
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                          else  
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                                  start_timer();          uint8_t cbp;
448                                  dequant4_inter(data[i], qcoeff[i], iQuant);          uint32_t limit;
                                 stop_iquant_timer();  
                         }  
449    
450                          cbp |= 1 << (5 - i);          /*
451             * There is no MBTrans8to16 for Inter block, that's done in motion compensation
452             * already
453             */
454    
455                          start_timer();          /* Perform DCT (and field decision) */
456                          idct(data[i]);          MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
                         stop_idct_timer();  
457    
458                          start_timer();          /* 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            /*
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                          switch(i) {                  /* Perform inverse DCT*/
477                          case 0:                  MBiDCT(data, cbp);
478                                  transfer_16to8add(pY_Cur, data[0], stride);  
479                                  break;                  /* Transfer back the data -- Add the data */
480                          case 1:                  MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
                                 transfer_16to8add(pY_Cur + 8, data[1], stride);  
                                 break;  
                         case 2:  
                                 transfer_16to8add(pY_Cur + 8 * stride, data[2], stride);  
                                 break;  
                         case 3:  
                                 transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride);  
                                 break;  
                         case 4:  
                                 transfer_16to8add(pU_Cur, data[4], stride / 2);  
                                 break;  
                         case 5:  
                                 transfer_16to8add(pV_Cur, data[5], stride / 2);  
                                 break;  
481                          }                          }
482                          stop_transfer_timer();  
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 };
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      return cbp;  
523            return (frame >= (field + 350));
524    }
525    
526    
527    /* deinterlace Y blocks vertically */
528    
529    #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
530    #define LINE(X,Y)       &data[X*64 + Y*8]
531    
532    void
533    MBFrameToField(int16_t data[6 * 64])
534    {
535            int16_t tmp[8];
536    
537            /* left blocks */
538    
539            // 1=2, 2=4, 4=8, 8=1
540            MOVLINE(tmp, LINE(0, 1));
541            MOVLINE(LINE(0, 1), LINE(0, 2));
542            MOVLINE(LINE(0, 2), LINE(0, 4));
543            MOVLINE(LINE(0, 4), LINE(2, 0));
544            MOVLINE(LINE(2, 0), tmp);
545    
546            // 3=6, 6=12, 12=9, 9=3
547            MOVLINE(tmp, LINE(0, 3));
548            MOVLINE(LINE(0, 3), LINE(0, 6));
549            MOVLINE(LINE(0, 6), LINE(2, 4));
550            MOVLINE(LINE(2, 4), LINE(2, 1));
551            MOVLINE(LINE(2, 1), tmp);
552    
553            // 5=10, 10=5
554            MOVLINE(tmp, LINE(0, 5));
555            MOVLINE(LINE(0, 5), LINE(2, 2));
556            MOVLINE(LINE(2, 2), tmp);
557    
558            // 7=14, 14=13, 13=11, 11=7
559            MOVLINE(tmp, LINE(0, 7));
560            MOVLINE(LINE(0, 7), LINE(2, 6));
561            MOVLINE(LINE(2, 6), LINE(2, 5));
562            MOVLINE(LINE(2, 5), LINE(2, 3));
563            MOVLINE(LINE(2, 3), tmp);
564    
565            /* right blocks */
566    
567            // 1=2, 2=4, 4=8, 8=1
568            MOVLINE(tmp, LINE(1, 1));
569            MOVLINE(LINE(1, 1), LINE(1, 2));
570            MOVLINE(LINE(1, 2), LINE(1, 4));
571            MOVLINE(LINE(1, 4), LINE(3, 0));
572            MOVLINE(LINE(3, 0), tmp);
573    
574            // 3=6, 6=12, 12=9, 9=3
575            MOVLINE(tmp, LINE(1, 3));
576            MOVLINE(LINE(1, 3), LINE(1, 6));
577            MOVLINE(LINE(1, 6), LINE(3, 4));
578            MOVLINE(LINE(3, 4), LINE(3, 1));
579            MOVLINE(LINE(3, 1), tmp);
580    
581            // 5=10, 10=5
582            MOVLINE(tmp, LINE(1, 5));
583            MOVLINE(LINE(1, 5), LINE(3, 2));
584            MOVLINE(LINE(3, 2), tmp);
585    
586            // 7=14, 14=13, 13=11, 11=7
587            MOVLINE(tmp, LINE(1, 7));
588            MOVLINE(LINE(1, 7), LINE(3, 6));
589            MOVLINE(LINE(3, 6), LINE(3, 5));
590            MOVLINE(LINE(3, 5), LINE(3, 3));
591            MOVLINE(LINE(3, 3), tmp);
592  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.21.2.9

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