• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __HI_COMM_3A_ADAPT_H__
17 #define __HI_COMM_3A_ADAPT_H__
18 
19 #include "hi_common_adapt.h"
20 #include "hi_comm_isp_adapt.h"
21 #include "hi_comm_sns.h"
22 #include "hi_comm_3a.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif /* End of #ifdef __cplusplus */
29 
30 #define is_linear_mode(mode)      ((mode) == WDR_MODE_NONE)
31 #define is_wdr_mode(mode)         ((!is_linear_mode(mode)) && ((mode) < WDR_MODE_BUTT))
32 #define is_hdr_mode(mode)         (((mode) > DYNAMIC_RANGE_SDR10) && ((mode) < DYNAMIC_RANGE_BUTT))
33 #define is_built_in_wdr_mode(mode) ((mode) == WDR_MODE_BUILT_IN)
34 #define is_fs_wdr_mode(mode)      ((!is_linear_mode(mode))&& (!is_built_in_wdr_mode(mode)) && ((mode) < WDR_MODE_BUTT))
35 #define is_2to1_wdr_mode(mode)    (((mode) == WDR_MODE_2To1_FRAME) || ((mode) == WDR_MODE_2To1_FRAME_FULL_RATE) || \
36                                    ((mode) == WDR_MODE_2To1_LINE) || ((mode) == WDR_MODE_QUDRA))
37 #define is_3to1_wdr_mode(mode)    (((mode) == WDR_MODE_3To1_FRAME) || ((mode) == WDR_MODE_3To1_FRAME_FULL_RATE) || \
38                                    ((mode) == WDR_MODE_3To1_LINE))
39 #define is_4to1_wdr_mode(mode)    (((mode) == WDR_MODE_4To1_FRAME) || ((mode) == WDR_MODE_4To1_FRAME_FULL_RATE) || \
40                                    ((mode) == WDR_MODE_4To1_LINE))
41 #define is_full_wdr_mode(mode)    (((mode) == WDR_MODE_2To1_FRAME_FULL_RATE) || \
42                                    ((mode) == WDR_MODE_3To1_FRAME_FULL_RATE) || \
43                                    ((mode) == WDR_MODE_4To1_FRAME_FULL_RATE))
44 #define is_half_wdr_mode(mode)    (((mode) == WDR_MODE_2To1_FRAME) || ((mode) == WDR_MODE_3To1_FRAME) || \
45                                    ((mode) == WDR_MODE_4To1_FRAME))
46 #define is_line_wdr_mode(mode)    (((mode) == WDR_MODE_2To1_LINE) || ((mode) == WDR_MODE_3To1_LINE) || \
47                                    ((mode) == WDR_MODE_4To1_LINE) || ((mode) == WDR_MODE_QUDRA))
48 
49 #define is_stitch_main_pipe(vi_pipe, main_pipe) ((vi_pipe) == (main_pipe))
50 #define is_offline_mode(mode)    ((mode) == ISP_MODE_RUNNING_OFFLINE)
51 #define is_online_mode(mode)     ((mode) == ISP_MODE_RUNNING_ONLINE)
52 #define is_sidebyside_mode(mode) ((mode) == ISP_MODE_RUNNING_SIDEBYSIDE)
53 #define is_striping_mode(mode)   ((mode) == ISP_MODE_RUNNING_STRIPING)
54 
55 typedef ISP_ALG_MOD_E  hi_isp_alg_mod;
56 typedef ISP_CTRL_CMD_E hi_isp_ctrl_cmd;
57 
58 typedef struct {
59     hi_char *proc_buff;
60     hi_u32   buff_len;
61     hi_u32   write_len;   /* the len count should contain '\0'. */
62 } hi_isp_ctrl_proc_write;
63 
64 typedef struct {
65     hi_bool stitch_enable;
66     hi_bool main_pipe;
67     hi_u8   stitch_pipe_num;
68     hi_s8   stitch_bind_id[VI_MAX_PIPE_NUM];
69 } hi_isp_stitch_attr;
70 
71 /* AE */
72 /* the init param of ae alg */
73 typedef struct {
74     SENSOR_ID sensor_id;
75     hi_u8  wdr_mode;
76     hi_u8  hdr_mode;
77     hi_u16 black_level;
78     hi_float fps;
79     hi_isp_bayer_format bayer;
80     hi_isp_stitch_attr stitch_attr;
81 
82     hi_s32 rsv;
83 } hi_isp_ae_param;
84 
85 /* the statistics of ae alg */
86 typedef struct {
87     hi_u32  pixel_count[ISP_CHN_MAX_NUM];
88     hi_u32  pixel_weight[ISP_CHN_MAX_NUM];
89     hi_u32  histogram_mem_array[ISP_CHN_MAX_NUM][HIST_NUM];
90 } hi_isp_fe_ae_stat_1;
91 
92 typedef struct {
93     hi_u16  global_avg_r[ISP_CHN_MAX_NUM];
94     hi_u16  global_avg_gr[ISP_CHN_MAX_NUM];
95     hi_u16  global_avg_gb[ISP_CHN_MAX_NUM];
96     hi_u16  global_avg_b[ISP_CHN_MAX_NUM];
97 } hi_isp_fe_ae_stat_2;
98 
99 typedef struct {
100     hi_u16  zone_avg[ISP_CHN_MAX_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][BAYER_PATTERN_NUM];
101 } hi_isp_fe_ae_stat_3;
102 
103 typedef struct {
104     hi_u16  zone_avg[VI_MAX_PIPE_NUM][ISP_CHN_MAX_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][BAYER_PATTERN_NUM];
105 } hi_isp_fe_ae_stitch_stat_3;
106 
107 typedef struct {
108     hi_u32  pixel_count;
109     hi_u32  pixel_weight;
110     hi_u32  histogram_mem_array[HIST_NUM];
111 } hi_isp_be_ae_stat_1;
112 
113 typedef struct {
114     hi_u16  global_avg_r;
115     hi_u16  global_avg_gr;
116     hi_u16  global_avg_gb;
117     hi_u16  global_avg_b;
118 } hi_isp_be_ae_stat_2;
119 
120 typedef struct {
121     hi_u16  zone_avg[AE_ZONE_ROW][AE_ZONE_COLUMN][BAYER_PATTERN_NUM];
122 } hi_isp_be_ae_stat_3;
123 
124 typedef struct {
125     hi_u16  zone_avg[VI_MAX_PIPE_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][BAYER_PATTERN_NUM];
126 } hi_isp_be_ae_stitch_stat_3;
127 
128 typedef struct {
129     hi_u32  frame_cnt;    /* the counting of frame */
130     hi_isp_smart_info smart_info;  /* Only used for Hi3516EV200/Hi3516EV300/Hi3518EV300 */
131 
132     hi_isp_fe_ae_stat_1 *fe_ae_stat1;
133     hi_isp_fe_ae_stat_2 *fe_ae_stat2;
134     hi_isp_fe_ae_stat_3 *fe_ae_stat3;
135     hi_isp_fe_ae_stitch_stat_3 *fe_ae_sti_stat;
136     hi_isp_be_ae_stat_1 *be_ae_stat1;
137     hi_isp_be_ae_stat_2 *be_ae_stat2;
138     hi_isp_be_ae_stat_3 *be_ae_stat3;
139     hi_isp_be_ae_stitch_stat_3 *be_ae_sti_stat;
140 } hi_isp_ae_info;
141 
142 typedef struct {
143     hi_bool change;
144 
145     hi_bool hist_adjust;
146     hi_u8 ae_be_sel;
147     hi_u8 four_plane_mode;
148     hi_u8 hist_offset_x;
149     hi_u8 hist_offset_y;
150     hi_u8 hist_skip_x;
151     hi_u8 hist_skip_y;
152 
153     hi_bool mode_update;
154     hi_u8 hist_mode;
155     hi_u8 aver_mode;
156     hi_u8 max_gain_mode;
157 
158     hi_bool wight_table_update;
159     hi_u8 weight_table[VI_MAX_PIPE_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN];
160 } hi_isp_ae_stat_attr;
161 
162 /* the final calculate of ae alg */
163 typedef struct {
164     hi_u32  int_time[AE_INT_TIME_NUM];
165     hi_u32  isp_dgain;
166     hi_u32  again;
167     hi_u32  dgain;
168     hi_u32  iso;
169     hi_u32  isp_dgain_sf;
170     hi_u32  again_sf;
171     hi_u32  dgain_sf;
172     hi_u32  iso_sf;
173     hi_u8   ae_run_interval;
174 
175     hi_bool piris_valid;
176     hi_s32  piris_pos;
177     hi_u32  piris_gain;
178     hi_u32  sns_lhcg_exp_ratio;
179 
180     hi_isp_fswdr_mode fswdr_mode;
181     hi_u32  wdr_gain[WDR_MAX_FRAME_NUM];
182     hi_u32  hmax_times; /* unit is ns */
183     hi_u32  vmax; /* unit is line */
184 
185     hi_isp_ae_stat_attr stat_attr;
186     hi_isp_dcf_update_info update_info;
187 } hi_isp_ae_result;
188 
189 typedef struct {
190     hi_u32 isp_dgain;
191     hi_u32 iso;
192 } hi_isp_ae_init_info;
193 
194 typedef struct {
195     hi_s32 (*pfn_ae_init)(hi_s32 handle, const hi_isp_ae_param *ae_param);
196     hi_s32 (*pfn_ae_run)(hi_s32 handle,
197                          const hi_isp_ae_info *ae_info,
198                          hi_isp_ae_result *ae_result,
199                          hi_s32 rsv);
200     hi_s32 (*pfn_ae_ctrl)(hi_s32 handle, hi_u32 cmd, hi_void *value);
201     hi_s32 (*pfn_ae_exit)(hi_s32 handle);
202 } hi_isp_ae_exp_func;
203 
204 typedef struct {
205     hi_isp_ae_exp_func ae_exp_func;
206 } hi_isp_ae_register;
207 
208 /* AWB */
209 typedef AWB_CTRL_CMD_E hi_isp_awb_ctrl_cmd;
210 
211 typedef struct {
212     hi_bool awb_bypass_en;
213     hi_bool manual_sat_en;
214     hi_bool manual_temp_en;
215 
216     hi_u32  manual_sat_value;
217     hi_u32  manual_temp_value;
218     hi_u16  ccm_speed;
219 
220     hi_u16  high_ccm[CCM_MATRIX_SIZE];
221     hi_u16  low_ccm[CCM_MATRIX_SIZE];
222     hi_u16  high_color_temp;
223     hi_u16  low_color_temp;
224 } awb_ccm_config;
225 
226 /* the init param of awb alg */
227 typedef struct {
228     SENSOR_ID sensor_id;
229     hi_u8 wdr_mode;
230     hi_u8 awb_zone_row;
231     hi_u8 awb_zone_col;
232     hi_u8 awb_zone_bin;
233     hi_isp_stitch_attr stitch_attr;
234     hi_u16 awb_width;
235     hi_u16 awb_height;
236     hi_u32 init_iso;
237     hi_s8 rsv;
238 } hi_isp_awb_param;
239 
240 /* the statistics of awb alg */
241 typedef struct {
242     hi_u16  metering_awb_avg_r;
243     hi_u16  metering_awb_avg_g;
244     hi_u16  metering_awb_avg_b;
245     hi_u16  metering_awb_count_all;
246 } hi_isp_awb_stat_1;
247 
248 typedef struct {
249     hi_u16  metering_mem_array_avg_r[AWB_ZONE_NUM];
250     hi_u16  metering_mem_array_avg_g[AWB_ZONE_NUM];
251     hi_u16  metering_mem_array_avg_b[AWB_ZONE_NUM];
252     hi_u16  metering_mem_array_count_all[AWB_ZONE_NUM];
253 } hi_isp_awb_stat_2;
254 
255 typedef struct {
256     hi_u16  zone_col;
257     hi_u16  zone_row;
258     hi_u16  zone_bin;
259     hi_u16  metering_mem_array_avg_r[AWB_ZONE_STITCH_MAX];
260     hi_u16  metering_mem_array_avg_g[AWB_ZONE_STITCH_MAX];
261     hi_u16  metering_mem_array_avg_b[AWB_ZONE_STITCH_MAX];
262     hi_u16  metering_mem_array_count_all[AWB_ZONE_STITCH_MAX];
263 } hi_isp_awb_stat_stitch;
264 
265 typedef struct {
266     hi_u16 *zone_avg_r;
267     hi_u16 *zone_avg_g;
268     hi_u16 *zone_avg_b;
269     hi_u16 *zone_count;
270 } hi_isp_awb_stat_result;
271 
272 typedef struct {
273     hi_u32  frame_cnt;
274 
275     hi_isp_awb_stat_1 *awb_stat1;
276     hi_isp_awb_stat_result awb_stat2;
277     hi_u8  awb_gain_switch;
278     hi_u8  awb_stat_switch;
279     hi_bool wb_gain_in_sensor;
280     hi_u32 wdr_wb_gain[ISP_BAYER_CHN_NUM];
281 } hi_isp_awb_info;
282 
283 /* the statistics's attr of awb alg */
284 typedef struct {
285     hi_bool stat_cfg_update;
286 
287     hi_u16  metering_white_level_awb;
288     hi_u16  metering_black_level_awb;
289     hi_u16  metering_cr_ref_max_awb;
290     hi_u16  metering_cb_ref_max_awb;
291     hi_u16  metering_cr_ref_min_awb;
292     hi_u16  metering_cb_ref_min_awb;
293 } hi_isp_awb_raw_stat_attr;
294 
295 /* the final calculate of awb alg */
296 typedef struct {
297     hi_u32  white_balance_gain[ISP_BAYER_CHN_NUM];
298     hi_u16  color_matrix[CCM_MATRIX_SIZE];
299     hi_u32  color_temp;
300     hi_u8   saturation;
301     hi_isp_awb_raw_stat_attr raw_stat_attr;
302 } hi_isp_awb_result;
303 
304 typedef struct {
305     hi_s32 (*pfn_awb_init)(hi_s32 handle, const hi_isp_awb_param *awb_param, hi_isp_awb_result *awb_result);
306     hi_s32 (*pfn_awb_run)(hi_s32 handle,
307                           const hi_isp_awb_info *awb_info,
308                           hi_isp_awb_result *awb_result,
309                           hi_s32 rsv);
310     hi_s32 (*pfn_awb_ctrl)(hi_s32 handle, hi_u32 cmd, hi_void *value);
311     hi_s32 (*pfn_awb_exit)(hi_s32 handle);
312 } hi_isp_awb_exp_func;
313 
314 typedef struct {
315     hi_isp_awb_exp_func awb_exp_func;
316 } hi_isp_awb_register;
317 
318 /* AF */
319 /* the statistics of af alg */
320 typedef struct {
321     hi_u16  v1;
322     hi_u16  h1;
323     hi_u16  v2;
324     hi_u16  h2;
325     hi_u16  y;
326     hi_u16  hl_cnt;
327 } hi_isp_af_zone;
328 
329 typedef struct {
330     hi_isp_af_zone zone_metrics[WDR_CHN_MAX][AF_ZONE_ROW][AF_ZONE_COLUMN]; /* R; the zoned measure of contrast */
331 } hi_isp_fe_af_stat;
332 
333 typedef struct {
334     hi_isp_af_zone zone_metrics[AF_ZONE_ROW][AF_ZONE_COLUMN]; /* R; the zoned measure of contrast */
335 } hi_isp_be_af_stat;
336 
337 typedef struct {
338     hi_s32  id;
339     hi_char lib_name[ALG_LIB_NAME_SIZE_MAX];
340 } hi_isp_alg_lib;
341 
342 typedef struct {
343     SENSOR_ID       sensor_id;
344     hi_isp_alg_lib  ae_lib;
345     hi_isp_alg_lib  af_lib;
346     hi_isp_alg_lib  awb_lib;
347 } hi_isp_bind_attr;
348 
349 #ifdef __cplusplus
350 #if __cplusplus
351 }
352 #endif
353 #endif /* End of #ifdef __cplusplus */
354 
355 #endif /* __HI_COMM_3A_ADAPT_H__ */
356