[cvs] / xvidcore / src / quant / quant_matrix.c Repository:
ViewVC logotype

Diff of /xvidcore/src/quant/quant_matrix.c

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

revision 1.1.1.1, Fri Mar 8 02:44:55 2002 UTC revision 1.17, Tue Dec 28 19:19:43 2010 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *    XVID MPEG-4 VIDEO CODEC   *    XVID MPEG-4 VIDEO CODEC
4   *    mpeg-4 quantization matrix stuff   *  - Quantization matrix management code  -
5   *   *
6   *    This program is an implementation of a part of one or more MPEG-4   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *    Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *               2002 Peter Ross <pross@xvid.org>
  *    to use this software module in hardware or software products are  
  *    advised that its use may infringe existing patents or copyrights, and  
  *    any such use would be at such party's own risk.  The original  
  *    developer of this software module and his/her company, and subsequent  
  *    editors and their companies, will have no liability for use of this  
  *    software or modifications or derivatives thereof.  
8   *   *
9   *    This program is free software; you can redistribute it and/or modify   *    This program is free software; you can redistribute it and/or modify
10   *    it under the terms of the GNU General Public License as published by   *    it under the terms of the GNU General Public License as published by
# Line 24  Line 18 
18   *   *
19   *    You should have received a copy of the GNU General Public License   *    You should have received a copy of the GNU General Public License
20   *    along with this program; if not, write to the Free Software   *    along with this program; if not, write to the Free Software
21   *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   *************************************************************************/   * $Id$
   
 /**************************************************************************  
  *  
  *    History:  
24   *   *
25   *      2.3.2002    inital version <suxen_drol@hotmail.com>   ****************************************************************************/
26   *  
27   *************************************************************************/  #include "quant_matrix.h"
28    
29  #include "common.h"  #define FIX(X)   (((X)==1) ? 0xFFFF : ((1UL << 16) / (X) + 1))
30    #define FIXL(X)    ((1UL << 16) / (X) - 1)
31    
32    /*****************************************************************************
33     * Default matrices
34     ****************************************************************************/
35    
36  static const int16_t default_intra_matrix[64] = {  static const uint8_t default_intra_matrix[64] = {
37       8,17,18,19,21,23,25,27,       8,17,18,19,21,23,25,27,
38      17,18,19,21,23,25,27,28,      17,18,19,21,23,25,27,28,
39      20,21,22,23,24,26,28,30,      20,21,22,23,24,26,28,30,
# Line 50  Line 44 
44      27,28,30,32,35,38,41,45      27,28,30,32,35,38,41,45
45  };  };
46    
47  static const int16_t default_inter_matrix[64] = {  static const uint8_t default_inter_matrix[64] = {
48      16,17,18,19,20,21,22,23,      16,17,18,19,20,21,22,23,
49      17,18,19,20,21,22,23,24,      17,18,19,20,21,22,23,24,
50      18,19,20,21,22,23,24,25,      18,19,20,21,22,23,24,25,
# Line 61  Line 55 
55      23,24,25,27,28,30,31,33      23,24,25,27,28,30,31,33
56  };  };
57    
58    const uint16_t *
59    get_intra_matrix(const uint16_t * mpeg_quant_matrices)
60    {
61            return(mpeg_quant_matrices + 0*64);
62    }
63    
64  void quant4_intra_init(QMATRIX * qmatrix, int use_default)  const uint16_t *
65    get_inter_matrix(const uint16_t * mpeg_quant_matrices)
66  {  {
67          if (use_default)          return(mpeg_quant_matrices + 4*64);
68    }
69    
70    const uint8_t *
71    get_default_intra_matrix(void)
72          {          {
73                  memcpy(qmatrix->intra, default_intra_matrix, 64 * sizeof (int16_t));          return default_intra_matrix;
74          }          }
75    
76  #ifdef ARCH_X86  const uint8_t *
77          // TODO: generate mmx tables  get_default_inter_matrix(void)
78  #endif  {
79            return default_inter_matrix;
80    }
81    
82    int
83    is_custom_intra_matrix(const uint16_t * mpeg_quant_matrices)
84    {
85            int i;
86            const uint16_t *intra_matrix = get_intra_matrix(mpeg_quant_matrices);
87            const uint8_t *def_intra_matrix = get_default_intra_matrix();
88    
89            for (i = 0; i < 64; i++) {
90                    if(intra_matrix[i] != def_intra_matrix[i])
91                            return 1;
92            }
93            return 0;
94  }  }
95    
96    int
97    is_custom_inter_matrix(const uint16_t * mpeg_quant_matrices)
98    {
99            int i;
100            const uint16_t *inter_matrix = get_inter_matrix(mpeg_quant_matrices);
101            const uint8_t *def_inter_matrix = get_default_inter_matrix();
102    
103            for (i = 0; i < 64; i++) {
104                    if(inter_matrix[i] != (uint16_t)def_inter_matrix[i])
105                            return 1;
106            }
107            return 0;
108    }
109    
110    void
111    set_intra_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
112    {
113            int i;
114            uint16_t *intra_matrix = mpeg_quant_matrices + 0*64;
115    
116            for (i = 0; i < 64; i++) {
117                    intra_matrix[i] = (!i) ? (uint16_t)8: (uint16_t)matrix[i];
118            }
119    }
120    
121  void quant4_inter_init(QMATRIX * qmatrix, int use_default)  void
122    init_intra_matrix(uint16_t * mpeg_quant_matrices, uint32_t quant)
123  {  {
124          if (use_default)          int i;
125            uint16_t *intra_matrix = mpeg_quant_matrices + 0*64;
126            uint16_t *intra_matrix_rec = mpeg_quant_matrices + 1*64;
127    
128            for (i = 0; i < 64; i++) {
129                    uint32_t div = intra_matrix[i]*quant;
130                    intra_matrix_rec[i] = ((uint32_t)((1<<SCALEBITS) + (div>>1)))/div;
131            }
132    }
133    
134    void
135    set_inter_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
136          {          {
137                  memcpy(qmatrix->inter, default_inter_matrix, 64 * sizeof (int16_t));          int i;
138            uint16_t *inter_matrix = mpeg_quant_matrices + 4*64;
139            uint16_t *inter_matrix1 = mpeg_quant_matrices + 5*64;
140            uint16_t *inter_matrix_fix = mpeg_quant_matrices + 6*64;
141            uint16_t *inter_matrix_fixl = mpeg_quant_matrices + 7*64;
142    
143            for (i = 0; i < 64; i++) {
144                    inter_matrix1[i] = ((inter_matrix[i] = (int16_t) matrix[i])>>1);
145                    inter_matrix1[i] += ((inter_matrix[i] == 1) ? 1: 0);
146                    inter_matrix_fix[i] = (uint16_t) FIX(inter_matrix[i]);
147                    inter_matrix_fixl[i] = (uint16_t) FIXL(inter_matrix[i]);
148            }
149          }          }
150    
151  #ifdef ARCH_X86  void
152          // TODO: generate mmx tables  init_mpeg_matrix(uint16_t * mpeg_quant_matrices) {
153  #endif  
154            set_intra_matrix(mpeg_quant_matrices, default_intra_matrix);
155            set_inter_matrix(mpeg_quant_matrices, default_inter_matrix);
156  }  }

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

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