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
24
25#include <cstdio>
26#include <cstring>
27#include <string>
28#include <utility>
29
30
31using namespace yarp::sig;
32using namespace yarp::os;
33
34#define DBGPF1 if (0)
35
36//inline int PAD_BYTES (int len, int pad)
37//{
38// const int rem = len % pad;
39// return (rem != 0) ? (pad - rem) : rem;
40//}
41
47{
48 dest.resize(header.width, header.height);
49 unsigned char *mem = dest.getRawImage();
50 size_t allocatedBytes = dest.getRawImageSize();
51 yAssert(mem != nullptr);
52 //this check is redundant with assertion, I would remove it
53 if (dest.getRawImageSize() != static_cast<size_t>(header.imgSize)) {
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",
63 dest.width(), dest.height(), dest.getPixelCode(), dest.getQuantum(), allocatedBytes);
64 }
65 yAssert(allocatedBytes == (size_t) header.imgSize);
66 bool ok = connection.expectBlock(reinterpret_cast<char*>(mem), allocatedBytes);
67 return (!connection.isError() && ok);
68}
69
70
71
73public:
75 char **Data; // this is not IPL. it's char to maintain IPL compatibility
78 size_t quantum;
81
82protected:
84
86
87 // ipl allocation is done in two steps.
88 // _alloc allocates the actual ipl pointer.
89 // _alloc_data allocates the image array and data.
90 // memory is allocated in a single chunk. Row ptrs are then
91 // made to point appropriately. This is compatible with IPL and
92 // SOMEONE says it's more efficient on NT.
93 void _alloc ();
94 void _alloc_extern (const void *buf);
95 void _alloc_data ();
96 void _free ();
97 void _free_data ();
98
99 void _make_independent();
100 bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum,
101 bool topIsLow);
102 void _free_ipl_header();
103 void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum,
104 bool topIsLow);
105 void _free_complete();
106
107
108 // computes the # of padding bytes. These are always at the end of the row.
109 int _pad_bytes (size_t linesize, size_t align) const;
110
111 inline int GetPadding() const {
114 }
115
116public:
118 type_id = 0;
119 pImage = nullptr;
120 Data = nullptr;
121 is_owner = 1;
122 quantum = 0;
123 topIsLow = true;
124 extern_type_id = 0;
126 }
127
131
132 void resize(size_t x, size_t y, int pixel_type,
133 size_t quantum, bool topIsLow);
134
135 void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type,
136 size_t quantum, bool topIsLow);
137};
138
139
140void ImageStorage::resize(size_t x, size_t y, int pixel_type,
141 size_t quantum, bool topIsLow) {
142 int need_recreation = 1;
143
144 if (quantum==0) {
146 }
147
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);
152 }
155}
156
157// allocates an empty image.
159
160
161 _free(); // was iplDeallocateImage(pImage); but that won't work with refs
162
167 } else {
168 iplAllocateImage (pImage, 0, 0);
169 }
170
172}
173
174// installs an external buffer as the image data
175void ImageStorage::_alloc_extern (const void *buf)
176{
177 yAssert(pImage != nullptr);
178 yAssert(Data==nullptr);
179
180 if (pImage != nullptr) {
181 if (pImage->imageData != nullptr) {
183 }
184 }
185
186 //iplAllocateImage (pImage, 0, 0);
187 pImage->imageData = const_cast<char*>(reinterpret_cast<const char*>(buf));
188 // probably need to do more for real IPL
189
190 //iplSetBorderMode (pImage, IPL_BORDER_CONSTANT, IPL_SIDE_ALL, 0);
191}
192
193// allocates the Data pointer.
195{
196 DBGPF1 printf("alloc_data1\n"), fflush(stdout);
197 yAssert(pImage != nullptr);
198
199 yAssert(Data==nullptr);
200
201 char **ptr = new char *[pImage->height];
202
203 Data = ptr;
204
205 yAssert(Data != nullptr);
206
207 yAssert(pImage->imageData != nullptr);
208
209 int height = pImage->height;
210
211 char * DataArea = pImage->imageData;
212
213 for (int r = 0; r < height; r++)
214 {
215 if (topIsLow) {
216 Data[r] = DataArea;
217 } else {
218 Data[height-r-1] = DataArea;
219 }
221 }
222 DBGPF1 printf("alloc_data4\n");
223}
224
226{
227 if (pImage != nullptr) {
228 if (pImage->imageData != nullptr) {
229 if (is_owner) {
231 delete[] Data;
232 } else {
233 delete[] Data;
234 }
235
236 is_owner = 1;
237 Data = nullptr;
238 pImage->imageData = nullptr;
239 }
240 }
241}
242
244{
245 yAssert(Data==nullptr); // Now always free Data at same time
246}
247
248
250{
251 _free();
252 _free_data();
254}
255
256
258{
259 if (pImage!=nullptr)
260 {
262 }
263 pImage = nullptr;
264}
265
266
267void ImageStorage::_alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum,
268 bool topIsLow)
269{
273 _alloc ();
274 _alloc_data ();
275}
276
277
278
280{
281 // actually I think this isn't really needed -paulfitz
282}
283
285{
287 int depth;
288 const char* colorModel;
289 const char* channelSeq;
290};
291
294
295const std::map<int, pixelTypeIplParams> pixelCode2iplParams = {
301 {VOCAB_PIXEL_YUV_420, iplPixelTypeMono}, // {1, 12, "GRAY", "GRAY"}},
302 {VOCAB_PIXEL_YUV_444, iplPixelTypeMono}, // {1, 24, "GRAY", "GRAY"}},
304 {VOCAB_PIXEL_YUV_411, iplPixelTypeMono}, // {1, 12, "GRAY", "GRAY"}},
310 {VOCAB_PIXEL_RGB, {3, IPL_DEPTH_8U, "RGB", "RGB" }},
311 {VOCAB_PIXEL_RGBA, {4, IPL_DEPTH_8U, "RGBA", "RGBA"}},
312 {VOCAB_PIXEL_BGRA, {4, IPL_DEPTH_8U, "BGRA", "BGRA"}},
313 {VOCAB_PIXEL_INT, {1, IPL_DEPTH_32S, "GRAY", "GRAY"}},
314 {VOCAB_PIXEL_HSV, {3, IPL_DEPTH_8U, "HSV", "HSV" }},
315 {VOCAB_PIXEL_BGR, {3, IPL_DEPTH_8U, "RGB", "BGR" }},
316 {VOCAB_PIXEL_MONO_SIGNED, {1, IPL_DEPTH_8S, "GRAY", "GRAY"}},
317 {VOCAB_PIXEL_RGB_INT, {3, IPL_DEPTH_32S, "RGB", "RGB" }},
318 {VOCAB_PIXEL_MONO_FLOAT, {1, IPL_DEPTH_32F, "GRAY", "GRAY"}},
319 {VOCAB_PIXEL_RGB_FLOAT, {3, IPL_DEPTH_32F, "RGB", "RGB" }},
320 {-2, iplPixelTypeMono16},
321 {-4, {1, IPL_DEPTH_32S, "GRAY", "GRAY"}}
322};
323
324bool ImageStorage::_set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum,
325 bool topIsLow)
326{
327 if (pImage != nullptr) {
329 pImage = nullptr;
330 }
331
333 // not a type!
334 printf ("*** Trying to allocate an invalid pixel type image\n");
335 std::exit(1);
336 }
338 // unknown pixel type. Should revert to a non-IPL mode... how?
339 return false;
340 }
341
343
344 if (quantum==0) {
346 }
347 int origin = topIsLow ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
348
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);
350
352 this->quantum = quantum;
353 this->topIsLow = topIsLow;
354 return true;
355}
356
357void ImageStorage::_alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
358{
359 if (quantum==0) {
360 quantum = 1;
361 }
362 this->quantum = quantum;
363 this->topIsLow = topIsLow;
364
368 Data = nullptr;
369 _alloc_extern (buf);
370 _alloc_data ();
371 is_owner = 0;
372}
373
374
375
376int ImageStorage::_pad_bytes (size_t linesize, size_t align) const
377{
378 return yarp::sig::PAD_BYTES (linesize, align);
379}
380
381const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
384 {VOCAB_PIXEL_MONO16, sizeof(yarp::sig::PixelMono16)},
385 {VOCAB_PIXEL_RGB, sizeof(yarp::sig::PixelRgb)},
386 {VOCAB_PIXEL_RGBA, sizeof(yarp::sig::PixelRgba)},
387 {VOCAB_PIXEL_BGRA, sizeof(yarp::sig::PixelBgra)},
388 {VOCAB_PIXEL_INT, sizeof(yarp::sig::PixelInt)},
389 {VOCAB_PIXEL_HSV, sizeof(yarp::sig::PixelHsv)},
390 {VOCAB_PIXEL_BGR, sizeof(yarp::sig::PixelBgr)},
392 {VOCAB_PIXEL_RGB_SIGNED, sizeof(yarp::sig::PixelRgbSigned)},
393 {VOCAB_PIXEL_RGB_INT, sizeof(yarp::sig::PixelRgbInt)},
395 {VOCAB_PIXEL_RGB_FLOAT, sizeof(yarp::sig::PixelRgbFloat)},
396 {VOCAB_PIXEL_HSV_FLOAT, sizeof(yarp::sig::PixelHsvFloat)},
409};
410
412 initialize();
413}
414
415void Image::initialize() {
416 implementation = nullptr;
417 data = nullptr;
418 imgWidth = imgHeight = 0;
419 imgPixelSize = imgRowSize = 0;
420 imgPixelCode = 0;
421 imgQuantum = 0;
422 topIsLow = true;
423 implementation = new ImageStorage(*this);
424 yAssert(implementation!=nullptr);
425}
426
427
429 if (implementation!=nullptr) {
430 delete static_cast<ImageStorage*>(implementation);
431 implementation = nullptr;
432 }
433}
434
435
436size_t Image::getPixelSize() const {
437 return imgPixelSize;
438}
439
440
442 return imgPixelCode;
443}
444
445
447 if (getRawImage()!=nullptr) {
449 }
450}
451
452
453void Image::resize(size_t imgWidth, size_t imgHeight) {
454
455 int code = getPixelCode();
456 bool change = false;
457 if (code!=imgPixelCode) {
458 setPixelCode(code);
459 change = true;
460 }
461 if (imgPixelCode!=(static_cast<ImageStorage*>(implementation))->extern_type_id) {
462 change = true;
463 }
464 if (imgQuantum!=(static_cast<ImageStorage*>(implementation))->extern_type_quantum) {
465 change = true;
466 }
467
468 if (imgWidth!=width()||imgHeight!=height()) {
469 change = true;
470 }
471
472 if (change) {
473 (static_cast<ImageStorage*>(implementation))->resize(imgWidth,
474 imgHeight,
475 imgPixelCode,
476 imgQuantum,
477 topIsLow);
478 synchronize();
479 //printf("CHANGE! %ld\n", (long int)(this));
480 }
481}
482
483void Image::setPixelSize(size_t imgPixelSize) {
484 if(imgPixelSize == pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode))) {
485 return;
486 }
487
488 setPixelCode(-imgPixelSize);
489}
490
491void Image::setPixelCode(int imgPixelCode) {
492 this->imgPixelCode = imgPixelCode;
493 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
494
495 if (implementation) {
496 auto* impl = static_cast<ImageStorage*>(implementation);
497 impl->type_id = imgPixelCode;
498 }
499}
500
501
502void Image::setQuantum(size_t imgQuantum) {
503 this->imgQuantum = imgQuantum;
504
505 if (implementation) {
506 auto* impl = static_cast<ImageStorage*>(implementation);
507 impl->quantum = imgQuantum;
508 }
509}
510
511
513 topIsLow = flag;
514
515 if (implementation) {
516 auto* impl = static_cast<ImageStorage*>(implementation);
517 if (impl->pImage) {
518 impl->pImage->origin = topIsLow ? IPL_ORIGIN_TL : IPL_ORIGIN_BL;
519 }
520 }
521}
522
523void Image::synchronize() {
524 auto* impl = static_cast<ImageStorage*>(implementation);
525 yAssert(impl!=nullptr);
526 if (impl->pImage!=nullptr) {
527 imgWidth = impl->pImage->width;
528 imgHeight = impl->pImage->height;
529 data = impl->Data;
530 imgQuantum = impl->quantum;
531 imgRowSize = impl->pImage->widthStep;
532 setPixelCode(impl->type_id);
533 topIsLow = impl->pImage->origin == IPL_ORIGIN_TL;
534 } else {
535 data = nullptr;
536 imgWidth = 0;
537 imgHeight = 0;
538 }
539}
540
541
542unsigned char *Image::getRawImage() const {
543 auto* impl = static_cast<ImageStorage*>(implementation);
544 yAssert(impl!=nullptr);
545 if (impl->pImage!=nullptr) {
546 return reinterpret_cast<unsigned char*>(impl->pImage->imageData);
547 }
548 return nullptr;
549}
550
552 auto* impl = static_cast<ImageStorage*>(implementation);
553 yAssert(impl!=nullptr);
554 if (impl->pImage!=nullptr) {
555 return impl->pImage->imageSize;
556 }
557 return 0;
558}
559
561
562 // auto-convert text mode interaction
563 connection.convertTextMode();
564
565 ImageNetworkHeader header;
566
567 bool ok = connection.expectBlock(reinterpret_cast<char*>(&header),sizeof(header));
568 if (!ok) {
569 return false;
570 }
571
572 //first check that the received image size is reasonable
573 if (header.width == 0 || header.height == 0)
574 {
575 // I maintain the previous logic, although we should probably return false
576 return !connection.isError();
577 }
578
579 setPixelCode(header.id);
580
581 size_t q = getQuantum();
582 if (q==0) {
583 //q = YARP_IMAGE_ALIGN;
584 setQuantum(header.quantum);
585 q = getQuantum();
586 }
587 if (q != static_cast<size_t>(header.quantum)) {
588 if ((header.depth*header.width)%header.quantum==0 &&
589 (header.depth*header.width)%q==0) {
590 header.quantum = q;
591 }
592 }
593
594 setTopIsLowIndex(header.topIsLow == 0);
595
596 // handle easy case, received and current image are compatible, no conversion needed
597 if (getPixelCode() == header.id && q == static_cast<size_t>(header.quantum) && imgPixelSize == static_cast<size_t>(header.depth))
598 {
599 return readFromConnection(*this, header, connection);
600 }
601
602 // image is bayer 8 bits, current image is MONO, copy as is (keep raw format)
603 if (getPixelCode() == VOCAB_PIXEL_MONO && isBayer8(header.id))
604 {
605 return readFromConnection(*this, header, connection);
606 }
607 // image is bayer 16 bits, current image is MONO16, copy as is (keep raw format)
608 if (getPixelCode() == VOCAB_PIXEL_MONO16 && isBayer16(header.id))
609 {
610 return readFromConnection(*this, header, connection);
611 }
612
614 // Received and current images are binary incompatible do our best to convert
615 //
616
617 // handle here all bayer encoding 8 bits
618 if (isBayer8(header.id))
619 {
621 flex.setPixelCode(VOCAB_PIXEL_MONO);
622 flex.setQuantum(header.quantum);
623 flex.setTopIsLowIndex(header.topIsLow == 0);
624
625 bool ok = readFromConnection(flex, header, connection);
626 if (!ok) {
627 return false;
628 }
629
631 return deBayer_GRBG8_TO_BGR(flex, *this, 3);
632 }
634 return deBayer_GRBG8_TO_BGR(flex, *this, 4);
635 }
637 return deBayer_GRBG8_TO_RGB(flex, *this, 3);
638 }
640 return deBayer_GRBG8_TO_RGB(flex, *this, 4);
641 }
642
643 YARP_FIXME_NOTIMPLEMENTED("Conversion from bayer encoding not yet implemented\n");
644 return false;
645 }
646
647 // handle here all bayer encodings 16 bits
648 if (isBayer16(header.id))
649 {
650 // as bayer16 seems unlikely we defer implementation for later
651 YARP_FIXME_NOTIMPLEMENTED("Conversion from bayer encoding 16 bits not yet implemented\n");
652 return false;
653 }
654
655 // Received image has valid YARP pixels and can be converted using Image primitives
656 // prepare a FlexImage, set it to be compatible with the received image
657 // read new image into FlexImage then copy from it.
659 flex.setPixelCode(header.id);
660 flex.setQuantum(header.quantum);
661 flex.setTopIsLowIndex(header.topIsLow == 0);
662 ok = readFromConnection(flex, header, connection);
663 if (ok) {
664 copy(flex);
665 }
666
667 return ok;
668}
669
670
672 ImageNetworkHeader header;
673 header.setFromImage(*this);
674 connection.appendBlock(reinterpret_cast<char*>(&header),sizeof(header));
675 unsigned char *mem = getRawImage();
676 if (header.width!=0&&header.height!=0) {
677 yAssert(mem!=nullptr);
678
679 // Note use of external block.
680 // Implies care needed about ownership.
681 connection.appendExternalBlock(reinterpret_cast<char *>(mem),header.imgSize);
682 }
683
684 // if someone is foolish enough to connect in text mode,
685 // let them see something readable.
686 connection.convertTextMode();
687
688 return !connection.isError();
689}
690
691
693{
694 initialize();
695 copy(alt);
696}
697
699 : implementation(std::exchange(other.implementation, nullptr))
700{
701 synchronize();
702}
703
704Image& Image::operator=(Image&& other) noexcept
705{
706 delete static_cast<ImageStorage*>(implementation);
707 implementation = std::exchange(other.implementation, nullptr);
708 synchronize();
709 return *this;
710}
711
712
714{
715 if (&alt != this) {
716 copy(alt);
717 }
718 return *this;
719}
720
721
723{
724 if (&alt != this)
725 {
726 int myCode = getPixelCode();
727 if (myCode==0) {
728 setPixelCode(alt.getPixelCode());
729 setQuantum(alt.getQuantum());
730 }
731 resize(alt.width(),alt.height());
732 setTopIsLowIndex(alt.topIsLowIndex());
733
734 int q1 = alt.getQuantum();
735 int q2 = getQuantum();
736 if (q1==0) { q1 = YARP_IMAGE_ALIGN; }
737 if (q2==0) { q2 = YARP_IMAGE_ALIGN; }
738
739 bool o1 = alt.topIsLowIndex();
740 bool o2 = topIsLowIndex();
741
742 yAssert(width()==alt.width());
743 yAssert(height()==alt.height());
744 if (getPixelCode()==alt.getPixelCode()) {
745 if (getQuantum()==alt.getQuantum()) {
746 yAssert(getRawImageSize()==alt.getRawImageSize());
747 yAssert(q1==q2);
748 }
749 }
750
751 copyPixels(alt.getRawImage(),alt.getPixelCode(),
753 width(),height(),
755 }
756 return true;
757}
758
759
760bool Image::move(Image&& alt) noexcept
761{
762 // Cannot move an image of the wrong type inside an ImageOf that does not
763 // support it.
764 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
765 if (&alt != this) {
766 delete static_cast<ImageStorage*>(implementation);
767 implementation = std::exchange(alt.implementation, nullptr);
768 synchronize();
769 }
770 return true;
771}
772
773
775{
776 // Cannot swap two ImageOf of different type, or an image of the wrong type
777 // inside an ImageOf that does not support it.
778 yAssert(dynamic_cast<FlexImage*>(this) || getPixelCode() == alt.getPixelCode() || alt.getPixelCode() == 0);
779 yAssert(dynamic_cast<FlexImage*>(&alt) || getPixelCode() == alt.getPixelCode() || getPixelCode() == 0);
780 if (&alt != this) {
781 std::swap(alt.implementation, implementation);
782 synchronize();
783 alt.synchronize();
784 }
785 return true;
786}
787
788
789void Image::setExternal(const void *data, size_t imgWidth, size_t imgHeight) {
790 if (imgQuantum==0) {
791 imgQuantum = 1;
792 }
793 (static_cast<ImageStorage*>(implementation))->_alloc_complete_extern(data,
794 imgWidth,
795 imgHeight,
796 getPixelCode(),
797 imgQuantum,
798 topIsLow);
799 synchronize();
800}
801
802
803bool Image::copy(const Image& alt, size_t w, size_t h) {
804 if (getPixelCode()==0) {
805 setPixelCode(alt.getPixelCode());
806 setQuantum(alt.getQuantum());
807 setTopIsLowIndex(alt.topIsLowIndex());
808 }
809 if (&alt==this) {
810 FlexImage img;
811 img.copy(alt);
812 return copy(img,w,h);
813 }
814
815 if (getPixelCode()!=alt.getPixelCode()) {
816 FlexImage img;
818 img.setQuantum(getQuantum());
820 img.copy(alt);
821 return copy(img,w,h);
822 }
823
824 resize(w,h);
825 size_t d = getPixelSize();
826
827 size_t nw = w;
828 size_t nh = h;
829 w = alt.width();
830 h = alt.height();
831
832 float di = (static_cast<float>(h))/nh;
833 float dj = (static_cast<float>(w))/nw;
834
835 for (size_t i=0; i<nh; i++)
836 {
837 auto i0 = static_cast<size_t>(di*i);
838 for (size_t j=0; j<nw; j++)
839 {
840 auto j0 = static_cast<size_t>(dj*j);
842 alt.getPixelAddress(j0,i0),
843 d);
844 }
845 }
846 return true;
847}
bool deBayer_GRBG8_TO_RGB(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
Definition DeBayer.cpp:75
bool deBayer_GRBG8_TO_BGR(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
Definition DeBayer.cpp:9
bool isBayer8(int v)
Basic implementations of debayering functions.
Definition DeBayer.h:19
bool isBayer16(int v)
Definition DeBayer.h:28
#define DBGPF1
Definition Image.cpp:34
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
Definition Image.cpp:295
const pixelTypeIplParams iplPixelTypeMono16
Definition Image.cpp:293
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
Definition Image.cpp:46
const pixelTypeIplParams iplPixelTypeMono
Definition Image.cpp:292
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 iplDeallocateImage(IplImage *image)
Definition IplImage.cpp:739
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)
Definition IplImage.cpp:795
void iplAllocateImageFP(IplImage *image, int doFill, float fillValue)
Definition IplImage.cpp:701
void iplSetBorderMode(IplImage *src, int mode, int border, int constVal)
Definition IplImage.cpp:932
void iplDeallocate(IplImage *image, int flag)
Definition IplImage.cpp:910
void iplAllocateImage(IplImage *image, int doFill, int fillValue)
Definition IplImage.cpp:667
#define YARP_FIXME_NOTIMPLEMENTED(what)
Definition Log.h:411
#define yAssert(x)
Definition Log.h:388
RandScalar * implementation(void *t)
void _free_complete()
Definition Image.cpp:249
size_t quantum
Definition Image.cpp:78
bool topIsLow
Definition Image.cpp:79
ImageStorage(Image &owner)
Definition Image.cpp:117
void _free_ipl_header()
Definition Image.cpp:257
void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:140
size_t extern_type_quantum
Definition Image.cpp:77
void _alloc()
Definition Image.cpp:158
IplImage * pImage
Definition Image.cpp:74
int extern_type_id
Definition Image.cpp:76
int GetPadding() const
Definition Image.cpp:111
void _alloc_data()
Definition Image.cpp:194
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:357
int _pad_bytes(size_t linesize, size_t align) const
Definition Image.cpp:376
char ** Data
Definition Image.cpp:75
void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:267
bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
Definition Image.cpp:324
void _alloc_extern(const void *buf)
Definition Image.cpp:175
void _free()
Definition Image.cpp:225
void _free_data()
Definition Image.cpp:243
int is_owner
Definition Image.cpp:85
Image & owner
Definition Image.cpp:83
void _make_independent()
Definition Image.cpp:279
int type_id
Definition Image.cpp:80
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:374
void setQuantum(size_t imgQuantum)
Definition Image.h:389
void setPixelCode(int imgPixelCode)
Definition Image.h:377
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:774
Image & operator=(const Image &alt)
Assignment operator.
Definition Image.cpp:713
bool topIsLowIndex() const
Definition Image.h:313
void setQuantum(size_t imgQuantum)
Definition Image.cpp:502
size_t width() const
Gets width of image in pixels.
Definition Image.h:163
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
Definition Image.cpp:560
void setPixelCode(int imgPixelCode)
Definition Image.cpp:491
bool move(Image &&alt) noexcept
move operator.
Definition Image.cpp:760
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
Definition Image.cpp:789
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:542
Image()
Default constructor.
Definition Image.cpp:411
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
Definition Image.cpp:436
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
Definition Image.cpp:671
bool copy(const Image &alt)
Copy operator.
Definition Image.cpp:722
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:551
~Image() override
Destructor.
Definition Image.cpp:428
void setPixelSize(size_t imgPixelSize)
Definition Image.cpp:483
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:453
void setTopIsLowIndex(bool flag)
control whether image has origin at top left (default) or bottom left.
Definition Image.cpp:512
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
Definition Image.h:196
void zero()
Set all pixels to 0.
Definition Image.cpp:446
size_t height() const
Gets height of image in pixels.
Definition Image.h:169
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:441
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
Definition Image.h:237
#define IPL_SIDE_ALL
Definition IplImage.h:293
#define IPL_ORIGIN_BL
Definition IplImage.h:71
#define IPL_BORDER_CONSTANT
Definition IplImage.h:283
#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_IMAGE_HEADER
Definition IplImage.h:147
#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:313
#define IPL_DATA_ORDER_PIXEL
Definition IplImage.h:67
#define IPL_ALIGN_QWORD
Definition IplImage.h:79
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:84
int height
image height in pixels
Definition IplImage.h:97
char * imageData
pointer to aligned image data
Definition IplImage.h:105
int origin
0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style)
Definition IplImage.h:92
int widthStep
size of aligned image row in bytes
Definition IplImage.h:106
int width
image width in pixels
Definition IplImage.h:96
const char * colorModel
Definition Image.cpp:288
const char * channelSeq
Definition Image.cpp:289