| 172 | */ |
| 173 | template <typename T> |
| 174 | void fill_image(T &image) |
| 175 | { |
| 176 | ARM_COMPUTE_ERROR_ON(!is_open()); |
| 177 | ARM_COMPUTE_ERROR_ON(image.info()->dimension(0) != _width || image.info()->dimension(1) != _height); |
| 178 | ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(&image, Format::U8, Format::RGB888); |
| 179 | ARM_COMPUTE_ERROR_ON(_feeder.get() == nullptr); |
| 180 | try |
| 181 | { |
| 182 | // Map buffer if creating a CLTensor |
| 183 | map(image, true); |
| 184 | |
| 185 | // Validate feeding data |
| 186 | validate_info(image.info()); |
| 187 | |
| 188 | switch (image.info()->format()) |
| 189 | { |
| 190 | case Format::U8: |
| 191 | { |
| 192 | // We need to convert the data from RGB to grayscale: |
| 193 | // Iterate through every pixel of the image |
| 194 | Window window; |
| 195 | window.set(Window::DimX, Window::Dimension(0, _width, 1)); |
| 196 | window.set(Window::DimY, Window::Dimension(0, _height, 1)); |
| 197 | |
| 198 | Iterator out(&image, window); |
| 199 | |
| 200 | unsigned char red = 0; |
| 201 | unsigned char green = 0; |
| 202 | unsigned char blue = 0; |
| 203 | |
| 204 | execute_window_loop( |
| 205 | window, |
| 206 | [&](const Coordinates &) |
| 207 | { |
| 208 | red = _feeder->get(); |
| 209 | green = _feeder->get(); |
| 210 | blue = _feeder->get(); |
| 211 | |
| 212 | *out.ptr() = 0.2126f * red + 0.7152f * green + 0.0722f * blue; |
| 213 | }, |
| 214 | out); |
| 215 | |
| 216 | break; |
| 217 | } |
| 218 | case Format::RGB888: |
| 219 | { |
| 220 | // There is no format conversion needed: we can simply copy the content of the input file to the image one row at the time. |
| 221 | // Create a vertical window to iterate through the image's rows: |
| 222 | Window window; |
| 223 | window.set(Window::DimY, Window::Dimension(0, _height, 1)); |
| 224 | |
| 225 | Iterator out(&image, window); |
| 226 | size_t row_size = _width * image.info()->element_size(); |
| 227 | |
| 228 | execute_window_loop( |
| 229 | window, [&](const Coordinates &) { _feeder->get_row(out.ptr(), row_size); }, out); |
| 230 | |
| 231 | break; |
no test coverage detected