MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_FindColor

Function SDL_FindColor

deps/SDL2/src/video/SDL_pixels.c:776–802  ·  view source on GitHub ↗

* Match an RGB value to a particular palette index */

Source from the content-addressed store, hash-verified

774 * Match an RGB value to a particular palette index
775 */
776Uint8
777SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
778{
779 /* Do colorspace distance matching */
780 unsigned int smallest;
781 unsigned int distance;
782 int rd, gd, bd, ad;
783 int i;
784 Uint8 pixel = 0;
785
786 smallest = ~0;
787 for (i = 0; i < pal->ncolors; ++i) {
788 rd = pal->colors[i].r - r;
789 gd = pal->colors[i].g - g;
790 bd = pal->colors[i].b - b;
791 ad = pal->colors[i].a - a;
792 distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
793 if (distance < smallest) {
794 pixel = i;
795 if (distance == 0) { /* Perfect match! */
796 break;
797 }
798 smallest = distance;
799 }
800 }
801 return (pixel);
802}
803
804/* Find the opaque pixel value corresponding to an RGB triple */
805Uint32

Callers 3

SDL_MapRGBFunction · 0.85
SDL_MapRGBAFunction · 0.85
Map1to1Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected