mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-01 11:49:17 -05:00
REVIEW: GetImageData() and GetImageAlphaBorder()
This commit is contained in:
@ -459,6 +459,8 @@ Color *GetImageData(Image image)
|
|||||||
{
|
{
|
||||||
Color *pixels = (Color *)RL_MALLOC(image.width*image.height*sizeof(Color));
|
Color *pixels = (Color *)RL_MALLOC(image.width*image.height*sizeof(Color));
|
||||||
|
|
||||||
|
if (pixels == NULL) return pixels;
|
||||||
|
|
||||||
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
|
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -683,8 +685,12 @@ Vector4 *GetImageDataNormalized(Image image)
|
|||||||
// Get image alpha border rectangle
|
// Get image alpha border rectangle
|
||||||
Rectangle GetImageAlphaBorder(Image image, float threshold)
|
Rectangle GetImageAlphaBorder(Image image, float threshold)
|
||||||
{
|
{
|
||||||
|
Rectangle crop = { 0 };
|
||||||
|
|
||||||
Color *pixels = GetImageData(image);
|
Color *pixels = GetImageData(image);
|
||||||
|
|
||||||
|
if (pixels != NULL)
|
||||||
|
{
|
||||||
int xMin = 65536; // Define a big enough number
|
int xMin = 65536; // Define a big enough number
|
||||||
int xMax = 0;
|
int xMax = 0;
|
||||||
int yMin = 65536;
|
int yMin = 65536;
|
||||||
@ -704,9 +710,10 @@ Rectangle GetImageAlphaBorder(Image image, float threshold)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle crop = { xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin };
|
crop = (Rectangle){ xMin, yMin, (xMax + 1) - xMin, (yMax + 1) - yMin };
|
||||||
|
|
||||||
RL_FREE(pixels);
|
RL_FREE(pixels);
|
||||||
|
}
|
||||||
|
|
||||||
return crop;
|
return crop;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user