Mercurial > sdl-ios-xcode
comparison src/video/SDL_pixels.c @ 2275:12ea0fdc0df2
Split out the SDL_rect and SDL_surface functions into their own headers.
Removed unused count from the dirty rect list.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Sep 2007 12:20:02 +0000 |
parents | c785543d1843 |
children | 24a6b3588eac 204be4fc2726 |
comparison
equal
deleted
inserted
replaced
2274:aedfcdeb69b6 | 2275:12ea0fdc0df2 |
---|---|
534 return (pixel); | 534 return (pixel); |
535 } | 535 } |
536 | 536 |
537 /* Find the opaque pixel value corresponding to an RGB triple */ | 537 /* Find the opaque pixel value corresponding to an RGB triple */ |
538 Uint32 | 538 Uint32 |
539 SDL_MapRGB(const SDL_PixelFormat * const format, const Uint8 r, const Uint8 g, | 539 SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) |
540 const Uint8 b) | |
541 { | 540 { |
542 if (format->palette == NULL) { | 541 if (format->palette == NULL) { |
543 return (r >> format->Rloss) << format->Rshift | 542 return (r >> format->Rloss) << format->Rshift |
544 | (g >> format->Gloss) << format->Gshift | 543 | (g >> format->Gloss) << format->Gshift |
545 | (b >> format->Bloss) << format->Bshift | format->Amask; | 544 | (b >> format->Bloss) << format->Bshift | format->Amask; |
548 } | 547 } |
549 } | 548 } |
550 | 549 |
551 /* Find the pixel value corresponding to an RGBA quadruple */ | 550 /* Find the pixel value corresponding to an RGBA quadruple */ |
552 Uint32 | 551 Uint32 |
553 SDL_MapRGBA(const SDL_PixelFormat * const format, const Uint8 r, | 552 SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, |
554 const Uint8 g, const Uint8 b, const Uint8 a) | 553 Uint8 a) |
555 { | 554 { |
556 if (format->palette == NULL) { | 555 if (format->palette == NULL) { |
557 return (r >> format->Rloss) << format->Rshift | 556 return (r >> format->Rloss) << format->Rshift |
558 | (g >> format->Gloss) << format->Gshift | 557 | (g >> format->Gloss) << format->Gshift |
559 | (b >> format->Bloss) << format->Bshift | 558 | (b >> format->Bloss) << format->Bshift |
562 return SDL_FindColor(format->palette, r, g, b); | 561 return SDL_FindColor(format->palette, r, g, b); |
563 } | 562 } |
564 } | 563 } |
565 | 564 |
566 void | 565 void |
567 SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat * fmt, | 566 SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g, |
567 Uint8 * b) | |
568 { | |
569 if (format->palette == NULL) { | |
570 /* | |
571 * This makes sure that the result is mapped to the | |
572 * interval [0..255], and the maximum value for each | |
573 * component is 255. This is important to make sure | |
574 * that white is indeed reported as (255, 255, 255). | |
575 * This only works for RGB bit fields at least 4 bit | |
576 * wide, which is almost always the case. | |
577 */ | |
578 unsigned v; | |
579 v = (pixel & format->Rmask) >> format->Rshift; | |
580 *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); | |
581 v = (pixel & format->Gmask) >> format->Gshift; | |
582 *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); | |
583 v = (pixel & format->Bmask) >> format->Bshift; | |
584 *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); | |
585 } else { | |
586 *r = format->palette->colors[pixel].r; | |
587 *g = format->palette->colors[pixel].g; | |
588 *b = format->palette->colors[pixel].b; | |
589 } | |
590 } | |
591 | |
592 void | |
593 SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, | |
568 Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) | 594 Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) |
569 { | 595 { |
570 if (fmt->palette == NULL) { | 596 if (format->palette == NULL) { |
571 /* | 597 /* |
572 * This makes sure that the result is mapped to the | 598 * This makes sure that the result is mapped to the |
573 * interval [0..255], and the maximum value for each | 599 * interval [0..255], and the maximum value for each |
574 * component is 255. This is important to make sure | 600 * component is 255. This is important to make sure |
575 * that white is indeed reported as (255, 255, 255), | 601 * that white is indeed reported as (255, 255, 255), |
576 * and that opaque alpha is 255. | 602 * and that opaque alpha is 255. |
577 * This only works for RGB bit fields at least 4 bit | 603 * This only works for RGB bit fields at least 4 bit |
578 * wide, which is almost always the case. | 604 * wide, which is almost always the case. |
579 */ | 605 */ |
580 unsigned v; | 606 unsigned v; |
581 v = (pixel & fmt->Rmask) >> fmt->Rshift; | 607 v = (pixel & format->Rmask) >> format->Rshift; |
582 *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); | 608 *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); |
583 v = (pixel & fmt->Gmask) >> fmt->Gshift; | 609 v = (pixel & format->Gmask) >> format->Gshift; |
584 *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); | 610 *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); |
585 v = (pixel & fmt->Bmask) >> fmt->Bshift; | 611 v = (pixel & format->Bmask) >> format->Bshift; |
586 *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); | 612 *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); |
587 if (fmt->Amask) { | 613 if (format->Amask) { |
588 v = (pixel & fmt->Amask) >> fmt->Ashift; | 614 v = (pixel & format->Amask) >> format->Ashift; |
589 *a = (v << fmt->Aloss) + (v >> (8 - (fmt->Aloss << 1))); | 615 *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1))); |
590 } else { | 616 } else { |
591 *a = SDL_ALPHA_OPAQUE; | 617 *a = SDL_ALPHA_OPAQUE; |
592 } | 618 } |
593 } else { | 619 } else { |
594 *r = fmt->palette->colors[pixel].r; | 620 *r = format->palette->colors[pixel].r; |
595 *g = fmt->palette->colors[pixel].g; | 621 *g = format->palette->colors[pixel].g; |
596 *b = fmt->palette->colors[pixel].b; | 622 *b = format->palette->colors[pixel].b; |
597 *a = SDL_ALPHA_OPAQUE; | 623 *a = SDL_ALPHA_OPAQUE; |
598 } | |
599 } | |
600 | |
601 void | |
602 SDL_GetRGB(Uint32 pixel, SDL_PixelFormat * fmt, Uint8 * r, Uint8 * g, | |
603 Uint8 * b) | |
604 { | |
605 if (fmt->palette == NULL) { | |
606 /* the note for SDL_GetRGBA above applies here too */ | |
607 unsigned v; | |
608 v = (pixel & fmt->Rmask) >> fmt->Rshift; | |
609 *r = (v << fmt->Rloss) + (v >> (8 - (fmt->Rloss << 1))); | |
610 v = (pixel & fmt->Gmask) >> fmt->Gshift; | |
611 *g = (v << fmt->Gloss) + (v >> (8 - (fmt->Gloss << 1))); | |
612 v = (pixel & fmt->Bmask) >> fmt->Bshift; | |
613 *b = (v << fmt->Bloss) + (v >> (8 - (fmt->Bloss << 1))); | |
614 } else { | |
615 *r = fmt->palette->colors[pixel].r; | |
616 *g = fmt->palette->colors[pixel].g; | |
617 *b = fmt->palette->colors[pixel].b; | |
618 } | 624 } |
619 } | 625 } |
620 | 626 |
621 /* Apply gamma to a set of colors - this is easy. :) */ | 627 /* Apply gamma to a set of colors - this is easy. :) */ |
622 void | 628 void |