REVIEWED: ImageFromImage() - ROS: CLN-007

This commit is contained in:
Ray 2026-07-11 16:20:41 +02:00
commit c31666fe2a

View file

@ -1228,6 +1228,11 @@ Image ImageFromImage(Image image, Rectangle rec)
{
Image result = { 0 };
// Basic rectangle validation: size smaller than image size
if ((rec.x > 0) && (rec.y > 0) && (rec.width > 0) && (rec.height > 0) &&
(((int)rec.x + (int)rec.width) < image.width) &&
(((int)rec.y + (int)rec.height) < image.height))
{
int bytesPerPixel = GetPixelDataSize(1, 1, image.format);
result.width = (int)rec.width;
@ -1240,6 +1245,8 @@ Image ImageFromImage(Image image, Rectangle rec)
{
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;
}