コード例 #1
0
        //Method to generate Array of HSV values
        public void generateHSVBits()
        {
            HSVBits = new HSVBit[Width * Height];
            int length = Bits.Length;

            for (int i = 0; i < length; i++)
            {
                HSVBits[i] = HSVBit.getFromColor(Color.FromArgb(Bits[i]));
            }
        }
コード例 #2
0
        static public HSVBit getFromColor(Color color)
        {
            HSVBit hsvBit = new HSVBit();

            float redPrim   = (float)color.R / 255;
            float greenPrim = (float)color.G / 255;
            float bluePrim  = (float)color.B / 255;

            float cMax = HSVBit.maxValue(redPrim, greenPrim, bluePrim);
            float cMin = HSVBit.minValue(redPrim, greenPrim, bluePrim);

            float delta = cMax - cMin;

            if (delta == 0)
            {
                hsvBit.HUE = 0;
            }
            else
            {
                if (cMax == redPrim)
                {
                    hsvBit.HUE = 60 * (((greenPrim - bluePrim) / delta) % 6);
                }
                else if (cMax == greenPrim)
                {
                    hsvBit.HUE = 60 * ((bluePrim - redPrim) / delta + 2);
                }
                else if (cMax == bluePrim)
                {
                    hsvBit.HUE = 60 * ((redPrim - greenPrim) / delta + 4);
                }
            }

            if (hsvBit.HUE < 0)
            {
                hsvBit.HUE = hsvBit.HUE + 360;
            }


            if (cMax == 0)
            {
                hsvBit.saturation = 0;
            }
            else
            {
                hsvBit.saturation = delta / cMax;
            }

            hsvBit.value = cMax;



            return(hsvBit);
        }