1 /*
2  * blender.h - blender interface
3  *
4  *  Copyright (c) 2017 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_INTERFACE_BLENDER_H
22 #define XCAM_INTERFACE_BLENDER_H
23 
24 #include <xcam_std.h>
25 #include <video_buffer.h>
26 #include <interface/data_types.h>
27 
28 #define XCAM_BLENDER_IMAGE_NUM 2
29 
30 namespace XCam {
31 
32 class Blender;
33 
34 class Blender
35 {
36 public:
37     explicit Blender (uint32_t alignment_x, uint32_t alignment_y);
38     virtual ~Blender ();
39     static SmartPtr<Blender> create_ocl_blender ();
40     static SmartPtr<Blender> create_soft_blender ();
41 
42     void set_output_size (uint32_t width, uint32_t height);
43     void get_output_size (uint32_t &width, uint32_t &height) const {
44         width = _out_width;
45         height = _out_height;
46     }
47     bool set_input_valid_area (const Rect &area, uint32_t index);
48     bool set_merge_window (const Rect &window);
49     virtual bool set_input_merge_area (const Rect &area, uint32_t index);
50 
51     const Rect &get_merge_window () const {
52         return _merge_window;
53     }
54 
55     const Rect &get_input_merge_area (uint32_t index) const {
56         return _input_merge_area[index];
57     }
58     const Rect &get_input_valid_area (uint32_t index) const {
59         return _input_valid_area[index];
60     }
61 
62     bool is_merge_window_set () const {
63         return _merge_window.pos_x || _merge_window.width;
64     }
65 
66     uint32_t get_alignment_x () const {
67         return _alignment_x;
68     }
69     uint32_t get_alignment_y () const {
70         return _alignment_y;
71     }
72 
73     virtual XCamReturn blend (
74         const SmartPtr<VideoBuffer> &in0,
75         const SmartPtr<VideoBuffer> &in1,
76         SmartPtr<VideoBuffer> &out_buf);
77 
78 protected:
79     bool auto_calc_merge_window (
80         uint32_t width0, uint32_t width1, uint32_t blend_width, Rect &out_window);
81 
82 private:
83     XCAM_DEAD_COPY (Blender);
84 
85 private:
86     uint32_t                         _alignment_x, _alignment_y;
87     uint32_t                         _out_width, _out_height;
88     Rect                             _input_valid_area[XCAM_BLENDER_IMAGE_NUM];
89     Rect                             _merge_window;  // for output buffer
90 
91 protected:
92     Rect                             _input_merge_area[XCAM_BLENDER_IMAGE_NUM];
93 };
94 
95 }
96 
97 #endif //XCAM_INTERFACE_BLENDER_H
98