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
39inline bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader& connection)
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, 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.imgSize));
54 printf("my space: width %zu, height %zu, code %d, quantum %zu, size %zu\n",
55 dest.width(), dest.height(), dest.getPixelCode(), dest.getQuantum(), allocatedBytes);
56 }
57 yAssert(allocatedBytes == (size_t) header.imgSize);
58 bool ok = connection.expectBlock(reinterpret_cast<char*>(mem), allocatedBytes);
59 return (!connection.isError() && ok);
60}
61
62
63
65public:
67 char **Data; // this is not IPL. it's char to maintain IPL compatibility
70 size_t quantum;
72
73protected:
75
77
78 // ipl allocation is done in two steps.
79 // _alloc allocates the actual ipl pointer.
80 // _alloc_data allocates the image array and data.
81 // memory is allocated in a single chunk. Row ptrs are then
82 // made to point appropriately. This is compatible with IPL and
83 // SOMEONE says it's more efficient on NT.
84 void _alloc ();
85 void _alloc_extern (const void *buf);
86 void _alloc_data ();
87 void _free ();
88
89 bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum);
90 void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum);
91 void _free_complete();
92
93
94 // computes the # of padding bytes. These are always at the end of the row.
95 int _pad_bytes (size_t linesize, size_t align) const;
96
97 inline int GetPadding() const {
100 }
101
102public:
104 type_id = 0;
105 pImage = nullptr;
106 Data = nullptr;
107 is_owner = 1;
108 quantum = 0;
109 extern_type_id = 0;
111 }
112
116
117 void resize(size_t x, size_t y, int pixel_type, size_t quantum);
118 void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum);
119};
120
121
122void ImageStorage::resize(size_t x, size_t y, int pixel_type, size_t quantum)
123{
124 int need_recreation = 1;
125
126 if (quantum==0) {
128 }
129
130 if (need_recreation) {
132 DBGPF1 printf("HIT recreation for %p %p: %zu %zu %d\n", static_cast<void*>(this), static_cast<void*>(pImage), x, y, pixel_type);
134 }
137}
138
139// allocates an empty image.
141{
142 _free(); // was iplDeallocateImage(pImage); but that won't work with refs
143
145}
146
147// installs an external buffer as the image data
148void ImageStorage::_alloc_extern (const void *buf)
149{
150 yAssert(pImage != nullptr);
151 yAssert(Data==nullptr);
152
153 if (pImage != nullptr) {
154 if (pImage->imageData != nullptr) {
156 }
157 }
158
159 pImage->imageData = const_cast<char*>(reinterpret_cast<const char*>(buf));
160}
161
162// allocates the Data pointer.
164{
165 DBGPF1 printf("alloc_data1\n"), fflush(stdout);
166 yAssert(pImage != nullptr);
167
168 yAssert(Data==nullptr);
169
170 char **ptr = new char *[pImage->height];
171
172 Data = ptr;
173
174 yAssert(Data != nullptr);
175
176 yAssert(pImage->imageData != nullptr);
177
178 int height = pImage->height;
179
180 char * DataArea = pImage->imageData;
181
182 for (int r = 0; r < height; r++)
183 {
184 Data[r] = DataArea;
186 }
187 DBGPF1 printf("alloc_data4\n");
188}
189
191{
192 if (pImage != nullptr) {
193 if (pImage->imageData != nullptr) {
194 if (is_owner) {
196 delete[] Data;
197 } else {
198 delete[] Data;
199 }
200
201 is_owner = 1;
202 Data = nullptr;
203 pImage->imageData = nullptr;
204 }
205 }
206}
207
208
210{
211 _free();
212
213 if (pImage != nullptr)
214 {
216 }
217 pImage = nullptr;
218}
219
220void ImageStorage::_alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum)
221{
224 _alloc ();
225 _alloc_data ();
226}
227
228
230{
232 int depth;
233};
234
263
264bool ImageStorage::_set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum)
265{
266 if (pImage != nullptr) {
268 pImage = nullptr;
269 }
270
272 // not a type!
273 printf ("*** Trying to allocate an invalid pixel type image\n");
274 std::exit(1);
275 }
277 // unknown pixel type. Should revert to a non-IPL mode... how?
278 return false;
279 }
280
282
283 if (quantum==0) {
285 }
286
287 pImage = iplCreateImageHeader(param.nChannels, param.depth, quantum, x, y);
288
290 this->quantum = quantum;
291 return true;
292}
293
294void ImageStorage::_alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum)
295{
296 if (quantum==0) {
297 quantum = 1;
298 }
299 this->quantum = quantum;
300
303 Data = nullptr;
304 _alloc_extern (buf);
305 _alloc_data ();
306 is_owner = 0;
307}
308
309
310
311int ImageStorage::_pad_bytes (size_t linesize, size_t align) const
312{
313 return yarp::sig::PAD_BYTES (linesize, align);
314}
315
316const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
319 {VOCAB_PIXEL_MONO16, sizeof(yarp::sig::PixelMono16)},
320 {VOCAB_PIXEL_RGB, sizeof(yarp::sig::PixelRgb)},
321 {VOCAB_PIXEL_RGBA, sizeof(yarp::sig::PixelRgba)},
322 {VOCAB_PIXEL_BGRA, sizeof(yarp::sig::PixelBgra)},
323 {VOCAB_PIXEL_INT, sizeof(yarp::sig::PixelInt)},
324 {VOCAB_PIXEL_HSV, sizeof(yarp::sig::PixelHsv)},
325 {VOCAB_PIXEL_BGR, sizeof(yarp::sig::PixelBgr)},
327 {VOCAB_PIXEL_RGB_SIGNED, sizeof(yarp::sig::PixelRgbSigned)},
328 {VOCAB_PIXEL_RGB_INT, sizeof(yarp::sig::PixelRgbInt)},
330 {VOCAB_PIXEL_RGB_FLOAT, sizeof(yarp::sig::PixelRgbFloat)},
331 {VOCAB_PIXEL_HSV_FLOAT, sizeof(yarp::sig::PixelHsvFloat)},
344};
345
347 initialize();
348}
349
350void Image::initialize() {
351 implementation = nullptr;
352 data = nullptr;
353 imgWidth = imgHeight = 0;
354 imgPixelSize = imgRowSize = 0;
355 imgPixelCode = 0;
356 imgQuantum = 0;
357 implementation = new ImageStorage(*this);
358 yAssert(implementation!=nullptr);
359}
360
361
363 if (implementation!=nullptr) {
364 delete static_cast<ImageStorage*>(implementation);
365 implementation = nullptr;
366 }
367}
368
369
370size_t Image::getPixelSize() const {
371 return imgPixelSize;
372}
373
374
376 return imgPixelCode;
377}
378
379
381 if (getRawImage()!=nullptr) {
383 }
384}
385
386
387void Image::resize(size_t imgWidth, size_t imgHeight) {
388
389 int code = getPixelCode();
390 bool change = false;
391 if (code!=imgPixelCode) {
392 setPixelCode(code);
393 change = true;
394 }
395 if (imgPixelCode!=(static_cast<ImageStorage*>(implementation))->extern_type_id) {
396 change = true;
397 }
398 if (imgQuantum!=(static_cast<ImageStorage*>(implementation))->extern_type_quantum) {
399 change = true;
400 }
401
402 if (imgWidth!=width()||imgHeight!=height()) {
403 change = true;
404 }
405
406 if (change) {
407 (static_cast<ImageStorage*>(implementation))->resize(imgWidth,
408 imgHeight,
409 imgPixelCode,
410 imgQuantum);
411 synchronize();
412 //printf("CHANGE! %ld\n", (long int)(this));
413 }
414}
415
416void Image::setPixelSize(size_t imgPixelSize) {
417 if(imgPixelSize == pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode))) {
418 return;
419 }
420
421 setPixelCode(-imgPixelSize);
422}
423
424void Image::setPixelCode(int imgPixelCode) {
425 this->imgPixelCode = imgPixelCode;
426 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
427
428 if (implementation) {
429 auto* impl = static_cast<ImageStorage*>(implementation);
430 impl->type_id = imgPixelCode;
431 }
432}
433
434
435void Image::setQuantum(size_t imgQuantum) {
436 this->imgQuantum = imgQuantum;
437
438 if (implementation) {
439 auto* impl = static_cast<ImageStorage*>(implementation);
440 impl->quantum = imgQuantum;
441 }
442}
443
444void Image::synchronize() {
445 auto* impl = static_cast<ImageStorage*>(implementation);
446 yAssert(impl!=nullptr);
447 if (impl->pImage!=nullptr) {
448 imgWidth = impl->pImage->width;
449 imgHeight = impl->pImage->height;
450 data = impl->Data;
451 imgQuantum = impl->quantum;
452 imgRowSize = impl->pImage->widthStep;
453 setPixelCode(impl->type_id);
454 } else {
455 data = nullptr;
456 imgWidth = 0;
457 imgHeight = 0;
458 }
459}
460
461
462unsigned char *Image::getRawImage() const {
463 auto* impl = static_cast<ImageStorage*>(implementation);
464 yAssert(impl!=nullptr);
465 if (impl->pImage!=nullptr) {
466 return reinterpret_cast<unsigned char*>(impl->pImage->imageData);
467 }
468 return nullptr;
469}
470
472 auto* impl = static_cast<ImageStorage*>(implementation);
473 yAssert(impl!=nullptr);
474 if (impl->pImage!=nullptr) {
475 return impl->pImage->imageSize;
476 }
477 return 0;
478}
479
481
482 // auto-convert text mode interaction
483 connection.convertTextMode();
484
485 ImageNetworkHeader header;
486
487 bool ok = connection.expectBlock(reinterpret_cast<char*>(&header),sizeof(header));
488 if (!ok) {
489 return false;
490 }
491
492 //first check that the received image size is reasonable
493 if (header.width == 0 || header.height == 0)
494 {
495 // I maintain the previous logic, although we should probably return false
496 return !connection.isError();
497 }
498
499 setPixelCode(header.id);
500
501 size_t q = getQuantum();
502 if (q==0) {
503 //q = YARP_IMAGE_ALIGN;
504 setQuantum(header.quantum);
505 q = getQuantum();
506 }
507 if (q != static_cast<size_t>(header.quantum)) {
508 if ((header.depth*header.width)%header.quantum==0 &&
509 (header.depth*header.width)%q==0) {
510 header.quantum = q;
511 }
512 }
513
514 // handle easy case, received and current image are compatible, no conversion needed
515 if (getPixelCode() == header.id && q == static_cast<size_t>(header.quantum) && imgPixelSize == static_cast<size_t>(header.depth))
516 {
517 return readFromConnection(*this, header, connection);
518 }
519
520 // received and current images are binary incompatible, so
521 // prepare a FlexImage, set it to be compatible with the received image
522 // read new image into FlexImage then copy from it.
524 flex.setPixelCode(header.id);
525 flex.setQuantum(header.quantum);
526 ok = readFromConnection(flex, header, connection);
527 if (ok) {
528 copy(flex);
529 }
530
531 return ok;
532}
533
534
536 ImageNetworkHeader header;
537 header.setFromImage(*this);
538 connection.appendBlock(reinterpret_cast<char*>(&header),sizeof(header));
539 unsigned char *mem = getRawImage();
540 if (header.width!=0&&header.height!=0) {
541 yAssert(mem!=nullptr);
542
543 // Note use of external block.
544 // Implies care needed about ownership.
545 connection.appendExternalBlock(reinterpret_cast<char *>(mem),header.imgSize);
546 }
547
548 // if someone is foolish enough to connect in text mode,
549 // let them see something readable.
550 connection.convertTextMode();
551
552 return !connection.isError();
553}
554
555
557{
558 initialize();
559 copy(alt);
560}
561
563 : implementation(std::exchange(other.implementation, nullptr))
564{
565 synchronize();
566}
567
568Image& Image::operator=(Image&& other) noexcept
569{
570 delete static_cast<ImageStorage*>(implementation);
571 implementation = std::exchange(other.implementation, nullptr);
572 synchronize();
573 return *this;
574}
575
576bool Image::operator==(const Image& alt) const
577{
578 //test general properties
579 if (width() != alt.width()) return false;
580 if (height() != alt.height()) return false;
581 if (imgPixelCode != alt.imgPixelCode) return false;
582 size_t raw1size = getRawImageSize();
583 size_t raw2size = alt.getRawImageSize();
584 if (raw1size != raw2size)
585 {
586 return false;
587 }
588 //test byte per byte
589 unsigned char* raw1 = getRawImage();
590 unsigned char* raw2 = alt.getRawImage();
591 if (raw1 == nullptr) { return false;}
592 if (raw2 == nullptr) { return false;}
593 for (size_t i = 0; i < raw1size; i++)
594 {
595 if (raw1[i] != raw2[i]) {
596 return false;
597 }
598 }
599 return true;
600}
601
603{
604 if (&alt != this) {
605 copy(alt);
606 }
607 return *this;
608}
609
610
612{
613 if (&alt != this)
614 {
615 int myCode = getPixelCode();
616 if (myCode==0) {
617 setPixelCode(alt.getPixelCode());
618 setQuantum(alt.getQuantum());
619 }
620 resize(alt.width(),alt.height());
621
622 int q1 = alt.getQuantum();
623 int q2 = getQuantum();
624 if (q1==0) { q1 = YARP_IMAGE_ALIGN; }
625 if (q2==0) { q2 = YARP_IMAGE_ALIGN; }
626
627 yAssert(width()==alt.width());
628 yAssert(height()==alt.height());
629 if (getPixelCode()==alt.getPixelCode()) {
630 if (getQuantum()==alt.getQuantum()) {
631 yAssert(getRawImageSize()==alt.getRawImageSize());
632 yAssert(q1==q2);
633 }
634 }
635
636 copyPixels(alt.getRawImage(),alt.getPixelCode(),
638 width(),height(),
640 }
641 return true;
642}
643
644
645bool Image::move(Image&& alt) noexcept
646{
647 // Cannot move an image of the wrong type inside an ImageOf that does not
648 // support it.
649 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
650 if (&alt != this) {
651 delete static_cast<ImageStorage*>(implementation);
652 implementation = std::exchange(alt.implementation, nullptr);
653 synchronize();
654 }
655 return true;
656}
657
658
660{
661 // Cannot swap two ImageOf of different type, or an image of the wrong type
662 // inside an ImageOf that does not support it.
663 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
664 yAssert(dynamic_cast<FlexImage*>(&alt) || getPixelCode() == alt.getPixelCode() || getPixelCode() == 0);
665 if (&alt != this) {
666 std::swap(alt.implementation, implementation);
667 synchronize();
668 alt.synchronize();
669 }
670 return true;
671}
672
673
674void Image::setExternal(const void *data, size_t imgWidth, size_t imgHeight) {
675 if (imgQuantum==0) {
676 imgQuantum = 1;
677 }
678 (static_cast<ImageStorage*>(implementation))->_alloc_complete_extern(data,
679 imgWidth,
680 imgHeight,
681 getPixelCode(),
682 imgQuantum);
683 synchronize();
684}
685
686
687bool Image::copy(const Image& alt, size_t w, size_t h) {
688 if (getPixelCode()==0) {
689 setPixelCode(alt.getPixelCode());
690 setQuantum(alt.getQuantum());
691 }
692 if (&alt==this) {
693 FlexImage img;
694 img.copy(alt);
695 return copy(img,w,h);
696 }
697
698 if (getPixelCode()!=alt.getPixelCode()) {
699 FlexImage img;
701 img.setQuantum(getQuantum());
702 img.copy(alt);
703 return copy(img,w,h);
704 }
705
706 resize(w,h);
707 size_t d = getPixelSize();
708
709 size_t nw = w;
710 size_t nh = h;
711 w = alt.width();
712 h = alt.height();
713
714 float di = (static_cast<float>(h))/nh;
715 float dj = (static_cast<float>(w))/nw;
716
717 for (size_t i=0; i<nh; i++)
718 {
719 auto i0 = static_cast<size_t>(di*i);
720 for (size_t j=0; j<nw; j++)
721 {
722 auto j0 = static_cast<size_t>(dj*j);
724 alt.getPixelAddress(j0,i0),
725 d);
726 }
727 }
728 return true;
729}
#define DBGPF1
Definition Image.cpp:33
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
Definition Image.cpp:235
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:120
void iplAllocateImage(MiniIplImage *image)
Definition IplImage.cpp:43
MiniIplImage * iplCreateImageHeader(int nChannels, int depth, int align, int width, int height)
Definition IplImage.cpp:84
void iplDeallocateImage(MiniIplImage *image)
Definition IplImage.cpp:48
#define IPL_DEPTH_16U
Definition IplImage.h:60
#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:144
#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:209
size_t quantum
Definition Image.cpp:70
ImageStorage(Image &owner)
Definition Image.cpp:103
size_t extern_type_quantum
Definition Image.cpp:69
void _alloc()
Definition Image.cpp:140
int extern_type_id
Definition Image.cpp:68
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum)
Definition Image.cpp:294
int GetPadding() const
Definition Image.cpp:97
void _alloc_data()
Definition Image.cpp:163
int _pad_bytes(size_t linesize, size_t align) const
Definition Image.cpp:311
char ** Data
Definition Image.cpp:67
void _alloc_extern(const void *buf)
Definition Image.cpp:148
void _free()
Definition Image.cpp:190
void resize(size_t x, size_t y, int pixel_type, size_t quantum)
Definition Image.cpp:122
MiniIplImage * pImage
Definition Image.cpp:66
int is_owner
Definition Image.cpp:76
Image & owner
Definition Image.cpp:74
void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum)
Definition Image.cpp:220
int type_id
Definition Image.cpp:71
bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum)
Definition Image.cpp:264
A mini-server for performing network communication in the background.
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.
Definition Portable.h:25
Image class with user control of representation details.
Definition Image.h:361
void setQuantum(size_t imgQuantum)
Definition Image.h:376
void setPixelCode(int imgPixelCode)
Definition Image.h:364
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:659
Image & operator=(const Image &alt)
Assignment operator.
Definition Image.cpp:602
bool operator==(const Image &alt) const
Comparison operator.
Definition Image.cpp:576
void setQuantum(size_t imgQuantum)
Definition Image.cpp:435
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:480
void setPixelCode(int imgPixelCode)
Definition Image.cpp:424
bool move(Image &&alt) noexcept
move operator.
Definition Image.cpp:645
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
Definition Image.cpp:674
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:462
Image()
Default constructor.
Definition Image.cpp:346
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
Definition Image.cpp:370
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
Definition Image.cpp:535
bool copy(const Image &alt)
Copy operator.
Definition Image.cpp:611
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:471
~Image() override
Destructor.
Definition Image.cpp:362
void setPixelSize(size_t imgPixelSize)
Definition Image.cpp:416
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:387
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:380
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:375
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:88
char * imageData
pointer to aligned image data
Definition IplImage.h:92
int widthStep
size of aligned image row in bytes
Definition IplImage.h:93
int width
image width in pixels
Definition IplImage.h:87