Compute the indices for the smallest, middle, and largest elements of RGB[3]. (Trying to be clever and do this without branching.)
| 725 | // Compute the indices for the smallest, middle, and largest elements of |
| 726 | // RGB[3]. (Trying to be clever and do this without branching.) |
| 727 | inline void Order3(const float* RGB, int& min, int& mid, int& max) |
| 728 | { |
| 729 | // 0 1 2 3 4 5 6 7 8 (typical val - 3) |
| 730 | static const int table[] = { 2, 1, 0, 2, 1, 0, 2, 1, 2, 0, 1, 2 }; |
| 731 | |
| 732 | int val = (int(RGB[0] > RGB[1]) * 5 + int(RGB[1] > RGB[2]) * 4) |
| 733 | - int(RGB[0] > RGB[2]) * 3 + 3; |
| 734 | |
| 735 | // A NaN in a logical comparison always results in False. |
| 736 | // So the case to be careful of here is { A, NaN, B } with A > B. |
| 737 | // In that case, the first two compares are false but the third is true |
| 738 | // (something that would never happen with regular numbers). |
| 739 | // So that is the reason for the +3, to make val 0 in that case. |
| 740 | |
| 741 | max = table[val]; |
| 742 | mid = table[++val]; |
| 743 | min = table[++val]; |
| 744 | } |
| 745 | }; |
| 746 | |
| 747 |
no outgoing calls