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
37 /* Advance the iterator to the first character which is not a comment
39 * @param[in,out] fs Stream to drop comments from
41 void discard_comments(std::ifstream &fs)
43 while(fs.peek() == '#')
45 fs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
49 /* Advance the string iterator to the next character which is neither a space or a comment
51 * @param[in,out] fs Stream to drop comments from
53 void discard_comments_and_spaces(std::ifstream &fs)
59 if(isspace(fs.peek()) == 0)
69 int run_example(int argc, const char **argv, example &func)
78 std::cout << "\nTest passed\n";
84 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
85 std::cerr << std::endl
86 << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl;
87 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
89 #endif /* ARM_COMPUTE_CL */
90 catch(std::runtime_error &err)
92 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
93 std::cerr << std::endl
94 << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl;
95 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
98 std::cout << "\nTest FAILED\n";
103 void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b)
105 ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(tensor, Format::RGB888);
107 uint8_t *top = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y)) + tensor->buffer();
108 uint8_t *bottom = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y + rect.height)) + tensor->buffer();
110 uint8_t *right = tensor->info()->offset_element_in_bytes(Coordinates(rect.x + rect.width, rect.y)) + tensor->buffer();
111 size_t stride = tensor->info()->strides_in_bytes()[Window::DimY];
113 for(size_t x = 0; x < rect.width; ++x)
126 for(size_t y = 0; y < rect.height; ++y)
140 std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
142 // Check the PPM magic number is valid
143 std::array<char, 2> magic_number{ { 0 } };
144 fs >> magic_number[0] >> magic_number[1];
145 ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
146 ARM_COMPUTE_UNUSED(magic_number);
148 discard_comments_and_spaces(fs);
150 unsigned int width = 0;
153 discard_comments_and_spaces(fs);
155 unsigned int height = 0;
158 discard_comments_and_spaces(fs);
163 discard_comments(fs);
165 ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
168 return std::make_tuple(width, height, max_val);
171 } // namespace arm_compute