2 * Copyright (c) 2017 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
33 /* Advance the iterator to the first character which is not a comment
35 * @param[in,out] fs Stream to drop comments from
37 void discard_comments(std::ifstream &fs)
39 while(fs.peek() == '#')
41 fs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
45 /* Advance the string iterator to the next character which is neither a space or a comment
47 * @param[in,out] fs Stream to drop comments from
49 void discard_comments_and_spaces(std::ifstream &fs)
55 if(isspace(fs.peek()) == 0)
65 int test_helpers::run_example(int argc, const char **argv, example &func)
74 std::cout << "\nTest passed\n";
80 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
81 std::cerr << std::endl
82 << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl;
83 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
85 #endif /* ARM_COMPUTE_CL */
86 catch(std::runtime_error &err)
88 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
89 std::cerr << std::endl
90 << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl;
91 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
94 std::cout << "\nTest FAILED\n";
99 void test_helpers::draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b)
101 ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(tensor, Format::RGB888);
103 uint8_t *top = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y)) + tensor->buffer();
104 uint8_t *bottom = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y + rect.height)) + tensor->buffer();
106 uint8_t *right = tensor->info()->offset_element_in_bytes(Coordinates(rect.x + rect.width, rect.y)) + tensor->buffer();
107 size_t stride = tensor->info()->strides_in_bytes()[Window::DimY];
109 for(size_t x = 0; x < rect.width; ++x)
122 for(size_t y = 0; y < rect.height; ++y)
136 std::tuple<unsigned int, unsigned int, int> test_helpers::parse_ppm_header(std::ifstream &fs)
138 // Check the PPM magic number is valid
139 std::array<char, 2> magic_number{ { 0 } };
140 fs >> magic_number[0] >> magic_number[1];
141 ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
142 ARM_COMPUTE_UNUSED(magic_number);
144 discard_comments_and_spaces(fs);
146 unsigned int width = 0;
149 discard_comments_and_spaces(fs);
151 unsigned int height = 0;
154 discard_comments_and_spaces(fs);
159 discard_comments(fs);
161 ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
164 return std::make_tuple(width, height, max_val);