Home | History | Annotate | Download | only in ocl
      1 /*
      2  * cl_image_360_stitch.h - CL Image 360 stitch
      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 (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_CL_IMAGE_360_STITCH_H
     22 #define XCAM_CL_IMAGE_360_STITCH_H
     23 
     24 #include <xcam_std.h>
     25 #include <interface/stitcher.h>
     26 #include <interface/feature_match.h>
     27 #include <ocl/cl_multi_image_handler.h>
     28 #include <ocl/cl_fisheye_handler.h>
     29 #include <ocl/cl_blender.h>
     30 
     31 namespace XCam {
     32 
     33 struct CLFisheyeParams {
     34     SmartPtr<CLFisheyeHandler>  handler;
     35     SmartPtr<BufferPool>        pool;
     36     SmartPtr<VideoBuffer>       buf;
     37 
     38     uint32_t                    width;
     39     uint32_t                    height;
     40 
     41     CLFisheyeParams () : width (0), height (0) {}
     42 };
     43 
     44 class CLImage360Stitch;
     45 class CLBlenderGlobalScaleKernel
     46     : public CLBlenderScaleKernel
     47 {
     48 public:
     49     explicit CLBlenderGlobalScaleKernel (
     50         const SmartPtr<CLContext> &context, SmartPtr<CLImage360Stitch> &stitch, bool is_uv);
     51 
     52 protected:
     53     virtual SmartPtr<CLImage> get_input_image ();
     54     virtual SmartPtr<CLImage> get_output_image ();
     55     virtual bool get_output_info (uint32_t &out_width, uint32_t &out_height, int &out_offset_x);
     56 
     57 private:
     58     SmartPtr<CLImage360Stitch>  _stitch;
     59 };
     60 
     61 class CLImage360Stitch
     62     : public CLMultiImageHandler
     63 {
     64 public:
     65     explicit CLImage360Stitch (
     66         const SmartPtr<CLContext> &context, CLBlenderScaleMode scale_mode, SurroundMode surround_mode,
     67         StitchResMode res_mode, int fisheye_num, bool all_in_one_img);
     68 
     69     bool set_stitch_info (StitchInfo stitch_info);
     70     StitchInfo get_stitch_info ();
     71     void set_output_size (uint32_t width, uint32_t height) {
     72         _output_width = width; //XCAM_ALIGN_UP (width, XCAM_BLENDER_ALIGNED_WIDTH);
     73         _output_height = height;
     74     }
     75 
     76     bool set_fisheye_handler (SmartPtr<CLFisheyeHandler> fisheye, int index);
     77     bool set_blender (SmartPtr<CLBlender> blender, int idx);
     78 
     79     void set_fisheye_intrinsic (IntrinsicParameter intrinsic_param, int index);
     80     void set_fisheye_extrinsic (ExtrinsicParameter extrinsic_param, int index);
     81 
     82     const BowlDataConfig &get_fisheye_bowl_config (int index = 0);
     83 
     84     bool set_image_overlap (const int idx, const Rect &overlap0, const Rect &overlap1);
     85     const Rect &get_image_overlap (int img_idx, int num) {
     86         XCAM_ASSERT (img_idx < _fisheye_num && num < 2);
     87         return _overlaps[img_idx][num];
     88     }
     89 
     90     SmartPtr<VideoBuffer> &get_global_scale_input () {
     91         return _scale_global_input;
     92     }
     93     SmartPtr<VideoBuffer> &get_global_scale_output () {
     94         return _scale_global_output;
     95     }
     96 
     97     void set_feature_match_ocl (bool use_ocl);
     98 #if HAVE_OPENCV
     99     void set_feature_match_config (const int idx, CVFMConfig config);
    100     CVFMConfig get_feature_match_config (const int idx);
    101 #endif
    102 
    103 protected:
    104     virtual XCamReturn prepare_buffer_pool_video_info (const VideoBufferInfo &input, VideoBufferInfo &output);
    105     virtual XCamReturn prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
    106     virtual XCamReturn execute_done (SmartPtr<VideoBuffer> &output);
    107 
    108     XCamReturn ensure_fisheye_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
    109     XCamReturn prepare_local_scale_blender_parameters (
    110         SmartPtr<VideoBuffer> &input0, SmartPtr<VideoBuffer> &input1, SmartPtr<VideoBuffer> &output, int idx, int idx_next);
    111     XCamReturn prepare_global_scale_blender_parameters (
    112         SmartPtr<VideoBuffer> &input0, SmartPtr<VideoBuffer> &input1, SmartPtr<VideoBuffer> &output,
    113         int idx, int idx_next, int &cur_start_pos);
    114 
    115     bool create_buffer_pool (SmartPtr<BufferPool> &buf_pool, uint32_t width, uint32_t height);
    116     XCamReturn reset_buffer_info (SmartPtr<VideoBuffer> &input);
    117 
    118     virtual XCamReturn sub_handler_execute_done (SmartPtr<CLImageHandler> &handler);
    119 
    120     void calc_fisheye_initial_info (SmartPtr<VideoBuffer> &output);
    121     void update_image_overlap ();
    122 
    123 private:
    124     XCAM_DEAD_COPY (CLImage360Stitch);
    125 
    126 private:
    127     SmartPtr<CLContext>         _context;
    128     CLFisheyeParams             _fisheye[XCAM_STITCH_FISHEYE_MAX_NUM];
    129     SmartPtr<CLBlender>         _blender[XCAM_STITCH_FISHEYE_MAX_NUM];
    130     SmartPtr<FeatureMatch>      _feature_match[XCAM_STITCH_FISHEYE_MAX_NUM];
    131 
    132     uint32_t                    _output_width;
    133     uint32_t                    _output_height;
    134     ImageMergeInfo              _img_merge_info[XCAM_STITCH_FISHEYE_MAX_NUM];
    135     Rect                        _overlaps[XCAM_STITCH_FISHEYE_MAX_NUM][2];   // 2=>Overlap0 and overlap1
    136 
    137     CLBlenderScaleMode          _scale_mode;
    138     SmartPtr<BufferPool>        _scale_buf_pool;
    139     SmartPtr<VideoBuffer>       _scale_global_input;
    140     SmartPtr<VideoBuffer>       _scale_global_output;
    141 
    142     SurroundMode                _surround_mode;
    143     StitchResMode               _res_mode;
    144 
    145     bool                        _is_stitch_inited;
    146     int                         _fisheye_num;
    147     bool                        _all_in_one_img;
    148     StitchInfo                  _stitch_info;
    149 };
    150 
    151 SmartPtr<CLImageHandler>
    152 create_image_360_stitch (
    153     const SmartPtr<CLContext> &context,
    154     bool need_seam = false,
    155     CLBlenderScaleMode scale_mode = CLBlenderScaleLocal,
    156     bool fisheye_map = false,
    157     bool need_lsc = false,
    158     SurroundMode surround_mode = SphereView,
    159     StitchResMode res_mode = StitchRes1080P,
    160     int fisheye_num = 2,
    161     bool all_in_one_img = true);
    162 
    163 }
    164 
    165 #endif //XCAM_CL_IMAGE_360_STITCH_H
    166