Compute Library  18.03
neon_scale.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, 2018 ARM Limited.
3  *
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  */
25 
26 #include "arm_compute/core/Types.h"
27 #include "utils/Utils.h"
28 
29 using namespace arm_compute;
30 using namespace utils;
31 
32 class NEONScaleExample : public Example
33 {
34 public:
35  void do_setup(int argc, char **argv) override
36  {
37  PPMLoader ppm;
38 
39  if(argc < 2)
40  {
41  // Print help
42  std::cout << "Usage: ./build/neon_scale[input_image.ppm]\n\n";
43  std::cout << "No input_image provided, creating a dummy 640x480 image\n";
44  // Create an empty grayscale 640x480 image
45  src.allocator()->init(TensorInfo(640, 480, Format::U8));
46  }
47  else
48  {
49  ppm.open(argv[1]);
51  }
52 
53  constexpr int scale_factor = 2;
54 
55  TensorInfo dst_tensor_info(src.info()->dimension(0) / scale_factor, src.info()->dimension(1) / scale_factor,
56  Format::U8);
57 
58  // Configure the destination image
59  dst.allocator()->init(dst_tensor_info);
60 
61  // Configure Scale function object:
63 
64  // Allocate all the images
65  src.allocator()->allocate();
66  dst.allocator()->allocate();
67 
68  // Fill the input image with the content of the PPM image if a filename was provided:
69  if(ppm.is_open())
70  {
71  ppm.fill_image(src);
72  output_filename = std::string(argv[1]) + "_out.ppm";
73  }
74  }
75  void do_run() override
76  {
77  // Run the scale operation:
78  scale.run();
79  }
80  void do_teardown() override
81  {
82  // Save the result to file:
83  if(!output_filename.empty())
84  {
85  save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
86  }
87  }
88 
89 private:
90  Image src{}, dst{};
91  NEScale scale{};
92  std::string output_filename{};
93 };
94 
100 int main(int argc, char **argv)
101 {
102  return utils::run_example<NEONScaleExample>(argc, argv);
103 }
void fill_image(T &image)
Fill an image with the content of the currently open PPM file.
Definition: Utils.h:312
void save_to_ppm(T &tensor, const std::string &ppm_filename)
Template helper function to save a tensor image to a PPM file.
Definition: Utils.h:655
ITensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
1 channel, 1 U8 per channel
Output values are defined to match the source pixel whose center is nearest to the sample position...
Basic function to run NEScaleKernel.
Definition: NEScale.h:40
This file contains all available output stages for GEMMLowp on OpenCL.
void open(const std::string &ppm_filename)
Open a PPM file and reads its metadata (Width, height)
Definition: Utils.h:264
Abstract Example class.
Definition: Utils.h:62
bool is_open()
Return true if a PPM file is currently open.
Definition: Utils.h:284
Structure to hold Image information.
Definition: helpers.h:140
virtual void allocate()=0
Interface to be implemented by the child class to allocate the tensor.
int main(int argc, char **argv)
Main program for convolution test.
Definition: neon_scale.cpp:100
Borders are left undefined.
void init(const TensorInfo &input)
Initialize a tensor based on the passed TensorInfo.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:44
void init_image(T &image, arm_compute::Format format)
Initialise an image&#39;s metadata with the dimensions of the PPM file currently open.
Definition: Utils.h:295
convolution configure & src
Class to load the content of a PPM file into an Image.
Definition: Utils.h:253