diff options
| author | Ray <raysan5@gmail.com> | 2019-10-11 20:08:41 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2019-10-11 20:08:41 +0200 |
| commit | 12d3e21f1bfa66f3aca334bcb01da9b52f96b089 (patch) | |
| tree | a18b75efa7ab5e2ccdd642a4fb954d3914240f08 /src | |
| parent | 161c8b7d082dcaf7f71d14396f22ed6ddf8699e4 (diff) | |
| download | raylib-12d3e21f1bfa66f3aca334bcb01da9b52f96b089.tar.gz raylib-12d3e21f1bfa66f3aca334bcb01da9b52f96b089.zip | |
REVIEW: ImageAlphaMask()
When adding alpha mask to GRAYSCALE image, if using ImageFormat(), it could change pixel values, now we avoid that, mask is just added as an extra channel
Diffstat (limited to 'src')
| -rw-r--r-- | src/textures.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/textures.c b/src/textures.c index 1c7edac9..4e48d1f7 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1181,13 +1181,18 @@ void ImageAlphaMask(Image *image, Image alphaMask) // In case image is only grayscale, we just add alpha channel if (image->format == UNCOMPRESSED_GRAYSCALE) { - ImageFormat(image, UNCOMPRESSED_GRAY_ALPHA); + unsigned char *data = (unsigned char *)RL_MALLOC(image->width*image->height*2); // Apply alpha mask to alpha channel - for (int i = 0, k = 1; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2) + for (int i = 0, k = 0; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2) { - ((unsigned char *)image->data)[k] = ((unsigned char *)mask.data)[i]; + data[k] = ((unsigned char *)image->data)[i]; + data[k + 1] = ((unsigned char *)mask.data)[i]; } + + RL_FREE(image->data); + image->data = data; + image->format = UNCOMPRESSED_GRAY_ALPHA; } else { |
