diff options
| author | raysan5 <[email protected]> | 2020-06-08 18:24:53 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-06-08 18:24:53 +0200 |
| commit | 82f7dd017ee3899ff09475c25222e995f70a80b8 (patch) | |
| tree | 18616bf3771f9062adae57675f59ee62e2fc2d42 /src/textures.c | |
| parent | 40bc6afdbd06d213a07a5e321f4f285d613a1fe5 (diff) | |
| download | raylib-82f7dd017ee3899ff09475c25222e995f70a80b8.tar.gz raylib-82f7dd017ee3899ff09475c25222e995f70a80b8.zip | |
REVIEWED: ImageAlphaPremultiply(), optimization
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/textures.c b/src/textures.c index 1a8af614..05003581 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1182,10 +1182,19 @@ void ImageAlphaPremultiply(Image *image) for (int i = 0; i < image->width*image->height; i++) { - alpha = (float)pixels[i].a/255.0f; - pixels[i].r = (unsigned char)((float)pixels[i].r*alpha); - pixels[i].g = (unsigned char)((float)pixels[i].g*alpha); - pixels[i].b = (unsigned char)((float)pixels[i].b*alpha); + if (pixels[i].a == 0) + { + pixels[i].r = 0; + pixels[i].g = 0; + pixels[i].b = 0; + } + else if (pixels[i].a < 255) + { + alpha = (float)pixels[i].a/255.0f; + pixels[i].r = (unsigned char)((float)pixels[i].r*alpha); + pixels[i].g = (unsigned char)((float)pixels[i].g*alpha); + pixels[i].b = (unsigned char)((float)pixels[i].b*alpha); + } } RL_FREE(image->data); |
