2 * Copyright (c) 2016-2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #include "arm_compute/runtime/MultiImage.h"
26 #include "arm_compute/core/Error.h"
27 #include "arm_compute/core/TensorInfo.h"
28 #include "arm_compute/core/Utils.h"
29 #include "arm_compute/runtime/TensorAllocator.h"
31 using namespace arm_compute;
33 MultiImage::MultiImage()
38 const MultiImageInfo *MultiImage::info() const
43 void MultiImage::init(unsigned int width, unsigned int height, Format format)
45 internal_init(width, height, format, false);
48 void MultiImage::init_auto_padding(unsigned int width, unsigned int height, Format format)
50 internal_init(width, height, format, true);
53 void MultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding)
55 TensorShape shape = adjust_odd_shape(TensorShape{ width, height }, format);
56 TensorInfo info(shape, Format::U8);
73 case Format::RGBA8888:
77 TensorInfo info_full(shape, format);
81 info_full.auto_padding();
84 std::get<0>(_plane).allocator()->init(info_full);
90 const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
91 TensorInfo info_uv88(shape_uv88, Format::UV88);
95 info_uv88.auto_padding();
98 std::get<0>(_plane).allocator()->init(info);
99 std::get<1>(_plane).allocator()->init(info_uv88);
104 const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
105 TensorInfo info_sub2(shape_sub2, Format::U8);
109 info_sub2.auto_padding();
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);
118 std::get<0>(_plane).allocator()->init(info);
119 std::get<1>(_plane).allocator()->init(info);
120 std::get<2>(_plane).allocator()->init(info);
123 ARM_COMPUTE_ERROR("Not supported");
127 _info.init(shape.x(), shape.y(), format);
130 void MultiImage::allocate()
132 switch(_info.format())
142 case Format::RGBA8888:
143 case Format::YUYV422:
144 case Format::UYVY422:
145 std::get<0>(_plane).allocator()->allocate();
149 std::get<0>(_plane).allocator()->allocate();
150 std::get<1>(_plane).allocator()->allocate();
154 std::get<0>(_plane).allocator()->allocate();
155 std::get<1>(_plane).allocator()->allocate();
156 std::get<2>(_plane).allocator()->allocate();
159 ARM_COMPUTE_ERROR("Not supported");
164 void MultiImage::create_subimage(MultiImage *image, const Coordinates &coords, unsigned int width, unsigned int height)
166 arm_compute::Format format = image->info()->format();
167 const TensorInfo info(width, height, Format::U8);
179 case Format::RGBA8888:
180 case Format::YUYV422:
181 case Format::UYVY422:
183 const TensorInfo info_full(width, height, format);
184 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info_full);
190 const TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
191 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
192 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(1))->allocator(), coords, info_uv88);
197 const TensorInfo info_sub2(width / 2, height / 2, Format::U8);
198 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
199 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(1))->allocator(), coords, info_sub2);
200 std::get<2>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(2))->allocator(), coords, info_sub2);
204 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
205 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
206 std::get<2>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
209 ARM_COMPUTE_ERROR("Not supported");
213 _info.init(width, height, format);
216 Image *MultiImage::plane(unsigned int index)
218 return &_plane[index];
221 const Image *MultiImage::plane(unsigned int index) const
223 return &_plane[index];