comparison src/video/SDL_pixels.c @ 688:c0522010bb6d

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)));
author Sam Lantinga <slouken@libsdl.org>
date Tue, 12 Aug 2003 15:17:20 +0000
parents e561e8752d33
children 8f579a0e17e6
comparison
equal deleted inserted replaced
687:91400ecf307d 688:c0522010bb6d
379 * This only works for RGB bit fields at least 4 bit 379 * This only works for RGB bit fields at least 4 bit
380 * wide, which is almost always the case. 380 * wide, which is almost always the case.
381 */ 381 */
382 unsigned v; 382 unsigned v;
383 v = (pixel & fmt->Rmask) >> fmt->Rshift; 383 v = (pixel & fmt->Rmask) >> fmt->Rshift;
384 *r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss)); 384 *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1)));
385 v = (pixel & fmt->Gmask) >> fmt->Gshift; 385 v = (pixel & fmt->Gmask) >> fmt->Gshift;
386 *g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss)); 386 *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1)));
387 v = (pixel & fmt->Bmask) >> fmt->Bshift; 387 v = (pixel & fmt->Bmask) >> fmt->Bshift;
388 *b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss)); 388 *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1)));
389 if(fmt->Amask) { 389 if(fmt->Amask) {
390 v = (pixel & fmt->Amask) >> fmt->Ashift; 390 v = (pixel & fmt->Amask) >> fmt->Ashift;
391 *a = (v << fmt->Aloss) + (v >> (8 - fmt->Aloss)); 391 *a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1)));
392 } else 392 } else
393 *a = SDL_ALPHA_OPAQUE; 393 *a = SDL_ALPHA_OPAQUE;
394 } else { 394 } else {
395 *r = fmt->palette->colors[pixel].r; 395 *r = fmt->palette->colors[pixel].r;
396 *g = fmt->palette->colors[pixel].g; 396 *g = fmt->palette->colors[pixel].g;
403 { 403 {
404 if ( fmt->palette == NULL ) { 404 if ( fmt->palette == NULL ) {
405 /* the note for SDL_GetRGBA above applies here too */ 405 /* the note for SDL_GetRGBA above applies here too */
406 unsigned v; 406 unsigned v;
407 v = (pixel & fmt->Rmask) >> fmt->Rshift; 407 v = (pixel & fmt->Rmask) >> fmt->Rshift;
408 *r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss)); 408 *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1)));
409 v = (pixel & fmt->Gmask) >> fmt->Gshift; 409 v = (pixel & fmt->Gmask) >> fmt->Gshift;
410 *g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss)); 410 *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1)));
411 v = (pixel & fmt->Bmask) >> fmt->Bshift; 411 v = (pixel & fmt->Bmask) >> fmt->Bshift;
412 *b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss)); 412 *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1)));
413 } else { 413 } else {
414 *r = fmt->palette->colors[pixel].r; 414 *r = fmt->palette->colors[pixel].r;
415 *g = fmt->palette->colors[pixel].g; 415 *g = fmt->palette->colors[pixel].g;
416 *b = fmt->palette->colors[pixel].b; 416 *b = fmt->palette->colors[pixel].b;
417 } 417 }