1 /*****************************************************************************
2 * set.c: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2005 x264 project
6 * Authors: Loren Merritt <lorenm@u.washington.edu>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
25 static const int dequant4_scale[6][3] =
34 static const int quant4_scale[6][3] =
36 { 13107, 8066, 5243 },
37 { 11916, 7490, 4660 },
38 { 10082, 6554, 4194 },
44 static const int quant8_scan[16] =
46 0,3,4,3, 3,1,5,1, 4,5,2,5, 3,1,5,1
48 static const int dequant8_scale[6][6] =
50 { 20, 18, 32, 19, 25, 24 },
51 { 22, 19, 35, 21, 28, 26 },
52 { 26, 23, 42, 24, 33, 31 },
53 { 28, 25, 45, 26, 35, 33 },
54 { 32, 28, 51, 30, 40, 38 },
55 { 36, 32, 58, 34, 46, 43 },
57 static const int quant8_scale[6][6] =
59 { 13107, 11428, 20972, 12222, 16777, 15481 },
60 { 11916, 10826, 19174, 11058, 14980, 14290 },
61 { 10082, 8943, 15978, 9675, 12710, 11985 },
62 { 9362, 8228, 14913, 8931, 11984, 11259 },
63 { 8192, 7346, 13159, 7740, 10486, 9777 },
64 { 7282, 6428, 11570, 6830, 9118, 8640 }
67 void x264_cqm_init( x264_t *h )
69 int def_quant4[6][16];
70 int def_quant8[6][64];
71 int def_dequant4[6][16];
72 int def_dequant8[6][64];
75 for( q = 0; q < 6; q++ )
77 for( i = 0; i < 16; i++ )
79 int j = (i&1) + ((i>>2)&1);
80 def_dequant4[q][i] = dequant4_scale[q][j];
81 def_quant4[q][i] = quant4_scale[q][j];
83 for( i = 0; i < 64; i++ )
85 int j = quant8_scan[((i>>1)&12) | (i&3)];
86 def_dequant8[q][i] = dequant8_scale[q][j];
87 def_quant8[q][i] = quant8_scale[q][j];
91 for( q = 0; q < 6; q++ )
93 for( i_list = 0; i_list < 4; i_list++ )
94 for( i = 0; i < 16; i++ )
96 h->dequant4_mf[i_list][q][0][i] = def_dequant4[q][i] * h->pps->scaling_list[i_list][i];
97 h-> quant4_mf[i_list][q][0][i] = def_quant4[q][i] * 16 / h->pps->scaling_list[i_list][i];
99 for( i_list = 0; i_list < 2; i_list++ )
100 for( i = 0; i < 64; i++ )
102 h->dequant8_mf[i_list][q][0][i] = def_dequant8[q][i] * h->pps->scaling_list[4+i_list][i];
103 h-> quant8_mf[i_list][q][0][i] = def_quant8[q][i] * 16 / h->pps->scaling_list[4+i_list][i];