summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPierre Joye <pierre.php@gmail.com>2021-08-25 18:44:02 +0700
committerPierre Joye <pierre.php@gmail.com>2021-08-25 18:44:02 +0700
commit67cc752b40393cfed9602a8614c9b19aaf35ac61 (patch)
tree38e0517514edffc44f9fcc1897f3820e20c70d9e /src
parentbdc281eadb1d58d5c0c7bbc1125ee4674256df08 (diff)
downloadlibgd-67cc752b40393cfed9602a8614c9b19aaf35ac61.tar.gz
Fix #405, -1 aims to reset the transparent color; refactor a bit; add test to existing test for -1
Diffstat (limited to 'src')
-rw-r--r--src/gd.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/gd.c b/src/gd.c
index 51d87d1..51221cc 100644
--- a/src/gd.c
+++ b/src/gd.c
@@ -895,19 +895,24 @@ BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color)
*/
BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color)
{
- if (color < 0) {
+ // Reset ::transparent
+ if (color == -1) {
+ im->transparent = -1;
+ }
+ if (color < -1) {
+ return;
+ }
+ if (im->trueColor) {
+ im->transparent = color;
return;
}
- if (!im->trueColor) {
- if (color >= gdMaxColors) {
- return;
- }
- if (im->transparent != -1) {
- im->alpha[im->transparent] = gdAlphaOpaque;
- }
- im->alpha[color] = gdAlphaTransparent;
+ // Palette Image
+ if (color >= gdMaxColors) {
+ return;
}
+ im->alpha[im->transparent] = gdAlphaOpaque;
+ im->alpha[color] = gdAlphaTransparent;
im->transparent = color;
}