blob: 7a8fa0b608dea92a5d161ae506df1407cc8495b3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016, 2017 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/core/PyramidInfo.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/TensorShape.h"
28
29#include <cmath>
30
31using namespace arm_compute;
32
33PyramidInfo::PyramidInfo()
34 : _num_levels(0), _tensor_shape(), _format(Format::UNKNOWN), _scale(0.0f)
35{
36}
37
38PyramidInfo::PyramidInfo(size_t num_levels, float scale, size_t width, size_t height, Format format)
39 : PyramidInfo()
40{
41 init(num_levels, scale, width, height, format);
42}
43
44PyramidInfo::PyramidInfo(size_t num_levels, float scale, const TensorShape &tensor_shape, Format format)
45 : PyramidInfo()
46{
47 init(num_levels, scale, tensor_shape, format);
48}
49
50void PyramidInfo::init(size_t num_levels, float scale, size_t width, size_t height, Format format)
51{
52 init(num_levels, scale, TensorShape(width, height), format);
53}
54
55void PyramidInfo::init(size_t num_levels, float scale, const TensorShape &tensor_shape, Format format)
56{
57 ARM_COMPUTE_ERROR_ON(0 == num_levels);
58 ARM_COMPUTE_ERROR_ON(0.0f == scale);
59 ARM_COMPUTE_ERROR_ON(0 == tensor_shape.x());
60 ARM_COMPUTE_ERROR_ON(0 == tensor_shape.y());
61 ARM_COMPUTE_ERROR_ON(Format::IYUV == format);
62 ARM_COMPUTE_ERROR_ON(Format::NV12 == format);
63 ARM_COMPUTE_ERROR_ON(Format::NV21 == format);
64 ARM_COMPUTE_ERROR_ON(Format::UYVY422 == format);
65 ARM_COMPUTE_ERROR_ON(Format::YUV444 == format);
66 ARM_COMPUTE_ERROR_ON(Format::YUYV422 == format);
67 ARM_COMPUTE_ERROR_ON_MSG(0 != _num_levels, "PyramidInfo already initialized");
68 ARM_COMPUTE_ERROR_ON(0 == (tensor_shape.x() * pow(scale, num_levels)));
69 ARM_COMPUTE_ERROR_ON(0 == (tensor_shape.y() * pow(scale, num_levels)));
70
71 _num_levels = num_levels;
72 _format = format;
73 _scale = scale;
74 _tensor_shape = tensor_shape;
75}
76
77size_t PyramidInfo::num_levels() const
78{
79 return _num_levels;
80}
81
82size_t PyramidInfo::width() const
83{
84 return _tensor_shape.x();
85}
86
87size_t PyramidInfo::height() const
88{
89 return _tensor_shape.y();
90}
91
92const TensorShape &PyramidInfo::tensor_shape() const
93{
94 return _tensor_shape;
95}
96
97Format PyramidInfo::format() const
98{
99 return _format;
100}
101
102float PyramidInfo::scale() const
103{
104 return _scale;
105}