private void UpdateSample(int xPos, int yPos)
        {
            if (m_colorSample == null)
            {
                return;
            }

            if (xPos < 0 || xPos > m_colorSample.Width)
            {
                return;
            }

            if (yPos < 0 || yPos > m_colorSample.Height)
            {
                return;
            }

            m_sampleSelector.SetValue(Canvas.LeftProperty, xPos - (m_sampleSelector.Height / 2));
            m_sampleSelector.SetValue(Canvas.TopProperty, yPos - (m_sampleSelector.Height / 2));

            float yComponent = 1 - (float)(yPos / m_colorSample.Height);
            float xComponent = (float)(xPos / m_colorSample.Width);

            this.SelectedColor       = m_colorSpace.ConvertHsvToRgb(m_selectedHue, xComponent, yComponent);
            m_selectedColorView.Fill = new SolidColorBrush(this.SelectedColor);
            m_hexValue.Text          = m_colorSpace.GetHexCode(this.SelectedColor);

            if (ColorSelected != null)
            {
                ColorSelected(this.SelectedColor);
            }
        }
        private Color GetColor()
        {
            double yComponent   = 1 - (m_sampleY / m_colorSample.Height);
            double xComponent   = m_sampleX / m_colorSample.Width;
            double hueComponent = (m_huePos / m_hueMonitor.Height) * 360;

            return(m_colorSpace.ConvertHsvToRgb(hueComponent, xComponent, yComponent));
        }
 public void RgbHsvConversion()
 {
     ColorSpace cs = new ColorSpace();
     for(int r = 0; r<255; r+=5)
         for(int g=0; g<255; g+=5)
             for(int b=0; b<255; b+=5)
             {
                 Color c1 = Color.FromArgb(255, (byte)r, (byte)g, (byte)b);
                 HSV tmpHSL = cs.ConvertRgbToHsv(c1);
                 Color c2 = cs.ConvertHsvToRgb(tmpHSL.Hue, tmpHSL.Saturation, tmpHSL.Value);
                 Assert.AreEqual(c1.R, c2.R);
                 Assert.AreEqual(c1.G, c2.G);
                 Assert.AreEqual(c1.B, c2.B);
                 Assert.AreEqual(c1.A, c2.A);
             }
 }