Work on ImageResizeCanvas()
This commit is contained in:
parent
cbfa35a39e
commit
29d1323bd1
1 changed files with 47 additions and 14 deletions
|
@ -1399,22 +1399,55 @@ void ImageResizeNN(Image *image,int newWidth,int newHeight)
|
||||||
void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int offsetX, int offsetY, Color color)
|
void ImageResizeCanvas(Image *image, int newWidth,int newHeight, int offsetX, int offsetY, Color color)
|
||||||
{
|
{
|
||||||
// TODO: Review different scaling situations
|
// TODO: Review different scaling situations
|
||||||
|
|
||||||
if ((newWidth > image->width) && (newHeight > image->height))
|
if ((newWidth != image->width) || (newHeight != image->height))
|
||||||
{
|
{
|
||||||
Image imTemp = GenImageColor(newWidth, newHeight, color);
|
if ((newWidth > image->width) && (newHeight > image->height))
|
||||||
Rectangle srcRec = { 0.0f, 0.0f, (float)image->width, (float)image->height };
|
{
|
||||||
Rectangle dstRec = { (float)offsetX, (float)offsetY, (float)srcRec.width, (float)srcRec.height };
|
Image imTemp = GenImageColor(newWidth, newHeight, color);
|
||||||
|
|
||||||
|
Rectangle srcRec = { 0.0f, 0.0f, (float)image->width, (float)image->height };
|
||||||
|
Rectangle dstRec = { (float)offsetX, (float)offsetY, (float)srcRec.width, (float)srcRec.height };
|
||||||
|
|
||||||
ImageDraw(&imTemp, *image, srcRec, dstRec);
|
ImageDraw(&imTemp, *image, srcRec, dstRec);
|
||||||
ImageFormat(&imTemp, image->format);
|
ImageFormat(&imTemp, image->format);
|
||||||
UnloadImage(*image);
|
UnloadImage(*image);
|
||||||
*image = imTemp;
|
*image = imTemp;
|
||||||
}
|
}
|
||||||
else if ((newWidth < image->width) && (newHeight < image->height))
|
else if ((newWidth < image->width) && (newHeight < image->height))
|
||||||
{
|
{
|
||||||
Rectangle crop = { (float)offsetX, (float)offsetY, newWidth, newHeight };
|
Rectangle crop = { (float)offsetX, (float)offsetY, newWidth, newHeight };
|
||||||
ImageCrop(image, crop);
|
ImageCrop(image, crop);
|
||||||
|
}
|
||||||
|
else // One side is bigger and the other is smaller
|
||||||
|
{
|
||||||
|
Image imTemp = GenImageColor(newWidth, newHeight, color);
|
||||||
|
|
||||||
|
Rectangle srcRec = { 0.0f, 0.0f, (float)image->width, (float)image->height };
|
||||||
|
Rectangle dstRec = { (float)offsetX, (float)offsetY, (float)newWidth, (float)newHeight };
|
||||||
|
|
||||||
|
if (newWidth < image->width)
|
||||||
|
{
|
||||||
|
srcRec.x = offsetX;
|
||||||
|
srcRec.width = newWidth;
|
||||||
|
|
||||||
|
dstRec.x = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newHeight < image->height)
|
||||||
|
{
|
||||||
|
srcRec.y = offsetY;
|
||||||
|
srcRec.height = newHeight;
|
||||||
|
|
||||||
|
dstRec.y = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ImageDraw() could be buggy?
|
||||||
|
ImageDraw(&imTemp, *image, srcRec, dstRec);
|
||||||
|
ImageFormat(&imTemp, image->format);
|
||||||
|
UnloadImage(*image);
|
||||||
|
*image = imTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue