Compute Library
 21.05
JPEGLoader Class Reference

Class to load the content of a JPEG file into an Image. More...

#include <ImageLoader.h>

Collaboration diagram for JPEGLoader:
[legend]

Public Member Functions

 JPEGLoader ()
 Default Constructor. More...
 
bool is_open () override
 Return true if the image file is currently open. More...
 
void open (const std::string &filename) override
 Open an image file and reads its metadata (Width, height) More...
 
void close () override
 Closes an image file. More...
 
void release ()
 Explicitly Releases the memory of the loaded data. More...
 
- Public Member Functions inherited from IImageLoader
 IImageLoader ()
 Default Constructor. More...
 
virtual ~IImageLoader ()=default
 Virtual base destructor. More...
 
unsigned int width () const
 Return the width of the currently open image file. More...
 
unsigned int height () const
 Return the height of the currently open image file. More...
 
template<typename T >
void init_image (T &image, Format format)
 Initialise an image's metadata with the dimensions of the image file currently open. More...
 
template<typename T >
void fill_image (T &image)
 Fill an image with the content of the currently open image file. More...
 
template<typename T >
void fill_planar_tensor (T &tensor, bool bgr=false)
 Fill a tensor with 3 planes (one for each channel) with the content of the currently open image file. More...
 

Detailed Description

Class to load the content of a JPEG file into an Image.

Definition at line 432 of file ImageLoader.h.

Constructor & Destructor Documentation

◆ JPEGLoader()

JPEGLoader ( )
inline

Default Constructor.

Definition at line 446 of file ImageLoader.h.

447  : IImageLoader(), _is_loaded(false), _data(nullptr)
448  {
449  }
IImageLoader()
Default Constructor.
Definition: ImageLoader.h:130

Member Function Documentation

◆ close()

void close ( )
inlineoverridevirtual

Closes an image file.

Implements IImageLoader.

Definition at line 473 of file ImageLoader.h.

474  {
475  if(is_open())
476  {
477  _width = 0;
478  _height = 0;
479  release();
480  }
482  }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
bool is_open() override
Return true if the image file is currently open.
Definition: ImageLoader.h:452
void release()
Explicitly Releases the memory of the loaded data.
Definition: ImageLoader.h:484

References ARM_COMPUTE_ERROR_ON, JPEGLoader::is_open(), and JPEGLoader::release().

◆ is_open()

bool is_open ( )
inlineoverridevirtual

Return true if the image file is currently open.

Implements IImageLoader.

Definition at line 452 of file ImageLoader.h.

453  {
454  return _is_loaded;
455  }

Referenced by JPEGLoader::close().

◆ open()

void open ( const std::string &  filename)
inlineoverridevirtual

Open an image file and reads its metadata (Width, height)

Parameters
[in]filenameFile to open

Implements IImageLoader.

Definition at line 456 of file ImageLoader.h.

457  {
458  int bpp, width, height;
459  uint8_t *rgb_image = stbi_load(filename.c_str(), &width, &height, &bpp, 3);
460  if(rgb_image == NULL)
461  {
462  ARM_COMPUTE_ERROR_VAR("Accessing %s failed", filename.c_str());
463  }
464  else
465  {
466  _width = width;
467  _height = height;
468  _data = std::unique_ptr<uint8_t, malloc_deleter>(rgb_image);
469  _is_loaded = true;
470  _feeder = std::make_unique<MemoryImageFeeder>(_data.get());
471  }
472  }
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
unsigned int width() const
Return the width of the currently open image file.
Definition: ImageLoader.h:137
unsigned int height() const
Return the height of the currently open image file.
Definition: ImageLoader.h:142

References ARM_COMPUTE_ERROR_VAR, IImageLoader::height(), and IImageLoader::width().

Referenced by ValidationInputAccessor::access_tensor().

◆ release()

void release ( )
inline

Explicitly Releases the memory of the loaded data.

Definition at line 484 of file ImageLoader.h.

485  {
486  if(_is_loaded)
487  {
488  _data.reset();
489  _is_loaded = false;
490  _feeder = nullptr;
491  }
492  }

Referenced by JPEGLoader::close().


The documentation for this class was generated from the following file: