1 /*
2  * rk_aiq_types_amfnr_algo_int_v1.h
3  *
4  *  Copyright (c) 2019 Rockchip Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
20 #ifndef _RK_AIQ_TYPE_AMFNR_ALGO_INT_V1_H_
21 #define _RK_AIQ_TYPE_AMFNR_ALGO_INT_V1_H_
22 
23 #include <math.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include "rk_aiq_comm.h"
27 #include "RkAiqCalibDbTypes.h"
28 #include "amfnr/rk_aiq_types_amfnr_algo_v1.h"
29 #include "mfnr_head_v1.h"
30 
31 RKAIQ_BEGIN_DECLARE
32 
33 /************mfnr***************/
34 #define WAVELET_LEVEL_NUM               4
35 #define MAX_INTEPORATATION_LUMAPOINT    17
36 #define POLT_ORDER                  4
37 #define MAX_BACK_REF_NUM            1
38 #define LIMIT_RANGE_LEFT_BIT8       16
39 #define LIMIT_RANGE_RIGHT_BIT8      236
40 #define Y_CALIBRATION_BITS          12
41 #define Y_SIGMA_TABLE_BITS          8
42 #define Y_SIGMA_TABLE_BITS_DEHAZE   8
43 #define MFNR_POLYORDER              POLT_ORDER
44 #define MFNR_MAX_GAUS_SIZE          10
45 #define MFNR_DIR_NUM                2
46 #define DIR_LO                      0
47 #define DIR_HI                      1
48 #define MFNR_MAX_LVL_UV             3
49 #define MFNR_MAX_LVL                4
50 #define MFNR_MAX_LVL_DEPTH          ((MFNR_MAX_LVL_UV + 1 > MFNR_MAX_LVL) ? (MFNR_MAX_LVL_UV + 1) : MFNR_MAX_LVL)
51 #define MFNR_DELTA_SQR_EXP_POINT    17
52 #define LUMANRCURVE_STEP            6
53 #define MFNR_TILE_W                 16
54 #define MFNR_TILE_H                 128
55 #define MFNR_F_INTE_SIGMA           6
56 
57 
58 
59 #define MFNR_MAX_ISO_STEP_V1 (CALIBDB_NR_SHARP_MAX_ISO_LEVEL)
60 
61 typedef enum Amfnr_Result_V1_e {
62     AMFNR_RET_V1_SUCCESS             = 0,   // this has to be 0, if clauses rely on it
63     AMFNR_RET_V1_FAILURE             = 1,   // process failure
64     AMFNR_RET_V1_INVALID_PARM        = 2,   // invalid parameter
65     AMFNR_RET_V1_WRONG_CONFIG        = 3,   // feature not supported
66     AMFNR_RET_V1_BUSY                = 4,   // there's already something going on...
67     AMFNR_RET_V1_CANCELED            = 5,   // operation canceled
68     AMFNR_RET_V1_OUTOFMEM            = 6,   // out of memory
69     AMFNR_RET_V1_OUTOFRANGE          = 7,   // parameter/value out of range
70     AMFNR_RET_V1_NULL_POINTER        = 8,   // the/one/all parameter(s) is a(are) NULL pointer(s)
71     AMFNR_RET_V1_DIVISION_BY_ZERO    = 9,   // a divisor equals ZERO
72     AMFNR_RET_V1_NO_INPUTIMAGE       = 10   // no input image
73 } Amfnr_Result_V1_t;
74 
75 typedef enum Amfnr_State_V1_e {
76     AMFNR_STATE_V1_INVALID           = 0,                   /**< initialization value */
77     AMFNR_STATE_V1_INITIALIZED       = 1,                   /**< instance is created, but not initialized */
78     AMFNR_STATE_V1_STOPPED           = 2,                   /**< instance is confiured (ready to start) or stopped */
79     AMFNR_STATE_V1_RUNNING           = 3,                   /**< instance is running (processes frames) */
80     AMFNR_STATE_V1_LOCKED            = 4,                   /**< instance is locked (for taking snapshots) */
81     AMFNR_STATE_V1_MAX                                      /**< max */
82 } Amfnr_State_V1_t;
83 
84 typedef enum Amfnr_OPMode_V1_e {
85     AMFNR_OP_MODE_V1_INVALID           = 0,                   /**< initialization value */
86     AMFNR_OP_MODE_V1_AUTO              = 1,                   /**< instance is created, but not initialized */
87     AMFNR_OP_MODE_V1_MANUAL            = 2,                   /**< instance is confiured (ready to start) or stopped */
88     AMFNR_OP_MODE_V1_MAX                                      /**< max */
89 } Amfnr_OPMode_V1_t;
90 
91 typedef enum Amfnr_ParamMode_V1_e {
92     AMFNR_PARAM_MODE_V1_INVALID           = 0,
93     AMFNR_PARAM_MODE_V1_NORMAL          = 1,                   /**< initialization value */
94     AMFNR_PARAM_MODE_V1_HDR              = 2,                   /**< instance is created, but not initialized */
95     AMFNR_PARAM_MODE_V1_GRAY            = 3,                   /**< instance is confiured (ready to start) or stopped */
96     AMFNR_PARAM_MODE_V1_MAX                                      /**< max */
97 } Amfnr_ParamMode_V1_t;
98 
99 typedef struct Amfnr_ExpInfo_V1_s {
100     int hdr_mode;
101     float arTime[3];
102     float arAGain[3];
103     float arDGain[3];
104     int arIso[3];
105     int arDcgMode[3];
106     int cur_snr_mode;
107     int snr_mode;
108 
109     float preTime[3];
110     float preAGain[3];
111     float preDGain[3];
112     int preIso[3];
113     int preDcgMode[3];
114     int pre_snr_mode;
115 
116     int mfnr_mode_3to1;
117 } Amfnr_ExpInfo_V1_t;
118 
119 
120 typedef struct RK_MFNR_Params_V1_Select_s
121 {
122 
123     int back_ref_num;
124 
125     int weight_limit_y[MFNR_MAX_LVL_DEPTH];
126     int weight_limit_uv[MFNR_MAX_LVL_UV];
127     double ratio_frq[4];
128     double luma_w_in_chroma[MFNR_MAX_LVL_UV];
129     double awb_uv_ratio[2];
130 
131     double ci                   [MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
132     double dnweight             [MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
133     double scale                    [MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
134     double lumanrpoint          [MFNR_DIR_NUM][LUMANRCURVE_STEP];
135     double lumanrcurve          [MFNR_DIR_NUM][LUMANRCURVE_STEP];
136     double dnstr                    [MFNR_DIR_NUM];
137     double gfdelta              [MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH][MFNR_MAX_GAUS_SIZE];
138 
139     double ci_uv                    [MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
140     double dnweight_uv          [MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
141     double scale_uv             [MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
142     double lumanrpoint_uv       [MFNR_DIR_NUM][LUMANRCURVE_STEP];
143     double lumanrcurve_uv       [MFNR_DIR_NUM][LUMANRCURVE_STEP];
144     double dnstr_uv             [MFNR_DIR_NUM];
145     double gfdelta_uv           [MFNR_DIR_NUM][MFNR_MAX_LVL_UV][MFNR_MAX_GAUS_SIZE];
146 
147     double gfsigma              [MFNR_MAX_LVL][MFNR_MAX_GAUS_SIZE];
148 
149     double noise_sigma          [1 << Y_CALIBRATION_BITS];
150     double noise_sigma_sample   [MAX_INTEPORATATION_LUMAPOINT];
151     double noise_sigma_dehaze   [MAX_INTEPORATATION_LUMAPOINT];
152     unsigned short  fix_x_pos           [MAX_INTEPORATATION_LUMAPOINT];
153     unsigned short  fix_x_pos_dehaze    [MAX_INTEPORATATION_LUMAPOINT];
154 
155     float mfnr_sigma_scale;
156 
157 } RK_MFNR_Params_V1_Select_t;
158 
159 
160 
161 typedef struct RK_MFNR_Params_V1_s
162 {
163 #ifndef RK_SIMULATOR_HW
164     float iso[MFNR_MAX_ISO_STEP_V1];
165 #endif
166 
167     int back_ref_num;
168 
169     int weight_limit_y  [MFNR_MAX_ISO_STEP_V1][MFNR_MAX_LVL_DEPTH];
170     int weight_limit_uv [MFNR_MAX_ISO_STEP_V1][MFNR_MAX_LVL_UV];
171     double ratio_frq        [MFNR_MAX_ISO_STEP_V1][4];
172     double luma_w_in_chroma[MFNR_MAX_ISO_STEP_V1][MFNR_MAX_LVL_UV];
173     double awb_uv_ratio [4][2];
174     double curve        [MFNR_MAX_ISO_STEP_V1][MFNR_POLYORDER + 1];
175     double curve_x0     [MFNR_MAX_ISO_STEP_V1];
176 
177     double ci           [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
178     double dnweight     [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
179     double scale            [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH];
180     double lumanrpoint  [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][LUMANRCURVE_STEP];
181     double lumanrcurve  [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][LUMANRCURVE_STEP];
182     double dnstr            [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM];
183     double gfdelta      [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_DEPTH][MFNR_MAX_GAUS_SIZE];
184 
185     double ci_uv            [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
186     double dnweight_uv  [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
187     double scale_uv     [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_UV];
188     double lumanrpoint_uv[MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][LUMANRCURVE_STEP];
189     double lumanrcurve_uv[MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][LUMANRCURVE_STEP];
190     double dnstr_uv     [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM];
191     double gfdelta_uv   [MFNR_MAX_ISO_STEP_V1][MFNR_DIR_NUM][MFNR_MAX_LVL_UV][MFNR_MAX_GAUS_SIZE];
192 
193     double gfsigma      [MFNR_MAX_ISO_STEP_V1][MFNR_MAX_LVL][MFNR_MAX_GAUS_SIZE];
194 
195     double noise_sigma  [MFNR_MAX_ISO_STEP_V1][1 << Y_CALIBRATION_BITS];
196     float mfnr_sigma_scale[MFNR_MAX_ISO_STEP_V1];
197     int motion_detection_enable;
198     char mfnr_ver_char;
199 
200 } RK_MFNR_Params_V1_t;
201 
202 
203 typedef struct RK_MFNR_Dynamic_V1_s {
204     int enable;
205     float lowth_iso;
206     float lowth_time;
207     float highth_iso;
208     float highth_time;
209     int mfnr_enable_state;
210 } RK_MFNR_Dynamic_V1_t;
211 
212 
213 typedef struct Amfnr_Manual_Attr_V1_s
214 {
215     int mfnrEn;
216     RK_MFNR_Params_V1_Select_t stSelect;
217 
218     RK_MFNR_Dynamic_V1_t stMfnr_dynamic;
219 
220 } Amfnr_Manual_Attr_V1_t;
221 
222 typedef struct Amfnr_Auto_Attr_V1_s
223 {
224     //all ISO params and select param
225     int mfnrEn;
226 
227     RK_MFNR_Params_V1_t stParams;
228     RK_MFNR_Params_V1_Select_t stSelect;
229 
230     RK_MFNR_Dynamic_V1_t stMfnr_dynamic;
231     CalibDb_MFNR_Motion_t  stMotion;
232 
233 } Amfnr_Auto_Attr_V1_t;
234 
235 typedef struct Amfnr_ProcResult_V1_s {
236     int mfnrEn;
237 
238     //for sw simultaion
239     RK_MFNR_Params_V1_Select_t stSelect;
240 
241     //for hw register
242     RK_MFNR_Fix_V1_t stFix;
243 
244     CalibDb_MFNR_Motion_t  stMotion;
245 
246 } Amfnr_ProcResult_V1_t;
247 
248 
249 typedef struct Amfnr_Config_V1_s {
250     Amfnr_State_V1_t eState;
251     Amfnr_OPMode_V1_t eMode;
252 } Amfnr_Config_V1_t;
253 
254 
255 typedef struct rk_aiq_mfnr_attrib_v1_s {
256     Amfnr_OPMode_V1_t eMode;
257     Amfnr_Auto_Attr_V1_t stAuto;
258     Amfnr_Manual_Attr_V1_t stManual;
259 } rk_aiq_mfnr_attrib_v1_t;
260 
261 
262 typedef struct rk_aiq_mfnr_IQPara_V1_s {
263     CalibDb_MFNR_t stMfnrPara;
264 } rk_aiq_mfnr_IQPara_V1_t;
265 
266 
267 typedef struct rk_aiq_mfnr_JsonPara_V1_s {
268     CalibDbV2_MFNR_t mfnr_v1;
269 } rk_aiq_mfnr_JsonPara_V1_t;
270 
271 
272 
273 RKAIQ_END_DECLARE
274 
275 #endif
276 
277