Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int NearestColor(Color Pixel)
- {
- int diffR; int diffB; int diffG;
- int smallestDiffValue = 0x7FFFFFFF;
- int SmallestDiff = 0x00;
- int diff = 0x00;
- for (int C = 0; C < 256; C++)
- {
- diffR = Pixel.R - Palette[C].R;
- diffB = Pixel.B - Palette[C].B;
- diffG = Pixel.G - Palette[C].G;
- diff = diffR*diffR + diffB*diffB + diffG*diffG;
- if (diff == 0) { return C; } // Quit early if match found
- if (diff < smallestDiffValue) // Otherwise compare to smallest color found
- { SmallestDiff = C; smallestDiffValue = diff; }
- }
- return SmallestDiff;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement