• 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_H__
17 #define __HI_COMM_3A_H__
18 
19 #include "hi_common.h"
20 #include "hi_comm_isp.h"
21 #include "hi_comm_sns.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif /* End of #ifdef __cplusplus */
28 
29 #define IS_LINEAR_MODE(mode)      ((mode) == WDR_MODE_NONE)
30 #define IS_WDR_MODE(mode)         ((!IS_LINEAR_MODE(mode)) && ((mode) < WDR_MODE_BUTT))
31 #define IS_HDR_MODE(mode)         (((mode) > DYNAMIC_RANGE_SDR10) && ((mode) < DYNAMIC_RANGE_BUTT))
32 #define IS_BUILT_IN_WDR_MODE(mode) ((mode) == WDR_MODE_BUILT_IN)
33 #define IS_FS_WDR_MODE(mode)      ((!IS_LINEAR_MODE(mode))&& (!IS_BUILT_IN_WDR_MODE(mode)) && ((mode) < WDR_MODE_BUTT))
34 #define IS_2to1_WDR_MODE(mode)    (((mode) == WDR_MODE_2To1_FRAME) || ((mode) == WDR_MODE_2To1_FRAME_FULL_RATE) || \
35                                    ((mode) == WDR_MODE_2To1_LINE) || ((mode) == WDR_MODE_QUDRA))
36 #define IS_3to1_WDR_MODE(mode)    (((mode) == WDR_MODE_3To1_FRAME) || ((mode) == WDR_MODE_3To1_FRAME_FULL_RATE) || \
37                                    ((mode) == WDR_MODE_3To1_LINE))
38 #define IS_4to1_WDR_MODE(mode)    (((mode) == WDR_MODE_4To1_FRAME) || ((mode) == WDR_MODE_4To1_FRAME_FULL_RATE) || \
39                                    ((mode) == WDR_MODE_4To1_LINE))
40 #define IS_FULL_WDR_MODE(mode)    (((mode) == WDR_MODE_2To1_FRAME_FULL_RATE) || \
41                                    ((mode) == WDR_MODE_3To1_FRAME_FULL_RATE) || \
42                                    ((mode) == WDR_MODE_4To1_FRAME_FULL_RATE))
43 #define IS_HALF_WDR_MODE(mode)    (((mode) == WDR_MODE_2To1_FRAME) || ((mode) == WDR_MODE_3To1_FRAME) || \
44                                    ((mode) == WDR_MODE_4To1_FRAME))
45 #define IS_LINE_WDR_MODE(mode)    (((mode) == WDR_MODE_2To1_LINE) || ((mode) == WDR_MODE_3To1_LINE) || \
46                                    ((mode) == WDR_MODE_4To1_LINE) || ((mode) == WDR_MODE_QUDRA))
47 
48 #define MAX_REGISTER_ALG_LIB_NUM 2
49 
50 typedef enum hiISP_ALG_MOD_E {
51     ISP_ALG_AE = 0,
52     ISP_ALG_AF,
53     ISP_ALG_AWB,
54     ISP_ALG_BLC,
55     ISP_ALG_FELOGLUT,
56     ISP_ALG_LOGLUT,
57     ISP_ALG_DP,
58     ISP_ALG_PREGAMMA,
59     ISP_ALG_DRC,
60     ISP_ALG_DEMOSAIC,
61     ISP_ALG_ANTIFALSECOLOR,
62     ISP_ALG_GAMMA,
63     ISP_ALG_GE,
64     ISP_ALG_SHARPEN,
65     ISP_ALG_EDGEAMRK,
66     ISP_ALG_FrameWDR,
67     ISP_ALG_FPN,
68     ISP_ALG_DEHAZE,
69     ISP_ALG_ACM,
70     ISP_ALG_LCAC,
71     ISP_ALG_GCAC,
72     ISP_ALG_CSC,
73     ISP_ALG_EXPANDER,
74     ISP_ALG_MCDS,
75     ISP_ALG_ACS,
76     ISP_ALG_LSC,
77     ISP_ALG_RLSC,
78     ISP_ALG_FeLSC,
79     ISP_ALG_RC,
80     ISP_ALG_RGBIR,
81     ISP_ALG_HRS,
82     ISP_ALG_DG,
83     ISP_ALG_BAYERNR,
84     ISP_ALG_FLICKER,
85     ISP_ALG_SPLIT,
86     ISP_ALG_LDCI,
87     ISP_ALG_CA,
88     ISP_ALG_CLUT,
89     ISP_ALG_DETAIL,
90     ISP_ALG_CCM,
91     ISP_ALG_AI,
92     ISP_ALG_BUTT,
93 } ISP_ALG_MOD_E;
94 
95 typedef enum hiISP_CTRL_CMD_E {
96     ISP_WDR_MODE_SET = 8000,
97     ISP_PROC_WRITE,
98 
99     ISP_AE_FPS_BASE_SET,
100     ISP_AE_BLC_SET,
101     ISP_AE_RC_SET,
102     ISP_AE_BAYER_FORMAT_SET,
103     ISP_AE_INIT_INFO_GET,
104 
105     ISP_AWB_ISO_SET,  /* set iso, change saturation when iso change */
106     ISP_CHANGE_IMAGE_MODE_SET,
107     ISP_UPDATE_INFO_GET,
108     ISP_FRAMEINFO_GET,
109     ISP_ATTACHINFO_GET,
110     ISP_COLORGAMUTINFO_GET,
111     ISP_AWB_INTTIME_SET,
112     ISP_BAS_MODE_SET,
113     ISP_PROTRIGGER_SET,
114     ISP_AWB_PIRIS_SET,
115     ISP_AWB_SNAP_MODE_SET,
116     ISP_AWB_ZONE_ROW_SET,
117     ISP_AWB_ZONE_COL_SET,
118     ISP_AWB_ZONE_BIN_SET,
119     ISP_AWB_ERR_GET,
120     ISP_CTRL_CMD_BUTT,
121 } ISP_CTRL_CMD_E;
122 
123 typedef struct hiISP_CTRL_PROC_WRITE_S {
124     HI_CHAR *pcProcBuff;
125     HI_U32   u32BuffLen;
126     HI_U32   u32WriteLen;   /* The len count should contain '\0'. */
127 } ISP_CTRL_PROC_WRITE_S;
128 
129 typedef struct hiISP_STITCH_ATTR_S {
130     HI_BOOL bStitchEnable;
131     HI_BOOL bMainPipe;
132     HI_U8   u8StitchPipeNum;
133     HI_S8   as8StitchBindId[VI_MAX_PIPE_NUM];
134 } ISP_STITCH_ATTR_S;
135 /* AE  */
136 /* the init param of ae alg */
137 typedef struct hiISP_AE_PARAM_S {
138     SENSOR_ID SensorId;
139     HI_U8  u8WDRMode;
140     HI_U8  u8HDRMode;
141     HI_U16 u16BlackLevel;
142     HI_FLOAT f32Fps;
143     ISP_BAYER_FORMAT_E enBayer;
144     ISP_STITCH_ATTR_S stStitchAttr;
145 
146     HI_S32 s32Rsv;
147 } ISP_AE_PARAM_S;
148 
149 /* the statistics of ae alg */
150 typedef struct hiISP_FE_AE_STAT_1_S {
151     HI_U32  u32PixelCount[ISP_CHN_MAX_NUM];
152     HI_U32  u32PixelWeight[ISP_CHN_MAX_NUM];
153     HI_U32  au32HistogramMemArray[ISP_CHN_MAX_NUM][HIST_NUM];
154 } ISP_FE_AE_STAT_1_S;
155 
156 typedef struct hiISP_FE_AE_STAT_2_S {
157     HI_U16  u16GlobalAvgR[ISP_CHN_MAX_NUM];
158     HI_U16  u16GlobalAvgGr[ISP_CHN_MAX_NUM];
159     HI_U16  u16GlobalAvgGb[ISP_CHN_MAX_NUM];
160     HI_U16  u16GlobalAvgB[ISP_CHN_MAX_NUM];
161 } ISP_FE_AE_STAT_2_S;
162 
163 typedef struct hiISP_FE_AE_STAT_3_S {
164     HI_U16  au16ZoneAvg[ISP_CHN_MAX_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][ISP_BAYER_CHN_NUM];
165 } ISP_FE_AE_STAT_3_S;
166 
167 typedef struct hiISP_FE_AE_STITCH_STAT_3_S {
168     HI_U16  au16ZoneAvg[VI_MAX_PIPE_NUM][ISP_CHN_MAX_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][ISP_BAYER_CHN_NUM];
169 } ISP_FE_AE_STITCH_STAT_3_S;
170 
171 typedef struct hiISP_BE_AE_STAT_1_S {
172     HI_U32  u32PixelCount;
173     HI_U32  u32PixelWeight;
174     HI_U32  au32HistogramMemArray[HIST_NUM];
175 } ISP_BE_AE_STAT_1_S;
176 
177 typedef struct hiISP_BE_AE_STAT_2_S {
178     HI_U16  u16GlobalAvgR;
179     HI_U16  u16GlobalAvgGr;
180     HI_U16  u16GlobalAvgGb;
181     HI_U16  u16GlobalAvgB;
182 } ISP_BE_AE_STAT_2_S;
183 
184 typedef struct hiISP_BE_AE_STAT_3_S {
185     HI_U16  au16ZoneAvg[AE_ZONE_ROW][AE_ZONE_COLUMN][ISP_BAYER_CHN_NUM];
186 } ISP_BE_AE_STAT_3_S;
187 
188 typedef struct hiISP_BE_AE_STITCH_STAT_3_S {
189     HI_U16  au16ZoneAvg[VI_MAX_PIPE_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN][ISP_BAYER_CHN_NUM];
190 } ISP_BE_AE_STITCH_STAT_3_S;
191 
192 typedef struct hiISP_AE_INFO_S {
193     HI_U32  u32FrameCnt;    /* the counting of frame */
194     ISP_SMART_INFO_S stSmartInfo;
195 
196     ISP_FE_AE_STAT_1_S *pstFEAeStat1;
197     ISP_FE_AE_STAT_2_S *pstFEAeStat2;
198     ISP_FE_AE_STAT_3_S *pstFEAeStat3;
199     ISP_FE_AE_STITCH_STAT_3_S *pstFEAeStiStat;
200     ISP_BE_AE_STAT_1_S *pstBEAeStat1;
201     ISP_BE_AE_STAT_2_S *pstBEAeStat2;
202     ISP_BE_AE_STAT_3_S *pstBEAeStat3;
203     ISP_BE_AE_STITCH_STAT_3_S *pstBEAeStiStat;
204 } ISP_AE_INFO_S;
205 
206 typedef struct hiISP_AE_STAT_ATTR_S {
207     HI_BOOL bChange;
208 
209     HI_BOOL bHistAdjust;
210     HI_U8 u8AEBESel;
211     HI_U8 u8FourPlaneMode;
212     HI_U8 u8HistOffsetX;
213     HI_U8 u8HistOffsetY;
214     HI_U8 u8HistSkipX;
215     HI_U8 u8HistSkipY;
216 
217     HI_BOOL bModeUpdate;
218     HI_U8 u8HistMode;
219     HI_U8 u8AverMode;
220     HI_U8 u8MaxGainMode;
221 
222     HI_BOOL bWightTableUpdate;
223     HI_U8 au8WeightTable[VI_MAX_PIPE_NUM][AE_ZONE_ROW][AE_ZONE_COLUMN];
224 } ISP_AE_STAT_ATTR_S;
225 
226 /* the final calculate of ae alg */
227 #define AE_INT_TIME_NUM          4
228 typedef struct hiISP_AE_RESULT_S {
229     HI_U32  u32IntTime[AE_INT_TIME_NUM];
230     HI_U32  u32IspDgain;
231     HI_U32  u32Again;
232     HI_U32  u32Dgain;
233     HI_U32  u32Iso;
234     HI_U32  u32IspDgainSF;
235     HI_U32  u32AgainSF;
236     HI_U32  u32DgainSF;
237     HI_U32  u32IsoSF;
238     HI_U8   u8AERunInterval;
239 
240     HI_BOOL bPirisValid;
241     HI_S32  s32PirisPos;
242     HI_U32  u32PirisGain;
243     HI_U32  u32SnsLhcgExpRatio;
244 
245     ISP_FSWDR_MODE_E enFSWDRMode;
246     HI_U32  au32WDRGain[WDR_MAX_FRAME_NUM];
247     HI_U32  u32HmaxTimes; /* unit is ns */
248     HI_U32  u32Vmax; /* unit is line */
249 
250     ISP_AE_STAT_ATTR_S stStatAttr;
251     ISP_DCF_UPDATE_INFO_S stUpdateInfo;
252 } ISP_AE_RESULT_S;
253 
254 typedef struct hiISP_AE_INIT_INFO_S {
255     HI_U32 u32IspDgain;
256     HI_U32 u32Iso;
257 } ISP_AE_INIT_INFO_S;
258 
259 typedef struct hiISP_AE_EXP_FUNC_S {
260     HI_S32 (*pfn_ae_init)(HI_S32 s32Handle, const ISP_AE_PARAM_S *pstAeParam);
261     HI_S32 (*pfn_ae_run)(HI_S32 s32Handle,
262                          const ISP_AE_INFO_S *pstAeInfo,
263                          ISP_AE_RESULT_S *pstAeResult,
264                          HI_S32 s32Rsv);
265     HI_S32 (*pfn_ae_ctrl)(HI_S32 s32Handle, HI_U32 u32Cmd, HI_VOID *pValue);
266     HI_S32 (*pfn_ae_exit)(HI_S32 s32Handle);
267 } ISP_AE_EXP_FUNC_S;
268 
269 typedef struct hiISP_AE_REGISTER_S {
270     ISP_AE_EXP_FUNC_S stAeExpFunc;
271 } ISP_AE_REGISTER_S;
272 
273 /* AWB */
274 typedef enum hiAWB_CTRL_CMD_E {
275     AWB_CCM_CONFIG_SET,
276     AWB_CCM_CONFIG_GET,
277 
278     AWB_DEBUG_ATTR_SET,
279     AWB_DEBUG_ATTR_GET,
280 
281     AWB_CTRL_BUTT,
282 } AWB_CTRL_CMD_E;
283 
284 typedef struct hiAWB_CCM_CONFIG_S {
285     HI_BOOL bAWBBypassEn;
286     HI_BOOL bManualSatEn;
287     HI_BOOL bManualTempEn;
288 
289     HI_U32  u32ManualSatValue;
290     HI_U32  u32ManualTempValue;
291     HI_U16  u16CCMSpeed;
292 
293     HI_U16  au16HighCCM[CCM_MATRIX_SIZE];
294     HI_U16  au16LowCCM[CCM_MATRIX_SIZE];
295     HI_U16  u16HighColorTemp;
296     HI_U16  u16LowColorTemp;
297 } AWB_CCM_CONFIG_S;
298 
299 /* the init param of awb alg */
300 typedef struct hiISP_AWB_PARAM_S {
301     SENSOR_ID SensorId;
302     HI_U8 u8WDRMode;
303     HI_U8 u8AWBZoneRow;
304     HI_U8 u8AWBZoneCol;
305     HI_U8 u8AWBZoneBin;
306     ISP_STITCH_ATTR_S stStitchAttr;
307     HI_U16 u16AWBWidth;
308     HI_U16 u16AWBHeight;
309     HI_U32 u32InitIso;
310     HI_S8 s8Rsv;
311 } ISP_AWB_PARAM_S;
312 
313 /* the statistics of awb alg */
314 typedef struct hiISP_AWB_STAT_1_S {
315     HI_U16  u16MeteringAwbAvgR;
316     HI_U16  u16MeteringAwbAvgG;
317     HI_U16  u16MeteringAwbAvgB;
318     HI_U16  u16MeteringAwbCountAll;
319 } ISP_AWB_STAT_1_S;
320 
321 typedef struct hiISP_AWB_STAT_2_S {
322     HI_U16  au16MeteringMemArrayAvgR[AWB_ZONE_NUM];
323     HI_U16  au16MeteringMemArrayAvgG[AWB_ZONE_NUM];
324     HI_U16  au16MeteringMemArrayAvgB[AWB_ZONE_NUM];
325     HI_U16  au16MeteringMemArrayCountAll[AWB_ZONE_NUM];
326 } ISP_AWB_STAT_2_S;
327 
328 typedef struct hiISP_AWB_STAT_STITCH_S {
329     HI_U16  u16ZoneCol;
330     HI_U16  u16ZoneRow;
331     HI_U16  u16ZoneBin;
332     HI_U16  au16MeteringMemArrayAvgR[AWB_ZONE_STITCH_MAX];
333     HI_U16  au16MeteringMemArrayAvgG[AWB_ZONE_STITCH_MAX];
334     HI_U16  au16MeteringMemArrayAvgB[AWB_ZONE_STITCH_MAX];
335     HI_U16  au16MeteringMemArrayCountAll[AWB_ZONE_STITCH_MAX];
336 } ISP_AWB_STAT_STITCH_S;
337 
338 typedef struct hiISP_AWB_STAT_RESULT_S {
339     HI_U16 *pau16ZoneAvgR;
340     HI_U16 *pau16ZoneAvgG;
341     HI_U16 *pau16ZoneAvgB;
342     HI_U16 *pau16ZoneCount;
343 } ISP_AWB_STAT_RESULT_S;
344 
345 typedef struct hiISP_AWB_INFO_S {
346     HI_U32  u32FrameCnt;
347 
348     ISP_AWB_STAT_1_S *pstAwbStat1;
349     ISP_AWB_STAT_RESULT_S stAwbStat2;
350     HI_U8 u8AwbGainSwitch;
351     HI_U8 u8AwbStatSwitch;
352     HI_BOOL bWbGainInSensor;
353     HI_U32 au32WDRWBGain[ISP_BAYER_CHN_NUM];
354 } ISP_AWB_INFO_S;
355 
356 /* the statistics's attr of awb alg */
357 typedef struct hiISP_AWB_RAW_STAT_ATTR_S {
358     HI_BOOL bStatCfgUpdate;
359 
360     HI_U16  u16MeteringWhiteLevelAwb;
361     HI_U16  u16MeteringBlackLevelAwb;
362     HI_U16  u16MeteringCrRefMaxAwb;
363     HI_U16  u16MeteringCbRefMaxAwb;
364     HI_U16  u16MeteringCrRefMinAwb;
365     HI_U16  u16MeteringCbRefMinAwb;
366 } ISP_AWB_RAW_STAT_ATTR_S;
367 
368 /* the final calculate of awb alg */
369 typedef struct hiISP_AWB_RESULT_S {
370     HI_U32  au32WhiteBalanceGain[ISP_BAYER_CHN_NUM];
371     HI_U16  au16ColorMatrix[CCM_MATRIX_SIZE];
372     HI_U32  u32ColorTemp;
373     HI_U8   u8Saturation;
374     ISP_AWB_RAW_STAT_ATTR_S stRawStatAttr;
375 } ISP_AWB_RESULT_S;
376 
377 typedef struct hiISP_AWB_EXP_FUNC_S {
378     HI_S32 (*pfn_awb_init)(HI_S32 s32Handle, const ISP_AWB_PARAM_S *pstAwbParam, ISP_AWB_RESULT_S *pstAwbResult);
379     HI_S32 (*pfn_awb_run)(HI_S32 s32Handle,
380                           const ISP_AWB_INFO_S *pstAwbInfo,
381                           ISP_AWB_RESULT_S *pstAwbResult,
382                           HI_S32 s32Rsv);
383     HI_S32 (*pfn_awb_ctrl)(HI_S32 s32Handle, HI_U32 u32Cmd, HI_VOID *pValue);
384     HI_S32 (*pfn_awb_exit)(HI_S32 s32Handle);
385 } ISP_AWB_EXP_FUNC_S;
386 
387 typedef struct hiISP_AWB_REGISTER_S {
388     ISP_AWB_EXP_FUNC_S stAwbExpFunc;
389 } ISP_AWB_REGISTER_S;
390 
391 /* AF */
392 /* the statistics of af alg */
393 typedef struct hiISP_AF_ZONE_S {
394     HI_U16  u16v1;
395     HI_U16  u16h1;
396     HI_U16  u16v2;
397     HI_U16  u16h2;
398     HI_U16  u16y;
399     HI_U16  u16HlCnt;
400 } ISP_AF_ZONE_S;
401 
402 typedef struct hiISP_FE_AF_STAT_S {
403     ISP_AF_ZONE_S stZoneMetrics[WDR_CHN_MAX][AF_ZONE_ROW][AF_ZONE_COLUMN]; /* R; The zoned measure of contrast */
404 } ISP_FE_AF_STAT_S;
405 
406 typedef struct hiISP_BE_AF_STAT_S {
407     ISP_AF_ZONE_S stZoneMetrics[AF_ZONE_ROW][AF_ZONE_COLUMN]; /* R; The zoned measure of contrast */
408 } ISP_BE_AF_STAT_S;
409 
410 #define ALG_LIB_NAME_SIZE_MAX    20
411 typedef struct hiALG_LIB_S {
412     HI_S32  s32Id;
413     HI_CHAR acLibName[ALG_LIB_NAME_SIZE_MAX];
414 } ALG_LIB_S;
415 
416 typedef struct hiISP_BIND_ATTR_S {
417     SENSOR_ID   SensorId;
418     ALG_LIB_S   stAeLib;
419     ALG_LIB_S   stAfLib;
420     ALG_LIB_S   stAwbLib;
421 } ISP_BIND_ATTR_S;
422 
423 #ifdef __cplusplus
424 #if __cplusplus
425 }
426 #endif
427 #endif /* End of #ifdef __cplusplus */
428 
429 #endif /* __HI_COMM_SNS_H__ */
430