comparison src/video/SDL_pixels.c @ 628:e561e8752d33

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Thu, 29 May 2003 04:29:13 +0000
parents f6ffac90895c
children c0522010bb6d
comparison
equal deleted inserted replaced
627:8b9ac38381d0 628:e561e8752d33
377 * that white is indeed reported as (255, 255, 255), 377 * that white is indeed reported as (255, 255, 255),
378 * and that opaque alpha is 255. 378 * and that opaque alpha is 255.
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 rv, gv, bv, av; 382 unsigned v;
383 rv = (pixel & fmt->Rmask) >> fmt->Rshift; 383 v = (pixel & fmt->Rmask) >> fmt->Rshift;
384 *r = (rv << fmt->Rloss) + (rv >> (8 - fmt->Rloss)); 384 *r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss));
385 gv = (pixel & fmt->Gmask) >> fmt->Gshift; 385 v = (pixel & fmt->Gmask) >> fmt->Gshift;
386 *g = (gv << fmt->Gloss) + (gv >> (8 - fmt->Gloss)); 386 *g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss));
387 bv = (pixel & fmt->Bmask) >> fmt->Bshift; 387 v = (pixel & fmt->Bmask) >> fmt->Bshift;
388 *b = (bv << fmt->Bloss) + (bv >> (8 - fmt->Bloss)); 388 *b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss));
389 if(fmt->Amask) { 389 if(fmt->Amask) {
390 av = (pixel & fmt->Amask) >> fmt->Ashift; 390 v = (pixel & fmt->Amask) >> fmt->Ashift;
391 *a = (av << fmt->Aloss) + (av >> (8 - fmt->Aloss)); 391 *a = (v << fmt->Aloss) + (v >> (8 - fmt->Aloss));
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;
401 401
402 void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r,Uint8 *g,Uint8 *b) 402 void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r,Uint8 *g,Uint8 *b)
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 rv, gv, bv; 406 unsigned v;
407 rv = (pixel & fmt->Rmask) >> fmt->Rshift; 407 v = (pixel & fmt->Rmask) >> fmt->Rshift;
408 *r = (rv << fmt->Rloss) + (rv >> (8 - fmt->Rloss)); 408 *r = (v << fmt->Rloss) + (v >> (8 - fmt->Rloss));
409 gv = (pixel & fmt->Gmask) >> fmt->Gshift; 409 v = (pixel & fmt->Gmask) >> fmt->Gshift;
410 *g = (gv << fmt->Gloss) + (gv >> (8 - fmt->Gloss)); 410 *g = (v << fmt->Gloss) + (v >> (8 - fmt->Gloss));
411 bv = (pixel & fmt->Bmask) >> fmt->Bshift; 411 v = (pixel & fmt->Bmask) >> fmt->Bshift;
412 *b = (bv << fmt->Bloss) + (bv >> (8 - fmt->Bloss)); 412 *b = (v << fmt->Bloss) + (v >> (8 - fmt->Bloss));
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 }