- #7, imagecopy doen't copy the alpha channel, palette to truecolor copy

master
pajoye 2006-10-08 21:43:16 +00:00
parent 9575411e8d
commit 05c826bd50
3 changed files with 81 additions and 43 deletions

View File

@ -9,3 +9,5 @@ GDBUGS NEWS
#4, TrueColor transparent color not used with GIF output (palette)
#5, Numerous security fixes in GIF loader. When the gif palette is broken,
the image size is invalid or NULL block at unexpected postions.
#6, Add test for gdImagePng and transparent color
#7, gdIimageCopy doen't use the alpha channel (palette to truecolor copy)

View File

@ -1975,52 +1975,60 @@ BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dst
int tox, toy;
int i;
int colorMap[gdMaxColors];
if (dst->trueColor)
{
/* 2.0: much easier when the destination is truecolor. */
/* 2.0.10: needs a transparent-index check that is still valid if
the source is not truecolor. Thanks to Frank Warmerdam. */
for (y = 0; (y < h); y++)
{
for (x = 0; (x < w); x++)
{
int p = gdImageGetPixel (src, srcX + x, srcY + y);
if (p != src->transparent)
{
int c = gdImageGetTrueColorPixel (src, srcX + x,
srcY + y);
gdImageSetPixel (dst, dstX + x, dstY + y, c);
}
}
}
return;
}
if (dst->trueColor) {
/* 2.0: much easier when the destination is truecolor. */
/* 2.0.10: needs a transparent-index check that is still valid if
* * the source is not truecolor. Thanks to Frank Warmerdam.
* */
if (src->trueColor) {
for (y = 0; (y < h); y++) {
for (x = 0; (x < w); x++) {
int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
gdImageSetPixel (dst, dstX + x, dstY + y, c);
}
}
} else {
/* source is palette based */
for (y = 0; (y < h); y++) {
for (x = 0; (x < w); x++) {
int c = gdImageGetPixel (src, srcX + x, srcY + y);
if (c != src->transparent) {
gdImageSetPixel(dst, dstX + x, dstY + y, gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]));
}
}
}
}
return;
}
for (i = 0; (i < gdMaxColors); i++)
{
colorMap[i] = (-1);
}
{
colorMap[i] = (-1);
}
toy = dstY;
for (y = srcY; (y < (srcY + h)); y++)
{
tox = dstX;
for (x = srcX; (x < (srcX + w)); x++)
{
int nc;
int mapTo;
c = gdImageGetPixel (src, x, y);
/* Added 7/24/95: support transparent copies */
if (gdImageGetTransparent (src) == c)
{
tox++;
continue;
}
/* Have we established a mapping for this color? */
if (src->trueColor)
{
/* 2.05: remap to the palette available in the
destination image. This is slow and
works badly, but it beats crashing! Thanks
to Padhrig McCarthy. */
{
tox = dstX;
for (x = srcX; (x < (srcX + w)); x++)
{
int nc;
int mapTo;
c = gdImageGetPixel (src, x, y);
/* Added 7/24/95: support transparent copies */
if (gdImageGetTransparent (src) == c)
{
tox++;
continue;
}
/* Have we established a mapping for this color? */
if (src->trueColor)
{
/* 2.05: remap to the palette available in the
destination image. This is slow and
works badly, but it beats crashing! Thanks
to Padhrig McCarthy. */
mapTo = gdImageColorResolveAlpha (dst,
gdTrueColorGetRed (c),
gdTrueColorGetGreen (c),

28
src/tests/bug00007.c Normal file
View File

@ -0,0 +1,28 @@
#include "gd.h"
int main()
{
gdImagePtr dst_tc, src;
FILE *fp;
int c0,c1,c3;
src = gdImageCreate(5,5);
c0 = gdImageColorAllocate(src, 255,255,255);
c1 = gdImageColorAllocateAlpha(src, 255,0,0,70);
gdImageAlphaBlending(src, 0);
gdImageFill(src, 0,0, c1);
dst_tc = gdImageCreateTrueColor(5,5);
gdImageAlphaBlending(dst_tc, 0);
gdImageCopy(dst_tc, src, 0,0, 0,0, gdImageSX(src), gdImageSY(src));
gdImagePng(dst_tc, fp);
fclose(fp);
/* Destroy it */
gdImageDestroy(src);
gdImageDestroy(dst_tc);
return 0;
}