Encapsulates an image. More...
#include <gz/common/common.hh>
Public Types | |
| enum class | Channel { RED = 0 , GREEN = 1 , BLUE = 2 , ALPHA = 3 } |
| Image channel. More... | |
| enum | PixelFormatType { UNKNOWN_PIXEL_FORMAT = 0 , L_INT8 , L_INT16 , RGB_INT8 , RGBA_INT8 , BGRA_INT8 , RGB_INT16 , RGB_INT32 , BGR_INT8 , BGR_INT16 , BGR_INT32 , R_FLOAT16 , RGB_FLOAT16 , R_FLOAT32 , RGB_FLOAT32 , BAYER_RGGB8 , BAYER_BGGR8 , BAYER_GBRG8 , BAYER_GRBG8 , COMPRESSED_PNG , PIXEL_FORMAT_COUNT , COMPRESSED_JPEG } |
| Pixel formats enumeration. More... | |
Public Member Functions | |
| Image (const std::string &_filename="") | |
| Constructor. More... | |
| virtual | ~Image () |
| Destructor. More... | |
| math::Color | AvgColor () const |
| Get the average color. More... | |
| unsigned int | BPP () const |
| Get the size of one pixel in bits. More... | |
| std::vector< unsigned char > | ChannelData (Channel _channel) const |
| Extract a single channel (red, green, blue, or alpha) from an RGB[A] image and return a single channel 8 bit image data. More... | |
| std::vector< unsigned char > | Data () const |
| Get the image as a data array. More... | |
| void | Data (unsigned char **_data, unsigned int &_count) const |
| Get the image as a data array. More... | |
| std::string | Filename () const |
| Get the full filename of the image. More... | |
| unsigned int | Height () const |
| Get the height. More... | |
| int | Load (const std::string &_filename) |
| Load an image. Return 0 on success. More... | |
| math::Color | MaxColor () const |
| Get the max color. More... | |
| int | Pitch () const |
| math::Color | Pixel (const unsigned int _x, const unsigned int _y) const |
| Get a pixel color value. More... | |
| PixelFormatType | PixelFormat () const |
| Get the pixel format. More... | |
| void | Rescale (const int _width, const int _height) |
| Rescale the image. More... | |
| std::vector< unsigned char > | RGBAData () const |
| Get the RGBA data from the image. This will add an alpha channel if one is not present. More... | |
| void | RGBAData (unsigned char **_data, unsigned int &_count) const |
| Get the RGBA data from the image. This will add an alpha channel if one is not present. More... | |
| std::vector< unsigned char > | RGBData () const |
| Get only the RGB data from the image. This will drop the alpha channel if one is present. More... | |
| void | RGBData (unsigned char **_data, unsigned int &_count) const |
| Get only the RGB data from the image. This will drop the alpha channel if one is present. More... | |
| void | SavePNG (const std::string &_filename) |
| Save the image in PNG format. More... | |
| void | SavePNGToBuffer (std::vector< unsigned char > &_buffer) |
| Get the PNG image in a buffer. More... | |
| void | SetFromCompressedData (unsigned char *_data, unsigned int _size, Image::PixelFormatType _format) |
| Set the image from compressed (i.e. png) data. More... | |
| void | SetFromData (const unsigned char *_data, unsigned int _width, unsigned int _height, Image::PixelFormatType _format) |
| Set the image from raw data. More... | |
| bool | Valid () const |
| Returns whether this is a valid image. More... | |
| unsigned int | Width () const |
| Get the width. More... | |
Static Public Member Functions | |
| static Image::PixelFormatType | ConvertPixelFormat (const std::string &_format) |
| Convert a string to a Image::PixelFormat. More... | |
| template<typename T > | |
| static void | ConvertToRGBImage (const void *_data, unsigned int _width, unsigned int _height, Image &_output, T _min=std::numeric_limits< T >::max(), T _max=std::numeric_limits< T >::lowest(), bool _flip=false) |
| Convert a single channel image data buffer into an RGB image. During the conversion, the input image data are normalized to 8 bit values i.e. [0, 255]. Optionally, specify min and max values to use when normalizing the input image data. For example, if min and max are set to 1 and 10, a data value 2 will be normalized to: (2 - 1) / (10 - 1) * 255. More... | |
Detailed Description
Encapsulates an image.
Member Enumeration Documentation
◆ Channel
|
strong |
Image channel.
| Enumerator | |
|---|---|
| RED | Red channel. |
| GREEN | Green channel. |
| BLUE | Blue channel. |
| ALPHA | Alpha channel. |
◆ PixelFormatType
| enum PixelFormatType |
Constructor & Destructor Documentation
◆ Image()
|
explicit |
Constructor.
- Parameters
-
[in] _filename the path to the image
◆ ~Image()
|
virtual |
Destructor.
Member Function Documentation
◆ AvgColor()
| math::Color AvgColor | ( | ) | const |
Get the average color.
- Returns
- The average color
◆ BPP()
| unsigned int BPP | ( | ) | const |
Get the size of one pixel in bits.
- Returns
- The BPP of the image
◆ ChannelData()
| std::vector<unsigned char> ChannelData | ( | Channel | _channel | ) | const |
Extract a single channel (red, green, blue, or alpha) from an RGB[A] image and return a single channel 8 bit image data.
- Parameters
-
[in] _channel Channel to extract
- Returns
- 8 bit single channel image data
◆ ConvertPixelFormat()
|
static |
Convert a string to a Image::PixelFormat.
- Parameters
-
[in] _format Pixel format string.
- See also
- Image::PixelFormatNames
- Returns
- Image::PixelFormat
◆ ConvertToRGBImage()
|
inlinestatic |
Convert a single channel image data buffer into an RGB image. During the conversion, the input image data are normalized to 8 bit values i.e. [0, 255]. Optionally, specify min and max values to use when normalizing the input image data. For example, if min and max are set to 1 and 10, a data value 2 will be normalized to: (2 - 1) / (10 - 1) * 255.
- Parameters
-
[in] _data input image data buffer [in] _width image width [in] _height image height [out] _output Output RGB image [in] _min Minimum value to be used when normalizing the input image data to RGB. [in] _max Maximum value to be used when normalizing the input image data to RGB. [in] _flip True to flip the values after normalization, i.e. lower values are converted to brigher pixels.
References gz::math::equal(), std::isinf(), numeric_limits::lowest(), numeric_limits::max(), and Image::SetFromData().
◆ Data() [1/2]
| std::vector<unsigned char> Data | ( | ) | const |
Get the image as a data array.
- Returns
- The image data
◆ Data() [2/2]
| void Data | ( | unsigned char ** | _data, |
| unsigned int & | _count | ||
| ) | const |
Get the image as a data array.
- Deprecated:
- Use the function returning std::vector instead
- Parameters
-
[out] _data Pointer to a NULL array of char. [out] _count The resulting data array size
◆ Filename()
| std::string Filename | ( | ) | const |
Get the full filename of the image.
- Returns
- The filename used to load the image
◆ Height()
| unsigned int Height | ( | ) | const |
Get the height.
- Returns
- The image height
◆ Load()
| int Load | ( | const std::string & | _filename | ) |
Load an image. Return 0 on success.
- Parameters
-
[in] _filename the path to the image file
- Returns
- 0 when the operation succeeds to open a file or -1 when fails.
◆ MaxColor()
| math::Color MaxColor | ( | ) | const |
Get the max color.
- Returns
- The max color
◆ Pitch()
| int Pitch | ( | ) | const |
- Returns
- The pitch of the image
◆ Pixel()
| math::Color Pixel | ( | const unsigned int | _x, |
| const unsigned int | _y | ||
| ) | const |
Get a pixel color value.
- Parameters
-
[in] _x Column location in the image [in] _y Row location in the image
- Returns
- The color of the given pixel
◆ PixelFormat()
| PixelFormatType PixelFormat | ( | ) | const |
Get the pixel format.
- Returns
- PixelFormat
◆ Rescale()
| void Rescale | ( | const int | _width, |
| const int | _height | ||
| ) |
Rescale the image.
- Parameters
-
[in] _width New image width [in] _height New image height
◆ RGBAData() [1/2]
| std::vector<unsigned char> RGBAData | ( | ) | const |
Get the RGBA data from the image. This will add an alpha channel if one is not present.
- Returns
- The image RGBA data
◆ RGBAData() [2/2]
| void RGBAData | ( | unsigned char ** | _data, |
| unsigned int & | _count | ||
| ) | const |
Get the RGBA data from the image. This will add an alpha channel if one is not present.
- Deprecated:
- Use the function returning std::vector instead
- Parameters
-
[out] _data Pointer to a NULL array of char. [out] _count The resulting data array size
◆ RGBData() [1/2]
| std::vector<unsigned char> RGBData | ( | ) | const |
Get only the RGB data from the image. This will drop the alpha channel if one is present.
- Returns
- The image RGB data
◆ RGBData() [2/2]
| void RGBData | ( | unsigned char ** | _data, |
| unsigned int & | _count | ||
| ) | const |
Get only the RGB data from the image. This will drop the alpha channel if one is present.
- Deprecated:
- Use the function returning std::vector instead
- Parameters
-
[out] _data Pointer to a NULL array of char. [out] _count The resulting data array size
◆ SavePNG()
| void SavePNG | ( | const std::string & | _filename | ) |
Save the image in PNG format.
- Parameters
-
[in] _filename The name of the saved image
◆ SavePNGToBuffer()
| void SavePNGToBuffer | ( | std::vector< unsigned char > & | _buffer | ) |
Get the PNG image in a buffer.
- Parameters
-
[out] _buffer Buffer with the data
◆ SetFromCompressedData()
| void SetFromCompressedData | ( | unsigned char * | _data, |
| unsigned int | _size, | ||
| Image::PixelFormatType | _format | ||
| ) |
Set the image from compressed (i.e. png) data.
- Parameters
-
[in] _data Pointer to the raw image data [in] _size Size of the buffer [in] _format Pixel format of the provided data
◆ SetFromData()
| void SetFromData | ( | const unsigned char * | _data, |
| unsigned int | _width, | ||
| unsigned int | _height, | ||
| Image::PixelFormatType | _format | ||
| ) |
Set the image from raw data.
- Parameters
-
[in] _data Pointer to the raw image data [in] _width Width in pixels [in] _height Height in pixels [in] _format Pixel format of the provided data
Referenced by Image::ConvertToRGBImage().
◆ Valid()
| bool Valid | ( | ) | const |
Returns whether this is a valid image.
- Returns
- true if image has a bitmap
◆ Width()
| unsigned int Width | ( | ) | const |
Get the width.
- Returns
- The image width
The documentation for this class was generated from the following file: