2 * Copyright (c) 2016, 2017 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/runtime/TensorAllocator.h"
30 using namespace arm_compute;
32 MultiImage::MultiImage()
37 const MultiImageInfo *MultiImage::info() const
42 void MultiImage::init(unsigned int width, unsigned int height, Format format)
44 internal_init(width, height, format, false);
47 void MultiImage::init_auto_padding(unsigned int width, unsigned int height, Format format)
49 internal_init(width, height, format, true);
52 void MultiImage::internal_init(unsigned int width, unsigned int height, Format format, bool auto_padding)
54 TensorInfo info(width, height, Format::U8);
71 case Format::RGBA8888:
75 TensorInfo info_full(width, height, format);
79 info_full.auto_padding();
82 std::get<0>(_plane).allocator()->init(info_full);
88 TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
92 info_uv88.auto_padding();
95 std::get<0>(_plane).allocator()->init(info);
96 std::get<1>(_plane).allocator()->init(info_uv88);
101 TensorInfo info_sub2(width / 2, height / 2, Format::U8);
105 info_sub2.auto_padding();
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);
114 std::get<0>(_plane).allocator()->init(info);
115 std::get<1>(_plane).allocator()->init(info);
116 std::get<2>(_plane).allocator()->init(info);
119 ARM_COMPUTE_ERROR("Not supported");
123 _info.init(width, height, format);
126 void MultiImage::allocate()
128 switch(_info.format())
138 case Format::RGBA8888:
139 case Format::YUYV422:
140 case Format::UYVY422:
141 std::get<0>(_plane).allocator()->allocate();
145 std::get<0>(_plane).allocator()->allocate();
146 std::get<1>(_plane).allocator()->allocate();
150 std::get<0>(_plane).allocator()->allocate();
151 std::get<1>(_plane).allocator()->allocate();
152 std::get<2>(_plane).allocator()->allocate();
155 ARM_COMPUTE_ERROR("Not supported");
160 void MultiImage::create_subimage(MultiImage *image, const Coordinates &coords, unsigned int width, unsigned int height)
162 arm_compute::Format format = image->info()->format();
163 const TensorInfo info(width, height, Format::U8);
175 case Format::RGBA8888:
176 case Format::YUYV422:
177 case Format::UYVY422:
179 const TensorInfo info_full(width, height, format);
180 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info_full);
186 const TensorInfo info_uv88(width / 2, height / 2, Format::UV88);
187 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
188 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(1))->allocator(), coords, info_uv88);
193 const TensorInfo info_sub2(width / 2, height / 2, Format::U8);
194 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
195 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(1))->allocator(), coords, info_sub2);
196 std::get<2>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(2))->allocator(), coords, info_sub2);
200 std::get<0>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
201 std::get<1>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
202 std::get<2>(_plane).allocator()->init(*dynamic_cast<Image *>(image->plane(0))->allocator(), coords, info);
205 ARM_COMPUTE_ERROR("Not supported");
209 _info.init(width, height, format);
212 Image *MultiImage::plane(unsigned int index)
214 return &_plane[index];
217 const Image *MultiImage::plane(unsigned int index) const
219 return &_plane[index];