YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Image.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
8 This file is in a pretty hacky state. Sorry!
9
10*/
11
12#include <yarp/sig/Image.h>
13
14#include <yarp/os/Bottle.h>
17#include <yarp/os/Log.h>
18#include <yarp/os/Time.h>
19#include <yarp/os/Vocab.h>
20
23
24#include <cstdio>
25#include <cstring>
26#include <string>
27#include <utility>
28
29
30using namespace yarp::sig;
31using namespace yarp::os;
32
33#define DBGPF1 if (0)
34
40{
41 dest.resize(header.width, header.height);
42 unsigned char *mem = dest.getRawImage();
43 size_t allocatedBytes = dest.getRawImageSize();
44 yAssert(mem != nullptr);
45 //this check is redundant with assertion, I would remove it
46 if (dest.getRawImageSize() != static_cast<size_t>(header.imgSize)) {
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",
56 dest.width(), dest.height(), dest.getPixelCode(), dest.getQuantum(), allocatedBytes);
57 }
58 yAssert(allocatedBytes == (size_t) header.imgSize);
59 bool ok = connection.expectBlock(reinterpret_cast<char*>(mem), allocatedBytes);
60 return (!connection.isError() && ok);
61}
62
63
64
66public:
68 char **Data; // this is not IPL. it's char to maintain IPL compatibility
71 size_t quantum;
74
75protected:
77
79
80 // ipl allocation is done in two steps.
81 // _alloc allocates the actual ipl pointer.
82 // _alloc_data allocates the image array and data.
83 // memory is allocated in a single chunk. Row ptrs are then
84 // made to point appropriately. This is compatible with IPL and
85 // SOMEONE says it's more efficient on NT.
86 void _alloc ();
87 void _alloc_extern (const void *buf);
88 void _alloc_data ();
89 void _free ();
90
91 bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum,
92 bool topIsLow);
93 void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum,
94 bool topIsLow);
95 void _free_complete();
96
97
98 // computes the # of padding bytes. These are always at the end of the row.
99 int _pad_bytes (size_t linesize, size_t align) const;
100
101 inline int GetPadding() const {
104 }
105
106public:
108 type_id = 0;
109 pImage = nullptr;
110 Data = nullptr;
111 is_owner = 1;
112 quantum = 0;
113 topIsLow = true;
114 extern_type_id = 0;
116 }
117
121
122 void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow);
123 void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow);
124};
125
126
127void ImageStorage::resize(size_t x, size_t y, int pixel_type,
128 size_t quantum, bool topIsLow) {
129 int need_recreation = 1;
130
131 if (quantum==0) {
133 }
134
135 if (need_recreation) {
137 DBGPF1 printf("HIT recreation for %p %p: %zu %zu %d\n", static_cast<void*>(this), static_cast<void*>(pImage), x, y, pixel_type);
139 }
142}
143
144// allocates an empty image.
146{
147 _free(); // was iplDeallocateImage(pImage); but that won't work with refs
148
150}
151
152// installs an external buffer as the image data
153void ImageStorage::_alloc_extern (const void *buf)
154{
155 yAssert(pImage != nullptr);
156 yAssert(Data==nullptr);
157
158 if (pImage != nullptr) {
159 if (pImage->imageData != nullptr) {
161 }
162 }
163
164 pImage->imageData = const_cast<char*>(reinterpret_cast<const char*>(buf));
165}
166
167// allocates the Data pointer.
169{
170 DBGPF1 printf("alloc_data1\n"), fflush(stdout);
171 yAssert(pImage != nullptr);
172
173 yAssert(Data==nullptr);
174
175 char **ptr = new char *[pImage->height];
176
177 Data = ptr;
178
179 yAssert(Data != nullptr);
180
181 yAssert(pImage->imageData != nullptr);
182
183 int height = pImage->height;
184
185 char * DataArea = pImage->imageData;
186
187 for (int r = 0; r < height; r++)
188 {
189 if (topIsLow) {
190 Data[r] = DataArea;
191 } else {
192 Data[height-r-1] = DataArea;
193 }
195 }
196 DBGPF1 printf("alloc_data4\n");
197}
198
200{
201 if (pImage != nullptr) {
202 if (pImage->imageData != nullptr) {
203 if (is_owner) {
205 delete[] Data;
206 } else {
207 delete[] Data;
208 }
209
210 is_owner = 1;
211 Data = nullptr;
212 pImage->imageData = nullptr;
213 }
214 }
215}
216
217
219{
220 _free();
221
222 if (pImage != nullptr)
223 {
225 }
226 pImage = nullptr;
227}
228
229void ImageStorage::_alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum,
230 bool topIsLow)
231{
234 _alloc ();
235 _alloc_data ();
236}
237
238
240{
242 int depth;
243};
244
273
274bool ImageStorage::_set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum,
275 bool topIsLow)
276{
277 if (pImage != nullptr) {
279 pImage = nullptr;
280 }
281
283 // not a type!
284 printf ("*** Trying to allocate an invalid pixel type image\n");
285 std::exit(1);
286 }
288 // unknown pixel type. Should revert to a non-IPL mode... how?
289 return false;
290 }
291
293
294 if (quantum==0) {
296 }
297 int origin = topIsLow ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
298
299 pImage = iplCreateImageHeader(param.nChannels, param.depth, origin, quantum, x, y);
300
302 this->quantum = quantum;
303 this->topIsLow = topIsLow;
304 return true;
305}
306
307void ImageStorage::_alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
308{
309 if (quantum==0) {
310 quantum = 1;
311 }
312 this->quantum = quantum;
313 this->topIsLow = topIsLow;
314
317 Data = nullptr;
318 _alloc_extern (buf);
319 _alloc_data ();
320 is_owner = 0;
321}
322
323
324
325int ImageStorage::_pad_bytes (size_t linesize, size_t align) const
326{
327 return yarp::sig::PAD_BYTES (linesize, align);
328}
329
330const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
333 {VOCAB_PIXEL_MONO16, sizeof(yarp::sig::PixelMono16)},
334 {VOCAB_PIXEL_RGB, sizeof(yarp::sig::PixelRgb)},
335 {VOCAB_PIXEL_RGBA, sizeof(yarp::sig::PixelRgba)},
336 {VOCAB_PIXEL_BGRA, sizeof(yarp::sig::PixelBgra)},
337 {VOCAB_PIXEL_INT, sizeof(yarp::sig::PixelInt)},
338 {VOCAB_PIXEL_HSV, sizeof(yarp::sig::PixelHsv)},
339 {VOCAB_PIXEL_BGR, sizeof(yarp::sig::PixelBgr)},
341 {VOCAB_PIXEL_RGB_SIGNED, sizeof(yarp::sig::PixelRgbSigned)},
342 {VOCAB_PIXEL_RGB_INT, sizeof(yarp::sig::PixelRgbInt)},
344 {VOCAB_PIXEL_RGB_FLOAT, sizeof(yarp::sig::PixelRgbFloat)},
345 {VOCAB_PIXEL_HSV_FLOAT, sizeof(yarp::sig::PixelHsvFloat)},
358};
359
361 initialize();
362}
363
364void Image::initialize() {
365 implementation = nullptr;
366 data = nullptr;
367 imgWidth = imgHeight = 0;
368 imgPixelSize = imgRowSize = 0;
369 imgPixelCode = 0;
370 imgQuantum = 0;
371 topIsLow = true;
372 implementation = new ImageStorage(*this);
373 yAssert(implementation!=nullptr);
374}
375
376
378 if (implementation!=nullptr) {
379 delete static_cast<ImageStorage*>(implementation);
380 implementation = nullptr;
381 }
382}
383
384
385size_t Image::getPixelSize() const {
386 return imgPixelSize;
387}
388
389
391 return imgPixelCode;
392}
393
394
396 if (getRawImage()!=nullptr) {
398 }
399}
400
401
402void Image::resize(size_t imgWidth, size_t imgHeight) {
403
404 int code = getPixelCode();
405 bool change = false;
406 if (code!=imgPixelCode) {
407 setPixelCode(code);
408 change = true;
409 }
410 if (imgPixelCode!=(static_cast<ImageStorage*>(implementation))->extern_type_id) {
411 change = true;
412 }
413 if (imgQuantum!=(static_cast<ImageStorage*>(implementation))->extern_type_quantum) {
414 change = true;
415 }
416
417 if (imgWidth!=width()||imgHeight!=height()) {
418 change = true;
419 }
420
421 if (change) {
422 (static_cast<ImageStorage*>(implementation))->resize(imgWidth,
423 imgHeight,
424 imgPixelCode,
425 imgQuantum,
426 topIsLow);
427 synchronize();
428 //printf("CHANGE! %ld\n", (long int)(this));
429 }
430}
431
432void Image::setPixelSize(size_t imgPixelSize) {
433 if(imgPixelSize == pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode))) {
434 return;
435 }
436
437 setPixelCode(-imgPixelSize);
438}
439
440void Image::setPixelCode(int imgPixelCode) {
441 this->imgPixelCode = imgPixelCode;
442 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
443
444 if (implementation) {
445 auto* impl = static_cast<ImageStorage*>(implementation);
446 impl->type_id = imgPixelCode;
447 }
448}
449
450
451void Image::setQuantum(size_t imgQuantum) {
452 this->imgQuantum = imgQuantum;
453
454 if (implementation) {
455 auto* impl = static_cast<ImageStorage*>(implementation);
456 impl->quantum = imgQuantum;
457 }
458}
459
460void Image::synchronize() {
461 auto* impl = static_cast<ImageStorage*>(implementation);
462 yAssert(impl!=nullptr);
463 if (impl->pImage!=nullptr) {
464 imgWidth = impl->pImage->width;
465 imgHeight = impl->pImage->height;
466 data = impl->Data;
467 imgQuantum = impl->quantum;
468 imgRowSize = impl->pImage->widthStep;
469 setPixelCode(impl->type_id);
470 topIsLow = impl->pImage->origin == IPL_ORIGIN_TL;
471 } else {
472 data = nullptr;
473 imgWidth = 0;
474 imgHeight = 0;
475 }
476}
477
478
479unsigned char *Image::getRawImage() const {
480 auto* impl = static_cast<ImageStorage*>(implementation);
481 yAssert(impl!=nullptr);
482 if (impl->pImage!=nullptr) {
483 return reinterpret_cast<unsigned char*>(impl->pImage->imageData);
484 }
485 return nullptr;
486}
487
489 auto* impl = static_cast<ImageStorage*>(implementation);
490 yAssert(impl!=nullptr);
491 if (impl->pImage!=nullptr) {
492 return impl->pImage->imageSize;
493 }
494 return 0;
495}
496
498
499 // auto-convert text mode interaction
500 connection.convertTextMode();
501
502 ImageNetworkHeader header;
503
504 bool ok = connection.expectBlock(reinterpret_cast<char*>(&header),sizeof(header));
505 if (!ok) {
506 return false;
507 }
508
509 //first check that the received image size is reasonable
510 if (header.width == 0 || header.height == 0)
511 {
512 // I maintain the previous logic, although we should probably return false
513 return !connection.isError();
514 }
515
516 setPixelCode(header.id);
517
518 size_t q = getQuantum();
519 if (q==0) {
520 //q = YARP_IMAGE_ALIGN;
521 setQuantum(header.quantum);
522 q = getQuantum();
523 }
524 if (q != static_cast<size_t>(header.quantum)) {
525 if ((header.depth*header.width)%header.quantum==0 &&
526 (header.depth*header.width)%q==0) {
527 header.quantum = q;
528 }
529 }
530
531 // handle easy case, received and current image are compatible, no conversion needed
532 if (getPixelCode() == header.id && q == static_cast<size_t>(header.quantum) && imgPixelSize == static_cast<size_t>(header.depth))
533 {
534 return readFromConnection(*this, header, connection);
535 }
536
537 // received and current images are binary incompatible, so
538 // prepare a FlexImage, set it to be compatible with the received image
539 // read new image into FlexImage then copy from it.
541 flex.setPixelCode(header.id);
542 flex.setQuantum(header.quantum);
543 ok = readFromConnection(flex, header, connection);
544 if (ok) {
545 copy(flex);
546 }
547
548 return ok;
549}
550
551
553 ImageNetworkHeader header;
554 header.setFromImage(*this);
555 connection.appendBlock(reinterpret_cast<char*>(&header),sizeof(header));
556 unsigned char *mem = getRawImage();
557 if (header.width!=0&&header.height!=0) {
558 yAssert(mem!=nullptr);
559
560 // Note use of external block.
561 // Implies care needed about ownership.
562 connection.appendExternalBlock(reinterpret_cast<char *>(mem),header.imgSize);
563 }
564
565 // if someone is foolish enough to connect in text mode,
566 // let them see something readable.
567 connection.convertTextMode();
568
569 return !connection.isError();
570}
571
572
574{
575 initialize();
576 copy(alt);
577}
578
580 : implementation(std::exchange(other.implementation, nullptr))
581{
582 synchronize();
583}
584
585Image& Image::operator=(Image&& other) noexcept
586{
587 delete static_cast<ImageStorage*>(implementation);
588 implementation = std::exchange(other.implementation, nullptr);
589 synchronize();
590 return *this;
591}
592
593bool Image::operator==(const Image& alt) const
594{
595 //test general properties
596 if (width() != alt.width()) return false;
597 if (height() != alt.height()) return false;
598 if (imgPixelCode != alt.imgPixelCode) return false;
599 size_t raw1size = getRawImageSize();
600 size_t raw2size = alt.getRawImageSize();
601 if (raw1size != raw2size)
602 {
603 return false;
604 }
605 //test byte per byte
606 unsigned char* raw1 = getRawImage();
607 unsigned char* raw2 = alt.getRawImage();
608 for (size_t i = 0; i < raw1size; i++, raw1++, raw2++)
609 {
610 if (*raw1 != *raw2) { return false; }
611 }
612 return true;
613}
614
616{
617 if (&alt != this) {
618 copy(alt);
619 }
620 return *this;
621}
622
623
625{
626 if (&alt != this)
627 {
628 int myCode = getPixelCode();
629 if (myCode==0) {
630 setPixelCode(alt.getPixelCode());
631 setQuantum(alt.getQuantum());
632 }
633 resize(alt.width(),alt.height());
634
635 int q1 = alt.getQuantum();
636 int q2 = getQuantum();
637 if (q1==0) { q1 = YARP_IMAGE_ALIGN; }
638 if (q2==0) { q2 = YARP_IMAGE_ALIGN; }
639
640 yAssert(width()==alt.width());
641 yAssert(height()==alt.height());
642 if (getPixelCode()==alt.getPixelCode()) {
643 if (getQuantum()==alt.getQuantum()) {
644 yAssert(getRawImageSize()==alt.getRawImageSize());
645 yAssert(q1==q2);
646 }
647 }
648
649 copyPixels(alt.getRawImage(),alt.getPixelCode(),
651 width(),height(),
652 getRawImageSize(),q1,q2,false,false);
653 }
654 return true;
655}
656
657
658bool Image::move(Image&& alt) noexcept
659{
660 // Cannot move an image of the wrong type inside an ImageOf that does not
661 // support it.
662 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
663 if (&alt != this) {
664 delete static_cast<ImageStorage*>(implementation);
665 implementation = std::exchange(alt.implementation, nullptr);
666 synchronize();
667 }
668 return true;
669}
670
671
673{
674 // Cannot swap two ImageOf of different type, or an image of the wrong type
675 // inside an ImageOf that does not support it.
676 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
677 yAssert(dynamic_cast<FlexImage*>(&alt) || getPixelCode() == alt.getPixelCode() || getPixelCode() == 0);
678 if (&alt != this) {
679 std::swap(alt.implementation, implementation);
680 synchronize();
681 alt.synchronize();
682 }
683 return true;
684}
685
686
687void Image::setExternal(const void *data, size_t imgWidth, size_t imgHeight) {
688 if (imgQuantum==0) {
689 imgQuantum = 1;
690 }
691 (static_cast<ImageStorage*>(implementation))->_alloc_complete_extern(data,
692 imgWidth,
693 imgHeight,
694 getPixelCode(),
695 imgQuantum,
696 topIsLow);
697 synchronize();
698}
699
700
701bool Image::copy(const Image& alt, size_t w, size_t h) {
702 if (getPixelCode()==0) {
703 setPixelCode(alt.getPixelCode());
704 setQuantum(alt.getQuantum());
705 }
706 if (&alt==this) {
707 FlexImage img;
708 img.copy(alt);
709 return copy(img,w,h);
710 }
711
712 if (getPixelCode()!=alt.getPixelCode()) {
713 FlexImage img;
715 img.setQuantum(getQuantum());
716 img.copy(alt);
717 return copy(img,w,h);
718 }
719
720 resize(w,h);
721 size_t d = getPixelSize();
722
723 size_t nw = w;
724 size_t nh = h;
725 w = alt.width();
726 h = alt.height();
727
728 float di = (static_cast<float>(h))/nh;
729 float dj = (static_cast<float>(w))/nw;
730
731 for (size_t i=0; i<nh; i++)
732 {
733 auto i0 = static_cast<size_t>(di*i);
734 for (size_t j=0; j<nw; j++)
735 {
736 auto j0 = static_cast<size_t>(dj*j);
738 alt.getPixelAddress(j0,i0),
739 d);
740 }
741 }
742 return true;
743}
#define DBGPF1
Definition Image.cpp:33
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
Definition Image.cpp:245
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
Definition Image.cpp:39
YarpVocabPixelTypesEnum
Definition Image.h:40
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
Definition Image.h:59
@ VOCAB_PIXEL_YUV_420
Definition Image.h:64
@ VOCAB_PIXEL_RGBA
Definition Image.h:45
@ VOCAB_PIXEL_INT
Definition Image.h:47
@ VOCAB_PIXEL_MONO16
Definition Image.h:43
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
Definition Image.h:58
@ VOCAB_PIXEL_YUV_444
Definition Image.h:65
@ VOCAB_PIXEL_BGRA
Definition Image.h:46
@ VOCAB_PIXEL_MONO_SIGNED
Definition Image.h:50
@ VOCAB_PIXEL_BGR
Definition Image.h:49
@ VOCAB_PIXEL_MONO_FLOAT
Definition Image.h:53
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB8
Definition Image.h:62
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
Definition Image.h:56
@ VOCAB_PIXEL_HSV_FLOAT
Definition Image.h:55
@ VOCAB_PIXEL_YUV_422
Definition Image.h:66
@ VOCAB_PIXEL_HSV
Definition Image.h:48
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG16
Definition Image.h:61
@ VOCAB_PIXEL_RGB_SIGNED
Definition Image.h:51
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG16
Definition Image.h:57
@ VOCAB_PIXEL_INVALID
Definition Image.h:41
@ VOCAB_PIXEL_RGB_FLOAT
Definition Image.h:54
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
Definition Image.h:60
@ VOCAB_PIXEL_MONO
Definition Image.h:42
@ VOCAB_PIXEL_RGB_INT
Definition Image.h:52
@ VOCAB_PIXEL_YUV_411
Definition Image.h:67
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB16
Definition Image.h:63
@ VOCAB_PIXEL_RGB
Definition Image.h:44
void iplDeallocateHeader(MiniIplImage *image)
Definition IplImage.cpp:122
MiniIplImage * iplCreateImageHeader(int nChannels, int depth, int origin, int align, int width, int height)
Definition IplImage.cpp:84
void iplAllocateImage(MiniIplImage *image)
Definition IplImage.cpp:43
void iplDeallocateImage(MiniIplImage *image)
Definition IplImage.cpp:48
#define IPL_ORIGIN_BL
Definition IplImage.h:71
#define IPL_DEPTH_16U
Definition IplImage.h:60
#define IPL_ORIGIN_TL
Definition IplImage.h:70
#define IPL_DEPTH_8U
Definition IplImage.h:59
#define IPL_DEPTH_8S
Definition IplImage.h:63
#define IPL_DEPTH_32S
Definition IplImage.h:65
#define IPL_DEPTH_32F
Definition IplImage.h:61
#define YARP_IMAGE_ALIGN
Definition IplImage.h:146
#define IPL_ALIGN_QWORD
Definition IplImage.h:79
#define yAssert(x)
Definition Log.h:388
RandScalar * implementation(void *t)
void _free_complete()
Definition Image.cpp:218
size_t quantum
Definition Image.cpp:71
bool topIsLow
Definition Image.cpp:72
ImageStorage(Image &owner)
Definition Image.cpp:107
void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:127
size_t extern_type_quantum
Definition Image.cpp:70
void _alloc()
Definition Image.cpp:145
int extern_type_id
Definition Image.cpp:69
int GetPadding() const
Definition Image.cpp:101
void _alloc_data()
Definition Image.cpp:168
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:307
int _pad_bytes(size_t linesize, size_t align) const
Definition Image.cpp:325
char ** Data
Definition Image.cpp:68
void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:229
bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:274
void _alloc_extern(const void *buf)
Definition Image.cpp:153
void _free()
Definition Image.cpp:199
MiniIplImage * pImage
Definition Image.cpp:67
int is_owner
Definition Image.cpp:78
Image & owner
Definition Image.cpp:76
int type_id
Definition Image.cpp:73
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.
Definition Portable.h:25
Image class with user control of representation details.
Definition Image.h:363
void setQuantum(size_t imgQuantum)
Definition Image.h:378
void setPixelCode(int imgPixelCode)
Definition Image.h:366
Byte order in image header for network transmission.
void setFromImage(const Image &image)
Base class for storing images.
Definition Image.h:79
bool swap(Image &alt)
swap operator.
Definition Image.cpp:672
Image & operator=(const Image &alt)
Assignment operator.
Definition Image.cpp:615
bool operator==(const Image &alt) const
Comparison operator.
Definition Image.cpp:593
void setQuantum(size_t imgQuantum)
Definition Image.cpp:451
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
Definition Image.cpp:497
void setPixelCode(int imgPixelCode)
Definition Image.cpp:440
bool move(Image &&alt) noexcept
move operator.
Definition Image.cpp:658
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
Definition Image.cpp:687
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:479
Image()
Default constructor.
Definition Image.cpp:360
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
Definition Image.cpp:385
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
Definition Image.cpp:552
bool copy(const Image &alt)
Copy operator.
Definition Image.cpp:624
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
Definition Image.cpp:488
~Image() override
Destructor.
Definition Image.cpp:377
void setPixelSize(size_t imgPixelSize)
Definition Image.cpp:432
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:402
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
Definition Image.h:204
void zero()
Set all pixels to 0.
Definition Image.cpp:395
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:390
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
Definition Image.h:245
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.
Definition Image.h:30
int nChannels
Most of OpenCV functions support 1,2,3 or 4 channels.
Definition IplImage.h:82
int height
image height in pixels
Definition IplImage.h:90
char * imageData
pointer to aligned image data
Definition IplImage.h:94
int widthStep
size of aligned image row in bytes
Definition IplImage.h:95
int width
image width in pixels
Definition IplImage.h:89