mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-17 23:21:22 +00:00
Merge branch 'pngpal-compare' into 'next'
Compare PNG palettes with the game's palette, instead of assuming they are the same See merge request STJr/SRB2!1185
This commit is contained in:
commit
b2dc35864e
1 changed files with 31 additions and 12 deletions
|
@ -887,17 +887,35 @@ static png_bytep *PNG_Read(
|
|||
// matches the color count of SRB2's palette: 256 colors.
|
||||
if (png_get_PLTE(png_ptr, png_info_ptr, &palette, &palette_size))
|
||||
{
|
||||
if (palette_size == 256)
|
||||
if (palette_size == 256 && pMasterPalette)
|
||||
{
|
||||
png_colorp pal = palette;
|
||||
INT32 i;
|
||||
|
||||
usepal = true;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UINT32 rgb = R_PutRgbaRGBA(pal->red, pal->green, pal->blue, 0xFF);
|
||||
if (rgb != pMasterPalette[i].rgba)
|
||||
{
|
||||
usepal = false;
|
||||
break;
|
||||
}
|
||||
pal++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If any of the tRNS colors have an alpha lower than 0xFF, and that
|
||||
// color is present on the image, the palette flag is disabled.
|
||||
if (usepal)
|
||||
{
|
||||
png_get_tRNS(png_ptr, png_info_ptr, &trans, &trans_num, &trans_values);
|
||||
|
||||
if (trans && trans_num == 256)
|
||||
{
|
||||
int i;
|
||||
INT32 i;
|
||||
for (i = 0; i < trans_num; i++)
|
||||
{
|
||||
// libpng will transform this image into RGB even if
|
||||
|
@ -910,6 +928,7 @@ static png_bytep *PNG_Read(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (usepal)
|
||||
*use_palette = true;
|
||||
|
|
Loading…
Reference in a new issue