Compute Library
 21.08
PPMLoader Class Reference

PPM Image loader concrete implementation. More...

#include <ImageLoader.h>

Collaboration diagram for PPMLoader:
[legend]

Public Member Functions

 PPMLoader ()
 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...
 
- 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

PPM Image loader concrete implementation.

Definition at line 367 of file ImageLoader.h.

Constructor & Destructor Documentation

◆ PPMLoader()

PPMLoader ( )
inline

Default Constructor.

Definition at line 371 of file ImageLoader.h.

372  : IImageLoader(), _fs()
373  {
374  }
IImageLoader()
Default Constructor.
Definition: ImageLoader.h:130

Member Function Documentation

◆ close()

void close ( )
inlineoverridevirtual

Closes an image file.

Implements IImageLoader.

Definition at line 402 of file ImageLoader.h.

403  {
404  if(is_open())
405  {
406  _fs.close();
407  _feeder = nullptr;
408  }
410  }
#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:377

◆ is_open()

bool is_open ( )
inlineoverridevirtual

Return true if the image file is currently open.

Implements IImageLoader.

Definition at line 377 of file ImageLoader.h.

378  {
379  return _fs.is_open();
380  }

◆ 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 381 of file ImageLoader.h.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG_VAR, and arm_compute::utils::parse_ppm_header().

382  {
384  try
385  {
386  _fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
387  _fs.open(filename, std::ios::in | std::ios::binary);
388 
389  unsigned int max_val = 0;
390  std::tie(_width, _height, max_val) = parse_ppm_header(_fs);
391 
392  ARM_COMPUTE_ERROR_ON_MSG_VAR(max_val >= 256, "2 bytes per colour channel not supported in file %s",
393  filename.c_str());
394 
395  _feeder = std::make_unique<FileImageFeeder>(_fs);
396  }
397  catch(std::runtime_error &e)
398  {
399  ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", filename.c_str(), e.what());
400  }
401  }
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
#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
#define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg,...)
Definition: Error.h:457
bool is_open() override
Return true if the image file is currently open.
Definition: ImageLoader.h:377
std::tuple< unsigned int, unsigned int, int > parse_ppm_header(std::ifstream &fs)
Parse the ppm header from an input file stream.
Definition: Utils.cpp:202

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