Go to the documentation of this file.
17 #ifndef IGNITION_COMMON_IMAGE_HH_
18 #define IGNITION_COMMON_IMAGE_HH_
25 #include <ignition/common/graphics/Export.hh>
39 "UNKNOWN_PIXEL_FORMAT",
63 class IGNITION_COMMON_GRAPHICS_VISIBLE
Image
68 UNKNOWN_PIXEL_FORMAT = 0,
103 public:
virtual ~
Image();
112 public:
void SavePNG(
const std::string &_filename);
123 public:
void SetFromData(
const unsigned char *_data,
125 unsigned int _height,
131 public:
void Data(
unsigned char **_data,
132 unsigned int &_count)
const;
138 public:
void RGBData(
unsigned char **_data,
139 unsigned int &_count)
const;
143 public:
unsigned int Width()
const;
147 public:
unsigned int Height()
const;
151 public:
unsigned int BPP()
const;
155 public:
int Pitch()
const;
163 public: PixelFormatType PixelFormat()
const;
170 const unsigned int _y)
const;
183 public:
void Rescale(
const int _width,
const int _height);
187 public:
bool Valid()
const;
205 public:
template<
typename T>
207 unsigned int _width,
unsigned int _height,
Image &_output,
211 unsigned int samples = _width * _height;
212 unsigned int bufferSize = samples *
sizeof(T);
215 memcpy(buffer.data(), _data, bufferSize);
224 for (
unsigned int i = 0; i < samples; ++i)
230 if (v > max && !
std::isinf(
static_cast<float>(v)))
232 if (v < min && !
std::isinf(
static_cast<float>(v)))
241 double range =
static_cast<double>(max - min);
244 unsigned int idx = 0;
245 for (
unsigned int j = 0; j < _height; ++j)
247 for (
unsigned int i = 0; i < _width; ++i)
249 auto v = buffer[idx++];
250 double t =
static_cast<double>(v - min) / range;
253 uint8_t r =
static_cast<uint8_t
>(255*t);
254 unsigned int outIdx = j * _width * 3 + i * 3;
255 outputRgbBuffer[outIdx] = r;
256 outputRgbBuffer[outIdx + 1] = r;
257 outputRgbBuffer[outIdx + 2] = r;
260 _output.
SetFromData(outputRgbBuffer.data(), _width, _height, RGB_INT8);
Forward declarations for the common classes.
@ BGR_INT8
Definition: Image.hh:76
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
@ L_INT8
Definition: Image.hh:69
@ RGBA_INT8
Definition: Image.hh:72
@ L_INT16
Definition: Image.hh:70
@ BAYER_RGGB8
Definition: Image.hh:83
@ BGR_INT16
Definition: Image.hh:77
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:37
@ BAYER_GBRG8
Definition: Image.hh:85
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: Image.hh:87
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: Image.hh:206
@ BGR_INT32
Definition: Image.hh:78
@ RGB_INT16
Definition: Image.hh:74
@ RGB_INT32
Definition: Image.hh:75
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
@ RGB_FLOAT32
Definition: Image.hh:82
@ RGB_FLOAT16
Definition: Image.hh:80
@ RGB_INT8
Definition: Image.hh:71
@ BAYER_GRBG8
Definition: Image.hh:86
@ BAYER_RGGR8
Definition: Image.hh:84
@ R_FLOAT16
Definition: Image.hh:79
@ BGRA_INT8
Definition: Image.hh:73
@ R_FLOAT32
Definition: Image.hh:81
PixelFormatType
Pixel formats enumeration.
Definition: Image.hh:66
Encapsulates an image.
Definition: Image.hh:63