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>
27 #include <ignition/utils/ImplPtr.hh>
37 "UNKNOWN_PIXEL_FORMAT",
60 class IGNITION_COMMON_GRAPHICS_VISIBLE
Image
65 UNKNOWN_PIXEL_FORMAT = 0,
99 public:
virtual ~
Image();
108 public:
void SavePNG(
const std::string &_filename);
119 public:
void SetFromData(
const unsigned char *_data,
121 unsigned int _height,
127 public:
void Data(
unsigned char **_data,
unsigned int &_count);
133 public:
void RGBData(
unsigned char **_data,
unsigned int &_count);
137 public:
unsigned int Width()
const;
141 public:
unsigned int Height()
const;
145 public:
unsigned int BPP()
const;
149 public:
int Pitch()
const;
157 public: PixelFormatType PixelFormat()
const;
164 const unsigned int _y)
const;
177 public:
void Rescale(
const int _width,
const int _height);
181 public:
bool Valid()
const;
199 public:
template<
typename T>
201 unsigned int _width,
unsigned int _height,
Image &_output,
205 unsigned int samples = _width * _height;
206 unsigned int bufferSize = samples *
sizeof(T);
209 memcpy(buffer.data(), _data, bufferSize);
218 for (
unsigned int i = 0; i < samples; ++i)
224 if (v > max && !
std::isinf(
static_cast<float>(v)))
226 if (v < min && !
std::isinf(
static_cast<float>(v)))
235 double range =
static_cast<double>(max - min);
238 unsigned int idx = 0;
239 for (
unsigned int j = 0; j < _height; ++j)
241 for (
unsigned int i = 0; i < _width; ++i)
243 auto v = buffer[idx++];
244 double t =
static_cast<double>(v - min) / range;
247 uint8_t r =
static_cast<uint8_t
>(255*t);
248 unsigned int outIdx = j * _width * 3 + i * 3;
249 outputRgbBuffer[outIdx] = r;
250 outputRgbBuffer[outIdx + 1] = r;
251 outputRgbBuffer[outIdx + 2] = r;
254 _output.
SetFromData(outputRgbBuffer.data(), _width, _height, RGB_INT8);
258 IGN_UTILS_IMPL_PTR(dataPtr)
Forward declarations for the common classes.
@ BGR_INT8
Definition: Image.hh:73
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
@ L_INT8
Definition: Image.hh:66
@ RGBA_INT8
Definition: Image.hh:69
@ L_INT16
Definition: Image.hh:67
@ BAYER_RGGB8
Definition: Image.hh:80
@ BGR_INT16
Definition: Image.hh:74
@ BAYER_BGGR8
Definition: Image.hh:81
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:35
@ BAYER_GBRG8
Definition: Image.hh:82
void SetFromData(const unsigned char *_data, unsigned int _width, unsigned int _height, Image::PixelFormatType _format)
Set the image from raw data.
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:200
@ BGR_INT32
Definition: Image.hh:75
@ RGB_INT16
Definition: Image.hh:71
@ RGB_INT32
Definition: Image.hh:72
@ RGB_FLOAT32
Definition: Image.hh:79
@ RGB_FLOAT16
Definition: Image.hh:77
@ RGB_INT8
Definition: Image.hh:68
@ BAYER_GRBG8
Definition: Image.hh:83
@ R_FLOAT16
Definition: Image.hh:76
@ BGRA_INT8
Definition: Image.hh:70
@ R_FLOAT32
Definition: Image.hh:78
PixelFormatType
Pixel formats enumeration.
Definition: Image.hh:63
Encapsulates an image.
Definition: Image.hh:60