[svn] / branches / release-1_3-branch / xvidcore / src / quant / quant_matrix.c Repository:
ViewVC logotype

Diff of /branches/release-1_3-branch/xvidcore/src/quant/quant_matrix.c

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

revision 653, Sun Nov 17 00:41:20 2002 UTC revision 1795, Wed Nov 26 01:04:34 2008 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Custom matrix quantization functions -   *  - Quantization matrix management code  -
5   *   *
6   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *               2002 Peter Ross <pross@xvid.org>   *               2002 Peter Ross <pross@xvid.org>
8   *   *
9   *  This file is part of XviD, a free MPEG-4 video encoder/decoder   *  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
  *  XviD is free software; you can redistribute it and/or modify it  
  *  under the terms of the GNU General Public License as published by  
11   *  the Free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
12   *  (at your option) any later version.   *  (at your option) any later version.
13   *   *
# Line 22  Line 20 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   *  Under section 8 of the GNU General Public License, the copyright   * $Id: quant_matrix.c,v 1.16 2008-11-26 01:04:34 Isibaar Exp $
  *  holders of XVID explicitly forbid distribution in the following  
  *  countries:  
  *  
  *    - Japan  
  *    - United States of America  
  *  
  *  Linking XviD statically or dynamically with other modules is making a  
  *  combined work based on XviD.  Thus, the terms and conditions of the  
  *  GNU General Public License cover the whole combination.  
  *  
  *  As a special exception, the copyright holders of XviD give you  
  *  permission to link XviD with independent modules that communicate with  
  *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
  *  license terms of these independent modules, and to copy and distribute  
  *  the resulting combined work under terms of your choice, provided that  
  *  every copy of the combined work is accompanied by a complete copy of  
  *  the source code of XviD (the version of XviD used to produce the  
  *  combined work), being distributed under the terms of the GNU General  
  *  Public License plus this exception.  An independent module is a module  
  *  which is not derived from or based on XviD.  
  *  
  *  Note that people who make modified versions of XviD are not obligated  
  *  to grant this special exception for their modified versions; it is  
  *  their choice whether to do so.  The GNU General Public License gives  
  *  permission to release a modified version without this exception; this  
  *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
  *  
  * $Id: quant_matrix.c,v 1.12 2002-11-17 00:41:19 edgomez Exp $  
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
27  #include "quant_matrix.h"  #include "quant_matrix.h"
28    
29  #define FIX(X) (1 << 16) / (X) + 1  #define FIX(X)   (((X)==1) ? 0xFFFF : ((1UL << 16) / (X) + 1))
30    #define FIXL(X)    ((1UL << 16) / (X) - 1)
31    
32  /*****************************************************************************  /*****************************************************************************
33   * Local data   * Default matrices
34   ****************************************************************************/   ****************************************************************************/
35    
36  /* ToDo : remove all this local to make this module thread safe */  static const uint8_t default_intra_matrix[64] = {
 uint8_t custom_intra_matrix = 0;  
 uint8_t custom_inter_matrix = 0;  
   
 uint8_t default_intra_matrix[64] = {  
         8, 17, 18, 19, 21, 23, 25, 27,  
         17, 18, 19, 21, 23, 25, 27, 28,  
         20, 21, 22, 23, 24, 26, 28, 30,  
         21, 22, 23, 24, 26, 28, 30, 32,  
         22, 23, 24, 26, 28, 30, 32, 35,  
         23, 24, 26, 28, 30, 32, 35, 38,  
         25, 26, 28, 30, 32, 35, 38, 41,  
         27, 28, 30, 32, 35, 38, 41, 45  
 };  
   
 int16_t 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 89  Line 44 
44          27, 28, 30, 32, 35, 38, 41, 45          27, 28, 30, 32, 35, 38, 41, 45
45  };  };
46    
47  int16_t intra_matrix_fix[64] = {  static const uint8_t default_inter_matrix[64] = {
         FIX(8), FIX(17), FIX(18), FIX(19), FIX(21), FIX(23), FIX(25), FIX(27),  
         FIX(17), FIX(18), FIX(19), FIX(21), FIX(23), FIX(25), FIX(27), FIX(28),  
         FIX(20), FIX(21), FIX(22), FIX(23), FIX(24), FIX(26), FIX(28), FIX(30),  
         FIX(21), FIX(22), FIX(23), FIX(24), FIX(26), FIX(28), FIX(30), FIX(32),  
         FIX(22), FIX(23), FIX(24), FIX(26), FIX(28), FIX(30), FIX(32), FIX(35),  
         FIX(23), FIX(24), FIX(26), FIX(28), FIX(30), FIX(32), FIX(35), FIX(38),  
         FIX(25), FIX(26), FIX(28), FIX(30), FIX(32), FIX(35), FIX(38), FIX(41),  
         FIX(27), FIX(28), FIX(30), FIX(32), FIX(35), FIX(38), FIX(41), FIX(45)  
 };  
   
 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 111  Line 55 
55          23, 24, 25, 27, 28, 30, 31, 33          23, 24, 25, 27, 28, 30, 31, 33
56  };  };
57    
58  int16_t inter_matrix[64] = {  const uint16_t *
59          16, 17, 18, 19, 20, 21, 22, 23,  get_intra_matrix(const uint16_t * mpeg_quant_matrices)
         17, 18, 19, 20, 21, 22, 23, 24,  
         18, 19, 20, 21, 22, 23, 24, 25,  
         19, 20, 21, 22, 23, 24, 26, 27,  
         20, 21, 22, 23, 25, 26, 27, 28,  
         21, 22, 23, 24, 26, 27, 28, 30,  
         22, 23, 24, 26, 27, 28, 30, 31,  
         23, 24, 25, 27, 28, 30, 31, 33  
 };  
   
 int16_t inter_matrix_fix[64] = {  
         FIX(16), FIX(17), FIX(18), FIX(19), FIX(20), FIX(21), FIX(22), FIX(23),  
         FIX(17), FIX(18), FIX(19), FIX(20), FIX(21), FIX(22), FIX(23), FIX(24),  
         FIX(18), FIX(19), FIX(20), FIX(21), FIX(22), FIX(23), FIX(24), FIX(25),  
         FIX(19), FIX(20), FIX(21), FIX(22), FIX(23), FIX(24), FIX(26), FIX(27),  
         FIX(20), FIX(21), FIX(22), FIX(23), FIX(25), FIX(26), FIX(27), FIX(28),  
         FIX(21), FIX(22), FIX(23), FIX(24), FIX(26), FIX(27), FIX(28), FIX(30),  
         FIX(22), FIX(23), FIX(24), FIX(26), FIX(27), FIX(28), FIX(30), FIX(31),  
         FIX(23), FIX(24), FIX(25), FIX(27), FIX(28), FIX(30), FIX(31), FIX(33)  
 };  
   
 /*****************************************************************************  
  * Functions  
  ****************************************************************************/  
   
 uint8_t  
 get_intra_matrix_status(void)  
