Fix a bug in palette_normalize_range which caused color distortion.

The luminance normalization now converts r,g,b to y,u,v and
normalizes y prior to converting back to r,g,b. This affects e.g. radarscp, dkong and mario drivers. [Couriersud]
This commit is contained in:
Couriersud 2011-01-28 07:42:32 +00:00
parent c6383e5972
commit 10ad09bac8

View File

@ -707,11 +707,13 @@ void palette_normalize_range(palette_t *palette, UINT32 start, UINT32 end, int l
for (index = start; index <= end; index++)
{
rgb_t rgb = palette->entry_color[index];
UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
UINT32 target = tmin + ((y - ymin) * (tmax - tmin + 1)) / (ymax - ymin);
UINT8 r = (y == 0) ? 0 : rgb_clamp(RGB_RED(rgb) * 1000 * target / y);
UINT8 g = (y == 0) ? 0 : rgb_clamp(RGB_GREEN(rgb) * 1000 * target / y);
UINT8 b = (y == 0) ? 0 : rgb_clamp(RGB_BLUE(rgb) * 1000 * target / y);
INT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
INT32 u = ((INT32)RGB_BLUE(rgb)-y /1000)*565 / 1000;
INT32 v = ((INT32)RGB_RED(rgb)-y / 1000)*713 / 1000;
INT32 target = tmin + ((y - ymin) * (tmax - tmin + 1)) / (ymax - ymin);
UINT8 r = rgb_clamp(target + 1403 * v / 1000);
UINT8 g = rgb_clamp(target - 344 * u / 1000 - 714 * v / 1000);
UINT8 b = rgb_clamp(target + 1770 * u / 1000);
palette_entry_set_color(palette, index, MAKE_RGB(r, g, b));
}
}