diff options
Diffstat (limited to 'utils/ImageLoader.h')
-rw-r--r-- | utils/ImageLoader.h | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/utils/ImageLoader.h b/utils/ImageLoader.h index aab0f5e770..2ae1a416e2 100644 --- a/utils/ImageLoader.h +++ b/utils/ImageLoader.h @@ -68,8 +68,7 @@ public: * * @param[in] fs Image file stream */ - FileImageFeeder(std::ifstream &fs) - : _fs(fs) + FileImageFeeder(std::ifstream &fs) : _fs(fs) { } // Inherited overridden methods @@ -94,8 +93,7 @@ public: * * @param[in] data Pointer to data */ - MemoryImageFeeder(const uint8_t *data) - : _data(data) + MemoryImageFeeder(const uint8_t *data) : _data(data) { } /** Prevent instances of this class from being copied (As this class contains pointers) */ @@ -127,8 +125,7 @@ class IImageLoader { public: /** Default Constructor */ - IImageLoader() - : _feeder(nullptr), _width(0), _height(0) + IImageLoader() : _feeder(nullptr), _width(0), _height(0) { } /** Virtual base destructor */ @@ -188,7 +185,7 @@ public: // Validate feeding data validate_info(image.info()); - switch(image.info()->format()) + switch (image.info()->format()) { case Format::U8: { @@ -204,15 +201,17 @@ public: unsigned char green = 0; unsigned char blue = 0; - execute_window_loop(window, [&](const Coordinates &) - { - red = _feeder->get(); - green = _feeder->get(); - blue = _feeder->get(); + execute_window_loop( + window, + [&](const Coordinates &) + { + red = _feeder->get(); + green = _feeder->get(); + blue = _feeder->get(); - *out.ptr() = 0.2126f * red + 0.7152f * green + 0.0722f * blue; - }, - out); + *out.ptr() = 0.2126f * red + 0.7152f * green + 0.0722f * blue; + }, + out); break; } @@ -226,11 +225,8 @@ public: Iterator out(&image, window); size_t row_size = _width * image.info()->element_size(); - execute_window_loop(window, [&](const Coordinates &) - { - _feeder->get_row(out.ptr(), row_size); - }, - out); + execute_window_loop( + window, [&](const Coordinates &) { _feeder->get_row(out.ptr(), row_size); }, out); break; } @@ -241,7 +237,7 @@ public: // Unmap buffer if creating a CLTensor unmap(image); } - catch(const std::ifstream::failure &e) + catch (const std::ifstream::failure &e) { ARM_COMPUTE_ERROR_VAR("Loading image file: %s", e.what()); } @@ -257,15 +253,19 @@ public: void fill_planar_tensor(T &tensor, bool bgr = false) { ARM_COMPUTE_ERROR_ON(!is_open()); - ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::U8, DataType::QASYMM8, DataType::F32, DataType::F16); + ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::U8, DataType::QASYMM8, DataType::F32, + DataType::F16); const DataLayout data_layout = tensor.info()->data_layout(); const TensorShape tensor_shape = tensor.info()->tensor_shape(); ARM_COMPUTE_UNUSED(tensor_shape); - ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH)] != _width); - ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT)] != _height); - ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL)] != 3); + ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH)] != + _width); + ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT)] != + _height); + ARM_COMPUTE_ERROR_ON(tensor_shape[get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL)] != + 3); ARM_COMPUTE_ERROR_ON(_feeder.get() == nullptr); @@ -282,7 +282,7 @@ public: // Iterate through every pixel of the image Window window; - if(data_layout == DataLayout::NCHW) + if (data_layout == DataLayout::NCHW) { window.set(Window::DimX, Window::Dimension(0, _width, 1)); window.set(Window::DimY, Window::Dimension(0, _height, 1)); @@ -303,48 +303,50 @@ public: unsigned char green = 0; unsigned char blue = 0; - execute_window_loop(window, [&](const Coordinates &) - { - red = _feeder->get(); - green = _feeder->get(); - blue = _feeder->get(); - - switch(tensor.info()->data_type()) + execute_window_loop( + window, + [&](const Coordinates &) { - case DataType::U8: - case DataType::QASYMM8: - { - *(out.ptr() + 0 * stride_z) = bgr ? blue : red; - *(out.ptr() + 1 * stride_z) = green; - *(out.ptr() + 2 * stride_z) = bgr ? red : blue; - break; - } - case DataType::F32: - { - *reinterpret_cast<float *>(out.ptr() + 0 * stride_z) = static_cast<float>(bgr ? blue : red); - *reinterpret_cast<float *>(out.ptr() + 1 * stride_z) = static_cast<float>(green); - *reinterpret_cast<float *>(out.ptr() + 2 * stride_z) = static_cast<float>(bgr ? red : blue); - break; - } - case DataType::F16: - { - *reinterpret_cast<half *>(out.ptr() + 0 * stride_z) = static_cast<half>(bgr ? blue : red); - *reinterpret_cast<half *>(out.ptr() + 1 * stride_z) = static_cast<half>(green); - *reinterpret_cast<half *>(out.ptr() + 2 * stride_z) = static_cast<half>(bgr ? red : blue); - break; - } - default: + red = _feeder->get(); + green = _feeder->get(); + blue = _feeder->get(); + + switch (tensor.info()->data_type()) { - ARM_COMPUTE_ERROR("Unsupported data type"); + case DataType::U8: + case DataType::QASYMM8: + { + *(out.ptr() + 0 * stride_z) = bgr ? blue : red; + *(out.ptr() + 1 * stride_z) = green; + *(out.ptr() + 2 * stride_z) = bgr ? red : blue; + break; + } + case DataType::F32: + { + *reinterpret_cast<float *>(out.ptr() + 0 * stride_z) = static_cast<float>(bgr ? blue : red); + *reinterpret_cast<float *>(out.ptr() + 1 * stride_z) = static_cast<float>(green); + *reinterpret_cast<float *>(out.ptr() + 2 * stride_z) = static_cast<float>(bgr ? red : blue); + break; + } + case DataType::F16: + { + *reinterpret_cast<half *>(out.ptr() + 0 * stride_z) = static_cast<half>(bgr ? blue : red); + *reinterpret_cast<half *>(out.ptr() + 1 * stride_z) = static_cast<half>(green); + *reinterpret_cast<half *>(out.ptr() + 2 * stride_z) = static_cast<half>(bgr ? red : blue); + break; + } + default: + { + ARM_COMPUTE_ERROR("Unsupported data type"); + } } - } - }, - out); + }, + out); // Unmap buffer if creating a CLTensor unmap(tensor); } - catch(const std::ifstream::failure &e) + catch (const std::ifstream::failure &e) { ARM_COMPUTE_ERROR_VAR("Loading image file: %s", e.what()); } @@ -368,8 +370,7 @@ class PPMLoader : public IImageLoader { public: /** Default Constructor */ - PPMLoader() - : IImageLoader(), _fs() + PPMLoader() : IImageLoader(), _fs() { } @@ -386,7 +387,7 @@ public: _fs.exceptions(std::ifstream::failbit | std::ifstream::badbit); _fs.open(filename, std::ios::in | std::ios::binary); - unsigned int max_val = 0; + unsigned int max_val = 0; std::tie(_width, _height, max_val) = parse_ppm_header(_fs); ARM_COMPUTE_ERROR_ON_MSG_VAR(max_val >= 256, "2 bytes per colour channel not supported in file %s", @@ -394,14 +395,14 @@ public: _feeder = std::make_unique<FileImageFeeder>(_fs); } - catch(std::runtime_error &e) + catch (std::runtime_error &e) { ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", filename.c_str(), e.what()); } } void close() override { - if(is_open()) + if (is_open()) { _fs.close(); _feeder = nullptr; @@ -443,8 +444,7 @@ private: public: /** Default Constructor */ - JPEGLoader() - : IImageLoader(), _is_loaded(false), _data(nullptr) + JPEGLoader() : IImageLoader(), _is_loaded(false), _data(nullptr) { } @@ -457,7 +457,7 @@ public: { int bpp, width, height; uint8_t *rgb_image = stbi_load(filename.c_str(), &width, &height, &bpp, 3); - if(rgb_image == NULL) + if (rgb_image == NULL) { ARM_COMPUTE_ERROR_VAR("Accessing %s failed", filename.c_str()); } @@ -472,7 +472,7 @@ public: } void close() override { - if(is_open()) + if (is_open()) { _width = 0; _height = 0; @@ -483,7 +483,7 @@ public: /** Explicitly Releases the memory of the loaded data */ void release() { - if(_is_loaded) + if (_is_loaded) { _data.reset(); _is_loaded = false; @@ -492,7 +492,7 @@ public: } private: - bool _is_loaded; + bool _is_loaded; std::unique_ptr<uint8_t, malloc_deleter> _data; }; @@ -509,7 +509,7 @@ public: static std::unique_ptr<IImageLoader> create(const std::string &filename) { ImageType type = arm_compute::utils::get_image_type_from_file(filename); - switch(type) + switch (type) { case ImageType::PPM: return std::make_unique<PPMLoader>(); |