blob: f53459231f8e6221543692a0d744ccd5e1ce4a6a [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Georgios Pinitas7c3b9242018-06-21 19:01:25 +01002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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
25#ifndef ARM_COMPUTE_GC /* Needed by Utils.cpp to handle OpenGL ES exceptions properly */
26#error "This example needs to be built with -DARM_COMPUTE_GC"
27#endif /* ARM_COMPUTE_GC */
28
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h"
31#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
Georgios Pinitas7c3b9242018-06-21 19:01:25 +010032#include "utils/ImageLoader.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010033#include "utils/Utils.h"
34
35using namespace arm_compute;
36using namespace utils;
37
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000038class GCAbsDiffExample : public Example
Anthony Barbier7068f992017-10-26 15:23:08 +010039{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000040public:
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010041 bool do_setup(int argc, char **argv) override
Anthony Barbier7068f992017-10-26 15:23:08 +010042 {
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000043 PPMLoader ppm1, ppm2;
44
45 GCScheduler::get().default_init();
46 if(argc < 2)
47 {
48 // Print help
49 std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n";
50 std::cout << "No input_image provided, creating two dummy 640x480 images\n";
51 // Create two empty grayscale 640x480 images
52 src1.allocator()->init(TensorInfo(640, 480, Format::U8));
53 src2.allocator()->init(TensorInfo(640, 480, Format::U8));
54 }
55 else if(argc < 3)
56 {
57 // Print help
58 std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n";
59 std::cout << "Only one input_image provided, creating a dummy 640x480 image\n";
60 ppm1.open(argv[1]);
61 ppm1.init_image(src1, Format::U8);
62 // Create an empty grayscale 640x480 image
63 src2.allocator()->init(TensorInfo(640, 480, Format::U8));
64 }
65 else
66 {
67 ppm1.open(argv[1]);
68 ppm1.init_image(src1, Format::U8);
69 ppm2.open(argv[2]);
70 ppm2.init_image(src2, Format::U8);
71 }
72
73 // Configure the temporary and destination images
74 dst.allocator()->init(*src1.info());
75
76 absdiff.configure(&src1, &src2, &dst);
77
78 // Allocate all the images
79 src1.allocator()->allocate();
80 src2.allocator()->allocate();
81 dst.allocator()->allocate();
82
83 // Fill the input image with the content of the PPM image if a filename was provided:
84 if(ppm1.is_open())
85 {
86 ppm1.fill_image(src1);
87 output_filename = std::string(argv[1]) + "_out.ppm";
88 }
89 if(ppm2.is_open())
90 {
91 ppm2.fill_image(src2);
92 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010093
94 return true;
Anthony Barbier7068f992017-10-26 15:23:08 +010095 }
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000096 void do_run() override
Anthony Barbier7068f992017-10-26 15:23:08 +010097 {
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +000098 // Execute the functions:
99 absdiff.run();
Anthony Barbier7068f992017-10-26 15:23:08 +0100100 }
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000101 void do_teardown() override
Anthony Barbier7068f992017-10-26 15:23:08 +0100102 {
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000103 // Save the result to file:
104 if(!output_filename.empty())
105 {
106 // save_to_ppm maps and unmaps the image to store as PPM
107 // The GCTensor::map call inside the save_to_ppm will block until all pending operations on that image have completed
108 save_to_ppm(dst, output_filename);
109 }
Anthony Barbier7068f992017-10-26 15:23:08 +0100110 }
111
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000112private:
113 GCImage src1{}, src2{}, dst{};
114 GCAbsoluteDifference absdiff{};
115 std::string output_filename{};
116};
Anthony Barbier7068f992017-10-26 15:23:08 +0100117
118/** Main program for absdiff test
119 *
120 * @param[in] argc Number of arguments
121 * @param[in] argv Arguments ( [optional] Path to the first PPM image to process, [optional] Path the the second PPM image to process )
122 */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000123int main(int argc, char **argv)
Anthony Barbier7068f992017-10-26 15:23:08 +0100124{
Michalis Spyrou2b5f0f22018-01-10 14:08:50 +0000125 return utils::run_example<GCAbsDiffExample>(argc, argv);
Anthony Barbier7068f992017-10-26 15:23:08 +0100126}