47 printf(
"There is a problem reading an image\n");
48 printf(
"incoming: width %zu, height %zu, code %zu, quantum %zu, topIsLow %zu, size %zu\n",
49 static_cast<size_t>(header.
width),
50 static_cast<size_t>(header.
height),
51 static_cast<size_t>(header.
id),
52 static_cast<size_t>(header.
quantum),
53 static_cast<size_t>(header.
topIsLow),
54 static_cast<size_t>(header.
imgSize));
55 printf(
"my space: width %zu, height %zu, code %d, quantum %zu, size %zu\n",
128 size_t quantum,
bool topIsLow) {
164 pImage->
imageData =
const_cast<char*
>(
reinterpret_cast<const char*
>(buf));
187 for (
int r = 0; r < height; r++)
284 printf (
"*** Trying to allocate an invalid pixel type image\n");
330const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
364void Image::initialize() {
365 implementation =
nullptr;
367 imgWidth = imgHeight = 0;
368 imgPixelSize = imgRowSize = 0;
373 yAssert(implementation!=
nullptr);
378 if (implementation!=
nullptr) {
380 implementation =
nullptr;
406 if (code!=imgPixelCode) {
410 if (imgPixelCode!=(
static_cast<ImageStorage*
>(implementation))->extern_type_id) {
413 if (imgQuantum!=(
static_cast<ImageStorage*
>(implementation))->extern_type_quantum) {
422 (
static_cast<ImageStorage*
>(implementation))->resize(imgWidth,
441 this->imgPixelCode = imgPixelCode;
442 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(
static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
444 if (implementation) {
445 auto* impl =
static_cast<ImageStorage*
>(implementation);
452 this->imgQuantum = imgQuantum;
454 if (implementation) {
455 auto* impl =
static_cast<ImageStorage*
>(implementation);
460void Image::synchronize() {
461 auto* impl =
static_cast<ImageStorage*
>(implementation);
463 if (impl->pImage!=
nullptr) {
464 imgWidth = impl->pImage->width;
465 imgHeight = impl->pImage->height;
467 imgQuantum = impl->quantum;
468 imgRowSize = impl->pImage->widthStep;
480 auto* impl =
static_cast<ImageStorage*
>(implementation);
482 if (impl->pImage!=
nullptr) {
483 return reinterpret_cast<unsigned char*
>(impl->pImage->imageData);
489 auto* impl =
static_cast<ImageStorage*
>(implementation);
491 if (impl->pImage!=
nullptr) {
492 return impl->pImage->imageSize;
504 bool ok =
connection.expectBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
524 if (
q !=
static_cast<size_t>(header.
quantum)) {
541 flex.setPixelCode(header.
id);
555 connection.appendBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
596 if (
width() !=
alt.width())
return false;
597 if (
height() !=
alt.height())
return false;
598 if (imgPixelCode !=
alt.imgPixelCode)
return false;
607 unsigned char*
raw2 =
alt.getRawImage();
610 if (*
raw1 != *
raw2) {
return false; }
635 int q1 =
alt.getQuantum();
649 copyPixels(
alt.getRawImage(),
alt.getPixelCode(),
662 yAssert(
dynamic_cast<FlexImage*
>(
this) || getPixelCode() ==
alt.getPixelCode() ||
alt.getPixelCode() == 0);
679 std::swap(
alt.implementation, implementation);
691 (
static_cast<ImageStorage*
>(implementation))->_alloc_complete_extern(data,
709 return copy(img,w,h);
717 return copy(img,w,h);
728 float di = (
static_cast<float>(h))/
nh;
729 float dj = (
static_cast<float>(w))/
nw;
731 for (
size_t i=0;
i<
nh;
i++)
733 auto i0 =
static_cast<size_t>(
di*
i);
734 for (
size_t j=0;
j<
nw;
j++)
736 auto j0 =
static_cast<size_t>(
dj*
j);
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
@ 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
void iplDeallocateHeader(MiniIplImage *image)
MiniIplImage * iplCreateImageHeader(int nChannels, int depth, int origin, int align, int width, int height)
void iplAllocateImage(MiniIplImage *image)
void iplDeallocateImage(MiniIplImage *image)
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)
A mini-server for performing network communication in the background.
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.
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 operator==(const Image &alt) const
Comparison operator.
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 resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
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.
An interface to the operating system, including Port based communication.
size_t PAD_BYTES(size_t len, size_t pad)
computes the padding of YARP images.
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
int widthStep
size of aligned image row in bytes
int width
image width in pixels