Fix crash when loading 24bit+transparency PNG images, such as http://pixeljoint.com/pixelart/51675.htm - This patch discards the transparency data in this case, because interpreting it correctly is a much bigger change: todo sometime later.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1458 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-04-16 00:36:41 +00:00
parent 8887d4ece5
commit 5e972c0659

View File

@ -3420,6 +3420,8 @@ void Load_PNG(T_IO_Context * context)
}
// Transparency (tRNS)
if (png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values))
{
if (color_type == PNG_COLOR_TYPE_PALETTE && trans!=NULL)
{
int i;
for (i=0; i<num_trans; i++)
@ -3432,6 +3434,21 @@ void Load_PNG(T_IO_Context * context)
}
}
}
else if ((color_type == PNG_COLOR_TYPE_GRAY
|| color_type == PNG_COLOR_TYPE_RGB) && trans_values!=NULL)
{
// In this case, num_trans is supposed to be "1",
// and trans_values[0] contains the reference color
// (RGB triplet) that counts as transparent.
// Ideally, we should reserve this color in the palette,
// (so it's not merged and averaged with a neighbor one)
// and after creating the optimized palette, find its
// index and mark it transparent.
// Current implementation: ignore.
}
}
context->Width=info_ptr->width;
context->Height=info_ptr->height;