• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * cl_fisheye_handler.h - CL fisheye handler
3  *
4  *  Copyright (c) 2016 Intel 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  * Author: Wind Yuan <feng.yuan@intel.com>
19  */
20 
21 #ifndef XCAM_CL_FISHEYE_HANDLER_H
22 #define XCAM_CL_FISHEYE_HANDLER_H
23 
24 #include <xcam_std.h>
25 #include <interface/data_types.h>
26 #include <ocl/cl_image_handler.h>
27 #include <ocl/cl_geo_map_handler.h>
28 #include <surview_fisheye_dewarp.h>
29 
30 namespace XCam {
31 
32 class CLFisheyeHandler;
33 class CLFisheye2GPSKernel
34     : public CLImageKernel
35 {
36 public:
37     explicit CLFisheye2GPSKernel (const SmartPtr<CLContext> &context, SmartPtr<CLFisheyeHandler> &handler);
38 
39 protected:
40     virtual XCamReturn prepare_arguments (CLArgList &args, CLWorkSize &work_size);
41 
42 private:
43     SmartPtr<CLFisheyeHandler>  _handler;
44 };
45 
46 class CLFisheyeHandler
47     : public CLImageHandler
48     , public GeoKernelParamCallback
49 {
50     friend class CLFisheye2GPSKernel;
51 public:
52     explicit CLFisheyeHandler (const SmartPtr<CLContext> &context, SurroundMode surround_mode, bool use_map, bool need_lsc);
53     virtual ~CLFisheyeHandler();
54 
55     void set_output_size (uint32_t width, uint32_t height);
56     void get_output_size (uint32_t &width, uint32_t &height) const;
57 
58     void set_dst_range (float longitude, float latitude);
59     void get_dst_range (float &longitude, float &latitude) const;
60     void set_fisheye_info (const FisheyeInfo &info);
get_fisheye_info()61     const FisheyeInfo &get_fisheye_info () const {
62         return _fisheye_info;
63     }
64 
65     void set_lsc_table (float *table, uint32_t table_size);
66     void set_lsc_gray_threshold (float min_threshold, float max_threshold);
67 
set_bowl_config(const BowlDataConfig bowl_data_config)68     void set_bowl_config(const BowlDataConfig bowl_data_config) {
69         _bowl_data_config = bowl_data_config;
70     }
get_bowl_config()71     const BowlDataConfig &get_bowl_config() {
72         return _bowl_data_config;
73     }
74 
set_intrinsic_param(const IntrinsicParameter intrinsic_param)75     void set_intrinsic_param(const IntrinsicParameter intrinsic_param) {
76         _intrinsic_param = intrinsic_param;
77     }
get_intrinsic_param()78     const IntrinsicParameter &get_intrinsic_param() {
79         return _intrinsic_param;
80     }
81 
set_extrinsic_param(const ExtrinsicParameter extrinsic_param)82     void set_extrinsic_param(const ExtrinsicParameter extrinsic_param) {
83         _extrinsic_param = extrinsic_param;
84     }
get_extrinsic_param()85     const ExtrinsicParameter &get_extrinsic_param() {
86         return _extrinsic_param;
87     }
88 
89 
90 protected:
91     // derived from CLImageHandler
92     virtual XCamReturn prepare_buffer_pool_video_info (
93         const VideoBufferInfo &input, VideoBufferInfo &output);
94     virtual XCamReturn prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
95     virtual XCamReturn execute_done (SmartPtr<VideoBuffer> &output);
96 
97     // derived from GeoKernelParamCallback
98     virtual SmartPtr<CLImage> get_geo_input_image (NV12PlaneIdx index);
99     virtual SmartPtr<CLImage> get_geo_output_image (NV12PlaneIdx index);
get_geo_map_table()100     virtual SmartPtr<CLImage> get_geo_map_table () {
101         return _geo_table;
102     }
103     virtual void get_geo_equivalent_out_size (float &width, float &height);
104     virtual void get_geo_pixel_out_size (float &width, float &height);
105 
106     virtual SmartPtr<CLImage> get_lsc_table ();
107     virtual float* get_lsc_gray_threshold ();
108 
109 private:
get_input_image(NV12PlaneIdx index)110     SmartPtr<CLImage> &get_input_image (NV12PlaneIdx index) {
111         XCAM_ASSERT (index < NV12PlaneMax);
112         return _input [index];
113     }
get_output_image(NV12PlaneIdx index)114     SmartPtr<CLImage> &get_output_image (NV12PlaneIdx index) {
115         XCAM_ASSERT (index < NV12PlaneMax);
116         return _output [index];
117     }
118 
119     SmartPtr<CLImage> create_cl_image (
120         uint32_t width, uint32_t height, cl_channel_order order, cl_channel_type type);
121     XCamReturn generate_fisheye_table (
122         uint32_t fisheye_width, uint32_t fisheye_height, const FisheyeInfo &fisheye_info);
123 
124     void ensure_lsc_params ();
125     XCamReturn generate_lsc_table (
126         uint32_t fisheye_width, uint32_t fisheye_height, FisheyeInfo &fisheye_info);
127 
128 
129     XCAM_DEAD_COPY (CLFisheyeHandler);
130 
131 private:
132     uint32_t                         _output_width;
133     uint32_t                         _output_height;
134     float                            _range_longitude;
135     float                            _range_latitude;
136     FisheyeInfo                    _fisheye_info;
137     float                            _map_factor;
138     bool                             _use_map;
139     uint32_t                         _need_lsc;
140     uint32_t                         _lsc_array_size;
141     float                            _gray_threshold[2];  // [min_gray_threshold, max_gray_threshold]
142     float                            *_lsc_array;
143 
144     BowlDataConfig                   _bowl_data_config;
145 
146     IntrinsicParameter               _intrinsic_param;
147     ExtrinsicParameter               _extrinsic_param;
148 
149     SurroundMode                     _surround_mode;
150 
151     SmartPtr<CLImage>                _geo_table;
152     SmartPtr<CLImage>                _lsc_table;
153     SmartPtr<CLImage>                _input[NV12PlaneMax];
154     SmartPtr<CLImage>                _output[NV12PlaneMax];
155 };
156 
157 SmartPtr<CLImageHandler>
158 create_fisheye_handler (const SmartPtr<CLContext> &context, SurroundMode surround_mode = SphereView, bool use_map = false, bool need_lsc = false);
159 
160 }
161 
162 #endif //XCAM_CL_FISHEYE_HANDLER_H
163 
164