private void initEmpty()
 {
     HexValue = new hexvalue();
     RGB      = new rgb();
     HSL      = new hsl();
     HSV      = new hsv();
     CMYK     = new cmyk();
     XYZ      = new xyz();
     Name     = new name();
     Image    = new image();
     Contrast = string.Empty;
 }
Example #2
0
        public static hsl toHSL(this rgb source)
        {
            hsl output = new hsl();

            //GETTING 0 - 1 VALUES

            float r = (float)source.R / 255.0f;
            float g = (float)source.G / 255.0f;
            float b = (float)source.B / 255.0f;

            //FIND MAX AND MIN
            float min = Math.Min(Math.Min(r, g), b);
            float max = Math.Max(Math.Max(r, g), b);

            //LUMINANCE CALCULATION
            output.L = (min + max) / 2;

            //SATURATION CALCULATIONS
            if (min == max)
            {
                output.H = 0;
                output.S = 0;
            }
            else
            {
                output.S = output.L < 0.5f ? (max - min) / (max + min) : (max - min) / (2.0f - max - min);
            }

            //HUE CALCULATIONS
            if (r == max)
            {
                output.H = (g - b) / (max - min);
            }
            else if (g == max)
            {
                output.H = 2.0f + (b - r) / (max - min);
            }
            else
            {
                output.H = 4.0f + (r - g) / (max - min);
            }

            //Fit to circle
            output.H *= 60;

            if (output.H < 0)
            {
                output.H += 360;
            }

            return(output);
        }
        public ColorfulRestProperty(object json)
        {
            var colorData = (ColorfulJsonParser)json;

            HexValue = new hexvalue(colorData.Hex);
            RGB      = new rgb(colorData.RGB);
            HSL      = new hsl(colorData.HSL);
            HSV      = new hsv(colorData.HSV);
            CMYK     = new cmyk(colorData.CMYK);
            XYZ      = new xyz(colorData.XYZ);
            Name     = new name(colorData.Name);
            Image    = new image(colorData.Image);
            Contrast = colorData.Contrast.value;
        }
        public ColorfulRestProperty(object json)
        {
            var colorData = (ColorfulJsonParser)json;

            HexValue = new hexvalue(colorData.Hex);
            RGB = new rgb(colorData.RGB);
            HSL = new hsl(colorData.HSL);
            HSV = new hsv(colorData.HSV);
            CMYK = new cmyk(colorData.CMYK);
            XYZ = new xyz(colorData.XYZ);
            Name = new name(colorData.Name);
            Image = new image(colorData.Image);
            Contrast = colorData.Contrast.value;
        }
Example #5
0
        public static rgb toRGB(this hsl source)
        {
            rgb output = new rgb();

            if (source.S == 0) //The colour is a shade of grey
            {
                float val = source.L * 255f;
                output.R = (int)val;
                output.G = (int)val;
                output.B = (int)val;
            }
            else //It has some saturation
            {
                float temp2 = source.L < 0.5f ? source.L * (1.0f + source.S) : source.L + source.S - (source.L * source.S);
                float temp1 = 2.0f * source.L - temp2;

                //Get all the color component
                output.R = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f) + 1.0f / 3.0f) * 255.0f);
                output.G = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f)) * 255.0f);
                output.B = (int)Math.Round(convGetColorComponent(temp1, temp2, (source.H / 360f) - 1.0f / 3.0f) * 255.0f);
            }
            return(output);
        }
 private void initEmpty()
 {
     HexValue = new hexvalue();
     RGB = new rgb();
     HSL = new hsl();
     HSV = new hsv();
     CMYK = new cmyk();
     XYZ = new xyz();
     Name = new name();
     Image = new image();
     Contrast = string.Empty;
 }