blob: 28b3f854f2bd930a1426d6cf29aa18d0cba69a94 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2018 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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"
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010028#include "arm_compute/core/Utils.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/runtime/ITensorAllocator.h"
30
31using namespace arm_compute;
32
33CLMultiImage::CLMultiImage()
34 : _info(), _plane()
35{
36}
37
38const MultiImageInfo *CLMultiImage::info() const
39{
40 return &_info;
41}
42
43void CLMultiImage::init(unsigned int width, unsigned int height, Format format)
44{
45 internal_init(width, height, format, false);
46}
47
48void CLMultiImage::init_auto_padding(unsigned int width, unsigned int height, Format format)
49{
50 internal_init(width, height, format, true);
51}
52
53void CLMultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding)
54{
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010055 TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format);
56 TensorInfo info(shape, Format::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057
58 if(auto_padding)
59 {
60 info.auto_padding();
61 }
62
63 switch(format)
64 {
65 case Format::U8:
66 case Format::S16:
67 case Format::U16:
68 case Format::S32:
69 case Format::F16:
70 case Format::F32:
71 case Format::U32:
72 case Format::RGB888:
73 case Format::RGBA8888:
74 case Format::YUYV422:
75 case Format::UYVY422:
76 {
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010077 TensorInfo info_full(shape, format);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078
79 if(auto_padding)
80 {
81 info_full.auto_padding();
82 }
83
84 std::get<0>(_plane).allocator()->init(info_full);
85 break;
86 }
87 case Format::NV12:
88 case Format::NV21:
89 {
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010090 const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
91 TensorInfo info_uv88(shape_uv88, Format::UV88);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092
93 if(auto_padding)
94 {
95 info_uv88.auto_padding();
96 }
97
98 std::get<0>(_plane).allocator()->init(info);
99 std::get<1>(_plane).allocator()->init(info_uv88);
100 break;
101 }
102 case Format::IYUV:
103 {
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +0100104 const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
105 TensorInfo info_sub2(shape_sub2, Format::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106
107 if(auto_padding)
108 {
109 info_sub2.auto_padding();
110 }
111
112 std::get<0>(_plane).allocator()->init(info);
113 std::get<1>(_plane).allocator()->init(info_sub2);
114 std::get<2>(_plane).allocator()->init(info_sub2);
115 break;
116 }
117 case Format::YUV444:
118 std::get<0>(_plane).allocator()->init(info);
119 std::get<1>(_plane).allocator()->init(info);
120 std::get<2>(_plane).allocator()->init(info);
121 break;
122 default:
123 ARM_COMPUTE_ERROR("Not supported");
124 break;
125 }
126
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +0100127 _info.init(shape.x(), shape.y(), format);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128}
129
130void CLMultiImage::allocate()
131{
132 switch(_info.format())
133 {
134 case Format::U8:
135 case Format::S16:
136 case Format::U16:
137 case Format::S32:
138 case Format::F16:
139 case Format::F32:
140 case Format::U32:
141 case Format::RGB888:
142 case Format::RGBA8888:
143 case Format::YUYV422:
144 case Format::UYVY422:
145 std::get<0>(_plane).allocator()->allocate();
146 break;
147 case Format::NV12:
148 case Format::NV21:
149 std::get<0>(_plane).allocator()->allocate();
150 std::get<1>(_plane).allocator()->allocate();
151 break;
152 case Format::IYUV:
153 case Format::YUV444:
154 std::get<0>(_plane).allocator()->allocate();
155 std::get<1>(_plane).allocator()->allocate();
156 std::get<2>(_plane).allocator()->allocate();
157 break;
158 default:
159 ARM_COMPUTE_ERROR("Not supported");
160 break;
161 }
162}
163
164CLImage *CLMultiImage::cl_plane(unsigned int index)
165{
166 return &_plane[index];
167}
168
169const CLImage *CLMultiImage::cl_plane(unsigned int index) const
170{
171 return &_plane[index];
172}