summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gd.c23
-rw-r--r--tests/gdimagecolortransparent/gdimagecolortransparent.c10
2 files changed, 23 insertions, 10 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;
}
diff --git a/tests/gdimagecolortransparent/gdimagecolortransparent.c b/tests/gdimagecolortransparent/gdimagecolortransparent.c
index aca380b..7d6e234 100644
--- a/tests/gdimagecolortransparent/gdimagecolortransparent.c
+++ b/tests/gdimagecolortransparent/gdimagecolortransparent.c
@@ -15,6 +15,7 @@ int main()
if(im->transparent == pos) {
error = -1;
+ goto exit;
}
pos = -2;
@@ -22,7 +23,14 @@ int main()
gdImageColorTransparent(im, pos);
if(im->transparent == pos) {
- error = -1;
+ error = -2;
+ goto exit;
+ }
+
+ pos = -1;
+ gdImageColorTransparent(im, pos);
+ if(im->transparent == pos) {
+ error = -3;
}
gdImageDestroy(im);