Mercurial > hg > openttd
changeset 18179:bdfa394ec375 draft
(svn r23008) -Add: Palette detection and conversion for the M part of 32bpp sprites.
author | frosch <frosch@openttd.org> |
---|---|
date | Thu, 06 Oct 2011 19:17:49 +0000 |
parents | a79cda68987f |
children | bc55ffc1085f |
files | src/spriteloader/png.cpp |
diffstat | 1 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -132,6 +132,7 @@ return true; } + bool win_palette = false; if (!mask) { if (bit_depth == 16) png_set_strip_16(png_ptr); @@ -156,6 +157,23 @@ pixelsize = sizeof(uint32); } else { pixelsize = sizeof(uint8); + + /* Check whether the DOS greyscale is in place. If not, we assume WIN palette */ + png_colorp palette; + int num_palette; + if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) && num_palette == 256) { + for (uint i = 3; i <= 5; i++) { + /* Allow differences between -4 and +4 */ + uint8 intensity = i * 16 - 4; + uint8 diff_r = palette[i].red - intensity; + uint8 diff_g = palette[i].green - intensity; + uint8 diff_b = palette[i].blue - intensity; + if (diff_r > 8 || diff_g > 8 || diff_b > 8) { + win_palette = true; + break; + } + } + } } png_bytep row_pointer = AllocaM(png_byte, png_get_image_width(png_ptr, info_ptr) * pixelsize); @@ -172,7 +190,9 @@ dst[x].g = 0; dst[x].b = 0; /* Alpha channel is used from the original image (to allow transparency in remap colours) */ - dst[x].m = row_pointer[x * sizeof(uint8)]; + extern const byte _palmap_w2d[]; + byte color = row_pointer[x * sizeof(uint8)]; + dst[x].m = win_palette ? _palmap_w2d[color] : color; } } else { dst[x].r = row_pointer[x * sizeof(uint32) + 0];