diff options
| author | Ray <[email protected]> | 2019-08-07 00:28:05 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-08-07 00:28:05 +0200 |
| commit | 2a913b6587d60dab64c3b81019990e6872a9ac75 (patch) | |
| tree | 375ec08ac3baf44bacd5fe5bf886f785faf4024b /src/textures.c | |
| parent | 042499188c55030cb675df2ac135cf8b71e841dd (diff) | |
| download | raylib-2a913b6587d60dab64c3b81019990e6872a9ac75.tar.gz raylib-2a913b6587d60dab64c3b81019990e6872a9ac75.zip | |
ADDED: GetImageAlphaBorder()
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c index 18021352..a25a23ab 100644 --- a/src/textures.c +++ b/src/textures.c @@ -680,6 +680,37 @@ Vector4 *GetImageDataNormalized(Image image) return pixels; } +// Get image alpha border rectangle +Rectangle GetImageAlphaBorder(Image image) +{ + Color *pixels = GetImageData(image); + + int xMin = 65536; // Define a big enough number + int xMax = 0; + int yMin = 65536; + int yMax = 0; + + for (int y = 0; y < image->height; y++) + { + for (int x = 0; x < image->width; x++) + { + if (pixels[y*image->width + x].a > (unsigned char)(threshold*255.0f)) + { + if (x < xMin) xMin = x; + if (x > xMax) xMax = x; + if (y < yMin) yMin = y; + if (y > yMax) yMax = y; + } + } + } + + Rectangle crop = { xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin }; + + RL_FREE(pixels); + + return crop; +} + // Get pixel data size in bytes (image or texture) // NOTE: Size depends on pixel format int GetPixelDataSize(int width, int height, int format) @@ -894,7 +925,9 @@ Image ImageFromImage(Image image, Rectangle rec) { Image result = ImageCopy(image); +#if defined(SUPPORT_IMAGE_MANIPULATION) ImageCrop(&result, rec); +#endif return result; } |
