title: convert RGB color to XY
body: <p>I have using RUCKUS API for changing color of lamp and I need to convert color from RGB to XY to call an API.</p>
  
  <p><strong>I have tried this code:</strong></p>
  
  <p>1) Get the RGB values from your color object and convert them to be between 0 and 1</p>
  
  <pre><code> function rgb_to_cie(red, green, blue)
      {
          //Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
          var red     = (red &gt; 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);
          var green   = (green &gt; 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);
          var blue    = (blue &gt; 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); 
  
          //RGB values to XYZ using the Wide RGB D65 conversion formula
          var X       = red * 0.664511 + green * 0.154324 + blue * 0.162028;
          var Y       = red * 0.283881 + green * 0.668433 + blue * 0.047685;
          var Z       = red * 0.000088 + green * 0.072310 + blue * 0.986039;
  
          //Calculate the xy values from the XYZ values
          var x       = (X / (X + Y + Z)).toFixed(4);
          var y       = (Y / (X + Y + Z)).toFixed(4);
  
          if (isNaN(x))
              x = 0;
          if (isNaN(y))
              y = 0;   
          return [x, y];
      }
  </code></pre>
  
  <p>but it didn't provide a proper solution.</p>
  
  <p>SO if i pass <strong>r:182 g: 255 B: 65</strong> as this then I got <strong>x as 22932</strong> and <strong>y as 35249</strong> (AS PER DOC OF API.)</p>
  
  <p>How can I do that?</p>