mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-12 14:28:15 +00:00
Added function: ImageAlphaMask()
This commit is contained in:
@@ -762,6 +762,7 @@ RLAPI Color *GetImageData(Image image);
|
|||||||
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
|
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
|
||||||
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
|
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
|
||||||
RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
|
RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
|
||||||
|
RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
|
||||||
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
|
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
|
||||||
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
|
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
|
||||||
RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle
|
RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle
|
||||||
|
@@ -548,7 +548,7 @@ void ImageFormat(Image *image, int newFormat)
|
|||||||
{
|
{
|
||||||
if (image->format != newFormat)
|
if (image->format != newFormat)
|
||||||
{
|
{
|
||||||
if ((image->format < 8) && (newFormat < 8))
|
if ((image->format < COMPRESSED_DXT1_RGB) && (newFormat < COMPRESSED_DXT1_RGB))
|
||||||
{
|
{
|
||||||
Color *pixels = GetImageData(*image);
|
Color *pixels = GetImageData(*image);
|
||||||
|
|
||||||
@@ -676,12 +676,40 @@ void ImageFormat(Image *image, int newFormat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply alpha mask to image
|
||||||
|
// NOTE: alphaMask must be should be same size as image
|
||||||
|
void ImageAlphaMask(Image *image, Image alphaMask)
|
||||||
|
{
|
||||||
|
if (image->format >= COMPRESSED_DXT1_RGB)
|
||||||
|
{
|
||||||
|
TraceLog(WARNING, "Alpha mask can not be applied to compressed data formats");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Force mask to be Grayscale
|
||||||
|
Image mask = ImageCopy(alphaMask);
|
||||||
|
ImageFormat(&mask, UNCOMPRESSED_GRAYSCALE);
|
||||||
|
|
||||||
|
// Convert image to RGBA
|
||||||
|
if (image->format != UNCOMPRESSED_R8G8B8A8) ImageFormat(image, UNCOMPRESSED_R8G8B8A8);
|
||||||
|
|
||||||
|
// Apply alpha mask to alpha channel
|
||||||
|
for (int i = 0, k = 3; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 4)
|
||||||
|
{
|
||||||
|
((unsigned char *)image->data)[k] = ((unsigned char *)mask.data)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
UnloadImage(mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
|
// Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
|
||||||
// NOTE: In case selected bpp do not represent an known 16bit format,
|
// NOTE: In case selected bpp do not represent an known 16bit format,
|
||||||
// dithered data is stored in the LSB part of the unsigned short
|
// dithered data is stored in the LSB part of the unsigned short
|
||||||
void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
|
void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp)
|
||||||
{
|
{
|
||||||
if (image->format >= 8)
|
if (image->format >= COMPRESSED_DXT1_RGB)
|
||||||
{
|
{
|
||||||
TraceLog(WARNING, "Compressed data formats can not be dithered");
|
TraceLog(WARNING, "Compressed data formats can not be dithered");
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user