60  {  {
61          return custom_intra_matrix;          return(mpeg_quant_matrices + 0*64);
62  }  }
63    
64  uint8_t  const uint16_t *
65  get_inter_matrix_status(void)  get_inter_matrix(const uint16_t * mpeg_quant_matrices)
66  {  {
67          return custom_inter_matrix;          return(mpeg_quant_matrices + 4*64);
68  }  }
69    
70  void  const uint8_t *
71  set_intra_matrix_status(uint8_t status)  get_default_intra_matrix(void)
72  {  {
73          custom_intra_matrix = status;          return default_intra_matrix;
74  }  }
75    
76  void  const uint8_t *
77  set_inter_matrix_status(uint8_t status)  get_default_inter_matrix(void)
78  {  {
79          custom_inter_matrix = status;          return default_inter_matrix;
80  }  }
81    
82  int16_t *  int
83  get_intra_matrix(void)  is_custom_intra_matrix(const uint16_t * mpeg_quant_matrices)
84  {  {
85          return intra_matrix;          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  int16_t *          for (i = 0; i < 64; i++) {
90  get_inter_matrix(void)                  if(intra_matrix[i] != def_intra_matrix[i])
91  {                          return 1;
92          return inter_matrix;          }
93            return 0;
94  }  }
95    
96  uint8_t *  int
97  get_default_intra_matrix(void)  is_custom_inter_matrix(const uint16_t * mpeg_quant_matrices)
98  {  {
99          return default_intra_matrix;          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  uint8_t *  void
111  get_default_inter_matrix(void)  set_intra_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
112  {  {
113          return default_inter_matrix;          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  uint8_t  void
122  set_intra_matrix(uint8_t * matrix)  init_intra_matrix(uint16_t * mpeg_quant_matrices, uint32_t quant)
123  {  {
124          int i, change = 0;          int i;
125            uint16_t *intra_matrix = mpeg_quant_matrices + 0*64;
126          custom_intra_matrix = 0;          uint16_t *intra_matrix_rec = mpeg_quant_matrices + 1*64;
127    
128          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
129                  if ((int16_t) default_intra_matrix[i] != matrix[i])                  uint32_t div = intra_matrix[i]*quant;
130                          custom_intra_matrix = 1;                  intra_matrix_rec[i] = ((uint32_t)((1<<SCALEBITS) + (div>>1)))/div;
                 if (intra_matrix[i] != matrix[i])  
                         change = 1;  
   
                 intra_matrix[i] = (int16_t) matrix[i];  
                 intra_matrix_fix[i] = FIX(intra_matrix[i]);  
131          }          }
         return /*custom_intra_matrix |*/ change;  
132  }  }
133    
134    void
135  uint8_t  set_inter_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
 set_inter_matrix(uint8_t * matrix)  
136  {  {
137          int i, change = 0;          int i;
138            uint16_t *inter_matrix = mpeg_quant_matrices + 4*64;
139          custom_inter_matrix = 0;          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++) {          for (i = 0; i < 64; i++) {
144                  if ((int16_t) default_inter_matrix[i] != matrix[i])                  inter_matrix1[i] = ((inter_matrix[i] = (int16_t) matrix[i])>>1);
145                          custom_inter_matrix = 1;                  inter_matrix1[i] += ((inter_matrix[i] == 1) ? 1: 0);
                 if (inter_matrix[i] != matrix[i])  
                         change = 1;  
   
                 inter_matrix[i] = (int16_t) matrix[i];  
146                  inter_matrix_fix[i] = FIX(inter_matrix[i]);                  inter_matrix_fix[i] = FIX(inter_matrix[i]);
147                    inter_matrix_fixl[i] = FIXL(inter_matrix[i]);
148            }
149          }          }
150          return /*custom_inter_matrix |*/ change;  
151    void
152    init_mpeg_matrix(uint16_t * mpeg_quant_matrices) {
153    
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.653  
changed lines
  Added in v.1795

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