Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void rgbToHSV(double r, double g, double b, double hsv[]) {
- double computedH, computedS, computedV;
- double minRGB, maxRGB;
- double d = 0, h = 0;
- r = r/1023; g = g/1023; b = b/1023;
- minRGB = min(r,min(g,b));
- maxRGB = max(r,max(g,b));
- if (minRGB == maxRGB) {
- // Black-gray-white
- computedV = minRGB;
- hsv[0] = 0; hsv[1] = 0; hsv[2] = computedV;
- } else {
- // Colors other than black-gray-white:
- d = (r == minRGB) ? g-b : ((b == minRGB) ? r-g : b-r);
- h = (r == minRGB) ? 3 : ((b == minRGB) ? 1 : 5);
- computedH = 60*(h - (d/(maxRGB - minRGB)));
- computedS = (maxRGB - minRGB)/maxRGB;
- computedV = maxRGB;
- hsv[0] = computedH; hsv[1] = computedS; hsv[2] = computedV;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement