54 printf(
"There is a problem reading an image\n");
55 printf(
"incoming: width %zu, height %zu, code %zu, quantum %zu, topIsLow %zu, size %zu\n",
56 static_cast<size_t>(header.
width),
57 static_cast<size_t>(header.
height),
58 static_cast<size_t>(header.
id),
59 static_cast<size_t>(header.
quantum),
60 static_cast<size_t>(header.
topIsLow),
61 static_cast<size_t>(header.
imgSize));
62 printf(
"my space: width %zu, height %zu, code %d, quantum %zu, size %zu\n",
66 bool ok = connection.
expectBlock(
reinterpret_cast<char*
>(mem), allocatedBytes);
67 return (!connection.
isError() && ok);
109 int _pad_bytes (
size_t linesize,
size_t align)
const;
132 void resize(
size_t x,
size_t y,
int pixel_type,
141 size_t quantum,
bool topIsLow) {
142 int need_recreation = 1;
148 if (need_recreation) {
150 DBGPF1 printf(
"HIT recreation for %p %p: %zu %zu %d\n",
static_cast<void*
>(
this),
static_cast<void*
>(
pImage), x, y, pixel_type);
187 pImage->
imageData =
const_cast<char*
>(
reinterpret_cast<const char*
>(buf));
196 DBGPF1 printf(
"alloc_data1\n"), fflush(stdout);
213 for (
int r = 0; r < height; r++)
218 Data[height-r-1] = DataArea;
222 DBGPF1 printf(
"alloc_data4\n");
334 printf (
"*** Trying to allocate an invalid pixel type image\n");
349 pImage =
iplCreateImageHeader(param.
nChannels, 0, param.
depth,
const_cast<char*
>(param.
colorModel),
const_cast<char*
>(param.
channelSeq),
IPL_DATA_ORDER_PIXEL, origin,
quantum, x, y,
nullptr,
nullptr,
nullptr,
nullptr);
381const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
415void Image::initialize() {
416 implementation =
nullptr;
418 imgWidth = imgHeight = 0;
419 imgPixelSize = imgRowSize = 0;
424 yAssert(implementation!=
nullptr);
429 if (implementation!=
nullptr) {
431 implementation =
nullptr;
457 if (code!=imgPixelCode) {
461 if (imgPixelCode!=(
static_cast<ImageStorage*
>(implementation))->extern_type_id) {
464 if (imgQuantum!=(
static_cast<ImageStorage*
>(implementation))->extern_type_quantum) {
473 (
static_cast<ImageStorage*
>(implementation))->resize(imgWidth,
492 this->imgPixelCode = imgPixelCode;
493 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(
static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
495 if (implementation) {
496 auto* impl =
static_cast<ImageStorage*
>(implementation);
503 this->imgQuantum = imgQuantum;
505 if (implementation) {
506 auto* impl =
static_cast<ImageStorage*
>(implementation);
515 if (implementation) {
516 auto* impl =
static_cast<ImageStorage*
>(implementation);
523void Image::synchronize() {
524 auto* impl =
static_cast<ImageStorage*
>(implementation);
526 if (impl->pImage!=
nullptr) {
527 imgWidth = impl->pImage->width;
528 imgHeight = impl->pImage->height;
530 imgQuantum = impl->quantum;
531 imgRowSize = impl->pImage->widthStep;
543 auto* impl =
static_cast<ImageStorage*
>(implementation);
545 if (impl->pImage!=
nullptr) {
546 return reinterpret_cast<unsigned char*
>(impl->pImage->imageData);
552 auto* impl =
static_cast<ImageStorage*
>(implementation);
554 if (impl->pImage!=
nullptr) {
555 return impl->pImage->imageSize;
560#ifndef YARP_NO_DEPRECATED
562 return (
static_cast<ImageStorage*
>(implementation))->pImage;
566 return (
static_cast<const ImageStorage*
>(implementation))->pImage;
571 auto* p =
static_cast<IplImage *
>(iplImage);
575 if (str==
"rgb"||str==
"RGB"||
576 str==
"bgr"||str==
"BGR"||
577 str==
"gray"||str==
"GRAY"||
578 str==
"graygray"||str==
"GRAYGRAY") {
580 if (str==
"rgb"||str==
"RGB") {
582 }
else if (str==
"bgr"||str==
"BGR") {
584 }
else if (str==
"gray"||str==
"GRAY"||
585 str==
"graygray"||str==
"GRAYGRAY") {
588 printf(
"specific IPL RGB order (%s) is not yet supported\n",
590 printf(
"Try RGB, BGR, or \n");
591 printf(
"Or fix code at %s line %d\n",__FILE__,__LINE__);
601 switch (color_code) {
613 switch (color_code) {
619 fprintf(stderr,
"No translation currently available for this pixel type\n");
624 switch (color_code) {
634 switch (color_code) {
646 fprintf(stderr,
"IPL pixel type / depth combination is not yet supported\n");
647 fprintf(stderr,
"Please email a YARP developer to complain, quoting this:\n");
648 fprintf(stderr,
" %s:%d\n", __FILE__, __LINE__);
652 printf(
"your specific IPL format (%s depth %d -> %s) does not match your YARP format (%s)\n",
657 printf(
"Making a copy instead of just wrapping...\n");
662 img.
setExternal(p->imageData, p->width, p->height);
682 bool ok = connection.
expectBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
702 if (q !=
static_cast<size_t>(header.
quantum)) {
712 if (
getPixelCode() == header.
id && q ==
static_cast<size_t>(header.
quantum) && imgPixelSize ==
static_cast<size_t>(header.
depth))
789 connection.
appendBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
896 std::swap(alt.implementation, implementation);
908 (
static_cast<ImageStorage*
>(implementation))->_alloc_complete_extern(data,
927 return copy(img,w,h);
936 return copy(img,w,h);
947 float di = (
static_cast<float>(h))/nh;
948 float dj = (
static_cast<float>(w))/nw;
950 for (
size_t i=0; i<nh; i++)
952 auto i0 =
static_cast<size_t>(di*i);
953 for (
size_t j=0; j<nw; j++)
955 auto j0 =
static_cast<size_t>(dj*j);
bool deBayer_GRBG8_TO_RGB(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
bool deBayer_GRBG8_TO_BGR(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
bool isBayer8(int v)
Basic implementations of debayering functions.
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
const pixelTypeIplParams iplPixelTypeMono16
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
const pixelTypeIplParams iplPixelTypeMono
void iplDeallocateImage(IplImage *image)
IplImage * iplCreateImageHeader(int nChannels, int alphaChannel, int depth, char *colorModel, char *channelSeq, int dataOrder, int origin, int align, int width, int height, IplROI *roi, IplImage *maskROI, void *imageId, IplTileInfo *tileInfo)
void iplAllocateImageFP(IplImage *image, int doFill, float fillValue)
void iplSetBorderMode(IplImage *src, int mode, int border, int constVal)
void iplDeallocate(IplImage *image, int flag)
void iplAllocateImage(IplImage *image, int doFill, int fillValue)
#define YARP_FIXME_NOTIMPLEMENTED(what)
RandScalar * implementation(void *t)
ImageStorage(Image &owner)
void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
size_t extern_type_quantum
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
int _pad_bytes(size_t linesize, size_t align) const
void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
void _alloc_extern(const void *buf)
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
An interface for writing to a network connection.
virtual bool isError() const =0
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Image class with user control of representation details.
void setQuantum(size_t imgQuantum)
void setPixelCode(int imgPixelCode)
Base class for storing images.
bool swap(Image &alt)
swap operator.
Image & operator=(const Image &alt)
Assignment operator.
bool topIsLowIndex() const
void wrapIplImage(void *iplImage)
Act as a wrapper around an IPL/OpenCV image.
void setQuantum(size_t imgQuantum)
size_t width() const
Gets width of image in pixels.
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
void setPixelCode(int imgPixelCode)
bool move(Image &&alt) noexcept
move operator.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
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 * getIplImage()
Returns IPL/OpenCV view of image, if possible.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
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.
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.
#define IPL_BORDER_CONSTANT
#define IPL_DATA_ORDER_PIXEL
@ 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
yarp::rosmsg::sensor_msgs::Image Image
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
An interface to the operating system, including Port based communication.
char PixelMonoSigned
Signed byte pixel type.
size_t PAD_BYTES(size_t len, size_t pad)
computes the padding of YARP images.
yarp::os::NetUint16 PixelMono16
16-bit monochrome pixel type.
unsigned char PixelMono
Monochrome pixel type.
float PixelFloat
Floating point pixel type.
yarp::os::NetInt32 PixelInt
32-bit integer pixel type.
int nChannels
Most of OpenCV functions support 1,2,3 or 4 channels.
int height
image height in pixels
char * imageData
pointer to aligned image data
char colorModel[4]
ignored by OpenCV
int origin
0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style)
int widthStep
size of aligned image row in bytes
int width
image width in pixels
Packed RGB pixel type, with pixels stored in reverse order.
Floating point HSV pixel type.
Packed HSV (hue/saturation/value pixel type.
Floating point RGB pixel type.
Signed, packed RGB pixel type.