diff options
| author | Ray <[email protected]> | 2019-03-15 13:34:09 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-03-15 13:34:09 +0100 |
| commit | 29d1323bd12b0c8155d8c2a9c2830a002ebc608b (patch) | |
| tree | 0edf10b431c6b23f3265f910a7d9c308b8e50f96 /src/textures.c | |
| parent | cbfa35a39e2075431aa84ed0c476c39ff3e30adc (diff) | |
| download | raylib-29d1323bd12b0c8155d8c2a9c2830a002ebc608b.tar.gz raylib-29d1323bd12b0c8155d8c2a9c2830a002ebc608b.zip | |
Work on ImageResizeCanvas()
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/src/textures.c b/src/textures.c index 070c83f3..7c942f18 100644 --- a/src/textures.c +++ b/src/textures.c @@ -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) { // 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); - Rectangle srcRec = { 0.0f, 0.0f, (float)image->width, (float)image->height }; - Rectangle dstRec = { (float)offsetX, (float)offsetY, (float)srcRec.width, (float)srcRec.height }; + if ((newWidth > image->width) && (newHeight > image->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); + ImageFormat(&imTemp, image->format); + UnloadImage(*image); + *image = imTemp; + } + else if ((newWidth < image->width) && (newHeight < image->height)) + { + Rectangle crop = { (float)offsetX, (float)offsetY, newWidth, newHeight }; + 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; + } - ImageDraw(&imTemp, *image, srcRec, dstRec); - ImageFormat(&imTemp, image->format); - UnloadImage(*image); - *image = imTemp; - } - else if ((newWidth < image->width) && (newHeight < image->height)) - { - Rectangle crop = { (float)offsetX, (float)offsetY, newWidth, newHeight }; - ImageCrop(image, crop); + // TODO: ImageDraw() could be buggy? + ImageDraw(&imTemp, *image, srcRec, dstRec); + ImageFormat(&imTemp, image->format); + UnloadImage(*image); + *image = imTemp; + } } } |
