1 /* 2 * cl_geo_map_handler.h - CL geometry map 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_GEO_MAP_HANDLER_H 22 #define XCAM_CL_GEO_MAP_HANDLER_H 23 24 #include <xcam_std.h> 25 #include <ocl/cl_image_handler.h> 26 27 namespace XCam { 28 29 struct GeoPos { 30 double x; 31 double y; 32 GeoPosGeoPos33 GeoPos () : x(0), y(0) {} 34 }; 35 36 class CLGeoMapKernel; 37 class GeoKernelParamCallback 38 { 39 friend class CLGeoMapKernel; 40 41 public: GeoKernelParamCallback()42 GeoKernelParamCallback () {} ~GeoKernelParamCallback()43 virtual ~GeoKernelParamCallback () {} 44 45 protected: 46 virtual SmartPtr<CLImage> get_geo_input_image (NV12PlaneIdx index) = 0; 47 virtual SmartPtr<CLImage> get_geo_output_image (NV12PlaneIdx index) = 0; 48 virtual SmartPtr<CLImage> get_geo_map_table () = 0; 49 virtual void get_geo_equivalent_out_size (float &width, float &height) = 0; 50 virtual void get_geo_pixel_out_size (float &width, float &height) = 0; 51 52 virtual SmartPtr<CLImage> get_lsc_table () = 0; 53 virtual float* get_lsc_gray_threshold() = 0; 54 55 private: 56 XCAM_DEAD_COPY (GeoKernelParamCallback); 57 }; 58 59 class CLGeoMapHandler; 60 class CLGeoMapKernel 61 : public CLImageKernel 62 { 63 public: 64 explicit CLGeoMapKernel ( 65 const SmartPtr<CLContext> &context, 66 const SmartPtr<GeoKernelParamCallback> handler, 67 bool need_lsc); 68 69 protected: 70 virtual XCamReturn prepare_arguments (CLArgList &args, CLWorkSize &work_size); 71 72 private: 73 SmartPtr<GeoKernelParamCallback> _handler; 74 bool _need_lsc; 75 }; 76 77 class CLGeoMapHandler 78 : public CLImageHandler 79 , public GeoKernelParamCallback 80 { 81 public: 82 explicit CLGeoMapHandler (const SmartPtr<CLContext> &context); set_output_size(uint32_t width,uint32_t height)83 void set_output_size (uint32_t width, uint32_t height) { 84 _output_width = width; 85 _output_height = height; 86 } get_output_size(uint32_t & width,uint32_t & height)87 void get_output_size (uint32_t &width, uint32_t &height) const { 88 width = _output_width; 89 height = _output_height; 90 } 91 92 bool set_map_data (GeoPos *data, uint32_t width, uint32_t height); 93 bool set_map_uint (float uint_x, float uint_y); get_map_uint(float & uint_x,float & uint_y)94 void get_map_uint (float &uint_x, float &uint_y) { 95 uint_x = _uint_x; 96 uint_y = _uint_y; 97 } 98 99 protected: 100 // derived from GeoKernelParamCallback get_geo_input_image(NV12PlaneIdx index)101 virtual SmartPtr<CLImage> get_geo_input_image (NV12PlaneIdx index) { 102 XCAM_ASSERT (index < NV12PlaneMax); 103 return _input [index]; 104 } get_geo_output_image(NV12PlaneIdx index)105 virtual SmartPtr<CLImage> get_geo_output_image (NV12PlaneIdx index) { 106 XCAM_ASSERT (index < NV12PlaneMax); 107 return _output [index]; 108 } get_geo_map_table()109 virtual SmartPtr<CLImage> get_geo_map_table () { 110 XCAM_ASSERT (_geo_image.ptr ()); 111 return _geo_image; 112 } 113 virtual void get_geo_equivalent_out_size (float &width, float &height); 114 virtual void get_geo_pixel_out_size (float &width, float &height); 115 get_lsc_table()116 virtual SmartPtr<CLImage> get_lsc_table () { 117 XCAM_ASSERT (false && "CLGeoMapHandler::lsc table is not supported"); 118 return NULL; 119 } get_lsc_gray_threshold()120 virtual float* get_lsc_gray_threshold () { 121 XCAM_ASSERT (false && "CLGeoMapHandler::lsc gray threshold is not supported"); 122 return NULL; 123 } 124 125 protected: 126 virtual XCamReturn prepare_buffer_pool_video_info ( 127 const VideoBufferInfo &input, 128 VideoBufferInfo &output); 129 virtual XCamReturn prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output); 130 virtual XCamReturn execute_done (SmartPtr<VideoBuffer> &output); 131 132 private: 133 bool normalize_geo_map (uint32_t image_w, uint32_t image_h); 134 bool check_geo_map_buf (uint32_t width, uint32_t height); 135 136 XCAM_DEAD_COPY (CLGeoMapHandler); 137 138 private: 139 uint32_t _output_width; 140 uint32_t _output_height; 141 uint32_t _map_width, _map_height; 142 uint32_t _map_aligned_width; 143 float _uint_x, _uint_y; 144 SmartPtr<CLImage> _input[NV12PlaneMax]; 145 SmartPtr<CLImage> _output[NV12PlaneMax]; 146 SmartPtr<CLBuffer> _geo_map; 147 SmartPtr<CLImage> _geo_image; 148 bool _geo_map_normalized; 149 }; 150 151 SmartPtr<CLImageKernel> 152 create_geo_map_kernel ( 153 const SmartPtr<CLContext> &context, SmartPtr<GeoKernelParamCallback> param_cb, bool need_lsc); 154 155 SmartPtr<CLImageHandler> 156 create_geo_map_handler (const SmartPtr<CLContext> &context, bool need_lsc = false); 157 158 } 159 160 #endif //XCAM_CL_GEO_MAP_HANDLER_H