* Match an RGB value to a particular palette index */
| 774 | * Match an RGB value to a particular palette index |
| 775 | */ |
| 776 | Uint8 |
| 777 | SDL_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 */ |
| 805 | Uint32 |
no outgoing calls
no test coverage detected