• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * cl_blender.h - CL blender
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_BLENDER_H
22 #define XCAM_CL_BLENDER_H
23 
24 #include <xcam_std.h>
25 #include <interface/data_types.h>
26 #include <interface/blender.h>
27 #include <ocl/cl_image_handler.h>
28 
29 #define XCAM_CL_BLENDER_ALIGNMENT_X 8
30 #define XCAM_CL_BLENDER_ALIGNMENT_Y 1
31 
32 namespace XCam {
33 
34 enum CLBlenderScaleMode {
35     CLBlenderScaleLocal = 0,
36     CLBlenderScaleGlobal,
37     CLBlenderScaleMax
38 };
39 
40 enum {
41     CLBlenderPlaneY = 0,
42     CLBlenderPlaneUV,
43     CLBlenderPlaneMax,
44 };
45 
46 class CLBlenderScaleKernel
47     : public CLImageKernel
48 {
49 public:
50     explicit CLBlenderScaleKernel (const SmartPtr<CLContext> &context, bool is_uv);
51 
52 protected:
53     virtual XCamReturn prepare_arguments (
54         CLArgList &args, CLWorkSize &work_size);
55 
56     virtual SmartPtr<CLImage> get_input_image () = 0;
57     virtual SmartPtr<CLImage> get_output_image () = 0;
58 
59     virtual bool get_output_info (uint32_t &out_width, uint32_t &out_height, int &out_offset_x) = 0;
60 
61 private:
62     XCAM_DEAD_COPY (CLBlenderScaleKernel);
63 
64 protected:
65     bool                               _is_uv;
66 };
67 
68 class CLBlender
69     : public CLImageHandler, public Blender
70 {
71 public:
72     explicit CLBlender (
73         const SmartPtr<CLContext> &context, const char *name,
74         bool need_uv, CLBlenderScaleMode scale_mode);
75 
76     //derived from Blender
77     virtual bool set_input_merge_area (const Rect &area, uint32_t index);
78 
need_uv()79     bool need_uv () const {
80         return _need_uv;
81     }
82 
get_scale_mode()83     CLBlenderScaleMode get_scale_mode () const {
84         return _scale_mode;
85     }
86 
swap_input_idx(bool flag)87     void swap_input_idx (bool flag) {
88         _swap_input_index = flag;
89     }
90 
91 protected:
92     virtual XCamReturn prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
93     virtual XCamReturn prepare_buffer_pool_video_info (
94         const VideoBufferInfo &input,
95         VideoBufferInfo &output);
96 
97     //abstract virtual functions
98     virtual XCamReturn allocate_cl_buffers (
99         SmartPtr<CLContext> context, SmartPtr<VideoBuffer> &input0,
100         SmartPtr<VideoBuffer> &input1, SmartPtr<VideoBuffer> &output) = 0;
101 
102 private:
103     XCAM_DEAD_COPY (CLBlender);
104 
105 private:
106     bool                             _need_uv;
107     bool                             _swap_input_index;
108     CLBlenderScaleMode               _scale_mode;
109 };
110 
111 SmartPtr<CLImageHandler>
112 create_linear_blender (const SmartPtr<CLContext> &context, bool need_uv = true);
113 
114 SmartPtr<CLImageHandler>
115 create_pyramid_blender (
116     const SmartPtr<CLContext> &context, int layer = 1, bool need_uv = true,
117     bool need_seam = true, CLBlenderScaleMode scale_mode = CLBlenderScaleLocal);
118 
119 };
120 
121 #endif //XCAM_CL_BLENDER_H
122