Public Types | Public Member Functions | Static Public Member Functions | Public Attributes

CxUtils::Image Class Reference

Simple image data structure for storing RAW image data and for easy conversion to/from a few compression formats. More...

#include <image.h>

List of all members.

Public Types

enum  Format {
  Unused = 0, Invalid = 0, MPEG2, MPEG4,
  MJPEG, NTSC, PAL, TIFF,
  JPEG, GIF, H263, H264,
  PNG, BMP, RAW, PPM,
  PGM, PNM
}
 

Enumeration of possible image formats supported by this library. However, not all are supported.

More...

Public Member Functions

 Image ()
 Constructor.
 Image (const Image &img)
 Copy Constructor.
 ~Image ()
 Destructor. Destroys the Image object and closes the temporary file produced by the mVirtual file.
int Create (const unsigned short width, const unsigned short height, const unsigned char channels, const unsigned char *rawImage=NULL, const bool verticalFlip=false)
 This initializes the Image.
int Create (const unsigned short width, const unsigned short height, const unsigned char channels, const unsigned char *rawImage, const double scale, const bool verticalFlip=false)
 This initializes the Image.
int Create (const unsigned short width, const unsigned short height, const unsigned char channels, const unsigned char *rawImage, const unsigned short maxWidth, const unsigned short maxHeight, const bool verticalFlip)
 This initializes the Image.
int Destroy ()
 Destroys the Image object data.
int Decompress (const unsigned char *compressed, const unsigned int len, const Format format)
 Takes a compressed image in the buffer, and uses one of the supported image decompression algorithms to convert to RAW image data.
int Compress (unsigned char **buffer, unsigned int *len, unsigned int *clen, const Format format, void *args=NULL) const
 The method compresses the image to buffer.
void ApplyTile (const Image &tile)
 Applies a tile repeatedly accross an image.
int Load (const std::string &file)
 The function loads image to internal structure. The image will be decompressed based on the extension of the file.
int Save (const std::string &file) const
 The function saves a frame to file. The format will be compressed based on the extension of the file.
void FlipChannels ()
Imageoperator= (const Image &img)
 Copies contents of image.

Static Public Member Functions

static int Compress (unsigned char *image, unsigned int width, unsigned int height, unsigned char channels, unsigned char **buffer, unsigned int *len, unsigned int *clen, const Format format, void *args=NULL)
 The method compresses the image to buffer.
static int SaveCompressedImage (const std::string &name, const unsigned char *data, const unsigned int size, const Format format)
 The funtion saves data to disk.
static Format GetFormat (const std::string &file)
 The function returns the format based on the extension of the file.
static void FlipColorChannels (unsigned char *colorImage, unsigned int width, unsigned int height)

Public Attributes

unsigned char mChannels
 Number of color channels 1, or 3.
unsigned short mWidth
 Horizontal resolution of image in pixels.
unsigned short mHeight
 Vertical resolution of image in pixels.
unsigned int mDataSize
 Size of RAW data in bytes.
unsigned char * mpImage
 Raw uncompressed image data.

Detailed Description

Simple image data structure for storing RAW image data and for easy conversion to/from a few compression formats.

The format for image data in this library must be BGR, not RGB, otherwise your images will look weird! BGR is used because this is the format that most used format from cameras and other capture devices.

Image compression and decompression software and image data storage. formats supported: + JPG - A modified version of libjpeg is used to convert channel order to BGR from RGB. + PNG - libpng is used

Definition at line 68 of file image.h.


Member Enumeration Documentation

Enumeration of possible image formats supported by this library. However, not all are supported.

Enumerator:
Unused 
Invalid 
MPEG2 
MPEG4 
MJPEG 
NTSC 
PAL 
TIFF 
JPEG 
GIF 
H263 
H264 
PNG 
BMP 
RAW 
PPM 
PGM 
PNM 

Definition at line 77 of file image.h.


Constructor & Destructor Documentation

Image::Image (  )

Constructor.

Definition at line 54 of file image.cpp.

Image::Image ( const Image img )

Copy Constructor.

Definition at line 68 of file image.cpp.

Image::~Image (  )

Destructor. Destroys the Image object and closes the temporary file produced by the mVirtual file.

Definition at line 85 of file image.cpp.


Member Function Documentation

void Image::ApplyTile ( const Image tile )

Applies a tile repeatedly accross an image.

Parameters:
tileTile image to stamp accross.

Definition at line 668 of file image.cpp.

int Image::Compress ( unsigned char **  buffer,
unsigned int *  len,
unsigned int *  clen,
const Format  format,
void *  args = NULL 
) const

The method compresses the image to buffer.

If necessary, this method will re-size the buffer to fit the compressed image.

Parameters:
[out]bufferThe pointer to the output buffer
[in]lenSpecify the lenght of the buffer
[out]clenIs the length of the compressed image in the output buffer.
[in]formatThe image format type to compress to. See jimageformats.h.
[in]argsPointer to additional compression arguments (like quality) which is converted the appropriate format for the compression routine based on data format. (by default is NULL and does nothing).
Returns:
0 on success, 1 on failure

Definition at line 400 of file image.cpp.

int Image::Compress ( unsigned char *  image,
unsigned int  width,
unsigned int  height,
unsigned char  channels,
unsigned char **  buffer,
unsigned int *  len,
unsigned int *  clen,
const Format  format,
void *  args = NULL 
) [static]

