REVIEWED: ImageFromImage() - ROS: CLN-007
This commit is contained in:
parent
ab35e0f712
commit
c31666fe2a
1 changed files with 16 additions and 9 deletions
|
|
@ -1228,18 +1228,25 @@ Image ImageFromImage(Image image, Rectangle rec)
|
||||||
{
|
{
|
||||||
Image result = { 0 };
|
Image result = { 0 };
|
||||||
|
|
||||||
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
|
// Basic rectangle validation: size smaller than image size
|
||||||
|
if ((rec.x > 0) && (rec.y > 0) && (rec.width > 0) && (rec.height > 0) &&
|
||||||
result.width = (int)rec.width;
|
(((int)rec.x + (int)rec.width) < image.width) &&
|
||||||
result.height = (int)rec.height;
|
(((int)rec.y + (int)rec.height) < image.height))
|
||||||
result.data = RL_CALLOC((int)rec.width*(int)rec.height*bytesPerPixel, 1);
|
|
||||||
result.format = image.format;
|
|
||||||
result.mipmaps = 1;
|
|
||||||
|
|
||||||
for (int y = 0; y < (int)rec.height; y++)
|
|
||||||
{
|
{
|
||||||
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
|
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
|
||||||
|
|
||||||
|
result.width = (int)rec.width;
|
||||||
|
result.height = (int)rec.height;
|
||||||
|
result.data = RL_CALLOC((int)rec.width*(int)rec.height*bytesPerPixel, 1);
|
||||||
|
result.format = image.format;
|
||||||
|
result.mipmaps = 1;
|
||||||
|
|
||||||
|
for (int y = 0; y < (int)rec.height; y++)
|
||||||
|
{
|
||||||
|
memcpy(((unsigned char *)result.data) + y*(int)rec.width*bytesPerPixel, ((unsigned char *)image.data) + ((y + (int)rec.y)*image.width + (int)rec.x)*bytesPerPixel, (int)rec.width*bytesPerPixel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "IMAGE: Rectangle provided for ImageToImage not valid");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue