7#ifndef YARP_SIG_IMAGE_H
8#define YARP_SIG_IMAGE_H
32 const size_t rem = len % pad;
33 return (rem != 0) ? (pad - rem) : rem;
140 bool copy(
const Image& alt,
size_t w,
size_t h);
163 inline size_t width()
const {
return imgWidth; }
169 inline size_t height()
const {
return imgHeight; }
204 const size_t ret=imgRowSize-imgWidth*imgPixelSize;
216 return reinterpret_cast<unsigned char *
>(data[r]);
225 inline const unsigned char *
getRow(
size_t r)
const
228 return reinterpret_cast<const unsigned char *
>(data[r]);
238 return reinterpret_cast<unsigned char *
>(data[y] + x*imgPixelSize);
247 inline bool isPixel(
size_t x,
size_t y)
const {
248 return (x<imgWidth && y<imgHeight);
265 void resize(
size_t imgWidth,
size_t imgHeight);
281 void setExternal(
const void *data,
size_t imgWidth,
size_t imgHeight);
352 static const std::map<YarpVocabPixelTypesEnum, size_t> pixelCode2Size;
353 size_t imgWidth, imgHeight, imgPixelSize, imgRowSize, imgQuantum;
363 void copyPixels(
const unsigned char *src,
size_t id1,
364 unsigned char *dest,
size_t id2,
size_t w,
size_t h,
365 size_t imageSize,
size_t quantum1,
size_t quantum2,
366 bool topIsLow1,
bool topIsLow2);
406typedef unsigned char PixelMono;
428 PixelRgb() =
default;
429 PixelRgb(
unsigned char n_r,
446 PixelRgba() =
default;
447 PixelRgba(
unsigned char n_r,
476 PixelBgra() =
default;
477 PixelBgra(
unsigned char n_r,
500 PixelBgr() =
default;
501 PixelBgr(
unsigned char n_r,
unsigned char n_g,
unsigned char n_b) :
525typedef char PixelMonoSigned;
542typedef float PixelFloat;
554 PixelRgbFloat() =
default;
555 PixelRgbFloat(
float n_r,
576 PixelRgbInt() =
default;
632 inline T&
pixel(
size_t x,
size_t y) {
636 inline T&
pixel(
size_t x,
size_t y)
const {
649 if (!
isPixel(x,y)) {
return nullPixel; }
654 if (!
isPixel(x,y)) {
return nullPixel; }
733 return -(
static_cast<int>(
sizeof(T)));
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
@ VOCAB_PIXEL_MONO_SIGNED
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB8
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG16
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG16
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB16
RandScalar * implementation(void *t)
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
static Type byName(const char *name)
Image class with user control of representation details.
void setQuantum(size_t imgQuantum)
void setPixelCode(int imgPixelCode)
void setPixelSize(size_t imgPixelSize)
T & safePixel(size_t x, size_t y)
T & pixel(size_t x, size_t y)
const T & operator()(size_t x, size_t y) const
int getPixelCode() const override
Gets pixel type identifier.
T & operator()(size_t x, size_t y)
size_t getPixelSize() const override
Gets pixel size in memory in bytes.
const T & safePixel(size_t x, size_t y) const
T & pixel(size_t x, size_t y) const
Base class for storing images.
bool swap(Image &alt)
swap operator.
Image & operator=(const Image &alt)
Assignment operator.
bool topIsLowIndex() const
unsigned char * getRow(size_t r)
Get the address of a the first byte of a row in memory.
void resize(const Image &alt)
Reallocate the size of the image to match another, throwing away the actual content of the image.
void setQuantum(size_t imgQuantum)
size_t width() const
Gets width of image in pixels.
size_t getPadding() const
Returns the number of padding bytes.
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
void setPixelCode(int imgPixelCode)
bool move(Image &&alt) noexcept
move operator.
char ** getRowArray()
Get an array of pointers to the rows of the image.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
size_t getRowSize() const
Size of the underlying image buffer rows.
unsigned char * getRawImage() const
Access to the internal image buffer.
Image()
Default constructor.
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
bool copy(const Image &alt)
Copy operator.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
~Image() override
Destructor.
void setPixelSize(size_t imgPixelSize)
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
yarp::os::Type getReadType() const override
bool isPixel(size_t x, size_t y) const
Check whether a coordinate lies within the image.
void setTopIsLowIndex(bool flag)
control whether image has origin at top left (default) or bottom left.
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
void zero()
Set all pixels to 0.
size_t height() const
Gets height of image in pixels.
const unsigned char * getRow(size_t r) const
Get the address of a the first byte of a row in memory, const versions.
virtual int getPixelCode() const
Gets pixel type identifier.
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
std::uint16_t NetUint16
Definition of the NetUint16 type.
std::int32_t NetInt32
Definition of the NetInt32 type.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
size_t PAD_BYTES(size_t len, size_t pad)
computes the padding of YARP images.
The main, catch-all namespace for YARP.
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING
Suppress MSVC C4251 warning for the next line.
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.