The method compresses the image to buffer.

If necessary, this method will re-size the buffer to fit the compressed image.

Parameters:
[in]imageImage data to compress.
[in]widthImage width in pixels.
[in]heightImage height in pixels.
[in]channelsNumber of color channels in image.
[out]bufferThe pointer to the output buffer
[in]lenSpecify the lenght of the buffer
[out]clenIs the length of the compressed image in the output buffer.
[in]formatThe image format type to compress to. See jimageformats.h.
[in]argsPointer to additional compression arguments (like quality) which is converted the appropriate format for the compression routine based on data format. (by default is NULL and does nothing).
Returns:
0 on success, 1 on failure

Definition at line 433 of file image.cpp.

int Image::Create ( const unsigned short  width,
const unsigned short  height,
const unsigned char  channels,
const unsigned char *  rawImage,
const double  scale,
const bool  verticalFlip = false 
)

This initializes the Image.

Parameters:
[in]widthThe width of the image
[in]heightThe height of the image
[in]channelsNumber of channels used (1, 3, or 4)
[in]rawImageThe image data to be copied to the image, if the pointer is NULL (default), only memory allocation takes place an no copying.
[in]scaleHow much to scale the image data.
[in]verticalFlipIf true, image is flipped vertically when copied.
Returns:
1 on success, 0 on failure

Definition at line 166 of file image.cpp.

int Image::Create ( const unsigned short  width,
const unsigned short  height,
const unsigned char  channels,
const unsigned char *  rawImage,
const unsigned short  maxWidth,
const unsigned short  maxHeight,
const bool  verticalFlip 
)

This initializes the Image.

Parameters:
[in]widthThe width of the image
[in]heightThe height of the image
[in]channelsNumber of channels used (1, 3, or 4)
[in]rawImageThe image data to be copied to the image, if the pointer is NULL (default), only memory allocation takes place an no copying.
[in]maxWidthMaximum width to store image as (will force scaling).
[in]maxHeightMaximum height to store image as (will force scaling).
[in]verticalFlipIf true, image is flipped vertically when copied.
Returns:
1 on success, 0 on failure

Definition at line 303 of file image.cpp.

int Image::Create ( const unsigned short  width,
const unsigned short  height,
const unsigned char  channels,
const unsigned char *  rawImage = NULL,
const bool  verticalFlip = false 
)

This initializes the Image.

Parameters:
[in]widthThe width of the image
[in]heightThe height of the image
[in]channelsNumber of channels used (1, 3, or 4)
[in]rawImageThe image data to be copied to the image, if the pointer is NULL (default), only memory allocation takes place an no copying.
[in]verticalFlipIf true, image is flipped vertically when copied.
Returns:
1 on success, 0 on failure

Definition at line 106 of file image.cpp.

int Image::Decompress ( const unsigned char *  compressed,
const unsigned int  len,
const Format  format 
)

Takes a compressed image in the buffer, and uses one of the supported image decompression algorithms to convert to RAW image data.

Parameters:
[in]compressedThe buffer with data
[in]lenThe size of the buffer
[in]formatThe format of the data in the compressed buffer
Returns:
1 on success, 0 on failure

Definition at line 491 of file image.cpp.

int Image::Destroy (  )

Destroys the Image object data.

Returns:
Always returns 1.

Definition at line 524 of file image.cpp.

void CxUtils::Image::FlipChannels (  ) [inline]

Definition at line 145 of file image.h.

static void CxUtils::Image::FlipColorChannels ( unsigned char *  colorImage,
unsigned int  width,
unsigned int  height 
) [inline, static]

Definition at line 152 of file image.h.

Image::Format Image::GetFormat ( const std::string &  file ) [static]

The function returns the format based on the extension of the file.

Parameters:
[in]fileThe name of the file
Returns:
The image format as devined in the Image class enumeration.

Definition at line 776 of file image.cpp.

int Image::Load ( const std::string &  file )

The function loads image to internal structure. The image will be decompressed based on the extension of the file.

Parameters:
fileThe name of the file
Returns:
1 on success, 0 on failure

Definition at line 714 of file image.cpp.

Image & Image::operator= ( const Image img )

Copies contents of image.

Definition at line 797 of file image.cpp.

int Image::Save ( const std::string &  file ) const

The function saves a frame to file. The format will be compressed based on the extension of the file.

Parameters:
[in]fileThe name of the file
Returns:
1 on success, 0 on failure

Definition at line 549 of file image.cpp.

int Image::SaveCompressedImage ( const std::string &  name,
const unsigned char *  data,
const unsigned int  size,
const Format  format 
) [static]

The funtion saves data to disk.

Parameters:
[in]nameThe name of the file (without extension).
[in]dataCompressed data.
[in]sizeSize of the image.
[in]formatImage format (for extension lookup).
Returns:
1 on success, 0 on failure

Definition at line 599 of file image.cpp.


Member Data Documentation

Number of color channels 1, or 3.

Definition at line 168 of file image.h.

Size of RAW data in bytes.

Definition at line 171 of file image.h.

unsigned short CxUtils::Image::mHeight

Vertical resolution of image in pixels.

Definition at line 170 of file image.h.

unsigned char* CxUtils::Image::mpImage

Raw uncompressed image data.

Definition at line 172 of file image.h.

unsigned short CxUtils::Image::mWidth

Horizontal resolution of image in pixels.

Definition at line 169 of file image.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines