summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Couriersud <couriersud@users.noreply.github.com>2011-01-28 07:42:32 +0000
committer Couriersud <couriersud@users.noreply.github.com>2011-01-28 07:42:32 +0000
commit10ad09bac8b399bd817238f9c09f17a0f84615b6 (patch)
tree7d238be6969a28555fb738bdd0a584ffb62cfa93 /src/lib
parentc6383e59725df17001916edd71a8500453ee8595 (diff)
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]
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/palette.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/util/palette.c b/src/lib/util/palette.c
index ab13edc76ea..d19bc1338a4 100644
--- a/src/lib/util/palette.c
+++ b/src/lib/util/palette.c
@@ -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));
}
}