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
master
Pierre Joye 2021-08-27 01:24:00 +07:00 committed by GitHub
commit b214ab236a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View File

@ -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;
}

View File

@ -22,7 +22,13 @@ int main()
gdImageColorTransparent(im, pos);
if(im->transparent == pos) {
error = -1;
error = -2;
}
pos = -1;
gdImageColorTransparent(im, pos);
if(im->transparent != pos) {
error = -3;
}
gdImageDestroy(im);