summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPierre Joye <pierre.php@gmail.com>2021-08-27 01:24:00 +0700
committerGitHub <noreply@github.com>2021-08-27 01:24:00 +0700
commitb214ab236acac1fb5cf84491894b544027bccba5 (patch)
tree0f7081b79b46e6fe388a881aa1cea224e27a6c9a /src
parent0bc3170fa7b8cb74868ab477652b541a91ac391d (diff)
parent3a4d2127efabc98c192335dd482c371a4adda54b (diff)
downloadlibgd-b214ab236acac1fb5cf84491894b544027bccba5.tar.gz
Merge pull request #737 from libgd/bug/405
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.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/gd.c b/src/gd.c
index 4c1c3b6..db96cc9 100644
--- a/src/gd.c
+++ b/src/gd.c
@@ -895,19 +895,27 @@ 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;
return;
}
- if (!im->trueColor) {
- if (color >= gdMaxColors) {
- return;
- }
- if (im->transparent != -1) {
- im->alpha[im->transparent] = gdAlphaOpaque;
- }
- im->alpha[color] = gdAlphaTransparent;
+ if (color < -1) {
+ return;
+ }
+
+ if (im->trueColor) {
+ im->transparent = color;
+ return;
+ }
+
+ // Palette Image
+ if (color >= gdMaxColors) {
+ return;
}
+ im->alpha[im->transparent] = gdAlphaOpaque;
+ im->alpha[color] = gdAlphaTransparent;
im->transparent = color;
}