VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Gr::Image Class Reference

A class holding shared read-only image data (Gr::ImageBuffer) and its associated image type (Gr::ImageType). More...

#include <grimage.h>

Public Member Functions

 Image ()
 Default constructor for an empty() image with an in-valid() type() and a null ptr(). More...
 
 Image (shared_ptr< const ImageBuffer > ptr, Gr::ImageType)
 Constructor, taking a shared pointer to the image data and its image type. More...
 
bool empty () const
 Returns true if constructed with no image data.
 
void clear ()
 Clears the image as if default constructed. More...
 
bool valid () const
 Returns !empty() && type().valid().
 
ImageType type () const
 Returns the image type.
 
size_t size () const
 Returns the image data total size.
 
shared_ptr< ImageBufferrecycle ()
 Creates a new shared pointer that can be deposited into a new Image, but if the current Image is not empty() and not shared (unique()) then its buffer is returned instead. More...
 
shared_ptr< const ImageBufferptr () const
 Returns the image data shared pointer.
 
const ImageBufferdata () const
 Returns the image data. More...
 

Static Public Member Functions

static void read (std::istream &, Image &, const std::string &exception_help_text=std::string())
 Reads an input stream into an image. Throws on error.
 
static bool receive (G::PublisherSubscription &channel, Image &, std::string &type_str)
 Reads a publication channel into an image. More...
 
static bool peek (G::PublisherSubscription &channel, Image &, std::string &type_str)
 A variant on receive() that does a channel peek().
 
static ImageBufferblank (Image &, ImageType raw_type, bool contiguous=false)
 Factory function for a not-really-blank raw image that is temporarily writable via the returned image buffer pointer. More...
 

Detailed Description

A class holding shared read-only image data (Gr::ImageBuffer) and its associated image type (Gr::ImageType).

Static methods are used to read images from file or publication channel.

Definition at line 41 of file grimage.h.

Constructor & Destructor Documentation

Gr::Image::Image ( )

Default constructor for an empty() image with an in-valid() type() and a null ptr().

Definition at line 37 of file grimage.cpp.

Gr::Image::Image ( shared_ptr< const ImageBuffer ptr,
Gr::ImageType  type 
)

Constructor, taking a shared pointer to the image data and its image type.

The image type is allowed to be in-valid() while still having a non-empty image buffer; this allows Image object to hold non-image data or non-standard image types, with the image or non-image type information held separately.

Definition at line 41 of file grimage.cpp.

Member Function Documentation

Gr::ImageBuffer * Gr::Image::blank ( Image image,
ImageType  raw_type,
bool  contiguous = false 
)
static

Factory function for a not-really-blank raw image that is temporarily writable via the returned image buffer pointer.

The implementation recycle()s the image and resizes its image buffer to match the given image type and contiguity. Precondition: type().isRaw()

Definition at line 54 of file grimage.cpp.

void Gr::Image::clear ( )

Clears the image as if default constructed.

Postcondition: empty()

Definition at line 95 of file grimage.cpp.

const Gr::ImageBuffer & Gr::Image::data ( ) const

Returns the image data.

Precondition: !empty()

Definition at line 112 of file grimage.cpp.

bool Gr::Image::receive ( G::PublisherSubscription channel,
Image image,
std::string &  type_str 
)
static

Reads a publication channel into an image.

If a non-image is received then the non-image type will be deposited in the supplied string and the Image type() will be invalid(). Returns false iff the channel receive fails.

Definition at line 155 of file grimage.cpp.

shared_ptr< Gr::ImageBuffer > Gr::Image::recycle ( )

Creates a new shared pointer that can be deposited into a new Image, but if the current Image is not empty() and not shared (unique()) then its buffer is returned instead.

This can avoid memory allocation when processing a sequence of images all of the same size, while still allowing slow code to take copies.

<
< Image ImageFactory::newImage( Image & old_image ) {
< shared_ptr<ImageBuffer> ptr = old_image.recycle() ;
< resize_and_fill( *ptr , m_type ) ;
< return Image( ptr , m_type ) ;
< }
<

Definition at line 117 of file grimage.cpp.


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