blob: 63059cb5f4d4266ea706fb7f802010500367ce00 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/runtime/CL/CLMultiImage.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/TensorInfo.h"
28#include "arm_compute/runtime/ITensorAllocator.h"
29
30using namespace arm_compute;
31
32CLMultiImage::CLMultiImage()
33 : _info(), _plane()
34{
35}
36
37const MultiImageInfo *CLMultiImage::info() const
38{
39 return &_info;
40}
41
42void CLMultiImage::init(unsigned int width, unsigned int height, Format format)
43{
44 internal_init(width, height, format, false);
45}
46
47void CLMultiImage::init_auto_padding(unsigned int width, unsigned int height, Format format)
48{
49 internal_init(width, height, format, true);
50}
51
52void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding)
53{
54 TensorInfo info(width, height, Format::U8);
55
56 if(auto_padding)
57 {
58 info.auto_padding();
59 }
60
61 switch(format)
62 {
63 case Format::U8:
64 case Format::S16:
65 case Format::U16:
66 case Format::S32:
67 case Format::F16:
68 case Format::F32:
69 case Format::U32:
70 case Format::RGB888:
71 case Format::RGBA8888:
72 case Format::YUYV422:
73 case Format::UYVY422:
74 {
75 TensorInfo info_full(width, height, format);
76
77 if(auto_padding)
78 {
79 info_full.auto_padding();
80 }
81
82 std::get<0>(_plane).allocator()->init(info_full);
83 break;
84 }
85 case Format::NV12:
86 case Format::NV21:
87 {
88 TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
89
90 if(auto_padding)
91 {
92 info_uv88.auto_padding();
93 }
94
95 std::get<0>(_plane).allocator()->init(info);
96 std::get<1>(_plane).allocator()->init(info_uv88);
97 break;
98 }
99 case Format::IYUV:
100 {
101 TensorInfo info_sub2(width / 2, height / 2, Format::U8);
102
103 if(auto_padding)
104 {
105 info_sub2.auto_padding();
106 }
107
108 std::get<0>(_plane).allocator()->init(info);
109 std::get<1>(_plane).allocator()->init(info_sub2);
110 std::get<2>(_plane).allocator()->init(info_sub2);
111 break;
112 }
113 case Format::YUV444:
114 std::get<0>(_plane).allocator()->init(info);
115 std::get<1>(_plane).allocator()->init(info);
116 std::get<2>(_plane).allocator()->init(info);
117 break;
118 default:
119 ARM_COMPUTE_ERROR("Not supported");
120 break;
121 }
122
123 _info.init(width, height, format);
124}
125
126void CLMultiImage::allocate()
127{
128 switch(_info.format())
129 {
130 case Format::U8:
131 case Format::S16:
132 case Format::U16:
133 case Format::S32:
134 case Format::F16:
135 case Format::F32:
136 case Format::U32:
137 case Format::RGB888:
138 case Format::RGBA8888:
139 case Format::YUYV422:
140 case Format::UYVY422:
141 std::get<0>(_plane).allocator()->allocate();
142 break;
143 case Format::NV12:
144 case Format::NV21:
145 std::get<0>(_plane).allocator()->allocate();
146 std::get<1>(_plane).allocator()->allocate();
147 break;
148 case Format::IYUV:
149 case Format::YUV444:
150 std::get<0>(_plane).allocator()->allocate();
151 std::get<1>(_plane).allocator()->allocate();
152 std::get<2>(_plane).allocator()->allocate();
153 break;
154 default:
155 ARM_COMPUTE_ERROR("Not supported");
156 break;
157 }
158}
159
160CLImage *CLMultiImage::cl_plane(unsigned int index)
161{
162 return &_plane[index];
163}
164
165const CLImage *CLMultiImage::cl_plane(unsigned int index) const
166{
167 return &_plane[index];
168}