This class implements a 2D image data structure. More...
#include <CImage.h>
Public Member Functions | |
cImage () | |
Default constructor of cImage. More... | |
cImage (const unsigned int a_width, const unsigned int a_height, const GLenum a_format=GL_RGB, const GLenum a_type=GL_UNSIGNED_BYTE) | |
Constructor of cImage. Initializes an image by passing its width, height, pixel format and pixel type. More... | |
virtual | ~cImage () |
Destructor of cImage. More... | |
cImagePtr | copy () |
This method creates a copy itself. More... | |
bool | allocate (const unsigned int a_width, const unsigned int a_height, const GLenum a_format=GL_RGB, const GLenum a_type=GL_UNSIGNED_BYTE) |
This method allocates a new image by defining its size, pixel format and pixel type. More... | |
void | erase () |
This method deletes all image data from memory. More... | |
virtual unsigned int | getImageCount () const |
This method returns the number of images stored. (1 only for class cImage). More... | |
bool | isInitialized () const |
This method returns true if the image has been allocated in memory, false otherwise. More... | |
void | setSize (const unsigned int a_width, const unsigned int a_height) |
This method sets and allocates the size of the image by defining its width and height. More... | |
unsigned int | getWidth () const |
This method returns the width of the image. More... | |
unsigned int | getHeight () const |
This method returns the height of the image. More... | |
GLenum | getFormat () const |
This method returns the pixel format of the image (GL_RGB, GL_RGBA, GL_LUMINANCE for instance). More... | |
GLenum | getType () const |
This method returns the pixel data type. (GL_UNSIGNED_BYTE, GL_UNSIGNED_INT for instance). More... | |
unsigned int | getBitsPerPixel () const |
This method returns the number of bits per pixel used to store this image. More... | |
unsigned int | getBytesPerPixel () const |
This method returns the number of bytes per pixel used to store this image. More... | |
unsigned int | getSizeInBytes () const |
This method returns the size in bytes of the current image. More... | |
bool | convert (const unsigned int a_newFormat) |
This method converts the image to a new format passed as argument. More... | |
cImage * | getImage () |
This method returns a pointer to this cImage object. More... | |
virtual unsigned char * | getData () |
This method returns a pointer to the actual image data. Use with care! More... | |
virtual void | setData (unsigned char *a_data, const unsigned int a_dataSizeInBytes, const bool a_dealloc=false) |
This method modifies the pointer to the actual image data. Use with care! More... | |
bool | setProperties (const unsigned int a_width, const unsigned int a_height, const GLenum a_format, const GLenum a_type) |
This method overrides the properties of the image. Use with care! More... | |
virtual void | clear () |
This method clears all image pixels with a black color. More... | |
virtual void | clear (const cColorb &a_color) |
This method clears all image pixels with a color passed as argument. More... | |
virtual void | clear (const unsigned char a_r, const unsigned char a_g, const unsigned char a_b, const unsigned char a_a=0xff) |
This method clears all image pixels with a color passed as argument. More... | |
virtual void | clear (const unsigned char a_grayLevel) |
This method clears all image pixels with a level of gray passed as argument. More... | |
virtual void | getPixelLocation (const cVector3d &a_texCoord, int &a_pixelX, int &a_pixelY, bool a_clampToImageSize=true) const |
This method retrieves the nearest pixel location from a texture coordinate. More... | |
virtual void | getPixelLocationInterpolated (const cVector3d &a_texCoord, double &a_pixelX, double &a_pixelY, bool a_clampToImageSize=true) const |
This method retrieves a pixel location from a texture coordinate. More... | |
virtual bool | getPixelColor (const unsigned int a_x, const unsigned int a_y, cColorb &a_color) const |
This method returns the color of a pixel at location (x,y). More... | |
virtual bool | getPixelColor (const unsigned int a_x, const unsigned int a_y, cColorf &a_color) const |
This method returns the color of a pixel at location (x,y). More... | |
virtual bool | getPixelColorInterpolated (const double a_x, const double a_y, cColorb &a_color) const |
This method returns the interpolated color of an image pixel at location (x,y). More... | |
virtual bool | getPixelColorInterpolated (const double a_x, const double a_y, cColorf &a_color) const |
This method returns the interpolated color of an image pixel at location (x,y). More... | |
virtual void | setPixelColor (const unsigned int a_x, const unsigned int a_y, const cColorb &a_color) |
This method sets the color of a pixel at location (x,y). More... | |
virtual void | setPixelColor (const unsigned int a_x, const unsigned int a_y, const unsigned char a_r, const unsigned char a_g, const unsigned char a_b) |
This method sets the color of a pixel at location (x,y). More... | |
virtual void | setPixelColor (const unsigned int a_x, const unsigned int a_y, const unsigned char a_grayLevel) |
This method sets the gray scale of a pixel at location (x,y). More... | |
virtual void | setTransparentColor (const cColorb &a_color, const unsigned char a_transparencyLevel) |
This method defines a specific pixel color to be transparent. More... | |
virtual void | setTransparentColor (const unsigned char a_r, const unsigned char a_g, const unsigned char a_b, const unsigned char a_transparencyLevel) |
This method defines a specific pixel color to be transparent. More... | |
virtual void | setTransparency (const unsigned char a_transparencyLevel) |
This method defines a transparency value to be applied to all image pixels. More... | |
virtual void | flipHorizontal () |
This method flips this image horizontally. More... | |
virtual void | getVoxelLocation (const cVector3d &a_texCoord, int &a_voxelX, int &a_voxelY, int &a_voxelZ, bool a_clampToImageSize=true) const |
This method retrieves the nearest voxel location from a texture coordinate. More... | |
virtual void | getVoxelLocationInterpolated (const cVector3d &a_texCoord, double &a_voxelX, double &a_voxelY, double &a_voxelZ, bool a_clampToImageSize=true) const |
This method retrieves the voxel location from a texture coordinate. More... | |
virtual bool | getVoxelColor (const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, cColorb &a_color) const |
This method returns the color of an image voxel at location (x,y,z). More... | |
virtual bool | getVoxelColorInterpolated (const double a_x, const double a_y, const double a_z, cColorb &a_color) const |
This method returns the interpolated color of an image voxel at location (x,y,z). More... | |
virtual bool | getVoxelColorInterpolated (const double a_x, const double a_y, const double a_z, cColorf &a_color) const |
This method returns the interpolated color of an image voxel at location (x,y,z). More... | |
virtual void | setVoxelColor (const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, const cColorb &a_color) |
This method sets the color of an image voxel at location (x,y,z). More... | |
virtual void | setVoxelColor (const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, const unsigned char a_r, const unsigned char a_g, const unsigned char a_b) |
This method sets the color of an image voxel at location (x,y,z). More... | |
virtual void | setVoxelColor (const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, const unsigned char a_grayLevel) |
This method sets the gray level of an image voxel at location (x,y,z). More... | |
void | copyTo (const unsigned int a_sourcePosX, const unsigned int a_sourcePosY, const unsigned int a_sourceSizeX, const unsigned int a_sourceSizeY, cImagePtr a_destImage, const unsigned int a_destPosX=0, const unsigned int a_destPosY=0) |
This method copies a section of this current image to a destination image. More... | |
void | copyTo (cImagePtr a_destImage, const unsigned int a_destPosX=0, const unsigned int a_destPosY=0) |
This method copies the entire image to a destination image. More... | |
virtual unsigned long | getCurrentIndex () |
This method returns the index number of the current image. For cImage objects, the value is always 0. More... | |
virtual bool | selectImage (unsigned long a_index) |
This method sets the current image. For cImage objects, this value is always 0. More... | |
virtual bool | loadFromFile (const std::string &a_filename) |
This method loads an image file by passing a filename as argument. More... | |
virtual bool | saveToFile (const std::string &a_filename) |
This method saves an image file by passing a filename as argument. More... | |
std::string | getFilename () const |
This method returns the filename from which this image was last loaded or saved. More... | |
Static Public Member Functions | |
static cImagePtr | create () |
Shared cImage allocator. More... | |
static int | queryBytesPerPixel (const GLenum a_format, const GLenum a_type) |
This method queries the number of bytes per pixel for a given format. More... | |
Public Attributes | |
cColorb | m_borderColor |
Returned color when accessing pixels located outside of the image. More... | |
Protected Member Functions | |
void | defaults () |
This method initializes all member variables. More... | |
void | cleanup () |
This method deletes memory and rid ourselves of any image previously stored. More... | |
Protected Attributes | |
std::string | m_filename |
Image filename. More... | |
unsigned int | m_width |
Width in pixels of the current image. More... | |
unsigned int | m_height |
Height in pixels of the current image. More... | |
GLenum | m_format |
Pixel format of the image (GL_RGB, GL_RGBA, GL_LUMINANCE). More... | |
GLenum | m_type |
Pixel data type. (GL_UNSIGNED_BYTE, GL_UNSIGNED_INT). More... | |
unsigned int | m_bytesPerPixel |
Number of bytes per pixel. More... | |
unsigned char * | m_data |
The image data itself. More... | |
unsigned int | m_memorySize |
Size of current image in bytes. More... | |
bool | m_allocated |
If true, then the image has been allocated in memory, false otherwise. More... | |
bool | m_responsibleForMemoryAllocation |
If true, then this object actually performed the memory allocation for this object. More... | |
This class provides support for 2D images of the following formats: GL_LUMINANCE, GL_RGB, and GL_RGBA.
Several file formats are also supported for loading and saving images to disk. These include bmp, gif, jpg, png, ppm, and raw.
chai3d::cImage::cImage | ( | ) |
Default Constructor of cImage.
chai3d::cImage::cImage | ( | const unsigned int | a_width, |
const unsigned int | a_height, | ||
const GLenum | a_format = GL_RGB , |
||
const GLenum | a_type = GL_UNSIGNED_BYTE |
||
) |
Constructor of cImage. Allocates the image by passing width, height and pixel format.
a_width | Width of image. |
a_height | Height of image. |
a_format | Pixel format. Accepted values are: GL_LUMINANCE, GL_RGB, GL_RGBA. |
a_type | Pixel type. Accepted values are: GL_UNSIGNED_BYTE, GL_UNSIGNED_INT. |
|
virtual |
Destructor of cImage.
|
inlinestatic |
cImagePtr chai3d::cImage::copy | ( | ) |
This method creates a copy of itself.
bool chai3d::cImage::allocate | ( | const unsigned int | a_width, |
const unsigned int | a_height, | ||
const GLenum | a_format = GL_RGB , |
||
const GLenum | a_type = GL_UNSIGNED_BYTE |
||
) |
This method allocates a new image by defining its width, height and pixel format.
a_width | Width of image |
a_height | Height of image |
a_format | Pixel format. Accepted values are: GL_LUMINANCE, GL_RGB, GL_RGBA |
a_type | Pixel type. Accepted values are: GL_UNSIGNED_BYTE, GL_UNSIGNED_INT |
|
inline |
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inline |
void chai3d::cImage::setSize | ( | const unsigned int | a_width, |
const unsigned int | a_height | ||
) |
This method sets the size of image by defining the width and height.
a_width | Width of image. |
a_height | Height of image. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool chai3d::cImage::convert | ( | const unsigned int | a_newFormat | ) |
This method converts this image into a new pixel format.
a_newFormat | New desired pixel format: GL_LUMINANCE, GL_RGB, GL_RGBA. |
|
static |
This method queries the number of bytes per pixel for a given format.
a_format | Pixel format of image. |
a_type | Pixel data type of image. |
|
inline |
|
inlinevirtual |
|
virtual |
This method assigns a different memory location for the image data. Use with care!
Make sure to call function setProperties() afterwards in order to correctly set the dimension and pixel format of the image described by the new data.
a_data | Pointer to new image data. |
a_dataSizeInBytes | Size in byte of the image data. |
a_dealloc | If true then this class is responsible for deallocating image data when the object is deleted. |
bool chai3d::cImage::setProperties | ( | const unsigned int | a_width, |
const unsigned int | a_height, | ||
const GLenum | a_format, | ||
const GLenum | a_type | ||
) |
This method assigns new properties including width, height and pixel format to the image. If the requested image properties do not match the exact amount of allocated data image, then the operation fails and the desired properties are ignored.
a_width | Width of new image. |
a_height | Height of new image. |
a_format | Pixel format. Accepted values are (GL_LUMINANCE, GL_RGB, GL_RGBA). |
a_type | Pixel data type. (GL_UNSIGNED_BYTE, GL_UNSIGNED_INT for instance). |
|
virtual |
This method clears an image with defaults data.
|
virtual |
This method clears an image with a defined color passed as argument.
a_color | New color of the image. |
|
inlinevirtual |
|
inlinevirtual |
|
virtual |
This method retrieves the nearest pixel location from a texture coordinate.
Each texture coordinate is a value defined between 0.0 and 1.0.
a_texCoord | Texture coordinate. |
a_pixelX | Return value for pixel coordinate X. |
a_pixelY | Return value for pixel coordinate Y. |
a_clampToImageSize | If true then pixel value is clamped to image size. |
|
virtual |
This method retrieves a pixel location from a texture coordinate.
Each texture coordinate is a value defined between 0.0 and 1.0.
a_texCoord | Texture coordinate. |
a_pixelX | Return value for pixel coordinate X. |
a_pixelY | Return value for pixel coordinate Y. |
a_clampToImageSize | If true then pixel value is clamped to image size. |
|
virtual |
This method returns the color of a pixel by passing its x and y image coordinates.
a_x | X coordinate of the pixel. |
a_y | Y coordinate of the pixel. |
a_color | Return color of the pixel. |
|
virtual |
This method returns the color of a pixel by passing its x and y image coordinates.
a_x | X coordinate of the pixel. |
a_y | Y coordinate of the pixel. |
a_color | Return color of the pixel. |
|
virtual |
This method returns the interpolated color of an image pixel at location (x,y).
a_x | X coordinate of the pixel. |
a_y | Y coordinate of the pixel. |
a_color | Return color of the pixel. |
|
virtual |
This method returns the interpolated color of an image pixel at location (x,y).
a_x | X coordinate of the pixel. |
a_y | Y coordinate of the pixel. |
a_color | Return color of the pixel. |
|
virtual |
This method sets the color of a pixel at a desired location (x,y).
a_x | X coordinate of the image pixel. |
a_y | Y coordinate of the image pixel. |
a_color | New pixel color. |
|
inlinevirtual |
|
virtual |
This method sets the gray level of a pixel at a desired location (x,y).
a_x | X coordinate of the pixel. |
a_y | Y coordinate of the pixel. |
a_grayLevel | New luminance value of the pixel. |
|
virtual |
This method defines a color to be transparent. If the image is not in GL_RGBA format, it is first converted in order to enable pixel transparency capabilities.
a_color | Selected pixel color. |
a_transparencyLevel | Transparency level. |
Reimplemented in chai3d::cMultiImage.
|
virtual |
Define a pixel color to be transparent. If the image is not in GL_RGBA format, it is first converted in order to enable pixel transparency capabilities.
a_r | Red component of selected pixel color. |
a_g | Green component of selected pixel color. |
a_b | Blue component of selected pixel color. |
a_transparencyLevel | Transparency level. |
Reimplemented in chai3d::cMultiImage.
|
virtual |
his method assigns a transparency level to all image pixels. If the image is not in GL_RGBA format, it is first converted in order to enable pixel transparency capabilities.
a_transparencyLevel | Transparency level. |
Reimplemented in chai3d::cMultiImage.
|
virtual |
This method flips the image horizontally.
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
void chai3d::cImage::copyTo | ( | const unsigned int | a_sourcePosX, |
const unsigned int | a_sourcePosY, | ||
const unsigned int | a_sourceSizeX, | ||
const unsigned int | a_sourceSizeY, | ||
cImagePtr | a_destImage, | ||
const unsigned int | a_destPosX = 0 , |
||
const unsigned int | a_destPosY = 0 |
||
) |
This method copies a section of this current image to a different location or onto a different destination image.
a_sourcePosX | X coordinate of top left pixel to copy. |
a_sourcePosY | Y coordinate of top left pixel to copy. |
a_sourceSizeX | Width of area to copy. |
a_sourceSizeY | Height of area to copy. |
a_destImage | Destination image when area will be pasted. |
a_destPosX | X coordinate of top left pixel on destination image where area is pasted. |
a_destPosY | Y coordinate of top left pixel on destination image where area is pasted. |
void chai3d::cImage::copyTo | ( | cImagePtr | a_destImage, |
const unsigned int | a_destPosX = 0 , |
||
const unsigned int | a_destPosY = 0 |
||
) |
This method copies this entire image to another destination image. If the destination images is smaller than the source, the copied area is cropped before being copied.
a_destImage | Destination image when area will be pasted. |
a_destPosX | X coordinate of top left pixel on destination image where area is pasted. |
a_destPosY | Y coordinate of top left pixel on destination image where area is pasted. |
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
inlinevirtual |
Reimplemented in chai3d::cMultiImage.
|
virtual |
Loads this image from the specified file. Returns true if all goes well. Note that regardless of whether it succeeds, this over-writes any image that had previously been loaded by this object.
a_filename | Image filename |
Reimplemented in chai3d::cMultiImage.
|
virtual |
Saves this image from the specified file. Returns true if all goes well. All images are saved in RGB format.
a_filename | Image filename. |
|
inline |
|
protected |
This method initializes internal variables.
|
protected |
This method frees memory that was used for image data, and re-initialize internal variables.
cColorb chai3d::cImage::m_borderColor |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |