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

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

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