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;
148 bool copy(
const Image& alt,
size_t w,
size_t h);
171 inline size_t width()
const {
return imgWidth; }
177 inline size_t height()
const {
return imgHeight; }
212 const size_t ret=imgRowSize-imgWidth*imgPixelSize;
224 return reinterpret_cast<unsigned char *
>(data[r]);
233 inline const unsigned char *
getRow(
size_t r)
const
236 return reinterpret_cast<const unsigned char *
>(data[r]);
246 return reinterpret_cast<unsigned char *
>(data[y] + x*imgPixelSize);
255 inline bool isPixel(
size_t x,
size_t y)
const {
256 return (x<imgWidth && y<imgHeight);
273 void resize(
size_t imgWidth,
size_t imgHeight);
289 void setExternal(
const void *data,
size_t imgWidth,
size_t imgHeight);
341 static const std::map<YarpVocabPixelTypesEnum, size_t> pixelCode2Size;
342 size_t imgWidth, imgHeight, imgPixelSize, imgRowSize, imgQuantum;
352 void copyPixels(
const unsigned char *src,
size_t id1,
353 unsigned char *dest,
size_t id2,
size_t w,
size_t h,
354 size_t imageSize,
size_t quantum1,
size_t quantum2,
355 bool topIsLow1,
bool topIsLow2);
395typedef unsigned char PixelMono;
417 PixelRgb() =
default;
418 PixelRgb(
unsigned char n_r,
435 PixelRgba() =
default;
436 PixelRgba(
unsigned char n_r,
465 PixelBgra() =
default;
466 PixelBgra(
unsigned char n_r,
489 PixelBgr() =
default;
490 PixelBgr(
unsigned char n_r,
unsigned char n_g,
unsigned char n_b) :
514typedef char PixelMonoSigned;
531typedef float PixelFloat;
543 PixelRgbFloat() =
default;
544 PixelRgbFloat(
float n_r,
565 PixelRgbInt() =
default;
621 inline T&
pixel(
size_t x,
size_t y) {
625 inline T&
pixel(
size_t x,
size_t y)
const {
638 if (!
isPixel(x,y)) {
return nullPixel; }
643 if (!
isPixel(x,y)) {
return nullPixel; }
722 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 operator==(const Image &alt) const
Comparison operator.
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.
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.