blob: 28590bd8616b270b08708aa95fa4b5e81ef465be [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2020 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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010024#include "arm_compute/core/Types.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "arm_compute/runtime/NEON/NEFunctions.h"
26
Georgios Pinitas7c3b9242018-06-21 19:01:25 +010027#include "utils/ImageLoader.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "utils/Utils.h"
29
30using namespace arm_compute;
31using namespace utils;
32
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000033class NEONScaleExample : public Example
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000035public:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010036 bool do_setup(int argc, char **argv) override
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000037 {
38 PPMLoader ppm;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010040 if (argc < 2)
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000041 {
42 // Print help
43 std::cout << "Usage: ./build/neon_scale[input_image.ppm]\n\n";
44 std::cout << "No input_image provided, creating a dummy 640x480 image\n";
45 // Create an empty grayscale 640x480 image
46 src.allocator()->init(TensorInfo(640, 480, Format::U8));
47 }
48 else
49 {
50 ppm.open(argv[1]);
51 ppm.init_image(src, Format::U8);
52 }
53
54 constexpr int scale_factor = 2;
55
56 TensorInfo dst_tensor_info(src.info()->dimension(0) / scale_factor, src.info()->dimension(1) / scale_factor,
57 Format::U8);
58
59 // Configure the destination image
60 dst.allocator()->init(dst_tensor_info);
61
62 // Configure Scale function object:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 scale.configure(&src, &dst,
64 ScaleKernelInfo{InterpolationPolicy::NEAREST_NEIGHBOR, BorderMode::UNDEFINED, PixelValue(),
65 SamplingPolicy::CENTER, false});
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000066
67 // Allocate all the images
68 src.allocator()->allocate();
69 dst.allocator()->allocate();
70
71 // Fill the input image with the content of the PPM image if a filename was provided:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 if (ppm.is_open())
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000073 {
74 ppm.fill_image(src);
75 output_filename = std::string(argv[1]) + "_out.ppm";
76 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010077
78 return true;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079 }
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000080 void do_run() override
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 {
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000082 // Run the scale operation:
83 scale.run();
84 }
85 void do_teardown() override
86 {
87 // Save the result to file:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 if (!output_filename.empty())
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000089 {
90 save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
91 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092 }
93
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000094private:
95 Image src{}, dst{};
96 NEScale scale{};
97 std::string output_filename{};
98};
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099
100/** Main program for convolution test
101 *
102 * @param[in] argc Number of arguments
103 * @param[in] argv Arguments ( [optional] Path to PPM image to process )
104 */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000105int main(int argc, char **argv)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000107 return utils::run_example<NEONScaleExample>(argc, argv);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100108}