1 /*
2  *rk_aiq_types_alsc_algo_int.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_AYNR_ALGO_INT_V1_H_
21 #define _RK_AIQ_TYPE_AYNR_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 "aynr/rk_aiq_types_aynr_algo_v1.h"
29 #include "ynr_head_v1.h"
30 
31 RKAIQ_BEGIN_DECLARE
32 
33 #define ISO_CURVE_POINT_BIT             4
34 #define ISO_CURVE_POINT_NUM             ((1 << ISO_CURVE_POINT_BIT)+1)
35 #define RKAIQ_YNR_SIGMA_BITS            10
36 #define WAVELET_LEVEL_NUM               4
37 #define GAIN_ENABLE_FLG                 1
38 #define GAIN_YNR_ENABLE_FLG             (GAIN_ENABLE_FLG & 1)
39 #define GAIN_YNR_FIX_BITS_DECI          4
40 #define GAIN_YUVNR_SOURCE_FLG           0
41 
42 #define YNR_MAX_ISO_STEP_V1 (CALIBDB_NR_SHARP_MAX_ISO_LEVEL)
43 
44 typedef enum Aynr_Result_V1_e {
45     AYNR_RET_V1_SUCCESS             = 0,   // this has to be 0, if clauses rely on it
46     AYNR_RET_V1_FAILURE             = 1,   // process failure
47     AYNR_RET_V1_INVALID_PARM        = 2,   // invalid parameter
48     AYNR_RET_V1_WRONG_CONFIG        = 3,   // feature not supported
49     AYNR_RET_V1_BUSY                = 4,   // there's already something going on...
50     AYNR_RET_V1_CANCELED            = 5,   // operation canceled
51     AYNR_RET_V1_OUTOFMEM            = 6,   // out of memory
52     AYNR_RET_V1_OUTOFRANGE          = 7,   // parameter/value out of range
53     AYNR_RET_V1_NULL_POINTER        = 8,   // the/one/all parameter(s) is a(are) NULL pointer(s)
54     AYNR_RET_V1_DIVISION_BY_ZERO    = 9,   // a divisor equals ZERO
55     AYNR_RET_V1_NO_INPUTIMAGE       = 10   // no input image
56 } Aynr_Result_V1_t;
57 
58 typedef enum Aynr_State_V1_e {
59     AYNR_STATE_V1_INVALID           = 0,                   /**< initialization value */
60     AYNR_STATE_V1_INITIALIZED       = 1,                   /**< instance is created, but not initialized */
61     AYNR_STATE_V1_STOPPED           = 2,                   /**< instance is confiured (ready to start) or stopped */
62     AYNR_STATE_V1_RUNNING           = 3,                   /**< instance is running (processes frames) */
63     AYNR_STATE_V1_LOCKED            = 4,                   /**< instance is locked (for taking snapshots) */
64     AYNR_STATE_V1_MAX                                      /**< max */
65 } Aynr_State_V1_t;
66 
67 typedef enum Aynr_OPMode_V1_e {
68     AYNR_OP_MODE_V1_INVALID           = 0,                   /**< initialization value */
69     AYNR_OP_MODE_V1_AUTO              = 1,                   /**< instance is created, but not initialized */
70     AYNR_OP_MODE_V1_MANUAL            = 2,                   /**< instance is confiured (ready to start) or stopped */
71     AYNR_OP_MODE_V1_MAX                                      /**< max */
72 } Aynr_OPMode_V1_t;
73 
74 typedef enum Aynr_ParamMode_V1_e {
75     AYNR_PARAM_MODE_V1_INVALID           = 0,
76     AYNR_PARAM_MODE_V1_NORMAL          = 1,                   /**< initialization value */
77     AYNR_PARAM_MODE_V1_HDR              = 2,                   /**< instance is created, but not initialized */
78     AYNR_PARAM_MODE_V1_GRAY            = 3,                   /**< instance is confiured (ready to start) or stopped */
79     AYNR_PARAM_MODE_V1_MAX                                      /**< max */
80 } Aynr_ParamMode_V1_t;
81 
82 typedef struct Aynr_ExpInfo_V1_s {
83     int hdr_mode;
84     float arTime[3];
85     float arAGain[3];
86     float arDGain[3];
87     int arIso[3];
88     int arDcgMode[3];
89     int cur_snr_mode;
90     int snr_mode;
91 
92     float preTime[3];
93     float preAGain[3];
94     float preDGain[3];
95     int preIso[3];
96     int preDcgMode[3];
97     int pre_snr_mode;
98 
99     int mfnr_mode_3to1;
100 } Aynr_ExpInfo_V1_t;
101 
102 
103 typedef struct RK_YNR_Params_V1_Select_s
104 {
105 #ifndef RK_SIMULATOR_HW
106     float iso;
107 #endif
108 
109     float ciISO[12];
110     float noiseSigma[ISO_CURVE_POINT_NUM];
111     short lumaPoints[ISO_CURVE_POINT_NUM];
112 
113     float loFreqNoiseCi[WAVELET_LEVEL_NUM];
114     float loFreqDenoiseWeight[WAVELET_LEVEL_NUM];
115     float loFreqBfScale[WAVELET_LEVEL_NUM];
116     float loFreqLumaNrCurvePoint[6];
117     float loFreqLumaNrCurveRatio[6];
118 
119     float loFreqDenoiseStrength[2];
120     float loFreqDirectionStrength;
121 
122     float hiFreqDenoiseWeight[WAVELET_LEVEL_NUM];
123     float hiFreqBfScale[WAVELET_LEVEL_NUM];
124     float hiFreqEdgeSoftness[WAVELET_LEVEL_NUM];
125     float hiFreqLumaNrCurvePoint[6];
126     float hiFreqLumaNrCurveRatio[6];
127     float hiFreqDenoiseStrength;
128     float hiFreqSoftThresholdScale[WAVELET_LEVEL_NUM];
129 
130     short radialNoiseCtrPoint[7];
131     float radialNoiseCtrRatio[7];
132 
133     float lscGainRatioAdjust[WAVELET_LEVEL_NUM];
134 
135     float detailThre[6];
136     float detailThreRatioLevel[3][6];
137     float detailMinAdjDnW;
138 
139     float detailThreLevel4[6];
140     float detailThreRatioLevel4[6];
141 
142     short waveLetCoeffDeltaHi;
143     short waveLetCoeffDeltaLo;
144     short hiValueThre;
145     short loValueThre;
146     int   ynr_level4_max_gain;
147 
148     char ynr_ver_char[64];
149 } RK_YNR_Params_V1_Select_t;
150 
151 
152 
153 typedef struct RK_YNR_Params_V1_s
154 {
155     RK_YNR_Params_V1_Select_t aYnrParamsISO[YNR_MAX_ISO_STEP_V1];
156 
157     short rawBit;
158     short isoValue;
159 
160     char ynr_ver_char[64];
161 
162 } RK_YNR_Params_V1_t;
163 
164 
165 typedef struct Aynr_Manual_Attr_V1_s
166 {
167     int ynrEn;
168     RK_YNR_Params_V1_Select_t stSelect;
169 
170 } Aynr_Manual_Attr_V1_t;
171 
172 typedef struct Aynr_Auto_Attr_V1_s
173 {
174     //all ISO params and select param
175     int ynrEn;
176 
177     RK_YNR_Params_V1_t stParams;
178     RK_YNR_Params_V1_Select_t stSelect;
179 
180 } Aynr_Auto_Attr_V1_t;
181 
182 typedef struct Aynr_ProcResult_V1_s {
183     int ynrEn;
184 
185     //for sw simultaion
186     RK_YNR_Params_V1_Select_t stSelect;
187 
188     //for hw register
189     RK_YNR_Fix_V1_t stFix;
190 
191 } Aynr_ProcResult_V1_t;
192 
193 
194 typedef struct Aynr_Config_V1_s {
195     Aynr_State_V1_t eState;
196     Aynr_OPMode_V1_t eMode;
197 } Aynr_Config_V1_t;
198 
199 
200 typedef struct rk_aiq_ynr_attrib_v1_s {
201     Aynr_OPMode_V1_t eMode;
202     Aynr_Auto_Attr_V1_t stAuto;
203     Aynr_Manual_Attr_V1_t stManual;
204 } rk_aiq_ynr_attrib_v1_t;
205 
206 
207 typedef struct rk_aiq_ynr_IQPara_V1_s {
208     CalibDb_YNR_t stYnrPara;
209 } rk_aiq_ynr_IQPara_V1_t;
210 
211 
212 typedef struct rk_aiq_ynr_JsonPara_V1_s {
213     CalibDbV2_YnrV1_t ynr_v1;
214 } rk_aiq_ynr_JsonPara_V1_t;
215 
216 
217 
218 RKAIQ_END_DECLARE
219 
220 #endif
221 
222