~siretart/x264/trunk

« back to all changes in this revision

Viewing changes to encoder/analyse.c

  • Committer: Anton Mitrofanov
  • Author(s): Vittorio Giovara
  • Date: 2017-12-24 20:47:24 UTC
  • Revision ID: git-v1:71ed44c7312438fac7c5c5301e45522e57127db4
Unify 8-bit and 10-bit CLI and libraries

Add 'i_bitdepth' to x264_param_t with the corresponding '--output-depth' CLI
option to set the bit depth at runtime.

Drop the 'x264_bit_depth' global variable. Rather than hardcoding it to an
incorrect value, it's preferable to induce a linking failure. If applications
relies on this symbol this will make it more obvious where the problem is.

Add Makefile rules that compiles modules with different bit depths. Assembly
on x86 is prefixed with the 'private_prefix' define, while all other archs
modify their function prefix internally.

Templatize the main C library, x86/x86_64 assembly, ARM assembly, AARCH64
assembly, PowerPC assembly, and MIPS assembly.

The depth and cache CLI filters heavily depend on bit depth size, so they
need to be duplicated for each value. This means having to rename these
filters, and adjust the callers to use the right version.

Unfortunately the threaded input CLI module inherits a common.h dependency
(input/frame -> common/threadpool -> common/frame -> common/common) which
is extremely complicated to address in a sensible way. Instead duplicate
the module and select the appropriate one at run time.

Each bitdepth needs different checkasm compilation rules, so split the main
checkasm target into two executables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
 
121
121
} x264_mb_analysis_t;
122
122
 
123
 
/* lambda = pow(2,qp/6-2) */
124
 
const uint16_t x264_lambda_tab[QP_MAX_MAX+1] =
125
 
{
126
 
   1,   1,   1,   1,   1,   1,   1,   1, /*  0- 7 */
127
 
   1,   1,   1,   1,   1,   1,   1,   1, /*  8-15 */
128
 
   2,   2,   2,   2,   3,   3,   3,   4, /* 16-23 */
129
 
   4,   4,   5,   6,   6,   7,   8,   9, /* 24-31 */
130
 
  10,  11,  13,  14,  16,  18,  20,  23, /* 32-39 */
131
 
  25,  29,  32,  36,  40,  45,  51,  57, /* 40-47 */
132
 
  64,  72,  81,  91, 102, 114, 128, 144, /* 48-55 */
133
 
 161, 181, 203, 228, 256, 287, 323, 362, /* 56-63 */
134
 
 406, 456, 512, 575, 645, 724, 813, 912, /* 64-71 */
135
 
1024,1149,1290,1448,1625,1825,2048,2299, /* 72-79 */
136
 
2580,2896,                               /* 80-81 */
137
 
};
138
 
 
139
 
/* lambda2 = pow(lambda,2) * .9 * 256 */
140
 
/* Capped to avoid overflow */
141
 
const int x264_lambda2_tab[QP_MAX_MAX+1] =
142
 
{
143
 
       14,       18,       22,       28,       36,       45,      57,      72, /*  0- 7 */
144
 
       91,      115,      145,      182,      230,      290,     365,     460, /*  8-15 */
145
 
      580,      731,      921,     1161,     1462,     1843,    2322,    2925, /* 16-23 */
146
 
     3686,     4644,     5851,     7372,     9289,    11703,   14745,   18578, /* 24-31 */
147
 
    23407,    29491,    37156,    46814,    58982,    74313,   93628,  117964, /* 32-39 */
148
 
   148626,   187257,   235929,   297252,   374514,   471859,  594505,  749029, /* 40-47 */
149
 
   943718,  1189010,  1498059,  1887436,  2378021,  2996119, 3774873, 4756042, /* 48-55 */
150
 
  5992238,  7549747,  9512085, 11984476, 15099494, 19024170,23968953,30198988, /* 56-63 */
151
 
 38048341, 47937906, 60397977, 76096683, 95875813,120795955,                   /* 64-69 */
152
 
134217727,134217727,134217727,134217727,134217727,134217727,                   /* 70-75 */
153
 
134217727,134217727,134217727,134217727,134217727,134217727,                   /* 76-81 */
154
 
};
155
 
 
156
 
const uint8_t x264_exp2_lut[64] =
157
 
{
158
 
      0,   3,   6,   8,  11,  14,  17,  20,  23,  26,  29,  32,  36,  39,  42,  45,
159
 
     48,  52,  55,  58,  62,  65,  69,  72,  76,  80,  83,  87,  91,  94,  98, 102,
160
 
    106, 110, 114, 118, 122, 126, 130, 135, 139, 143, 147, 152, 156, 161, 165, 170,
161
 
    175, 179, 184, 189, 194, 198, 203, 208, 214, 219, 224, 229, 234, 240, 245, 250
162
 
};
163
 
 
164
 
const float x264_log2_lut[128] =
165
 
