Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images using the data type unsigned char. More...
#include <ByteImage.h>
Classes | |
struct | myBITMAPFILEHEADER |
struct | myBITMAPINFOHEADER |
Public Types | |
enum | ImageType { eGrayScale, eRGB24, eRGB24Split } |
Enum specifying the supported image types. More... | |
Public Member Functions | |
CByteImage () | |
The default constructor. More... | |
CByteImage (int nImageWidth, int nImageHeight, ImageType imageType, bool bHeaderOnly=false) | |
Constructor for creating an image of a specific size and type. More... | |
CByteImage (const CByteImage *pImage, bool bHeaderOnly=false) | |
Constructor for creating an image given a pointer to a CByteImage. More... | |
CByteImage (const CByteImage &image, bool bHeaderOnly=false) | |
Copy constructor. More... | |
bool | IsCompatible (const CByteImage *pImage) const |
Checks whether two images are compatible or not. More... | |
bool | LoadFromFile (const char *pFileName) |
Loads an image from a file. More... | |
bool | SaveToFile (const char *pFileName) const |
Saves an image to a file. More... | |
void | Set (int nImageWidth, int nImageHeight, ImageType imageType, bool bHeaderOnly=false) |
Changes size and type of an image. More... | |
~CByteImage () | |
The destructor. More... | |
Public Attributes | |
int | bytesPerPixel |
The number of bytes used for encoding one pixel. More... | |
int | height |
The height of the image in pixels. More... | |
bool | m_bOwnMemory |
Flag signaling if memory is to be freed or not. More... | |
unsigned char * | pixels |
The pointer to the the pixels. More... | |
ImageType | type |
The type of the image. More... | |
int | width |
The width of the image in pixels. More... | |
Private Member Functions | |
void | FreeMemory () |
bool | LoadFromFileBMP (const char *pFileName) |
bool | LoadFromFilePNM (const char *pFileName) |
bool | SaveToFileBMP (const char *pFileName) const |
bool | SaveToFilePNM (const char *pFileName) const |
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images using the data type unsigned char.
CByteImage is the central class for the representation of grayscale and color images.
Images of type CByteImage can be directly loaded from or stored to files and visualized in GUIs. The image data is represented as a linear array of pixels, always starting from the top left corner and stored row wise.
In the case of grayscale images (CByteImage::eGraySclae), the grayscale value of each pixel is encoded in one byte (0: black, 255: white, nuances in between). In the case of 24-bit color images the color information of each pixel is encoded in three bytes (first: red, second: green, third: blue).
For 24-bit color images two variants are available: CByteImage::eRGB24 and CByteImage::eRGB24Split, the first encoding the three components of an RGB triple in three consecutive bytes, the latter encoding the three components in three separate channels (the first starting at CByteImage::pixels, the second at CByteImage::pixels + CByteImage::width * CByteImage::height, and the third starting at CByteImage::pixels + 2 * CByteImage::width * CByteImage::height.
Definition at line 80 of file ByteImage.h.
Enum specifying the supported image types.
Enumerator | |
---|---|
eGrayScale |
In the case of grayscale images the grayscale value of each pixel is encoded in one byte (0: black, 255: white). |
eRGB24 |
Each pixel is encoded in three consecutive bytes (first: red, second: green, third: blue). |
eRGB24Split |
The RGB color information is storted in three separate channels (the first starting at CByteImage::pixels, the second at CByteImage::pixels + CByteImage::width * CByteImage::height, and the third starting atCByteImage:: pixels + 2 * CByteImage::width * CByteImage::height. |
Definition at line 86 of file ByteImage.h.
CByteImage::CByteImage | ( | ) |
The default constructor.
The default constructor sets all member variables to zero, i.e. after construction no valid image is represented.
This constructor is useful in case an image is to be loaded from a file at a later point, e.g. with the method LoadFromFile(const char *).
Definition at line 80 of file ByteImage.cpp.
CByteImage::CByteImage | ( | int | nImageWidth, |
int | nImageHeight, | ||
ImageType | imageType, | ||
bool | bHeaderOnly = false |
||
) |
Constructor for creating an image of a specific size and type.
With this constructor, an instance of CByteImage is created, given the desired image resolution and image type. The contents of the image are not initialized, i.e. are undefined after creation.
[in] | nImageWidth | The desired width of the image in pixels. Must be > 0. |
[in] | nImageHeight | The desired height of the image in pixels. Must be > 0. |
[in] | imageType | The desired type of the image. See ImageType for further information. |
[in] | bHeaderOnly | If set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case. |
Definition at line 90 of file ByteImage.cpp.
CByteImage::CByteImage | ( | const CByteImage * | pImage, |
bool | bHeaderOnly = false |
||
) |
Constructor for creating an image given a pointer to a CByteImage.
This constructor creates a new instance with the same properties as the image provided by the parameter 'pImage'. Note that the contents of the image are not copied. Use ImageProcessor::CopyImage(const CByteImage*, CByteImage*, const MyRegion*, bool) for copying image contents.
[in] | pImage | The template image. |
[in] | bHeaderOnly | If set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case. |
Definition at line 139 of file ByteImage.cpp.
CByteImage::CByteImage | ( | const CByteImage & | image, |
bool | bHeaderOnly = false |
||
) |
Copy constructor.
This copy constructor creates a new instance with the same properties as the image provided by the parameter 'image'. Note that the contents of the image are not copied. Use ImageProcessor::CopyImage(const CByteImage*, CByteImage*, const MyRegion*, bool) for copying image contents.
[in] | image | The template image. |
[in] | bHeaderOnly | If set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case. |
Definition at line 120 of file ByteImage.cpp.
CByteImage::~CByteImage | ( | ) |
The destructor.
Definition at line 158 of file ByteImage.cpp.
|
private |
Definition at line 200 of file ByteImage.cpp.
bool CByteImage::IsCompatible | ( | const CByteImage * | pImage | ) | const |
Checks whether two images are compatible or not.
[in] | pImage | Pointer to the image to be checked compatibility with. |
Definition at line 212 of file ByteImage.cpp.
bool CByteImage::LoadFromFile | ( | const char * | pFileName | ) |
Loads an image from a file.
Loads an image from a BMP, PGM, or PPM file. The image type is recognized by the file name ending (.bmp, .pgm, .ppm or .BMP, .PGM, .PPM).
If an image is already loaded, reinitialization is performed automatically.
[in] | pFileName | The path to the image file to be loaded. |
Definition at line 232 of file ByteImage.cpp.
|
private |
Definition at line 255 of file ByteImage.cpp.
|
private |
Definition at line 810 of file ByteImage.cpp.
bool CByteImage::SaveToFile | ( | const char * | pFileName | ) | const |
Saves an image to a file.
Saves the current image to a BMP, PGM, or PPM file. The desired image type is recognized by the file name ending (.bmp, .pgm, .ppm or .BMP, .PGM, .PPM).
Be careful to provide the correct file ending for PGM/PPM files: .PGM for grayscale images or .PPM for RGB images.
[in] | pFileName | The path to the destination file. |
Definition at line 243 of file ByteImage.cpp.
|
private |
Definition at line 600 of file ByteImage.cpp.
|
private |
Definition at line 933 of file ByteImage.cpp.
void CByteImage::Set | ( | int | nImageWidth, |
int | nImageHeight, | ||
ImageType | imageType, | ||
bool | bHeaderOnly = false |
||
) |
Changes size and type of an image.
With this method, an existing instance of CByteImage is changed, given the desired image resolution and image type. The contents of the image are not initialized after calling this method, i.e. are undefined.
[in] | nImageWidth | The desired width of the image in pixels. Must be > 0. |
[in] | nImageHeight | The desired height of the image in pixels. Must be > 0. |
[in] | imageType | The desired type of the image. See ImageType for further information. |
[in] | bHeaderOnly | If set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case. |
Definition at line 168 of file ByteImage.cpp.
int CByteImage::bytesPerPixel |
The number of bytes used for encoding one pixel.
This information is redundant with the member type (ImageType::eGrayScale => 1; ImageType::eRGB24, ImageType::eRGB24Split => 3).
This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 273 of file ByteImage.h.
int CByteImage::height |
The height of the image in pixels.
This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 264 of file ByteImage.h.
bool CByteImage::m_bOwnMemory |
Flag signaling if memory is to be freed or not.
This flag signals whether the image memory must be freed throughut re-initiallization/destruction or not.
This flag is usually for internal use only. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 301 of file ByteImage.h.
unsigned char* CByteImage::pixels |
The pointer to the the pixels.
This is the pointer pointing to the memory area containing the pixels of the image, starting from the top left corner and stored row wise (see above for type dependent information).
This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 283 of file ByteImage.h.
ImageType CByteImage::type |
The type of the image.
The type of the image specifies its encoding. See above for type dependent information.
This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 292 of file ByteImage.h.
int CByteImage::width |
The width of the image in pixels.
Padding is not implemented (on purpose).
This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).
Definition at line 257 of file ByteImage.h.