Commit d8ae01f1 authored by Sam Lantinga's avatar Sam Lantinga

Date: Tue, 12 Aug 2003 14:26:19 +0200 (MEST)

From: "Mattias Engdeg?rd"
Subject: bug in SDL_GetRGB/GetRGBA

There's an embarrassing bug in GetRGB/GetRGBA which apparently has been there
for years. It incorrectly converts colours with < 8 bits/channel.
It came to my attention today in #sdl.

What it does now is (for each channel):

  rv = (pixel & fmt->Rmask) >> fmt->Rshift;
  *r = (rv << fmt->Rloss) + (rv >> (8 - fmt->Rloss));

which is wrong; the last line should be

  *r = (rv << fmt->Rloss) + (rv >> (8 - (fmt->Rloss << 1)));

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40689
parent 05e09aef
...@@ -381,14 +381,14 @@ void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, ...@@ -381,14 +381,14 @@ void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt,
*/ */
unsigned v; unsigned v;
v = (pixel & fmt->Rmask) >> fmt->Rshift; v = (pixel & fmt->Rmask) >> fmt->Rshift;
*r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss)); *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1)));
v = (pixel & fmt->Gmask) >> fmt->Gshift; v = (pixel & fmt->Gmask) >> fmt->Gshift;
*g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss)); *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1)));
v = (pixel & fmt->Bmask) >> fmt->Bshift; v = (pixel & fmt->Bmask) >> fmt->Bshift;
*b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss)); *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1)));
if(fmt->Amask) { if(fmt->Amask) {
v = (pixel & fmt->Amask) >> fmt->Ashift; v = (pixel & fmt->Amask) >> fmt->Ashift;
*a = (v << fmt->Aloss) + (v >> (8 - fmt->Aloss)); *a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1)));
} else } else
*a = SDL_ALPHA_OPAQUE; *a = SDL_ALPHA_OPAQUE;
} else { } else {
...@@ -405,11 +405,11 @@ void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r,Uint8 *g,Uint8 *b) ...@@ -405,11 +405,11 @@ void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r,Uint8 *g,Uint8 *b)
/* the note for SDL_GetRGBA above applies here too */ /* the note for SDL_GetRGBA above applies here too */
unsigned v; unsigned v;
v = (pixel & fmt->Rmask) >> fmt->Rshift; v = (pixel & fmt->Rmask) >> fmt->Rshift;
*r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss)); *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1)));
v = (pixel & fmt->Gmask) >> fmt->Gshift; v = (pixel & fmt->Gmask) >> fmt->Gshift;
*g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss)); *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1)));
v = (pixel & fmt->Bmask) >> fmt->Bshift; v = (pixel & fmt->Bmask) >> fmt->Bshift;
*b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss)); *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1)));
} else { } else {
*r = fmt->palette->colors[pixel].r; *r = fmt->palette->colors[pixel].r;
*g = fmt->palette->colors[pixel].g; *g = fmt->palette->colors[pixel].g;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment