Go to the documentation of this file.
17 #ifndef GZ_COMMON_IMAGE_HH_
18 #define GZ_COMMON_IMAGE_HH_
25 #include <gz/math/Color.hh>
26 #include <gz/common/graphics/Export.hh>
40 "UNKNOWN_PIXEL_FORMAT",
64 class IGNITION_COMMON_GRAPHICS_VISIBLE
Image
69 UNKNOWN_PIXEL_FORMAT = 0,
104 public:
virtual ~
Image();
113 public:
void SavePNG(
const std::string &_filename);
124 public:
void SetFromData(
const unsigned char *_data,
126 unsigned int _height,
132 public:
void Data(
unsigned char **_data,
133 unsigned int &_count)
const;
139 public:
void RGBData(
unsigned char **_data,
140 unsigned int &_count)
const;
144 public:
unsigned int Width()
const;
148 public:
unsigned int Height()
const;
152 public:
unsigned int BPP()
const;
156 public:
int Pitch()
const;
164 public: PixelFormatType PixelFormat()
const;
171 const unsigned int _y)
const;
184 public:
void Rescale(
const int _width,
const int _height);
188 public:
bool Valid()
const;
206 public:
template<
typename T>
208 unsigned int _width,
unsigned int _height,
Image &_output,
212 unsigned int samples = _width * _height;
213 unsigned int bufferSize = samples *
sizeof(T);
216 memcpy(buffer.data(), _data, bufferSize);
225 for (
unsigned int i = 0; i < samples; ++i)
231 if (v > max && !
std::isinf(
static_cast<float>(v)))
233 if (v < min && !
std::isinf(
static_cast<float>(v)))
242 double range =
static_cast<double>(max - min);
243 if (gz::math::equal(range, 0.0))
245 unsigned int idx = 0;
246 for (
unsigned int j = 0; j < _height; ++j)
248 for (
unsigned int i = 0; i < _width; ++i)
250 auto v = buffer[idx++];
251 double t =
static_cast<double>(v - min) / range;
254 uint8_t r =
static_cast<uint8_t
>(255*t);
255 unsigned int outIdx = j * _width * 3 + i * 3;
256 outputRgbBuffer[outIdx] = r;
257 outputRgbBuffer[outIdx + 1] = r;
258 outputRgbBuffer[outIdx + 2] = r;
261 _output.
SetFromData(outputRgbBuffer.data(), _width, _height, RGB_INT8);
Forward declarations for the common classes.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
@ BGR_INT8
Definition: gz/common/Image.hh:77
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
@ L_INT8
Definition: gz/common/Image.hh:70
@ RGBA_INT8
Definition: gz/common/Image.hh:73
@ L_INT16
Definition: gz/common/Image.hh:71
@ BAYER_RGGB8
Definition: gz/common/Image.hh:84
@ BGR_INT16
Definition: gz/common/Image.hh:78
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: gz/common/Image.hh:38
@ BAYER_GBRG8
Definition: gz/common/Image.hh:86
void SetFromData(const unsigned char *_data, unsigned int _width, unsigned int _height, Image::PixelFormatType _format)
Set the image from raw data.
@ PIXEL_FORMAT_COUNT
Definition: gz/common/Image.hh:88
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,...
Definition: gz/common/Image.hh:207
@ BGR_INT32
Definition: gz/common/Image.hh:79
@ RGB_INT16
Definition: gz/common/Image.hh:75
@ RGB_INT32
Definition: gz/common/Image.hh:76
@ RGB_FLOAT32
Definition: gz/common/Image.hh:83
@ RGB_FLOAT16
Definition: gz/common/Image.hh:81
@ RGB_INT8
Definition: gz/common/Image.hh:72
@ BAYER_GRBG8
Definition: gz/common/Image.hh:87
@ BAYER_RGGR8
Definition: gz/common/Image.hh:85
@ R_FLOAT16
Definition: gz/common/Image.hh:80
@ BGRA_INT8
Definition: gz/common/Image.hh:74
@ R_FLOAT32
Definition: gz/common/Image.hh:82
PixelFormatType
Pixel formats enumeration.
Definition: gz/common/Image.hh:67
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
Encapsulates an image.
Definition: gz/common/Image.hh:64