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_V3_H_
21 #define _RK_AIQ_TYPE_AYNR_ALGO_INT_V3_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 "aynr3/rk_aiq_types_aynr_algo_v3.h"
29 #include "ynr_head_v3.h"
30 #include "ynr_uapi_head_v3.h"
31 
32 
33 //RKAIQ_BEGIN_DECLARE
34 #define RK_YNR_V3_MAX_ISO_NUM (CALIBDB_MAX_ISO_LEVEL)
35 
36 
37 #define AYNRV3_RECALCULATE_DELTA_ISO       (10)
38 #define YNR_V3_SIGMA_BITS                  10
39 #define YNR_V3_NOISE_SIGMA_FIX_BIT              3
40 #define LOG2(x)                             (log((double)x)                 / log((double)2))
41 
42 
43 typedef enum Aynr_result_V3_e {
44     AYNRV3_RET_SUCCESS             = 0,   // this has to be 0, if clauses rely on it
45     AYNRV3_RET_FAILURE             = 1,   // process failure
46     AYNRV3_RET_INVALID_PARM        = 2,   // invalid parameter
47     AYNRV3_RET_WRONG_CONFIG        = 3,   // feature not supported
48     AYNRV3_RET_BUSY                = 4,   // there's already something going on...
49     AYNRV3_RET_CANCELED            = 5,   // operation canceled
50     AYNRV3_RET_OUTOFMEM            = 6,   // out of memory
51     AYNRV3_RET_OUTOFRANGE          = 7,   // parameter/value out of range
52     AYNRV3_RET_NULL_POINTER        = 8,   // the/one/all parameter(s) is a(are) NULL pointer(s)
53     AYNRV3_RET_DIVISION_BY_ZERO    = 9,   // a divisor equals ZERO
54     AYNRV3_RET_NO_INPUTIMAGE       = 10   // no input image
55 } Aynr_result_V3_t;
56 
57 typedef enum Aynr_State_V3_e {
58     AYNRV3_STATE_INVALID           = 0,                   /**< initialization value */
59     AYNRV3_STATE_INITIALIZED       = 1,                   /**< instance is created, but not initialized */
60     AYNRV3_STATE_STOPPED           = 2,                   /**< instance is confiured (ready to start) or stopped */
61     AYNRV3_STATE_RUNNING           = 3,                   /**< instance is running (processes frames) */
62     AYNRV3_STATE_LOCKED            = 4,                   /**< instance is locked (for taking snapshots) */
63     AYNRV3_STATE_MAX                                      /**< max */
64 } Aynr_State_V3_t;
65 
66 typedef enum Aynr_OPMode_V3_e {
67     AYNRV3_OP_MODE_INVALID           = 0,                   /**< initialization value */
68     AYNRV3_OP_MODE_AUTO              = 1,                   /**< instance is created, but not initialized */
69     AYNRV3_OP_MODE_MANUAL            = 2,                   /**< instance is confiured (ready to start) or stopped */
70     AYNRV3_OP_MODE_REG_MANUAL        = 3,
71     AYNRV3_OP_MODE_MAX                                      /**< max */
72 } Aynr_OPMode_V3_t;
73 
74 typedef enum Aynr_ParamMode_V3_e {
75     AYNRV3_PARAM_MODE_INVALID           = 0,
76     AYNRV3_PARAM_MODE_NORMAL          = 1,                   /**< initialization value */
77     AYNRV3_PARAM_MODE_HDR              = 2,                   /**< instance is created, but not initialized */
78     AYNRV3_PARAM_MODE_GRAY            = 3,                   /**< instance is confiured (ready to start) or stopped */
79     AYNRV3_PARAM_MODE_MAX                                      /**< max */
80 } Aynr_ParamMode_V3_t;
81 
82 
83 
84 #if 0
85 typedef struct RK_YNR_Params_V3_Select_s
86 {
87     int enable;
88     float lci;
89     float hci;
90     float sigma[YNR_V3_ISO_CURVE_POINT_NUM];
91     short lumaPoint[YNR_V3_ISO_CURVE_POINT_NUM];
92 
93     float lo_lumaPoint[6];
94     float lo_ratio[6];
95 
96     float hi_lumaPoint[6];
97     float hi_ratio[6];
98 
99     // low frequency
100     float rnr_strength[17];
101     int ynr_bft3x3_bypass;
102     int ynr_lbft5x5_bypass;
103     int ynr_lgft3x3_bypass;
104     int ynr_flt1x1_bypass;
105     int ynr_sft5x5_bypass;
106     float low_bf1;
107     float low_bf2;
108     float low_thred_adj;
109     float low_peak_supress;
110     float low_edge_adj_thresh;
111     float low_lbf_weight_thresh;
112     float low_center_weight;
113     float low_dist_adj;
114     float low_weight;
115     float low_filt1_strength;
116     float low_filt2_strength;
117     float low_bi_weight;
118 
119     // high frequency
120     float base_filter_weight1;
121     float base_filter_weight2;
122     float base_filter_weight3;
123     float high_thred_adj;
124     float high_weight;
125     float high_direction_weight[8];
126     float hi_min_adj;
127     float hi_edge_thed;
128 
129     //local gain control
130     float ynr_global_gain_alpha;
131     float ynr_global_gain;
132     float ynr_adjust_thresh;
133     float ynr_adjust_scale;
134 } RK_YNR_Params_V3_Select_t;
135 #endif
136 
137 typedef struct RK_YNR_Sigma_formula_s {
138     double sigma_curve[5];
139 } RK_YNR_Sigma_formula_t;
140 
141 typedef struct RK_YNR_Params_V3_s
142 {
143     int enable;
144     bool sigma_use_point;
145     char version[64];
146     float iso[RK_YNR_V3_MAX_ISO_NUM];
147     RK_YNR_Params_V3_Select_t arYnrParamsISO[RK_YNR_V3_MAX_ISO_NUM];
148     RK_YNR_Sigma_formula_t arSigmaFormulaISO[RK_YNR_V3_MAX_ISO_NUM];
149 } RK_YNR_Params_V3_t;
150 
151 
152 typedef struct Aynr_Manual_Attr_V3_s
153 {
154     RK_YNR_Params_V3_Select_t stSelect;
155 
156     RK_YNR_Fix_V3_t stFix;
157 
158 } Aynr_Manual_Attr_V3_t;
159 
160 typedef struct Aynr_Auto_Attr_V3_s
161 {
162     //all ISO params and select param
163 
164     RK_YNR_Params_V3_t stParams;
165     RK_YNR_Params_V3_Select_t stSelect;
166 
167 } Aynr_Auto_Attr_V3_t;
168 
169 typedef struct Aynr_ProcResult_V3_s {
170 
171     //for sw simultaion
172     RK_YNR_Params_V3_Select_t* stSelect;
173 
174     //for hw register
175     RK_YNR_Fix_V3_t* stFix;
176 } Aynr_ProcResult_V3_t;
177 
178 
179 typedef struct Aynr_Config_V3_s {
180     Aynr_State_V3_t eState;
181     Aynr_OPMode_V3_t eMode;
182     int rawHeight;
183     int rawWidth;
184 } Aynr_Config_V3_t;
185 
186 
187 typedef struct rk_aiq_ynr_attrib_v3_s {
188     /*
189      * @sync (param in): flags for param update mode,
190      *     true for sync, false for async.
191      * @done (parsm out): flags for param update status,
192      *     true indicate param has been updated, false
193      *     indicate param has not been updated.
194      */
195     rk_aiq_uapi_sync_t sync;
196 
197     Aynr_OPMode_V3_t eMode;
198     Aynr_Auto_Attr_V3_t stAuto;
199     Aynr_Manual_Attr_V3_t stManual;
200 } rk_aiq_ynr_attrib_v3_t;
201 
202 
203 typedef struct rk_aiq_ynr_strength_v3_s {
204     /*
205      * @sync (param in): flags for param update mode,
206      *     true for sync, false for async.
207      * @done (parsm out): flags for param update status,
208      *     true indicate param has been updated, false
209      *     indicate param has not been updated.
210      */
211     rk_aiq_uapi_sync_t sync;
212 
213     float percent;
214     bool strength_enable;
215 } rk_aiq_ynr_strength_v3_t;
216 
217 
218 //calibdb
219 
220 
221 //RKAIQ_END_DECLARE
222 
223 #endif
224 
225