blob: 18043e3fcae63de28f17f0ab368a18fbb8e0378f [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
2 * Copyright (c) 2017 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 */
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"
32#include "utils/Utils.h"
33
34using namespace arm_compute;
35using namespace utils;
36
37void main_gc_absdiff(int argc, const char **argv)
38{
39 PPMLoader ppm1, ppm2;
40 GCImage src1, src2, dst;
41 GCScheduler::get().default_init();
42 if(argc < 2)
43 {
44 // Print help
45 std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n";
46 std::cout << "No input_image provided, creating two dummy 640x480 images\n";
47 // Create two empty grayscale 640x480 images
48 src1.allocator()->init(TensorInfo(640, 480, Format::U8));
49 src2.allocator()->init(TensorInfo(640, 480, Format::U8));
50 }
51 else if(argc < 3)
52 {
53 // Print help
54 std::cout << "Usage: " << argv[0] << " [input0_image.ppm] [input1_image.ppm] \n\n";
55 std::cout << "Only one input_image provided, creating a dummy 640x480 image\n";
56 ppm1.open(argv[1]);
57 ppm1.init_image(src1, Format::U8);
58 // Create an empty grayscale 640x480 image
59 src2.allocator()->init(TensorInfo(640, 480, Format::U8));
60 }
61 else
62 {
63 ppm1.open(argv[1]);
64 ppm1.init_image(src1, Format::U8);
65 ppm2.open(argv[2]);
66 ppm2.init_image(src2, Format::U8);
67 }
68
69 // Configure the temporary and destination images
70 dst.allocator()->init(*src1.info());
71
72 GCAbsoluteDifference absdiff;
73 absdiff.configure(&src1, &src2, &dst);
74
75 // Allocate all the images
76 src1.allocator()->allocate();
77 src2.allocator()->allocate();
78 dst.allocator()->allocate();
79
80 // Fill the input image with the content of the PPM image if a filename was provided:
81 if(ppm1.is_open())
82 {
83 ppm1.fill_image(src1);
84 }
85 if(ppm2.is_open())
86 {
87 ppm2.fill_image(src2);
88 }
89
90 // Execute the functions:
91 absdiff.run();
92
Anthony Barbier7068f992017-10-26 15:23:08 +010093 // Save the result to file:
94 if(ppm1.is_open())
95 {
96 const std::string output_filename = std::string(argv[1]) + "_out.ppm";
Joel Liangeb8f71e2017-12-27 13:16:00 +080097 // save_to_ppm maps and unmaps the image to store as PPM
98 // The GCTensor::map call inside the save_to_ppm will block until all pending operations on that image have completed
99 save_to_ppm(dst, output_filename);
Anthony Barbier7068f992017-10-26 15:23:08 +0100100 }
101}
102
103/** Main program for absdiff test
104 *
105 * @param[in] argc Number of arguments
106 * @param[in] argv Arguments ( [optional] Path to the first PPM image to process, [optional] Path the the second PPM image to process )
107 */
108int main(int argc, const char **argv)
109{
110 return utils::run_example(argc, argv, main_gc_absdiff);
111}