{
166
 
    0.00000, 0.01123, 0.02237, 0.03342, 0.04439, 0.05528, 0.06609, 0.07682,
167
 
    0.08746, 0.09803, 0.10852, 0.11894, 0.12928, 0.13955, 0.14975, 0.15987,
168
 
    0.16993, 0.17991, 0.18982, 0.19967, 0.20945, 0.21917, 0.22882, 0.23840,
169
 
    0.24793, 0.25739, 0.26679, 0.27612, 0.28540, 0.29462, 0.30378, 0.31288,
170
 
    0.32193, 0.33092, 0.33985, 0.34873, 0.35755, 0.36632, 0.37504, 0.38370,
171
 
    0.39232, 0.40088, 0.40939, 0.41785, 0.42626, 0.43463, 0.44294, 0.45121,
172
 
    0.45943, 0.46761, 0.47573, 0.48382, 0.49185, 0.49985, 0.50779, 0.51570,
173
 
    0.52356, 0.53138, 0.53916, 0.54689, 0.55459, 0.56224, 0.56986, 0.57743,
174
 
    0.58496, 0.59246, 0.59991, 0.60733, 0.61471, 0.62205, 0.62936, 0.63662,
175
 
    0.64386, 0.65105, 0.65821, 0.66534, 0.67243, 0.67948, 0.68650, 0.69349,
176
 
    0.70044, 0.70736, 0.71425, 0.72110, 0.72792, 0.73471, 0.74147, 0.74819,
177
 
    0.75489, 0.76155, 0.76818, 0.77479, 0.78136, 0.78790, 0.79442, 0.80090,
178
 
    0.80735, 0.81378, 0.82018, 0.82655, 0.83289, 0.83920, 0.84549, 0.85175,
179
 
    0.85798, 0.86419, 0.87036, 0.87652, 0.88264, 0.88874, 0.89482, 0.90087,
180
 
    0.90689, 0.91289, 0.91886, 0.92481, 0.93074, 0.93664, 0.94251, 0.94837,
181
 
    0.95420, 0.96000, 0.96578, 0.97154, 0.97728, 0.98299, 0.98868, 0.99435,
182
 
};
183
 
 
184
 
/* Avoid an int/float conversion. */
185
 
const float x264_log2_lz_lut[32] =
186
 
{
187
 
    31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
188
 
};
189
 
 
190
 
// should the intra and inter lambdas be different?
191
 
// I'm just matching the behaviour of deadzone quant.
192
 
static const int x264_trellis_lambda2_tab[2][QP_MAX_MAX+1] =
193
 
{
194
 
    // inter lambda = .85 * .85 * 2**(qp/3. + 10 - LAMBDA_BITS)
195
 
    {
196
 
               46,       58,       73,       92,      117,      147,
197
 
              185,      233,      294,      370,      466,      587,
198
 
              740,      932,     1174,     1480,     1864,     2349,
199
 
             2959,     3728,     4697,     5918,     7457,     9395,
200
 
            11837,    14914,    18790,    23674,    29828,    37581,
201
 
            47349,    59656,    75163,    94699,   119313,   150326,
202
 
           189399,   238627,   300652,   378798,   477255,   601304,
203
 
           757596,   954511,  1202608,  1515192,  1909022,  2405217,
204
 
          3030384,  3818045,  4810435,  6060769,  7636091,  9620872,
205
 
         12121539, 15272182, 19241743, 24243077, 30544363, 38483486,
206
 
         48486154, 61088726, 76966972, 96972308,
207
 
        122177453,134217727,134217727,134217727,134217727,134217727,
208
 
        134217727,134217727,134217727,134217727,134217727,134217727,
209
 
    },
210
 
    // intra lambda = .65 * .65 * 2**(qp/3. + 10 - LAMBDA_BITS)
211
 
    {
212
 
               27,       34,       43,       54,       68,       86,
213
 
              108,      136,      172,      216,      273,      343,
214
 
              433,      545,      687,      865,     1090,     1374,
215
 
             1731,     2180,     2747,     3461,     4361,     5494,
216
 
             6922,     8721,    10988,    13844,    17442,    21976,
217
 
            27688,    34885,    43953,    55377,    69771,    87906,
218
 
           110755,   139543,   175813,   221511,   279087,   351627,
219
 
           443023,   558174,   703255,   886046,  1116348,  1406511,
220
 
          1772093,  2232697,  2813022,  3544186,  4465396,  5626046,
221
 
          7088374,  8930791, 11252092, 14176748, 17861583, 22504184,
222
 
         28353495, 35723165, 45008368, 56706990,
223
 
         71446330, 90016736,113413980,134217727,134217727,134217727,
224
 
        134217727,134217727,134217727,134217727,134217727,134217727,
225
 
        134217727,134217727,134217727,134217727,134217727,134217727,
226
 
    }
227
 
};
228
 
 
229
 
#define MAX_CHROMA_LAMBDA_OFFSET 36
230
 
static const uint16_t x264_chroma_lambda2_offset_tab[MAX_CHROMA_LAMBDA_OFFSET+1] =
231
 
{
232
 
       16,    20,    25,    32,    40,    50,
233
 
       64,    80,   101,   128,   161,   203,
234
 
      256,   322,   406,   512,   645,   812,
235
 
     1024,  1290,  1625,  2048,  2580,  3250,
236
 
     4096,  5160,  6501,  8192, 10321, 13003,
237
 
    16384, 20642, 26007, 32768, 41285, 52015,
238
 
    65535
239
 
};
240
 
 
241
123
/* TODO: calculate CABAC costs */
242
124
static const uint8_t i_mb_b_cost_table[X264_MBTYPE_MAX] =
243
125
{