xref: /aosp_15_r20/external/libavc/encoder/ih264e_globals.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /**
22 *******************************************************************************
23 * @file
24 *  ih264e_globals.c
25 *
26 * @brief
27 *  Contains definitions of global variables used across the encoder
28 *
29 * @author
30 *  ittiam
31 *
32 * @remarks
33 *
34 *******************************************************************************
35 */
36 
37 /*****************************************************************************/
38 /* File Includes                                                             */
39 /*****************************************************************************/
40 
41 /* User Include Files */
42 #include "ih264_typedefs.h"
43 #include "ih264_defs.h"
44 #include "ih264e_defs.h"
45 #include "ih264e_globals.h"
46 
47 /*****************************************************************************/
48 /* Global definitions                                                        */
49 /*****************************************************************************/
50 
51 /**
52 ******************************************************************************
53 * @brief  lambda for varying quantizer scales that would be used to
54 * compute the RD cost while deciding on the MB modes.
55 * input  : qp
56 * output : lambda
57 * @remarks lambda = 0.85 * pow(2, (qp - 12)/3), when SSD is used as metric
58 * for computing distortion (Bit rate estimation for cost function of H.264/
59 * AVC by Mohd Golam Sarwer et. al.)  If the use of distortion metric is SAD
60 * rather than SSD in the stage of encoding, consider sqrt(lambda) simply to
61 * adjust lambda for the lack of squaring operation in the error computation
62 * (from rate distortion optimization for video compression by sullivan).
63 ******************************************************************************
64 */
65 const UWORD8 gu1_qp_lambdaIP[52]=
66 {
67        0,      0,      0,      0,      0,      0,      0,      1,
68        1,      1,      1,      1,      1,      1,      1,      1,
69        1,      2,      2,      2,      2,      3,      3,      3,
70        4,      4,      5,      5,      6,      7,      7,      8,
71        9,     10,     12,     13,     15,     17,     19,     21,
72       23,     26,     30,     33,     37,     42,     47,     53,
73       59,     66,     74,     83,
74 };
75 
76 /**
77 ******************************************************************************
78 * @brief  lambda for varying quantizer scales that would be used to
79 * compute the RD cost while deciding on the MB modes.
80 * input  : qp
81 * output : lambda
82 * @remarks lambda = max(2, min(4, pow(2, (qp - 12)/6))) * gu1_qp_lambdaIP[]
83 ******************************************************************************
84 */
85 const UWORD8 gu1_qp_lambdaB[52]=
86 {
87         0,       0,       0,       0,       1,       1,       1,       1,
88         1,       1,       1,       1,       1,       1,       2,       2,
89         2,       2,       3,       3,       3,       4,       4,       5,
90         5,       6,       7,       8,      10,      11,      13,      15,
91        17,      20,      22,      26,      30,      33,      37,      42,
92        47,      53,      59,      66,      74,      83,      94,     105,
93       118,     132,     149,     167,
94 };
95 
96 /**
97 ******************************************************************************
98 * @brief  Lamda for varying quantizer scales that would be used to
99 * compute the RD cost while deciding on the MB modes.
100 * input  : qp
101 * output : lambda
102 * @remarks lambda = pow(2, (qp - 12)/6)
103 ******************************************************************************
104 */
105 const UWORD8 gu1_qp0[52]=
106 {
107        0,      0,      0,      0,      0,      0,      0,      0,
108        0,      0,      0,      0,      1,      1,      1,      1,
109        2,      2,      2,      2,      3,      3,      3,      4,
110        4,      4,      5,      6,      6,      7,      8,      9,
111       10,     11,     13,     14,     16,     18,     20,     23,
112       25,     29,     32,     36,     40,     45,     51,     57,
113       64,     72,     81,     91,
114 };
115 
116 /**
117 ******************************************************************************
118 * @brief  unsigned exp. goulumb codelengths to assign cost to a coefficient of
119 * mb types.
120 * input  : Integer
121 * output : codelength
122 * @remarks Refer sec. 9-1 in h264 specification
123 ******************************************************************************
124 */
125 const UWORD8 u1_uev_codelength[32] =
126 {
127      1,      3,      3,      5,      5,      5,      5,      7,
128      7,      7,      7,      7,      7,      7,      7,      9,
129      9,      9,      9,      9,      9,      9,      9,      9,
130      9,      9,      9,      9,      9,      9,      9,      11,
131 };
132 
133 /**
134 ******************************************************************************
135 * @brief  Look up table to assign cost to a coefficient of a residual block
136 * basing on its surrounding coefficients
137 * input  : Numbers of T1's
138 * output : coeff_cost
139 * @remarks Refer Section 2.3 Elimination of single coefficients in inter
140 * macroblocks in document JVT-O079
141 ******************************************************************************
142 */
143 const UWORD8 gu1_coeff_cost[6] =
144 {
145      3, 2, 2, 1, 1, 1
146 };
147 
148 /**
149 ******************************************************************************
150 * @brief  Indices map to raster scan for luma 4x4 block
151 * input  : scan index
152 * output : scan location
153 * @remarks None
154 ******************************************************************************
155 */
156 const UWORD8 gu1_luma_scan_order[16] =
157 {
158      0,  1,  4,  8,  5,  2,  3,  6,  9,  12, 13, 10, 7,  11, 14, 15
159 };
160 
161 /**
162 ******************************************************************************
163 * @brief  Indices map to raster scan for chroma AC block
164 * input  : scan index
165 * output : scan location
166 * @remarks None
167 ******************************************************************************
168 */
169 const UWORD8 gu1_chroma_scan_order[15] =
170 {
171      1,  4,  8,  5,  2,  3,  6,  9,  12, 13, 10, 7,  11, 14, 15
172 };
173 
174 /**
175 ******************************************************************************
176 * @brief  Indices map to raster scan for luma 4x4 dc block
177 * input  : scan index
178 * output : scan location
179 * @remarks : None
180 ******************************************************************************
181 */
182 const UWORD8 gu1_luma_scan_order_dc[16] =
183 {
184      0, 1,  4,  8,  5,  2,  3,  6,  9,  12, 13, 10, 7,  11, 14, 15
185 };
186 
187 /**
188 ******************************************************************************
189 * @brief  Indices map to raster scan for chroma 2x2 dc block
190 * input  : scan index
191 * output : scan location
192 * @remarks None
193 ******************************************************************************
194 */
195 const UWORD8 gu1_chroma_scan_order_dc[4] =
196 {
197      0, 1,  2,  3
198 };
199 
200 /**
201 ******************************************************************************
202 * @brief  choice of motion vectors to be used during mv prediction
203 * input  : formatted reference idx comparison metric
204 * output : mv prediction has to be median or a simple straight forward selec
205 * tion from neighbors.
206 * @remarks If only one of the candidate blocks has a reference frame equal to
207     the current block then use the same block as the final predictor. A simple
208     look up table to assist this mv prediction condition
209 ******************************************************************************
210 */
211 const WORD8 gi1_mv_pred_condition[8] =
212 {
213      -1,    0,    1,    -1,    2,    -1,    -1,    -1
214 };
215 
216 /**
217 ******************************************************************************
218 * @brief  Translation of Qstep <-> QP
219 * Qstep(QP) = Qstep(QP%6) * (2 ^ floor(QP/6))
220 * Qstep(QP, n = 0) {0.625, 0.6875, 0.8125, 0.875, 1.0, 1.125} for QP[0-5]
221 * @remarks QPRange[0-51] & QstepRange[1 - 224].
222 ******************************************************************************
223 */
224 const UWORD8 gau1_h264_to_mpeg2_qmap[H264_QP_ELEM] =
225 {
226      1,    1,    1,    1,    1,    1,    1,    1,
227      2,    2,    2,    2,    3,    3,    3,    4,
228      4,    5,    5,    6,    7,    7,    8,    9,
229     10,   11,   13,   14,   16,   18,   20,   22,
230     26,   28,   32,   36,   40,   44,   52,   56,
231     64,   72,   80,   88,  104,  112,  128,  144,
232     160,  176,  208,  224,
233 };
234 const UWORD8 gau1_mpeg2_to_h264_qmap[MPEG2_QP_ELEM] =
235 {
236      0,    4,   10,   13,   16,   18,   19,   21,
237     22,   23,   24,   25,   25,   26,   27,   27,
238     28,   28,   29,   30,   30,   30,   31,   31,
239     31,   32,   32,   32,   33,   33,   33,   34,
240     34,   34,   34,   35,   35,   36,   36,   36,
241     36,   36,   36,   37,   37,   37,   37,   37,
242     37,   38,   38,   38,   38,   38,   38,   39,
243     39,   39,   39,   39,   39,   40,   40,   40,
244     40,   40,   40,   40,   40,   41,   41,   41,
245     41,   42,   42,   42,   42,   42,   42,   42,
246     42,   42,   42,   42,   42,   43,   43,   43,
247     43,   43,   43,   43,   43,   43,   43,   43,
248     43,   44,   44,   44,   44,   44,   44,   44,
249     44,   44,   44,   44,   44,   45,   45,   45,
250     45,   45,   45,   45,   45,   45,   45,   45,
251     45,   46,   46,   46,   46,   46,   46,   46,
252     46,   46,   46,   46,   46,   46,   46,   46,
253     46,   47,   47,   47,   47,   47,   47,   47,
254     47,   48,   48,   48,   48,   48,   48,   48,
255     48,   48,   48,   48,   48,   48,   48,   48,
256     48,   48,   48,   48,   48,   48,   48,   48,
257     48,   49,   49,   49,   49,   49,   49,   49,
258     49,   49,   49,   49,   49,   49,   49,   49,
259     49,   49,   49,   49,   49,   49,   49,   49,
260     49,   50,   50,   50,   50,   50,   50,   50,
261     50,   50,   50,   50,   50,   50,   50,   50,
262     50,   50,   50,   50,   50,   50,   50,   50,
263     50,   51,   51,   51,   51,   51,   51,   51,
264     51,   51,   51,   51,   51,   51,   51,   51,
265     51,   51,   51,   51,   51,   51,   51,   51,
266     51,   52,   52,   52,   52,   52,   52,   52,
267     52,   52,   52,   52,   52,   52,   52,   52,
268 };
269 
270