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 #include "blender.h"
22
23 namespace XCam {
24
Blender(uint32_t alignment_x,uint32_t alignment_y)25 Blender::Blender (uint32_t alignment_x, uint32_t alignment_y)
26 : _alignment_x (alignment_x)
27 , _alignment_y (alignment_y)
28 , _out_width (0)
29 , _out_height (0)
30 {
31 }
32
~Blender()33 Blender::~Blender ()
34 {
35 }
36
37 void
set_output_size(uint32_t width,uint32_t height)38 Blender::set_output_size (uint32_t width, uint32_t height) {
39 _out_width = XCAM_ALIGN_UP (width, get_alignment_x ());
40 _out_height = XCAM_ALIGN_UP (height, get_alignment_y ());
41 }
42
43 bool
set_merge_window(const Rect & window)44 Blender::set_merge_window (const Rect &window) {
45 uint32_t alignmend_x = get_alignment_x ();
46
47 _merge_window = window;
48 _merge_window.pos_x = XCAM_ALIGN_AROUND (_merge_window.pos_x, alignmend_x);
49 _merge_window.width = XCAM_ALIGN_AROUND (_merge_window.width, alignmend_x);
50 XCAM_ASSERT (_merge_window.width >= (int32_t)alignmend_x);
51 XCAM_LOG_DEBUG(
52 "Blender merge window:(x:%d, width:%d), blend_width:%d",
53 _merge_window.pos_x, _merge_window.width, _out_width);
54 return true;
55 }
56
57 bool
set_input_valid_area(const Rect & area,uint32_t index)58 Blender::set_input_valid_area (const Rect &area, uint32_t index)
59 {
60 XCAM_ASSERT (index < XCAM_BLENDER_IMAGE_NUM);
61 _input_valid_area[index] = area;
62
63 uint32_t alignmend_x = get_alignment_x ();
64 _input_valid_area[index].pos_x = XCAM_ALIGN_DOWN (_input_valid_area[index].pos_x, alignmend_x);
65 _input_valid_area[index].width = XCAM_ALIGN_UP (_input_valid_area[index].width, alignmend_x);
66
67 XCAM_LOG_DEBUG(
68 "Blender buf(%d) valid area:(x:%d, width:%d)",
69 index, _input_valid_area[index].pos_x, _input_valid_area[index].width);
70 return true;
71 }
72
73 bool
set_input_merge_area(const Rect & area,uint32_t index)74 Blender::set_input_merge_area (const Rect &area, uint32_t index)
75 {
76 XCAM_ASSERT (index < XCAM_BLENDER_IMAGE_NUM);
77 if (!is_merge_window_set ()) {
78 XCAM_LOG_ERROR ("set_input_merge_area(idx:%d) failed, need set merge window first", index);
79 return false;
80 }
81
82 _input_merge_area[index] = area;
83 _input_merge_area[index].pos_x = XCAM_ALIGN_AROUND (_input_merge_area[index].pos_x, get_alignment_x ());
84 _input_merge_area[index].pos_y = XCAM_ALIGN_AROUND (_input_merge_area[index].pos_y, get_alignment_y ());
85
86 XCAM_LOG_DEBUG(
87 "Blender buf(%d) merge area:(x:%d, width:%d)",
88 index, _input_merge_area[index].pos_x, _input_merge_area[index].width);
89
90 return true;
91 }
92
93 bool
auto_calc_merge_window(uint32_t width0,uint32_t width1,uint32_t blend_width,Rect & out_window)94 Blender::auto_calc_merge_window (
95 uint32_t width0, uint32_t width1, uint32_t blend_width,
96 Rect &out_window)
97 {
98 out_window.pos_x = blend_width - width1;
99 out_window.width = (width0 + width1 - blend_width) / 2;
100
101 out_window.pos_x = XCAM_ALIGN_AROUND (out_window.pos_x, get_alignment_x ());
102 out_window.width = XCAM_ALIGN_AROUND (out_window.width, get_alignment_x ());
103 if ((int)blend_width < out_window.pos_x + out_window.width)
104 out_window.width = blend_width - out_window.pos_x;
105
106 XCAM_ASSERT (out_window.width > 0 && out_window.width <= (int)blend_width);
107 XCAM_ASSERT (out_window.pos_x >= 0 && out_window.pos_x <= (int)blend_width);
108
109 return true;
110 }
111
112 XCamReturn
blend(const SmartPtr<VideoBuffer> &,const SmartPtr<VideoBuffer> &,SmartPtr<VideoBuffer> &)113 Blender::blend (
114 const SmartPtr<VideoBuffer> &,
115 const SmartPtr<VideoBuffer> &,
116 SmartPtr<VideoBuffer> &)
117 {
118 XCAM_LOG_ERROR ("Blender interface blend must be derived.");
119 return XCAM_RETURN_ERROR_UNKNOWN;
120 }
121
122 }
123