SHARE
TWEET

Untitled

a guest Dec 8th, 2014 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void RGBtoHSV(unsigned char R, unsigned char G, unsigned char B, unsigned int &H, unsigned int &S, unsigned int &V) {
  2.         double var_R = (R / 255);
  3.         double var_G = (G / 255);
  4.         double var_B = (B / 255);
  5.  
  6.         unsigned char var_Min = (var_R < var_G) ? ((var_R < var_B) ? var_R : var_B) : ((var_G < var_B) ? var_G : var_B);
  7.         unsigned char var_Max = (var_R > var_G) ? ((var_R > var_B) ? var_R : var_B) : ((var_G > var_B) ? var_G : var_B);
  8.         unsigned char del_Max = var_Max - var_Min;
  9.  
  10.         V = var_Max;
  11.         if(del_Max == 0) {
  12.                 H = 0;
  13.                 S = 0;
  14.         } else {
  15.                 S = del_Max / var_Max;
  16.  
  17.                 double del_R = (((var_Max - var_R) / 6) + (del_Max / 2)) / del_Max;
  18.                 double del_G = (((var_Max - var_G) / 6) + (del_Max / 2)) / del_Max;
  19.                 double del_B = (((var_Max - var_B) / 6) + (del_Max / 2)) / del_Max;
  20.  
  21.                 if(var_R == var_Max) H = del_B - del_G;
  22.                 else if(var_G == var_Max) H = (1 / 3) + del_R - del_B;
  23.                 else if(var_B == var_Max) H = (2 / 3) + del_G - del_R;
  24.  
  25.                 if(H < 0) H += 1;
  26.                 if(H > 1) H -= 1;
  27.         }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top