34 size_t inHeight = inImg.
height();
35 size_t singleImage_rowSizeByte = outImgL.
getRowSize();
40 for(
size_t h=0; h<inHeight; h++)
43 memcpy(pixelLeft + h*singleImage_rowSizeByte, pixelInput, singleImage_rowSizeByte);
44 memcpy(pixelRight + h*singleImage_rowSizeByte, pixelInput+=singleImage_rowSizeByte, singleImage_rowSizeByte);
47 pixelInput+= singleImage_rowSizeByte;
77 size_t singleImage_rowSizeByte = inImgL.
getRowSize();
80 unsigned char * pixelOutLeft = outImg.
getRawImage();
81 unsigned char * pixelOutRight = outImg.
getRawImage() + singleImage_rowSizeByte;
83 size_t height = inImgL.
height();
85 for(
size_t h=0; h<height; h++)
88 memcpy(pixelOutLeft, pixelLeft, singleImage_rowSizeByte);
89 memcpy(pixelOutRight, pixelRight, singleImage_rowSizeByte);
92 pixelOutLeft += 2*singleImage_rowSizeByte;
93 pixelOutRight += 2*singleImage_rowSizeByte;
94 pixelLeft += singleImage_rowSizeByte;
95 pixelRight += singleImage_rowSizeByte;
116 const std::pair<unsigned int, unsigned int>& vertex1,
117 const std::pair<unsigned int, unsigned int>& vertex2,
125 auto tlx = std::min(vertex1.first, vertex2.first);
126 auto tly = std::min(vertex1.second, vertex2.second);
127 auto brx = std::max(vertex1.first, vertex2.first);
128 auto bry = std::max(vertex1.second, vertex2.second);
130 if (!inImg.
isPixel(brx, bry)) {
134 outImg.
resize(brx - tlx + 1, bry - tly + 1);
138 for (
unsigned int row = 0; row < outImg.
height(); row++) {
140 memcpy(pixelOut, pixelIn, outImg.
getRowSize());
147bool utils::sum(
Image& OutImg,
const Image& InImg,
bool enable_colorkey,
int colorkey,
bool enable_alpha,
float alpha,
size_t offset_x,
size_t offset_y)
151 yError() <<
"utils::sum() Input and Output images must have the same pixelcode";
157 yError() <<
"utils::sum() Unimplemented pixelcode";
161 yarp::sig::PixelRgb ColorkeyRGB;
162 ColorkeyRGB = *
reinterpret_cast<yarp::sig::PixelRgb*
>(&colorkey);
164 size_t yis = InImg.
height();
165 size_t xis = InImg.
width();
166 size_t yos = OutImg.
height();
167 size_t xos = OutImg.
width();
169 for (
size_t y = 0; y < yis; ++y)
171 for (
size_t x = 0; x < xis; ++x)
173 size_t xo = x + offset_x;
174 size_t yo = y + offset_y;
185 yarp::sig::PixelRgb* layer_pointer_rgb =
reinterpret_cast<yarp::sig::PixelRgb*
>(layer_pointer);
186 yarp::sig::PixelRgb* outimg_pointer_rgb =
reinterpret_cast<yarp::sig::PixelRgb*
>(outimg_pointer);
188 if (enable_colorkey && layer_pointer_rgb->r == ColorkeyRGB.r && layer_pointer_rgb->g == ColorkeyRGB.g && layer_pointer_rgb->b == ColorkeyRGB.b)
192 else if (enable_alpha)
194 outimg_pointer_rgb->r = layer_pointer_rgb->r * alpha + outimg_pointer_rgb->r * (1 - alpha);
195 outimg_pointer_rgb->g = layer_pointer_rgb->g * alpha + outimg_pointer_rgb->g * (1 - alpha);
196 outimg_pointer_rgb->b = layer_pointer_rgb->b * alpha + outimg_pointer_rgb->b * (1 - alpha);
200 outimg_pointer_rgb->r = layer_pointer_rgb->r;
201 outimg_pointer_rgb->g = layer_pointer_rgb->g;
202 outimg_pointer_rgb->b = layer_pointer_rgb->b;
static bool checkImages(const Image &bigImg, const Image &smallImg1, const Image &smallImg2)
Base class for storing images.
size_t width() const
Gets width of image in pixels.
size_t getRowSize() const
Size of the underlying image buffer rows.
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
bool isPixel(size_t x, size_t y) const
Check whether a coordinate lies within the image.
size_t height() const
Gets height of image in pixels.
virtual int getPixelCode() const
Gets pixel type identifier.
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
bool vertSplit(const yarp::sig::Image &inImg, yarp::sig::Image &outImgL, yarp::sig::Image &outImgR)
Split vertically an image in two images of the same size.
bool cropRect(const yarp::sig::Image &inImg, const std::pair< unsigned int, unsigned int > &vertex1, const std::pair< unsigned int, unsigned int > &vertex2, yarp::sig::Image &outImg)
Crop a rectangle area out of an image given two opposite vertices.
bool horzSplit(const yarp::sig::Image &inImg, yarp::sig::Image &outImgUp, yarp::sig::Image &outImgDown)
Split horizontally an image in two images of the same size.
bool vertConcat(const yarp::sig::Image &inImgUp, const yarp::sig::Image &inImgDown, yarp::sig::Image &outImg)
Concatenate vertically two images of the same size in one with double height.
bool horzConcat(const yarp::sig::Image &inImgL, const yarp::sig::Image &inImgR, yarp::sig::Image &outImg)
Concatenate horizontally two images of the same size in one with double width.
bool sum(yarp::sig::Image &OutImg, const yarp::sig::Image &InImg, bool colorkey_enable, int colorkey, bool alpha_enable, float alpha, size_t off_x, size_t off_y)
applies an image on the top over another image.