Skip to content

Commit 1cdaf44

Browse files
committed
fix
1 parent e6242dd commit 1cdaf44

File tree

5 files changed

+55
-37
lines changed

5 files changed

+55
-37
lines changed

src/libYARP_sig/src/yarp/sig/Image.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,13 @@ bool Image::operator==(const Image& alt) const
605605
//test byte per byte
606606
unsigned char* raw1 = getRawImage();
607607
unsigned char* raw2 = alt.getRawImage();
608-
for (size_t i = 0; i < raw1size; i++, raw1++, raw2++)
608+
if (raw1 == nullptr) { return false;}
609+
if (raw2 == nullptr) { return false;}
610+
for (size_t i = 0; i < raw1size; i++)
609611
{
610-
if (*raw1 != *raw2) { return false; }
612+
if (raw1[i] != raw2[i]) {
613+
return false;
614+
}
611615
}
612616
return true;
613617
}

src/libYARP_sig/src/yarp/sig/ImageUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ bool utils::sum(Image& OutImg, const Image& InImg, bool enable_colorkey, int col
159159
}
160160

161161
yarp::sig::PixelRgb ColorkeyRGB;
162-
ColorkeyRGB.r = colorkey;
163-
ColorkeyRGB.g = colorkey;
164-
ColorkeyRGB.b = colorkey;
162+
ColorkeyRGB = *reinterpret_cast<yarp::sig::PixelRgb*>(&colorkey);
165163

166164
size_t yis = InImg.height();
167165
size_t xis = InImg.width();

src/libYARP_sig/src/yarp/sig/ImageUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ bool YARP_sig_API cropRect(const yarp::sig::Image& inImg,
6969
yarp::sig::Image& outImg);
7070

7171
/**
72-
* @brief applies an image on the top over another image.
73-
* @param[in/out] OutImg the output image. It must be a valid image on the top of which data will be summed. It may contain a backgroud or it can be zero.
72+
* @brief applies an image on the top over another image. Currently it is implemented only for RGB Images
73+
* @param[in/out] OutImg the output image. It must be a valid image on the top of which data will be summed. It may contain a background or it can be zero.
7474
* @param[in] InImg the layer to be applied
75-
* @param[in] colorkey colorkey for the InImg image. If a pixel is == colorkey, then it will be made transparent and the backgroud will be visible.
75+
* @param[in] colorkey colorkey for the InImg image. If a pixel is == colorkey, then it will be made transparent and the background will be visible.
7676
* @param[in] alpha to be applied to InImg.
7777
* @param[in] off_x horizontal offset applied to InImg. Excess will be cropped.
7878
* @param[in] off_y vertical offset applied to InImg. Excess will be cropped.

src/libYARP_sig/src/yarp/sig/LayeredImage.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,42 @@ class YARP_sig_API yarp::sig::ImageLayer
2525
public:
2626
yarp::sig::FlexImage layer;
2727
bool enable=true;
28-
struct colorkey_s
28+
class colorkey_s
2929
{
30-
bool enable = true;
31-
int value=0;
30+
public:
31+
int value;
32+
bool enable;
3233

3334
//default constructor
34-
colorkey_s() = default;
35-
} colorkey;
36-
37-
struct alpha_s
35+
colorkey_s() : enable(true), value(0) {}
36+
37+
void setValueAsPixelRgb(yarp::sig::PixelRgb v)
38+
{
39+
value = *reinterpret_cast<int*>(&v);
40+
}
41+
yarp::sig::PixelRgb getValueAsPixelRgb()
42+
{
43+
return *reinterpret_cast<yarp::sig::PixelRgb*>(&value);
44+
}
45+
};
46+
colorkey_s colorkey;
47+
48+
class alpha_s
3849
{
39-
bool enable = true;
40-
float value=1.0;
50+
public:
51+
bool enable;
52+
float value;
4153

42-
//default constructor
43-
alpha_s() = default;
44-
} alpha;
54+
// default constructor
55+
alpha_s() : enable(true), value(1.0) {}
56+
};
57+
alpha_s alpha;
4558

4659
bool can_be_compressed = true;
4760
int offset_x=0;
4861
int offset_y=0;
4962

50-
ImageLayer(const yarp::sig::FlexImage& img, bool ena = true, colorkey_s ckey = colorkey_s {}, alpha_s alph = alpha_s {}, bool compress=true, int off_x = 0, int off_y = 0)
63+
ImageLayer(const yarp::sig::FlexImage& img, bool ena = true, colorkey_s ckey = colorkey_s(), alpha_s alph = alpha_s(), bool compress = true, int off_x = 0, int off_y = 0)
5164
{
5265
layer = img;
5366
enable = ena;

src/libYARP_sig/tests/LayeredImageTest.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,29 @@ TEST_CASE("sig::LayeredImageTest", "[yarp::sig]")
190190
yarp::sig::ImageOf<yarp::sig::PixelRgb> lay0;
191191
lay0.resize(4, 4);
192192
lay0.zero();
193-
imageback.pixel(0, 0).r = 20;
194-
imageback.pixel(1, 0).r = 20;
195-
imageback.pixel(2, 0).r = 20;
196-
imageback.pixel(3, 0).r = 20;
197-
imageback.pixel(0, 1).r = 20;
198-
imageback.pixel(1, 1).r = 50;
199-
imageback.pixel(2, 1).r = 50;
200-
imageback.pixel(3, 1).r = 20;
201-
imageback.pixel(0, 2).r = 20;
202-
imageback.pixel(1, 2).r = 50;
203-
imageback.pixel(2, 2).r = 50;
204-
imageback.pixel(3, 2).r = 20;
205-
imageback.pixel(0, 3).r = 20;
206-
imageback.pixel(1, 3).r = 50;
207-
imageback.pixel(2, 3).r = 20;
208-
imageback.pixel(3, 3).r = 20;
193+
lay0.pixel(0, 0).r = 20;
194+
lay0.pixel(1, 0).r = 20;
195+
lay0.pixel(2, 0).r = 20;
196+
lay0.pixel(3, 0).r = 20;
197+
lay0.pixel(0, 1).r = 20;
198+
lay0.pixel(1, 1).r = 50;
199+
lay0.pixel(2, 1).r = 50;
200+
lay0.pixel(3, 1).r = 20;
201+
lay0.pixel(0, 2).r = 20;
202+
lay0.pixel(1, 2).r = 50;
203+
lay0.pixel(2, 2).r = 50;
204+
lay0.pixel(3, 2).r = 20;
205+
lay0.pixel(0, 3).r = 20;
206+
lay0.pixel(1, 3).r = 50;
207+
lay0.pixel(2, 3).r = 20;
208+
lay0.pixel(3, 3).r = 20;
209209

210210
LayeredImage multiLayerImageIn;
211211
multiLayerImageIn.background = *(reinterpret_cast<yarp::sig::FlexImage*>(&imageback));
212212
multiLayerImageIn.layers.push_back(*(reinterpret_cast<yarp::sig::FlexImage*>(&lay0)));
213+
yarp::sig::PixelRgb colorkeyRgb;
214+
colorkeyRgb.r = 20;
215+
multiLayerImageIn.layers[0].colorkey.setValueAsPixelRgb(colorkeyRgb);
213216

214217
FlexImage flat_img = multiLayerImageIn;
215218
yarp::sig::ImageOf<yarp::sig::PixelRgb> flat_rgb_img = *(reinterpret_cast<yarp::sig::ImageOf<yarp::sig::PixelRgb>*>(&flat_img));

0 commit comments

Comments
 (0)