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_VIDEO_ADAPT_H__
17 #define __HI_COMM_VIDEO_ADAPT_H__
18 
19 #include "hi_type.h"
20 #include "hi_common.h"
21 #include "hi_comm_video.h"
22 #include "hi_common_adapt.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif /* __cplusplus */
29 
30 typedef OPERATION_MODE_E hi_operation_mode;
31 
32 typedef ROTATION_E hi_rotation;
33 typedef VB_SOURCE_E hi_vb_source;
34 typedef DATA_RATE_E hi_data_rate;
35 
36 typedef struct {
37     hi_u32 top_width;
38     hi_u32 bottom_width;
39     hi_u32 left_width;
40     hi_u32 right_width;
41     hi_u32 color;
42 } hi_border;
43 
44 typedef struct {
45     hi_s32 x;
46     hi_s32 y;
47 } hi_point;
48 
49 typedef struct {
50     hi_u32 width;
51     hi_u32 height;
52 } hi_size;
53 
54 typedef struct {
55     hi_s32 x;
56     hi_s32 y;
57     hi_u32 width;
58     hi_u32 height;
59 } hi_rect;
60 
61 typedef struct {
62     hi_u32           region_num;       /* W; count of the region */
63     hi_rect ATTRIBUTE *region;         /* W; region attribute */
64 } hi_video_region_info;
65 
66 typedef struct {
67     hi_bool enable;
68     hi_rect  rect;
69 } hi_crop_info;
70 
71 typedef struct {
72     hi_s32  src_frame_rate;        /* RW; source frame rate */
73     hi_s32  dst_frame_rate;        /* RW; dest frame rate */
74 } hi_frame_rate_ctrl;
75 
76 typedef ASPECT_RATIO_E hi_aspect_ratio_type;
77 
78 typedef struct {
79     hi_aspect_ratio_type mode;          /* aspect ratio mode: none/auto/manual */
80     hi_u32         bg_color;      /* background color, RGB 888 */
81     hi_rect         video_rect;     /* valid in ASPECT_RATIO_MANUAL mode */
82 } hi_aspect_ratio;
83 
84 /* we ONLY define picture format used, all unused will be deleted! */
85 typedef PIXEL_FORMAT_E hi_pixel_format;
86 
87 typedef VIDEO_FIELD_E hi_video_field;
88 
89 typedef VIDEO_FORMAT_E hi_video_format;
90 
91 typedef COMPRESS_MODE_E hi_compress_mode;
92 
93 typedef VIDEO_DISPLAY_MODE_E hi_video_display_mode;
94 
95 #define is_yuv_sp422(pixel_format)  ((pixel_format) == PIXEL_FORMAT_YUV_SEMIPLANAR_422)
96 #define is_yvu_sp422(pixel_format)  ((pixel_format) == PIXEL_FORMAT_YVU_SEMIPLANAR_422)
97 #define is_yuv_sp420(pixel_format)  ((pixel_format) == PIXEL_FORMAT_YUV_SEMIPLANAR_420)
98 #define is_yvu_sp420(pixel_format)  ((pixel_format) == PIXEL_FORMAT_YVU_SEMIPLANAR_420)
99 #define is_yuv_400(pixel_format)    ((pixel_format) == PIXEL_FORMAT_YUV_400)
100 #define is_sp422(pixel_format)      (is_yuv_sp422(pixel_format) || is_yvu_sp422(pixel_format))
101 #define is_sp420(pixel_format)      (is_yuv_sp420(pixel_format) || is_yvu_sp420(pixel_format))
102 
103 typedef struct {
104     hi_u64 luma_pix_sum;      /* luma sum of current frame */
105     hi_u32 luma_pix_average;  /* luma average of current frame */
106     hi_u64 pts;             /* PTS of current frame  */
107 } hi_luma_info;
108 
109 typedef struct {
110     hi_u8       image_description[DCF_DESCRIPTION_LENGTH];        /* describes image */
111     hi_u8       make[DCF_DESCRIPTION_LENGTH];          /* shows manufacturer of digital cameras */
112     hi_u8       model[DCF_DESCRIPTION_LENGTH];         /* shows model number of digital cameras */
113     hi_u8       software[DCF_DESCRIPTION_LENGTH];      /* shows firmware (internal software of digital cameras)
114                                                         version number */
115 
116     hi_u8       light_source;        /* light source, actually this means white balance setting. '0' means unknown,
117                                      '1' daylight, '2' fluorescent, '3' tungsten, '10' flash, '17' standard light A,
118                                      '18' standard light B, '19' standard lightC, '20' D55, '21' D65,
119                                      '22' D75, '255' other */
120     hi_u32      focal_length;         /* focal length of lens used to take image. unit is millimeter */
121     hi_u8       scene_type;           /* indicates the type of scene. value '0x01' means that the image was directly
122                                         photographed. */
123     hi_u8       custom_rendered;       /* indicates the use of special processing on image data, such as rendering
124                                         geared to output. 0 = normal process  1 = custom process */
125     hi_u8       focal_length_in35mm_film; /* indicates the equivalent focal length assuming a 35mm film camera, in mm */
126     hi_u8       scene_capture_type;       /* indicates the type of scene that was shot. 0 = standard, 1 = landscape,
127                                                 2 = portrait,3 = night scene. */
128     hi_u8       gain_control;           /* indicates the degree of overall image gain adjustment. 0 = none,
129                                         1 = low gain up,2 = high gain up,3 = low gain down,4 = high gain down. */
130     hi_u8       contrast;        /* indicates the direction of contrast processing applied by the camera when the image
131                                     was shot. 0 = normal,1 = soft,2 = hard */
132     hi_u8       saturation;     /* indicates the direction of saturation processing applied by the camera when
133                                     the image was shot. 0 = normal,1 = low saturation,2 = high saturation */
134     hi_u8       sharpness;    /* indicates the direction of sharpness processing applied by the camera when the image
135                                 was shot. 0 = normal,1 = soft,2 = hard . */
136     hi_u8       metering_mode;      /* exposure metering method. '0' means unknown, '1' average, '2' center weighted
137                                     average, '3' spot, '4' multi-spot, '5' multi-segment, '6' partial, '255' other */
138 } hi_isp_dcf_const_info;
139 
140 typedef struct {
141     hi_u32      iso_speed_ratings;        /* CCD sensitivity equivalent to ag-hr film speedrate */
142     hi_u32      exposure_time;           /* exposure time (reciprocal of shutter speed). */
143     hi_u32      exposure_bias_value;      /* exposure bias (compensation) value of taking picture */
144     hi_u8       exposure_program;   /* exposure program that the camera used when image was taken.
145                                        '1' means manual control, '2' program normal, '3' aperture priority,
146                                        '4' shutter priority, '5' program creative (slow program),
147                                        '6' program action(high-speed program), '7' portrait mode, '8' landscape mode */
148     hi_u32      f_number;                /* the actual F-number (F-stop) of lens when the image was taken */
149     hi_u32      max_aperture_value;       /* maximum aperture value of lens. */
150     hi_u8       exposure_mode;            /* indicates the exposure mode set when the image was shot.
151                                                      0 = auto exposure,1 = manual exposure, 2 = auto bracket */
152     hi_u8       white_balance;            /* indicates the white balance mode set when the image was shot.
153                                                        0 = auto white balance ,1 = manual white balance */
154 } hi_isp_dcf_update_info;
155 
156 typedef struct {
157     hi_isp_dcf_const_info  isp_dcf_const_info;
158     hi_isp_dcf_update_info isp_dcf_update_info;
159 } hi_isp_dcf_info;
160 
161 typedef struct {
162     hi_u8           capture_time[DCF_CAPTURE_TIME_LENGTH];   /* the date and time when the picture data was generated */
163     hi_bool         flash;               /* whether the picture is captured when a flash lamp is on */
164     hi_u32          digital_zoom_ratio; /* indicates the digital zoom ratio when the image was shot. if the
165                                          * numerator of the recorded value is 0, this indicates that digital zoom
166                                          * was not used. */
167     hi_isp_dcf_info isp_dcf_info;
168 } hi_jpeg_dcf;
169 
170 typedef struct {
171     hi_u32      iso;                    /* ISP internal ISO : again*dgain*is_pgain */
172     hi_u32      exposure_time;           /* exposure time (reciprocal of shutter speed),unit is us */
173     hi_u32      isp_dgain;
174     hi_u32      again;
175     hi_u32      dgain;
176     hi_u32      ratio[3];
177     hi_u32      isp_nr_strength;
178     hi_u32      f_number;                /* the actual F-number (F-stop) of lens when the image was taken */
179     hi_u32      sensor_id;               /* which sensor is used */
180     hi_u32      sensor_mode;
181     hi_u32      hmax_times;              /* sensor hmax_times,unit is ns */
182     hi_u32      vmax;                   /* sensor vmax,unit is line */
183     hi_u32      vc_num;                  /* when dump wdr frame, which is long or short  exposure frame. */
184 } hi_isp_frame_info;
185 
186 typedef struct {
187     hi_u32 numerator;   /* represents the numerator of a fraction, */
188     hi_u32 denominator; /* the denominator. */
189 } hi_dng_rational;
190 
191 /*
192 defines the structure of DNG image dynamic information
193 */
194 typedef struct {
195     hi_u32 black_level[ISP_BAYER_CHN];  /* RO;range: [0x0, 0xFFFF]; black level */
196     hi_dng_rational as_shot_neutral[CFACOLORPLANE]; /* specifies the selected white balance at time of capture,
197                                 encoded as the coordinates of a perfectly neutral color
198                                 in linear reference space values. */
199     hi_double ad_noise_profile[DNG_NP_SIZE];  /* RO;describes the amount of noise in a raw image */
200 } hi_dng_image_dynamic_info;
201 
202 typedef struct {
203     hi_u32 color_temp;
204     hi_u16 ccm[9];
205     hi_u8  saturation;
206 } hi_isp_hdr_info;
207 
208 typedef struct {
209     hi_isp_hdr_info     isp_hdr;
210     hi_u32 iso;
211     hi_u32 init_iso;
212     hi_u8 sns_wdr_mode;
213 } hi_isp_attach_info;
214 
215 typedef FRAME_FLAG_E hi_frame_flag;
216 
217 typedef struct {
218     hi_u32 iso;
219     hi_u32 isp_dgain;
220     hi_u32 exposure_time;
221     hi_u32 white_balance_gain[ISP_WB_GAIN_NUM];
222     hi_u32 color_temperature;
223     hi_u16 cap_ccm[ISP_CAP_CCM_NUM];
224 } hi_isp_config_info;
225 
226 typedef struct {
227     hi_u64   jpeg_dcf_phy_addr;
228     hi_u64   isp_info_phy_addr;
229     hi_u64   low_delay_phy_addr;
230     hi_u64   motion_data_phy_addr;
231     hi_u64   frame_dng_phy_addr;
232 
233     hi_void *ATTRIBUTE jpeg_dcf_vir_addr;        /* jpeg_dcf, used in JPEG DCF */
234     hi_void *ATTRIBUTE isp_info_vir_addr;        /* isp_frame_info, used in ISP debug, when get raw and send raw */
235     hi_void *ATTRIBUTE low_delay_vir_addr;       /* used in low delay */
236     hi_void *ATTRIBUTE motion_data_vir_addr;     /* vpss 3dnr use: gme motion data, filter motion data, gyro data. */
237     hi_void *ATTRIBUTE frame_dng_vir_addr;
238 } hi_video_supplement;
239 
240 typedef COLOR_GAMUT_E hi_color_gamut;
241 
242 typedef struct {
243     hi_color_gamut color_gamut;
244 } hi_isp_colorgammut_info;
245 
246 typedef DYNAMIC_RANGE_E hi_dynamic_range;
247 
248 typedef DATA_BITWIDTH_E hi_data_bitwidth;
249 
250 typedef struct {
251     hi_u32              width;
252     hi_u32              height;
253     hi_video_field       field;
254     hi_pixel_format      pixel_format;
255     hi_video_format      video_format;
256     hi_compress_mode     compress_mode;
257     hi_dynamic_range     dynamic_range;
258     hi_color_gamut       color_gamut;
259     hi_u32              header_stride[3];
260     hi_u32              stride[3];
261     hi_u32              ext_stride[3];
262 
263     hi_u64              header_phy_addr[3];
264     hi_u64              header_vir_addr[3];
265     hi_u64              phy_addr[3];
266     hi_u64              vir_addr[3];
267     hi_u64              ext_phy_addr[3];
268     hi_u64              ext_vir_addr[3];
269 
270     hi_s16              offset_top;        /* top offset of show area */
271     hi_s16              offset_bottom;    /* bottom offset of show area */
272     hi_s16              offset_left;        /* left offset of show area */
273     hi_s16              offset_right;        /* right offset of show area */
274 
275     hi_u32              max_luminance;
276     hi_u32              min_luminance;
277 
278     hi_u32              time_ref;
279     hi_u64              pts;
280 
281     hi_u64              private_data;
282     hi_u32              frame_flag;     /* frame_flag, can be OR operation. */
283     hi_video_supplement  supplement;
284 } hi_video_frame;
285 
286 typedef struct {
287     hi_video_frame v_frame;
288     hi_u32        pool_id;
289     hi_mod_id      mod_id;
290 } hi_video_frame_info;
291 
292 typedef struct {
293     hi_u32 vb_size;
294 
295     hi_u32 head_stride;
296     hi_u32 head_size;
297     hi_u32 head_y_size;
298 
299     hi_u32 main_stride;
300     hi_u32 main_size;
301     hi_u32 main_y_size;
302 
303     hi_u32 ext_stride;
304     hi_u32 ext_y_size;
305 } hi_vb_cal_config;
306 
307 typedef struct {
308     hi_pixel_format pixel_format;  /* bitmap's pixel format */
309     hi_u32 width;               /* bitmap's width */
310     hi_u32 height;              /* bitmap's height */
311     hi_void *ATTRIBUTE data;      /* address of bitmap's data */
312 } hi_bitmap;
313 
314 typedef struct {
315     hi_bool    aspect;             /* RW;range: [0, 1];whether aspect ration  is keep */
316     hi_s32     x_ratio;           /* RW; range: [0, 100]; field angle ration of  horizontal,valid when aspect=0. */
317     hi_s32     y_ratio;           /* RW; range: [0, 100]; field angle ration of  vertical,valid when aspect=0. */
318     hi_s32     xy_ratio;          /* RW; range: [0, 100]; field angle ration of  all,valid when aspect=1. */
319     hi_s32 center_x_offset;        /* RW; range: [-511, 511]; horizontal offset of the image distortion center
320                                     relative to image center. */
321     hi_s32 center_y_offset;        /* RW; range: [-511, 511]; vertical offset of the image distortion center relative
322                                     to image center. */
323     hi_s32 distortion_ratio;      /* RW; range: [-300, 500]; LDC distortion ratio.when spread on, distortion_ratio
324                                     range should be [0, 500] */
325 } hi_ldc_attr;
326 
327 typedef struct {
328     hi_s32 focal_len_x;                  /* RW; focal length in horizontal direction, with 2 decimal numbers */
329     hi_s32 focal_len_y;                  /* RW; focal length in vertical direction, with 2 decimal numbers */
330     hi_s32 coor_shift_x;                 /* RW; coordinate of image center, with 2 decimal numbers */
331     hi_s32 coor_shift_y;                 /* RW; Y coordinate of image center, with 2 decimal numbers */
332     hi_s32 src_cali_ratio[SRC_LENS_COEF_SEG][SRC_LENS_COEF_NUM];  /* RW; lens distortion coefficients of the source
333                                                                     image, with 5 decimal numbers */
334     hi_s32 src_jun_pt;                                             /* RW; junction point of the two segments */
335     hi_s32 dst_cali_ratio[DST_LENS_COEF_SEG][DST_LENS_COEF_NUM];  /* RW; lens distortion coefficients, with 5 decimal
336                                                                     numbers */
337     hi_s32 dst_jun_pt[DST_LENS_COEF_SEG_POINT];                   /* RW; junction point of the three segments */
338     hi_s32 max_du;                                                /* RW; max undistorted distance before 3rd
339                                                                     polynomial drop, with 16bits decimal */
340 } hi_ldc_v2_attr;
341 
342 typedef LDC_VIEW_TYPE_E hi_ldc_view_type;
343 
344 typedef struct {
345     hi_ldc_view_type view_type; /* RW; range: [0, 1], 0: all mode, 1: crop mode. */
346     hi_s32 center_x_offset;    /* RW; range: ABS(center_x_offset)->[0, min(128, width*0.08)], horizontal offset
347                                 of the image distortion center relative to image center. */
348     hi_s32 center_y_offset;    /* RW; range: ABS(center_x_offset)->[0, min(128, height*0.08)], vertical offset of
349                                 the image distortion center relative to image center. */
350     hi_s32 distortion_ratio;  /* RW; range: [-300, 300], LDC distortion ratio. */
351     hi_s32 min_ratio;         /* RW; range: [-300, 300], to remove the black region around when performing
352                                 pinchusion distortion correction with crop mode. */
353 } hi_ldc_v3_attr;
354 
355 typedef ROTATION_VIEW_TYPE_E hi_rotation_view_type;
356 
357 typedef struct {
358     hi_rotation_view_type view_type;       /* RW;range: [0, 2];rotation mode */
359     hi_u32               angle;         /* RW;range: [0,360];rotation angle:[0,360] */
360     hi_s32               center_x_offset; /* RW;range: [-511, 511];horizontal offset of the image distortion center
361                                             relative to image center. */
362     hi_s32               center_y_offset; /* RW;range: [-511, 511];vertical offset of the image distortion center
363                                             relative to image center. */
364     hi_size               dest_size;       /* RW;dest size of any angle rotation */
365 } hi_rotation_ex;
366 
367 typedef WDR_MODE_E hi_wdr_mode;
368 
369 typedef FRAME_INTERRUPT_TYPE_E hi_frame_interrupt_type;
370 
371 typedef struct {
372     hi_frame_interrupt_type int_type;
373     hi_u32 early_line;
374 } hi_frame_interrupt_attr;
375 
376 #ifdef __cplusplus
377 #if __cplusplus
378 }
379 #endif
380 #endif /* __cplusplus */
381 
382 #endif /* __HI_COMM_VIDEO_ADAPT_H__ */
383 
384