YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Image.copyPixels.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#include <yarp/os/Log.h>
8#include <yarp/os/Vocab.h>
9#include <yarp/sig/Image.h>
10
11#include <cstring>
12#include <cstdio>
13
14using namespace yarp::sig;
15
16#define DBG if(0)
17
18// Default copy mechanism
19template <class T1, class T2>
20static inline void CopyPixel(const T1 *src, T2 *dest)
21{
22 *dest = *src;
23}
24
25/******************************************************************************/
26
27static inline void CopyPixel(const PixelMono* src, PixelRgb* dest)
28{
29 dest->r = *src;
30 dest->g = *src;
31 dest->b = *src;
32}
33
34static inline void CopyPixel(const PixelMono* src, PixelRgba* dest)
35{
36 dest->r = *src;
37 dest->g = *src;
38 dest->b = *src;
39 dest->a = 255;
40}
41
42static inline void CopyPixel(const PixelMono* src, PixelBgra* dest)
43{
44 dest->r = *src;
45 dest->g = *src;
46 dest->b = *src;
47 dest->a = 255;
48}
49
50static inline void CopyPixel(const PixelMono* src, PixelRgbInt* dest)
51{
52 dest->r = *src;
53 dest->g = *src;
54 dest->b = *src;
55}
56
57static inline void CopyPixel(const PixelMono* src, PixelBgr* dest)
58{
59 dest->r = *src;
60 dest->g = *src;
61 dest->b = *src;
62}
63
64static inline void CopyPixel(const PixelMono* src, PixelHsv* dest)
65{
66 dest->v = *src;
67 dest->h = 0;
68 dest->s = 0;
69}
70
71static inline void CopyPixel(const PixelMono* src, PixelRgbSigned* dest)
72{
73 dest->r = *src;
74 dest->g = *src;
75 dest->b = *src;
76}
77
78static inline void CopyPixel(const PixelMono* src, PixelRgbFloat* dest)
79{
80 dest->r = *src;
81 dest->g = *src;
82 dest->b = *src;
83}
84
85static inline void CopyPixel(const PixelMono* src, PixelHsvFloat* dest)
86{
87 dest->v = *src;
88 dest->h = 0;
89 dest->s = 0;
90}
91
92static inline void CopyPixel(const PixelMono* src, PixelMonoSigned* dest)
93{
94 *dest = *src >> 1;
95}
96
97static inline void CopyPixel(const PixelMono* src, PixelInt* dest)
98{
99 *dest = *src;
100}
101
102static inline void CopyPixel(const PixelMono* src, PixelMono16* dest)
103{
104 *dest = *src;
105}
106
107static inline void CopyPixel(const PixelMono* src, PixelFloat* dest)
108{
109 *dest = *src;
110}
111
112/******************************************************************************/
113
114static inline void CopyPixel(const PixelRgb* src, PixelMono* dest)
115{
116 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
117}
118
119static inline void CopyPixel(const PixelRgb* src, PixelMono16* dest)
120{
121 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
122}
123
124static inline void CopyPixel(const PixelRgb* src, PixelInt* dest)
125{
126 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
127}
128
129static inline void CopyPixel(const PixelRgb* src, PixelHsv* dest)
130{
131 YARP_UNUSED(src);
132 YARP_UNUSED(dest);
133 yAssert(false); // Not implemented yet
134}
135
136static inline void CopyPixel(const PixelRgb* src, PixelMonoSigned* dest)
137{
138 *dest = static_cast<char>((src->r + src->g + src->b)/3);
139}
140
141static inline void CopyPixel(const PixelRgb* src, PixelRgbSigned* dest)
142{
143 dest->r = src->r;
144 dest->g = src->g;
145 dest->b = src->b;
146}
147
148static inline void CopyPixel(const PixelRgb* src, PixelRgba* dest)
149{
150 dest->r = src->r;
151 dest->g = src->g;
152 dest->b = src->b;
153 dest->a = 255;
154}
155
156static inline void CopyPixel(const PixelRgb* src, PixelBgra* dest)
157{
158 dest->r = src->r;
159 dest->g = src->g;
160 dest->b = src->b;
161 dest->a = 255;
162}
163
164static inline void CopyPixel(const PixelRgb* src, PixelRgbInt* dest)
165{
166 dest->r = src->r;
167 dest->g = src->g;
168 dest->b = src->b;
169}
170
171static inline void CopyPixel(const PixelRgb* src, PixelFloat* dest)
172{
173 *dest = ((src->r + src->g + src->b)/3.0f);
174}
175
176static inline void CopyPixel(const PixelRgb* src, PixelRgbFloat* dest)
177{
178 dest->r = src->r;
179 dest->g = src->g;
180 dest->b = src->b;
181}
182
183static inline void CopyPixel(const PixelRgb* src, PixelBgr* dest)
184{
185 dest->r = src->r;
186 dest->g = src->g;
187 dest->b = src->b;
188}
189
190static inline void CopyPixel(const PixelRgb* src, PixelHsvFloat* dest)
191{
192 YARP_UNUSED(src);
193 YARP_UNUSED(dest);
194 yAssert(false); // Not implemented yet
195}
196
197/******************************************************************************/
198
199static inline void CopyPixel(const PixelHsv* src, PixelMono* dest)
200{
201 YARP_UNUSED(src);
202 YARP_UNUSED(dest);
203 yAssert(false); // Not implemented yet
204}
205
206static inline void CopyPixel(const PixelHsv* src, PixelMono16* dest)
207{
208 YARP_UNUSED(src);
209 YARP_UNUSED(dest);
210 yAssert(false); // Not implemented yet
211}
212
213static inline void CopyPixel(const PixelHsv* src, PixelRgb* dest)
214{
215 YARP_UNUSED(src);
216 YARP_UNUSED(dest);
217 yAssert(false); // Not implemented yet
218}
219
220static inline void CopyPixel(const PixelHsv* src, PixelRgba* dest)
221{
222 YARP_UNUSED(src);
223 YARP_UNUSED(dest);
224 yAssert(false); // Not implemented yet
225}
226
227static inline void CopyPixel(const PixelHsv* src, PixelBgra* dest)
228{
229 YARP_UNUSED(src);
230 YARP_UNUSED(dest);
231 yAssert(false); // Not implemented yet
232}
233
234static inline void CopyPixel(const PixelHsv* src, PixelRgbInt* dest)
235{
236 YARP_UNUSED(src);
237 YARP_UNUSED(dest);
238 yAssert(false); // Not implemented yet
239}
240
241static inline void CopyPixel(const PixelHsv* src, PixelBgr* dest)
242{
243 YARP_UNUSED(src);
244 YARP_UNUSED(dest);
245 yAssert(false); // Not implemented yet
246}
247
248static inline void CopyPixel(const PixelHsv* src, PixelMonoSigned* dest)
249{
250 YARP_UNUSED(src);
251 YARP_UNUSED(dest);
252 yAssert(false); // Not implemented yet
253}
254
255static inline void CopyPixel(const PixelHsv* src, PixelRgbSigned* dest)
256{
257 YARP_UNUSED(src);
258 YARP_UNUSED(dest);
259 yAssert(false); // Not implemented yet
260}
261
262static inline void CopyPixel(const PixelHsv* src, PixelFloat* dest)
263{
264 YARP_UNUSED(src);
265 YARP_UNUSED(dest);
266 yAssert(false); // Not implemented yet
267}
268
269static inline void CopyPixel(const PixelHsv* src, PixelRgbFloat* dest)
270{
271 YARP_UNUSED(src);
272 YARP_UNUSED(dest);
273 yAssert(false); // Not implemented yet
274}
275
276static inline void CopyPixel(const PixelHsv* src, PixelHsvFloat* dest)
277{
278 YARP_UNUSED(src);
279 YARP_UNUSED(dest);
280 yAssert(false); // Not implemented yet
281}
282
283static inline void CopyPixel(const PixelHsv* src, PixelInt* dest)
284{
285 YARP_UNUSED(src);
286 YARP_UNUSED(dest);
287 yAssert(false); // Not implemented yet
288}
289
290/******************************************************************************/
291
292static inline void CopyPixel(const PixelBgr* src, PixelMono* dest)
293{
294 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
295}
296
297static inline void CopyPixel(const PixelBgr* src, PixelMono16* dest)
298{
299 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
300}
301
302static inline void CopyPixel(const PixelBgr* src, PixelInt* dest)
303{
304 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
305}
306
307static inline void CopyPixel(const PixelBgr* src, PixelHsv* dest)
308{
309 yAssert(false); // Not implemented yet
310}
311
312static inline void CopyPixel(const PixelBgr* src, PixelMonoSigned* dest)
313{
314 *dest = static_cast<char>((src->r + src->g + src->b)/3);
315}
316
317static inline void CopyPixel(const PixelBgr* src, PixelRgbSigned* dest)
318{
319 dest->r = src->r;
320 dest->g = src->g;
321 dest->b = src->b;
322}
323
324static inline void CopyPixel(const PixelBgr* src, PixelFloat* dest)
325{
326 *dest = ((src->r + src->g + src->b)/3.0f);
327}
328
329static inline void CopyPixel(const PixelBgr* src, PixelRgbFloat* dest)
330{
331 dest->r = src->r;
332 dest->g = src->g;
333 dest->b = src->b;
334}
335
336static inline void CopyPixel(const PixelBgr* src, PixelRgb* dest)
337{
338 dest->r = src->r;
339 dest->g = src->g;
340 dest->b = src->b;
341}
342
343static inline void CopyPixel(const PixelBgr* src, PixelRgba* dest)
344{
345 dest->r = src->r;
346 dest->g = src->g;
347 dest->b = src->b;
348 dest->a = 255;
349}
350
351static inline void CopyPixel(const PixelBgr* src, PixelBgra* dest)
352{
353 dest->r = src->r;
354 dest->g = src->g;
355 dest->b = src->b;
356 dest->a = 255;
357}
358
359static inline void CopyPixel(const PixelBgr* src, PixelRgbInt* dest)
360{
361 dest->r = src->r;
362 dest->g = src->g;
363 dest->b = src->b;
364}
365
366static inline void CopyPixel(const PixelBgr* src, PixelHsvFloat* dest)
367{
368 yAssert(false); // Not implemented yet
369}
370
371/******************************************************************************/
372
373static inline void CopyPixel(const PixelRgba* src, PixelMono* dest)
374{
375 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
376}
377
378static inline void CopyPixel(const PixelRgba* src, PixelMono16* dest)
379{
380 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
381}
382
383static inline void CopyPixel(const PixelRgba* src, PixelInt* dest)
384{
385 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
386}
387
388static inline void CopyPixel(const PixelRgba* src, PixelHsv* dest)
389{
390 yAssert(false); // Not implemented yet
391}
392
393static inline void CopyPixel(const PixelRgba* src, PixelMonoSigned* dest)
394{
395 *dest = static_cast<char>((src->r + src->g + src->b)/3);
396}
397
398static inline void CopyPixel(const PixelRgba* src, PixelRgbSigned* dest)
399{
400 dest->r = src->r;
401 dest->g = src->g;
402 dest->b = src->b;
403}
404
405static inline void CopyPixel(const PixelRgba* src, PixelFloat* dest)
406{
407 *dest = ((src->r + src->g + src->b)/3.0f);
408}
409
410static inline void CopyPixel(const PixelRgba* src, PixelRgbFloat* dest)
411{
412 dest->r = src->r;
413 dest->g = src->g;
414 dest->b = src->b;
415}
416
417static inline void CopyPixel(const PixelRgba* src, PixelRgb* dest)
418{
419 dest->r = src->r;
420 dest->g = src->g;
421 dest->b = src->b;
422}
423
424static inline void CopyPixel(const PixelRgba* src, PixelBgra* dest)
425{
426 dest->r = src->r;
427 dest->g = src->g;
428 dest->b = src->b;
429 dest->a = src->a;
430}
431
432static inline void CopyPixel(const PixelRgba* src, PixelBgr* dest)
433{
434 dest->r = src->r;
435 dest->g = src->g;
436 dest->b = src->b;
437}
438
439static inline void CopyPixel(const PixelRgba* src, PixelRgbInt* dest)
440{
441 dest->r = src->r;
442 dest->g = src->g;
443 dest->b = src->b;
444}
445
446static inline void CopyPixel(const PixelRgba* src, PixelHsvFloat* dest)
447{
448 yAssert(false); // Not implemented yet
449}
450
451/******************************************************************************/
452
453static inline void CopyPixel(const PixelBgra* src, PixelMono* dest)
454{
455 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
456}
457
458static inline void CopyPixel(const PixelBgra* src, PixelMono16* dest)
459{
460 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
461}
462
463static inline void CopyPixel(const PixelBgra* src, PixelInt* dest)
464{
465 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
466}
467
468static inline void CopyPixel(const PixelBgra* src, PixelHsv* dest)
469{
470 yAssert(false); // Not implemented yet
471}
472
473static inline void CopyPixel(const PixelBgra* src, PixelMonoSigned* dest)
474{
475 *dest = static_cast<char>((src->r + src->g + src->b)/3);
476}
477
478static inline void CopyPixel(const PixelBgra* src, PixelRgbSigned* dest)
479{
480 dest->r = src->r;
481 dest->g = src->g;
482 dest->b = src->b;
483}
484
485static inline void CopyPixel(const PixelBgra* src, PixelFloat* dest)
486{
487 *dest = ((src->r + src->g + src->b)/3.0f);
488}
489
490static inline void CopyPixel(const PixelBgra* src, PixelRgbFloat* dest)
491{
492 dest->r = src->r;
493 dest->g = src->g;
494 dest->b = src->b;
495}
496
497static inline void CopyPixel(const PixelBgra* src, PixelRgb* dest)
498{
499 dest->r = src->r;
500 dest->g = src->g;
501 dest->b = src->b;
502}
503
504static inline void CopyPixel(const PixelBgra* src, PixelRgba* dest)
505{
506 dest->r = src->r;
507 dest->g = src->g;
508 dest->b = src->b;
509 dest->a = src->a;
510}
511
512static inline void CopyPixel(const PixelBgra* src, PixelBgr* dest)
513{
514 dest->r = src->r;
515 dest->g = src->g;
516 dest->b = src->b;
517}
518
519static inline void CopyPixel(const PixelBgra* src, PixelRgbInt* dest)
520{
521 dest->r = src->r;
522 dest->g = src->g;
523 dest->b = src->b;
524}
525
526static inline void CopyPixel(const PixelBgra* src, PixelHsvFloat* dest)
527{
528 yAssert(false); // Not implemented yet
529}
530
531/******************************************************************************/
532
533static inline void CopyPixel(const PixelRgbInt* src, PixelMono* dest)
534{
535 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
536}
537
538static inline void CopyPixel(const PixelRgbInt* src, PixelMono16* dest)
539{
540 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
541}
542
543static inline void CopyPixel(const PixelRgbInt* src, PixelInt* dest)
544{
545 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
546}
547
548static inline void CopyPixel(const PixelRgbInt* src, PixelHsv* dest)
549{
550 yAssert(false); // Not implemented yet
551}
552
553static inline void CopyPixel(const PixelRgbInt* src, PixelMonoSigned* dest)
554{
555 *dest = static_cast<char>((src->r + src->g + src->b)/3);
556}
557
558static inline void CopyPixel(const PixelRgbInt* src, PixelRgbSigned* dest)
559{
560 dest->r = static_cast<char>(src->r);
561 dest->g = static_cast<char>(src->g);
562 dest->b = static_cast<char>(src->b);
563}
564
565static inline void CopyPixel(const PixelRgbInt* src, PixelFloat* dest)
566{
567 *dest = ((src->r + src->g + src->b)/3.0f);
568}
569
570static inline void CopyPixel(const PixelRgbInt* src, PixelRgbFloat* dest)
571{
572 dest->r = static_cast<float>(static_cast<int>(src->r));
573 dest->g = static_cast<float>(static_cast<int>(src->g));
574 dest->b = static_cast<float>(static_cast<int>(src->b));
575}
576
577static inline void CopyPixel(const PixelRgbInt* src, PixelRgb* dest)
578{
579 dest->r = static_cast<unsigned char>(src->r);
580 dest->g = static_cast<unsigned char>(src->g);
581 dest->b = static_cast<unsigned char>(src->b);
582}
583
584static inline void CopyPixel(const PixelRgbInt* src, PixelBgr* dest)
585{
586 dest->r = static_cast<unsigned char>(src->r);
587 dest->g = static_cast<unsigned char>(src->g);
588 dest->b = static_cast<unsigned char>(src->b);
589}
590
591static inline void CopyPixel(const PixelRgbInt* src, PixelRgba* dest)
592{
593 dest->r = static_cast<unsigned char>(src->r);
594 dest->g = static_cast<unsigned char>(src->g);
595 dest->b = static_cast<unsigned char>(src->b);
596 dest->a = 255;
597}
598
599static inline void CopyPixel(const PixelRgbInt* src, PixelBgra* dest)
600{
601 dest->r = static_cast<unsigned char>(src->r);
602 dest->g = static_cast<unsigned char>(src->g);
603 dest->b = static_cast<unsigned char>(src->b);
604 dest->a = 255;
605}
606
607static inline void CopyPixel(const PixelRgbInt* src, PixelHsvFloat* dest)
608{
609 yAssert(false); // Not implemented yet
610}
611
612/******************************************************************************/
613
614static inline void CopyPixel(const PixelMonoSigned* src, PixelRgb* dest)
615{
616 dest->r = *src;
617 dest->g = *src;
618 dest->b = *src;
619}
620
621static inline void CopyPixel(const PixelMonoSigned* src, PixelRgba* dest)
622{
623 dest->r = *src;
624 dest->g = *src;
625 dest->b = *src;
626 dest->a = 255;
627}
628
629static inline void CopyPixel(const PixelMonoSigned* src, PixelBgra* dest)
630{
631 dest->r = *src;
632 dest->g = *src;
633 dest->b = *src;
634 dest->a = 255;
635}
636
637static inline void CopyPixel(const PixelMonoSigned* src, PixelRgbInt* dest)
638{
639 dest->r = *src;
640 dest->g = *src;
641 dest->b = *src;
642}
643
644static inline void CopyPixel(const PixelMonoSigned* src, PixelBgr* dest)
645{
646 dest->r = *src;
647 dest->g = *src;
648 dest->b = *src;
649}
650
651static inline void CopyPixel(const PixelMonoSigned* src, PixelHsv* dest)
652{
653 dest->v = *src;
654 dest->h = 0;
655 dest->s = 0;
656}
657
658static inline void CopyPixel(const PixelMonoSigned* src, PixelRgbSigned* dest)
659{
660 dest->r = *src;
661 dest->g = *src;
662 dest->b = *src;
663}
664
665static inline void CopyPixel(const PixelMonoSigned* src, PixelRgbFloat* dest)
666{
667 dest->r = *src;
668 dest->g = *src;
669 dest->b = *src;
670}
671
672static inline void CopyPixel(const PixelMonoSigned* src, PixelHsvFloat* dest)
673{
674 dest->v = *src;
675 dest->h = 0;
676 dest->s = 0;
677}
678
679static inline void CopyPixel(const PixelMonoSigned* src, PixelMono* dest)
680{
681 *dest = *src + 128;
682}
683
684static inline void CopyPixel(const PixelMonoSigned* src, PixelInt* dest)
685{
686 *dest = *src;
687}
688
689static inline void CopyPixel(const PixelMonoSigned* src, PixelMono16* dest)
690{
691 *dest = static_cast<yarp::sig::PixelMono16>(*src);
692}
693
694/******************************************************************************/
695
696static inline void CopyPixel(const PixelRgbSigned* src, PixelMono* dest)
697{
698 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
699}
700
701static inline void CopyPixel(const PixelRgbSigned* src, PixelMono16* dest)
702{
703 *dest = static_cast<PixelMono16>((src->r + src->g + src->b)/3);
704}
705
706static inline void CopyPixel(const PixelRgbSigned* src, PixelInt* dest)
707{
708 *dest = static_cast<int>((src->r + src->g + src->b)/3);
709}
710
711static inline void CopyPixel(const PixelRgbSigned* src, PixelHsv* dest)
712{
713 yAssert(false); // Not implemented yet
714}
715
716static inline void CopyPixel(const PixelRgbSigned* src, PixelMonoSigned* dest)
717{
718 *dest = static_cast<char>((src->r + src->g + src->b)/3);
719}
720
721static inline void CopyPixel(const PixelRgbSigned* src, PixelRgb* dest)
722{
723 dest->r = src->r;
724 dest->g = src->g;
725 dest->b = src->b;
726}
727
728static inline void CopyPixel(const PixelRgbSigned* src, PixelRgba* dest)
729{
730 dest->r = src->r;
731 dest->g = src->g;
732 dest->b = src->b;
733 dest->a = 255;
734}
735
736static inline void CopyPixel(const PixelRgbSigned* src, PixelBgra* dest)
737{
738 dest->r = src->r;
739 dest->g = src->g;
740 dest->b = src->b;
741 dest->a = 255;
742}
743
744static inline void CopyPixel(const PixelRgbSigned* src, PixelRgbInt* dest)
745{
746 dest->r = src->r;
747 dest->g = src->g;
748 dest->b = src->b;
749}
750
751static inline void CopyPixel(const PixelRgbSigned* src, PixelBgr* dest)
752{
753 dest->r = src->r;
754 dest->g = src->g;
755 dest->b = src->b;
756}
757
758static inline void CopyPixel(const PixelRgbSigned* src, PixelFloat* dest)
759{
760 *dest = ((src->r + src->g + src->b)/3.0f);
761}
762
763static inline void CopyPixel(const PixelRgbSigned* src, PixelRgbFloat* dest)
764{
765 dest->r = src->r;
766 dest->g = src->g;
767 dest->b = src->b;
768}
769
770static inline void CopyPixel(const PixelRgbSigned* src, PixelHsvFloat* dest)
771{
772 yAssert(false); // Not implemented yet
773}
774
775/******************************************************************************/
776
777static inline void CopyPixel(const PixelFloat* src, PixelMono* dest)
778{
779 *dest = static_cast<unsigned char>(*src);
780}
781
782static inline void CopyPixel(const PixelFloat* src, PixelMono16* dest)
783{
784 *dest = static_cast<yarp::sig::PixelMono16>(*src);
785}
786
787static inline void CopyPixel(const PixelFloat* src, PixelInt* dest)
788{
789 *dest = static_cast<unsigned char>(*src);
790}
791
792static inline void CopyPixel(const PixelFloat* src, PixelMonoSigned* dest)
793{
794 *dest = static_cast<char>(*src);
795}
796
797static inline void CopyPixel(const PixelFloat* src, PixelRgb* dest)
798{
799 dest->r = static_cast<unsigned char>(*src);
800 dest->g = static_cast<unsigned char>(*src);
801 dest->b = static_cast<unsigned char>(*src);
802}
803
804static inline void CopyPixel(const PixelFloat* src, PixelRgba* dest)
805{
806 dest->r = static_cast<unsigned char>(*src);
807 dest->g = static_cast<unsigned char>(*src);
808 dest->b = static_cast<unsigned char>(*src);
809 dest->a = 255;
810}
811
812static inline void CopyPixel(const PixelFloat* src, PixelBgra* dest)
813{
814 dest->r = static_cast<unsigned char>(*src);
815 dest->g = static_cast<unsigned char>(*src);
816 dest->b = static_cast<unsigned char>(*src);
817 dest->a = 255;
818}
819
820static inline void CopyPixel(const PixelFloat* src, PixelRgbInt* dest)
821{
822 dest->r = static_cast<int>(*src);
823 dest->g = static_cast<int>(*src);
824 dest->b = static_cast<int>(*src);
825}
826
827static inline void CopyPixel(const PixelFloat* src, PixelBgr* dest)
828{
829 dest->r = static_cast<unsigned char>(*src);
830 dest->g = static_cast<unsigned char>(*src);
831 dest->b = static_cast<unsigned char>(*src);
832}
833
834static inline void CopyPixel(const PixelFloat* src, PixelHsv* dest)
835{
836 dest->v = static_cast<unsigned char>(*src);
837 dest->h = 0;
838 dest->s = 0;
839}
840
841static inline void CopyPixel(const PixelFloat* src, PixelRgbSigned* dest)
842{
843 dest->r = static_cast<signed char>(*src);
844 dest->g = static_cast<signed char>(*src);
845 dest->b = static_cast<signed char>(*src);
846}
847
848static inline void CopyPixel(const PixelFloat* src, PixelRgbFloat* dest)
849{
850 dest->r = *src;
851 dest->g = *src;
852 dest->b = *src;
853}
854
855static inline void CopyPixel(const PixelFloat* src, PixelHsvFloat* dest)
856{
857 dest->v = *src;
858 dest->h = 0;
859 dest->s = 0;
860}
861
862/******************************************************************************/
863
864static inline void CopyPixel(const PixelRgbFloat* src, PixelMono* dest)
865{
866 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
867}
868
869static inline void CopyPixel(const PixelRgbFloat* src, PixelInt* dest)
870{
871 *dest = static_cast<unsigned char>((src->r + src->g + src->b)/3);
872}
873
874static inline void CopyPixel(const PixelRgbFloat* src, PixelMono16* dest)
875{
876 *dest = static_cast<yarp::sig::PixelMono16>((src->r + src->g + src->b)/3);
877}
878
879static inline void CopyPixel(const PixelRgbFloat* src, PixelHsv* dest)
880{
881 yAssert(false); // Not implemented yet
882}
883
884static inline void CopyPixel(const PixelRgbFloat* src, PixelMonoSigned* dest)
885{
886 *dest = static_cast<char>((src->r + src->g + src->b)/3);
887}
888
889static inline void CopyPixel(const PixelRgbFloat* src, PixelRgb* dest)
890{
891 dest->r = static_cast<unsigned char>(src->r);
892 dest->g = static_cast<unsigned char>(src->g);
893 dest->b = static_cast<unsigned char>(src->b);
894}
895
896static inline void CopyPixel(const PixelRgbFloat* src, PixelRgba* dest)
897{
898 dest->r = static_cast<unsigned char>(src->r);
899 dest->g = static_cast<unsigned char>(src->g);
900 dest->b = static_cast<unsigned char>(src->b);
901 dest->a = 255;
902}
903
904static inline void CopyPixel(const PixelRgbFloat* src, PixelBgra* dest)
905{
906 dest->r = static_cast<unsigned char>(src->r);
907 dest->g = static_cast<unsigned char>(src->g);
908 dest->b = static_cast<unsigned char>(src->b);
909 dest->a = 255;
910}
911
912static inline void CopyPixel(const PixelRgbFloat* src, PixelRgbInt* dest)
913{
914 dest->r = static_cast<int>(src->r);
915 dest->g = static_cast<int>(src->g);
916 dest->b = static_cast<int>(src->b);
917}
918
919static inline void CopyPixel(const PixelRgbFloat* src, PixelBgr* dest)
920{
921 dest->r = static_cast<unsigned char>(src->r);
922 dest->g = static_cast<unsigned char>(src->g);
923 dest->b = static_cast<unsigned char>(src->b);
924}
925
926static inline void CopyPixel(const PixelRgbFloat* src, PixelFloat* dest)
927{
928 *dest = ((src->r + src->g + src->b)/3);
929}
930
931static inline void CopyPixel(const PixelRgbFloat* src, PixelRgbSigned* dest)
932{
933 dest->r = static_cast<signed char>(src->r);
934 dest->g = static_cast<signed char>(src->g);
935 dest->b = static_cast<signed char>(src->b);
936}
937
938static inline void CopyPixel(const PixelRgbFloat* src, PixelHsvFloat* dest)
939{
940 yAssert(false); // Not implemented yet
941}
942
943/******************************************************************************/
944
945static inline void CopyPixel(const PixelHsvFloat* src, PixelMono* dest)
946{
947 yAssert(false); // Not implemented yet
948}
949
950static inline void CopyPixel(const PixelHsvFloat* src, PixelMono16* dest)
951{
952 yAssert(false); // Not implemented yet
953}
954
955static inline void CopyPixel(const PixelHsvFloat* src, PixelRgb* dest)
956{
957 yAssert(false); // Not implemented yet
958}
959
960static inline void CopyPixel(const PixelHsvFloat* src, PixelBgr* dest)
961{
962 yAssert(false); // Not implemented yet
963}
964
965static inline void CopyPixel(const PixelHsvFloat* src, PixelRgba* dest)
966{
967 yAssert(false); // Not implemented yet
968}
969
970static inline void CopyPixel(const PixelHsvFloat* src, PixelBgra* dest)
971{
972 yAssert(false); // Not implemented yet
973}
974
975static inline void CopyPixel(const PixelHsvFloat* src, PixelRgbInt* dest)
976{
977 yAssert(false); // Not implemented yet
978}
979
980static inline void CopyPixel(const PixelHsvFloat* src, PixelMonoSigned* dest)
981{
982 yAssert(false); // Not implemented yet
983}
984
985static inline void CopyPixel(const PixelHsvFloat* src, PixelRgbSigned* dest)
986{
987 yAssert(false); // Not implemented yet
988}
989
990static inline void CopyPixel(const PixelHsvFloat* src, PixelFloat* dest)
991{
992 yAssert(false); // Not implemented yet
993}
994
995static inline void CopyPixel(const PixelHsvFloat* src, PixelRgbFloat* dest)
996{
997 yAssert(false); // Not implemented yet
998}
999
1000static inline void CopyPixel(const PixelHsvFloat* src, PixelHsv* dest)
1001{
1002 yAssert(false); // Not implemented yet
1003}
1004
1005static inline void CopyPixel(const PixelHsvFloat* src, PixelInt* dest)
1006{
1007 yAssert(false); // Not implemented yet
1008}
1009
1010/******************************************************************************/
1011
1012static inline void CopyPixel(const PixelInt* src, PixelRgb* dest)
1013{
1014 dest->r = static_cast<char>(*src);
1015 dest->g = static_cast<char>(*src);
1016 dest->b = static_cast<char>(*src);
1017}
1018
1019static inline void CopyPixel(const PixelInt* src, PixelRgba* dest)
1020{
1021 dest->r = static_cast<char>(*src);
1022 dest->g = static_cast<char>(*src);
1023 dest->b = static_cast<char>(*src);
1024 dest->a = 255;
1025}
1026
1027static inline void CopyPixel(const PixelInt* src, PixelBgra* dest)
1028{
1029 dest->r = static_cast<char>(*src);
1030 dest->g = static_cast<char>(*src);
1031 dest->b = static_cast<char>(*src);
1032 dest->a = 255;
1033}
1034
1035static inline void CopyPixel(const PixelInt* src, PixelRgbInt* dest)
1036{
1037 dest->r = *src;
1038 dest->g = *src;
1039 dest->b = *src;
1040}
1041
1042static inline void CopyPixel(const PixelInt* src, PixelBgr* dest)
1043{
1044 dest->r = static_cast<char>(*src);
1045 dest->g = static_cast<char>(*src);
1046 dest->b = static_cast<char>(*src);
1047}
1048
1049static inline void CopyPixel(const PixelInt* src, PixelHsv* dest)
1050{
1051 dest->v = static_cast<yarp::sig::PixelMono>(*src);
1052 dest->h = dest->s = 0;
1053}
1054
1055static inline void CopyPixel(const PixelInt* src, PixelRgbSigned* dest)
1056{
1057 dest->r = static_cast<yarp::sig::PixelMono>(*src);
1058 dest->g = static_cast<yarp::sig::PixelMono>(*src);
1059 dest->b = static_cast<yarp::sig::PixelMono>(*src);
1060}
1061
1062static inline void CopyPixel(const PixelInt* src, PixelFloat* dest)
1063{
1064 *dest = static_cast<float>(*src);
1065}
1066
1067static inline void CopyPixel(const PixelInt* src, PixelRgbFloat* dest)
1068{
1069 dest->r = static_cast<float>(*src);
1070 dest->g = static_cast<float>(*src);
1071 dest->b = static_cast<float>(*src);
1072}
1073
1074static inline void CopyPixel(const PixelInt* src, PixelHsvFloat* dest)
1075{
1076 dest->v = float(*src);
1077 dest->h = 0;
1078 dest->s = 0;
1079}
1080
1081static inline void CopyPixel(const PixelInt* src, PixelMonoSigned* dest)
1082{
1083 *dest = static_cast<char>(*src >> 1);
1084}
1085
1086static inline void CopyPixel(const PixelInt* src, PixelMono* dest)
1087{
1088 *dest = static_cast<yarp::sig::PixelMono>(*src);
1089}
1090
1091static inline void CopyPixel(const PixelInt* src, PixelMono16* dest)
1092{
1093 *dest = static_cast<yarp::sig::PixelMono16>(*src);
1094}
1095
1096/******************************************************************************/
1097
1098static inline void CopyPixel(const PixelMono16* src, PixelRgb* dest)
1099{
1100 dest->r = static_cast<char>(*src);
1101 dest->g = static_cast<char>(*src);
1102 dest->b = static_cast<char>(*src);
1103}
1104
1105static inline void CopyPixel(const PixelMono16* src, PixelRgba* dest)
1106{
1107 dest->r = static_cast<char>(*src);
1108 dest->g = static_cast<char>(*src);
1109 dest->b = static_cast<char>(*src);
1110 dest->a = 255;
1111}
1112
1113static inline void CopyPixel(const PixelMono16* src, PixelBgra* dest)
1114{
1115 dest->r = static_cast<char>(*src);
1116 dest->g = static_cast<char>(*src);
1117 dest->b = static_cast<char>(*src);
1118 dest->a = 255;
1119}
1120
1121static inline void CopyPixel(const PixelMono16* src, PixelRgbInt* dest)
1122{
1123 dest->r = static_cast<int>(static_cast<unsigned>(*src));
1124 dest->g = static_cast<int>(static_cast<unsigned>(*src));
1125 dest->b = static_cast<int>(static_cast<unsigned>(*src));
1126}
1127
1128static inline void CopyPixel(const PixelMono16* src, PixelInt* dest)
1129{
1130 *dest = static_cast<int>(static_cast<unsigned>(*src));
1131}
1132
1133static inline void CopyPixel(const PixelMono16* src, PixelBgr* dest)
1134{
1135 dest->r = static_cast<char>(*src);
1136 dest->g = static_cast<char>(*src);
1137 dest->b = static_cast<char>(*src);
1138}
1139
1140static inline void CopyPixel(const PixelMono16* src, PixelHsv* dest)
1141{
1142 dest->v = static_cast<yarp::sig::PixelMono>(*src);
1143 dest->h = 0;
1144 dest->s = 0;
1145}
1146
1147static inline void CopyPixel(const PixelMono16* src, PixelRgbSigned* dest)
1148{
1149 dest->r = static_cast<yarp::sig::PixelMono>(*src);
1150 dest->g = static_cast<yarp::sig::PixelMono>(*src);
1151 dest->b = static_cast<yarp::sig::PixelMono>(*src);
1152}
1153
1154static inline void CopyPixel(const PixelMono16* src, PixelFloat* dest)
1155{
1156 *dest = static_cast<float>(*src);
1157}
1158
1159static inline void CopyPixel(const PixelMono16* src, PixelRgbFloat* dest)
1160{
1161 dest->r = static_cast<float>(*src);
1162 dest->g = static_cast<float>(*src);
1163 dest->b = static_cast<float>(*src);
1164}
1165
1166static inline void CopyPixel(const PixelMono16* src, PixelHsvFloat* dest)
1167{
1168 dest->v = static_cast<float>(*src);
1169 dest->h = 0;
1170 dest->s = 0;
1171}
1172
1173static inline void CopyPixel(const PixelMono16* src, PixelMonoSigned* dest)
1174{
1175 *dest = static_cast<char>(*src >> 1);
1176}
1177
1178static inline void CopyPixel(const PixelMono16* src, PixelMono* dest)
1179{
1180 *dest = static_cast<yarp::sig::PixelMono>(*src);
1181}
1182
1183static inline void CopyPixel(const PixelInt* src, PixelInt* dest)
1184{
1185 *dest = *src;
1186}
1187
1188/******************************************************************************/
1189
1190
1191//static inline int PAD_BYTES (int len, int pad)
1192//{
1193// const int rem = len % pad;
1194// return (rem != 0) ? (pad - rem) : rem;
1195//}
1196
1199template <class T1, class T2>
1200static void CopyPixels(const T1 *osrc, int q1, T2 *odest, int q2,
1201 int w, int h,
1202 bool flip)
1203{
1204 const T1 *src = osrc;
1205 T2 *dest = odest;
1206 const int p1 = PAD_BYTES (w * sizeof(T1), q1);
1207 const int p2 = PAD_BYTES (w * sizeof(T2), q2);
1208 //const int step1 = w*sizeof(T1) + p1;
1209 const int step2 = w*sizeof(T2) + p2;
1210 DBG printf("q1 %d q2 %d (%dx%d) inc %d %d\n", q1, q2, w, h, p1, p2);
1211
1212 if (flip) {
1213 odest = reinterpret_cast<T2*>(((char *)odest) + step2*(h-1));
1214 dest = odest;
1215 }
1216
1217 for (int i=0; i<h; i++) {
1218 DBG printf("x,y = %d,%d\n", 0,i);
1219 for (int j = 0; j < w; j++) {
1220 CopyPixel(src,dest);
1221 src++;
1222 dest++;
1223 }
1224
1225 src = reinterpret_cast<const T1*>(((char *)src) + p1);
1226 odest = reinterpret_cast<T2*>(((char *)odest) + step2*(flip?-1:1));
1227 dest = odest;
1228 }
1229}
1230
1231
1233using Def_VOCAB_PIXEL_MONO16 = PixelMono16;
1234using Def_VOCAB_PIXEL_RGB = PixelRgb;
1235using Def_VOCAB_PIXEL_RGBA = PixelRgba;
1236using Def_VOCAB_PIXEL_BGRA = PixelBgra;
1237using Def_VOCAB_PIXEL_HSV = PixelHsv;
1238using Def_VOCAB_PIXEL_BGR = PixelBgr;
1239using Def_VOCAB_PIXEL_MONO_SIGNED = PixelMonoSigned;
1240using Def_VOCAB_PIXEL_RGB_SIGNED = PixelRgbSigned;
1242using Def_VOCAB_PIXEL_RGB_FLOAT = PixelRgbFloat;
1243using Def_VOCAB_PIXEL_HSV_FLOAT = PixelHsvFloat;
1244using Def_VOCAB_PIXEL_INT = PixelInt;
1245using Def_VOCAB_PIXEL_RGB_INT = PixelRgbInt;
1246
1247#define HASH(id1, id2) ((int)(((int)(id1%65537))*11 + ((long int)(id2))))
1248#define HANDLE_CASE(len, x1, T1, q1, o1, x2, T2, q2, o2) CopyPixels(reinterpret_cast<const T1*>(x1), q1, reinterpret_cast<T2*>(x2), q2, w, h, o1!=o2);
1249#define MAKE_CASE(id1, id2) case HASH(id1, id2): HANDLE_CASE(len, src, Def_##id1, quantum1, topIsLow1, dest, Def_##id2, quantum2, topIsLow2); break;
1250
1251// More elegant ways to do this, but needs to be efficient at pixel level
1252void Image::copyPixels(const unsigned char *src, size_t id1,
1253 char unsigned *dest, size_t id2, size_t w, size_t h,
1254 size_t imageSize, size_t quantum1, size_t quantum2,
1255 bool topIsLow1, bool topIsLow2)
1256{
1257 DBG printf("copyPixels...\n");
1258
1259 if (id1==id2&&quantum1==quantum2&&topIsLow1==topIsLow2) {
1260 memcpy(dest,src,imageSize);
1261 return;
1262 }
1263
1264
1265 switch(HASH(id1,id2)) {
1266 // Macros rely on len, x1, x2 variable names
1267
1268 // Each MAKE_CASE line here expands to something like this:
1269 //
1270 // case HASH(VOCAB_PIXEL_MONO, VOCAB_PIXEL_RGB):
1271 // CopyPixels(reinterpret_cast<const PixelMono*>(src), quantum1,
1272 // reinterpret_cast<PixelRgb*>(dest), quantum2,
1273 // w, h, topIsLow1!=topIsLow2);
1274 // break;
1275
1290
1305
1320
1335
1350
1365
1380
1395
1410
1425
1440
1455
1470
1485
1486 default:
1487 printf("*** Tried to copy type %s to %s\n",
1488 yarp::os::Vocab32::decode(id1).c_str(),
1489 yarp::os::Vocab32::decode(id2).c_str());
1490 std::exit(1);
1491 break;
1492 }
1493
1494 DBG printf("... done copyPixels\n");
1495}
PixelFloat Def_VOCAB_PIXEL_MONO_FLOAT
PixelRgbFloat Def_VOCAB_PIXEL_RGB_FLOAT
PixelRgb Def_VOCAB_PIXEL_RGB
#define DBG
#define MAKE_CASE(id1, id2)
static void CopyPixel(const T1 *src, T2 *dest)
PixelInt Def_VOCAB_PIXEL_INT
PixelBgra Def_VOCAB_PIXEL_BGRA
static void CopyPixels(const T1 *osrc, int q1, T2 *odest, int q2, int w, int h, bool flip)
PixelHsvFloat Def_VOCAB_PIXEL_HSV_FLOAT
PixelRgba Def_VOCAB_PIXEL_RGBA
PixelBgr Def_VOCAB_PIXEL_BGR
PixelRgbSigned Def_VOCAB_PIXEL_RGB_SIGNED
#define HASH(id1, id2)
PixelHsv Def_VOCAB_PIXEL_HSV
PixelMono16 Def_VOCAB_PIXEL_MONO16
PixelMonoSigned Def_VOCAB_PIXEL_MONO_SIGNED
PixelRgbInt Def_VOCAB_PIXEL_RGB_INT
@ VOCAB_PIXEL_RGBA
Definition Image.h:45
@ VOCAB_PIXEL_INT
Definition Image.h:47
@ VOCAB_PIXEL_MONO16
Definition Image.h:43
@ 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_HSV_FLOAT
Definition Image.h:55
@ VOCAB_PIXEL_HSV
Definition Image.h:48
@ VOCAB_PIXEL_RGB_SIGNED
Definition Image.h:51
@ VOCAB_PIXEL_RGB_FLOAT
Definition Image.h:54
@ VOCAB_PIXEL_MONO
Definition Image.h:42
@ VOCAB_PIXEL_RGB_INT
Definition Image.h:52
@ VOCAB_PIXEL_RGB
Definition Image.h:44
#define yAssert(x)
Definition Log.h:388
A mini-server for performing network communication in the background.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition Vocab.cpp:33
size_t PAD_BYTES(size_t len, size_t pad)
computes the padding of YARP images.
Definition Image.h:30
#define YARP_UNUSED(var)
Definition api.h:162