[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

trunk/xvidcore/src/quant/quant_matrix.c revision 519, Sun Sep 22 18:33:31 2002 UTC branches/release-1_3-branch/xvidcore/src/quant/quant_matrix.c revision 2180, Tue Nov 12 14:48:35 2019 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   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *   *               2002 Peter Ross <pross@xvid.org>
  *  This program is an implementation of a part of one or more MPEG-4  
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  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 28  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   *  $Id: quant_matrix.c,v 1.9 2002-09-22 18:33:31 h Exp $   * $Id$
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
27    #include "../global.h"
28  #include "quant_matrix.h"  #include "quant_matrix.h"
29    
30  #define FIX(X) (1 << 16) / (X) + 1  #define FIX(X)   (((X)==1) ? 0xFFFF : ((1UL << 16) / (X) + 1))
31    #define FIXL(X)    ((1UL << 16) / (X) - 1)
32    
33  /*****************************************************************************  /*****************************************************************************
34   * Local data   * Default matrices
35   ****************************************************************************/   ****************************************************************************/
36    
37  /* 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] = {  
38          8, 17, 18, 19, 21, 23, 25, 27,          8, 17, 18, 19, 21, 23, 25, 27,
39          17, 18, 19, 21, 23, 25, 27, 28,          17, 18, 19, 21, 23, 25, 27, 28,
40          20, 21, 22, 23, 24, 26, 28, 30,          20, 21, 22, 23, 24, 26, 28, 30,
# Line 66  Line 45 
45          27, 28, 30, 32, 35, 38, 41, 45          27, 28, 30, 32, 35, 38, 41, 45
46  };  };
47    
48  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] = {  
49          16, 17, 18, 19, 20, 21, 22, 23,          16, 17, 18, 19, 20, 21, 22, 23,
50          17, 18, 19, 20, 21, 22, 23, 24,          17, 18, 19, 20, 21, 22, 23, 24,
51          18, 19, 20, 21, 22, 23, 24, 25,          18, 19, 20, 21, 22, 23, 24, 25,
# Line 88  Line 56 
56          23, 24, 25, 27, 28, 30, 31, 33          23, 24, 25, 27, 28, 30, 31, 33
57  };  };
58    
59  int16_t inter_matrix[64] = {  const uint16_t *
60          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)  
61  {  {
62          return custom_intra_matrix;          return(mpeg_quant_matrices + 0*64);
63  }  }
64    
65  uint8_t  const uint16_t *
66  get_inter_matrix_status(void)  get_inter_matrix(const uint16_t * mpeg_quant_matrices)
67  {  {
68          return custom_inter_matrix;          return(mpeg_quant_matrices + 4*64);
69  }  }
70    
71  void  const uint8_t *
72  set_intra_matrix_status(uint8_t status)  get_default_intra_matrix(void)
73  {  {
74          custom_intra_matrix = status;          return default_intra_matrix;
75  }  }
76    
77  void  const uint8_t *
78  set_inter_matrix_status(uint8_t status)  get_default_inter_matrix(void)
79  {  {
80          custom_inter_matrix = status;          return default_inter_matrix;
81  }  }
82    
83  int16_t *  int
84  get_intra_matrix(void)  is_custom_intra_matrix(const uint16_t * mpeg_quant_matrices)
85  {  {
86          return intra_matrix;          int i;
87  }          const uint16_t *intra_matrix = get_intra_matrix(mpeg_quant_matrices);
88            const uint8_t *def_intra_matrix = get_default_intra_matrix();
89    
90  int16_t *          for (i = 0; i < 64; i++) {
91  get_inter_matrix(void)                  if(intra_matrix[i] != def_intra_matrix[i])
92  {                          return 1;
93          return inter_matrix;          }
94            return 0;
95  }  }
96    
97  uint8_t *  int
98  get_default_intra_matrix(void)  is_custom_inter_matrix(const uint16_t * mpeg_quant_matrices)
99  {  {
100          return default_intra_matrix;          int i;
101            const uint16_t *inter_matrix = get_inter_matrix(mpeg_quant_matrices);
102            const uint8_t *def_inter_matrix = get_default_inter_matrix();
103    
104            for (i = 0; i < 64; i++) {
105                    if(inter_matrix[i] != (uint16_t)def_inter_matrix[i])
106                            return 1;
107            }
108            return 0;
109  }  }
110    
111  uint8_t *  void
112  get_default_inter_matrix(void)  set_intra_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
113  {  {
114          return default_inter_matrix;          int i;
115            uint16_t *intra_matrix = mpeg_quant_matrices + 0*64;
116    
117            for (i = 0; i < 64; i++) {
118                    intra_matrix[i] = (!i) ? (uint16_t)8: (uint16_t)MAX(1, matrix[i]);
119            }
120  }  }
121    
122  uint8_t  void
123  set_intra_matrix(uint8_t * matrix)  init_intra_matrix(uint16_t * mpeg_quant_matrices, uint32_t quant)
124  {  {
125          int i, change = 0;          int i;
126            uint16_t *intra_matrix = mpeg_quant_matrices + 0*64;
127          custom_intra_matrix = 0;          uint16_t *intra_matrix_rec = mpeg_quant_matrices + 1*64;
128    
129          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
130                  if ((int16_t) default_intra_matrix[i] != matrix[i])                  uint32_t div = intra_matrix[i]*quant;
131                          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]);  
132          }          }
         return /*custom_intra_matrix |*/ change;  
133  }  }
134    
135    void
136  uint8_t  set_inter_matrix(uint16_t * mpeg_quant_matrices, const uint8_t * matrix)
 set_inter_matrix(uint8_t * matrix)  
137  {  {
138          int i, change = 0;          int i;
139            uint16_t *inter_matrix = mpeg_quant_matrices + 4*64;
140          custom_inter_matrix = 0;          uint16_t *inter_matrix1 = mpeg_quant_matrices + 5*64;
141            uint16_t *inter_matrix_fix = mpeg_quant_matrices + 6*64;
142            uint16_t *inter_matrix_fixl = mpeg_quant_matrices + 7*64;
143    
144          for (i = 0; i < 64; i++) {          for (i = 0; i < 64; i++) {
145                  if ((int16_t) default_inter_matrix[i] != matrix[i])                  inter_matrix1[i] = ((inter_matrix[i] = (int16_t)MAX(1, (matrix[i])>>1)));
146                          custom_inter_matrix = 1;                  inter_matrix1[i] += ((inter_matrix[i] == 1) ? 1: 0);
147                  if (inter_matrix[i] != matrix[i])                  inter_matrix_fix[i] = (uint16_t) FIX(inter_matrix[i]);
148                          change = 1;                  inter_matrix_fixl[i] = (uint16_t) FIXL(inter_matrix[i]);
149            }
                 inter_matrix[i] = (int16_t) matrix[i];  
                 inter_matrix_fix[i] = FIX(inter_matrix[i]);  
150          }          }
151          return /*custom_inter_matrix |*/ change;  
152    void
153    init_mpeg_matrix(uint16_t * mpeg_quant_matrices) {
154    
155            set_intra_matrix(mpeg_quant_matrices, default_intra_matrix);
156            set_inter_matrix(mpeg_quant_matrices, default_inter_matrix);
157  }  }

Legend:
Removed from v.519  
changed lines
  Added in v.2180

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