Exemple #1
0
        private static System.Drawing.Color getColour(ColorLab c1, ColorLab c2, double ratio)
        {
            double ratio2 = 1 - ratio;

            double L = ((c1.L * ratio2) + (c2.L * ratio));
            double a = ((c1.a * ratio2) + (c2.a * ratio));
            double b = ((c1.b * ratio2) + (c2.b * ratio));

            double alpha = 255 * (1 - (ratio * ratio));

            //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString());
            ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter
            ColorLab lab = new ColorLab(L, a, b);                                          //create new Lab color
            ColorRGB rgb = Converter.ToRGB(lab);                                           //convert to rgb
            ColorHSV hsv = Converter.ToHSV(rgb);                                           //conver to HSL

            //Console.WriteLine("hsl.l = " + hsv.V.ToString());
            hsv.V *= alpha / 255.0;        //darken
            rgb    = Converter.ToRGB(hsv); //convert to rgb
            //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString());
            if (ratio2 == 1.0)
            {
                breatheTopPause = true;
            }
            if (alpha < 0.02)
            {
                return(System.Drawing.Color.FromArgb(0, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)));
            }
            return(System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)));
        }
        public static System.Drawing.Color GetColour(ColorLab c1, ColorLab c2, double countup, int speed = 7, int fadespeed = 15)
        {
            speed = 21 - speed;
            double alpha_seed = countup * fadespeed;
            if (alpha_seed > 255) alpha_seed = 255;
            int alpha = (int)Math.Max(0, 255 - alpha_seed);

            double step = 1.0 / speed;
            double ratio = (countup - 1) * step;
            if (ratio > 1) ratio = 1;
            if (ratio < 0) ratio = 0;
            double ratio2 = 1 - ratio;

            double L = ((c1.L * ratio2) + (c2.L * ratio));
            double a = ((c1.a * ratio2) + (c2.a * ratio));
            double b = ((c1.b * ratio2) + (c2.b * ratio));

            //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString());
            ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter();    //create a new instance of a ColorConverter
            ColorLab lab = new ColorLab(L, a, b); //create new Lab color
            ColorRGB rgb = Converter.ToRGB(lab); //convert to rgb
            ColorHSV hsv = Converter.ToHSV(rgb);  //conver to HSL
            //Console.WriteLine("hsl.l = " + hsv.V.ToString());
            hsv.V *= alpha / 255.0; //darken
            rgb = Converter.ToRGB(hsv); //convert to rgb
            //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString());
            return System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255));
        }
Exemple #3
0
        private static System.Drawing.Color getColour(ColorLab c1, ColorLab c2, double countup, int speed = 7, int fadespeed = 15)
        {
            speed = 21 - speed;
            double alpha_seed = Math.Sqrt(countup) * fadespeed;

            if (alpha_seed > 255)
            {
                alpha_seed = 255;
            }
            int alpha = (int)Math.Max(0, 255 - alpha_seed);

            double step  = 1.0 / speed;
            double ratio = (countup - 1) * step;

            if (ratio > 1)
            {
                ratio = 1;
            }
            if (ratio < 0)
            {
                ratio = 0;
            }
            double ratio2 = 1 - ratio;

            double L = ((c1.L * ratio2) + (c2.L * ratio));
            double a = ((c1.a * ratio2) + (c2.a * ratio));
            double b = ((c1.b * ratio2) + (c2.b * ratio));

            //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString());
            ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter(); //create a new instance of a ColorConverter
            ColorLab lab = new ColorLab(L, a, b);                                          //create new Lab color
            ColorRGB rgb = Converter.ToRGB(lab);                                           //convert to rgb
            ColorHSV hsv = Converter.ToHSV(rgb);                                           //conver to HSL

            //Console.WriteLine("hsl.l = " + hsv.V.ToString());
            hsv.V *= alpha / 255.0;        //darken
            rgb    = Converter.ToRGB(hsv); //convert to rgb
            //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString());
            return(System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255)));
        }
        public static System.Drawing.Color GetColour(ColorLab c1, ColorLab c2, double ratio)
        {
            double ratio2 = 1 - ratio;

            double L = ((c1.L * ratio2) + (c2.L * ratio));
            double a = ((c1.a * ratio2) + (c2.a * ratio));
            double b = ((c1.b * ratio2) + (c2.b * ratio));

            double alpha = 255 * (1 - (ratio * ratio));
            //Console.WriteLine("Lab = " + L.ToString() + "," + a.ToString() + "," + b.ToString());
            ColorManagment.ColorConverter Converter = new ColorManagment.ColorConverter();    //create a new instance of a ColorConverter
            ColorLab lab = new ColorLab(L, a, b); //create new Lab color
            ColorRGB rgb = Converter.ToRGB(lab); //convert to rgb
            ColorHSV hsv = Converter.ToHSV(rgb);  //conver to HSL
            //Console.WriteLine("hsl.l = " + hsv.V.ToString());
            hsv.V *= alpha / 255.0; //darken
            rgb = Converter.ToRGB(hsv); //convert to rgb
            //Console.WriteLine("RGB + " + rgb.R.ToString() + "," + rgb.G.ToString() + "," + rgb.B.ToString());
            if (ratio2 == 1.0)
                Animations.breatheTopPause = true;
            if (alpha < 0.02)
                return System.Drawing.Color.FromArgb(0, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255));
            return System.Drawing.Color.FromArgb(255, (int)(rgb.R * 255), (int)(rgb.G * 255), (int)(rgb.B * 255));
        }
        private void Measure(object Data)
        {
            int end = (int)((object[])Data)[0];
            Color FromColor = (Color)((object[])Data)[1];
            Color ToColor = (Color)((object[])Data)[2];
            bool DoFast = (bool)((object[])Data)[3];
            Stopwatch watch = new Stopwatch();
            Color From2Color = FromColor;
            ColorConverter conv = new ColorConverter();

            if (DoFast)
            {
                RGBSpaceName n = ColorConverter.StandardColorspace;
                YCbCrSpaceName m = ColorConverter.StandardYCbCrSpace;
                if (ToColor.Model == ColorModel.YCbCr)
                {
                    n = ((ColorYCbCr)ToColor).BaseSpaceName;
                    m = ((ColorYCbCr)ToColor).SpaceName;
                }
                else if (ToColor.Model == ColorModel.RGB) n = ((ColorRGB)ToColor).SpaceName;
                else if (ToColor.Model == ColorModel.HSV) n = ((ColorRGB)ToColor).SpaceName;
                else if (ToColor.Model == ColorModel.HSL) n = ((ColorRGB)ToColor).SpaceName;

                if (n != ColorConverter.StandardColorspace) conv.SetFast(FromColor, ToColor.Model, n, m);
                else conv.SetFast(FromColor, ToColor.Model, ToColor.ReferenceWhite);
            }

            for (int i = 0; i < end / Threadcount && !MainWorker.CancellationPending; i++)
            {
                if (DoFast)
                {
                    watch.Start();
                    conv.ConvertFast(FromColor);
                    watch.Stop();
                }
                else
                {
                    if (FromColor.IsICCcolor && !FromColor.IsPCScolor)
                    {
                        watch.Start();
                        From2Color = conv.ToICC(FromColor);
                        watch.Stop();
                    }

                    switch (ToColor.Model)
                    {
                        case ColorModel.CIELab:
                            watch.Start();
                            conv.ToLab(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.CIELCHab:
                            watch.Start();
                            conv.ToLCHab(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.CIELCHuv:
                            watch.Start();
                            conv.ToLCHuv(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.CIELuv:
                            watch.Start();
                            conv.ToLuv(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.CIEXYZ:
                            watch.Start();
                            conv.ToXYZ(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.CIEYxy:
                            watch.Start();
                            conv.ToYxy(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.Gray:
                            watch.Start();
                            conv.ToGray(From2Color, ToColor.ReferenceWhite);
                            watch.Stop();
                            break;
                        case ColorModel.HSL:
                            RGBSpaceName n = ((ColorHSL)ToColor).SpaceName;
                            if (n == RGBSpaceName.ICC) goto default;
                            watch.Start();
                            conv.ToHSL(From2Color, n);
                            watch.Stop();
                            break;
                        case ColorModel.HSV:
                            n = ((ColorHSV)ToColor).SpaceName;
                            if (n == RGBSpaceName.ICC) goto default;
                            watch.Start();
                            conv.ToHSV(From2Color, n);
                            watch.Stop();
                            break;
                        case ColorModel.RGB:
                            n = ((ColorRGB)ToColor).SpaceName;
                            if (n == RGBSpaceName.ICC) goto default;
                            watch.Start();
                            conv.ToRGB(From2Color, n);
                            watch.Stop();
                            break;
                        case ColorModel.YCbCr:
                            n = ((ColorYCbCr)ToColor).BaseSpaceName;
                            YCbCrSpaceName m = ((ColorYCbCr)ToColor).SpaceName;
                            if (m == YCbCrSpaceName.ICC) goto default;
                            watch.Start();
                            conv.ToYCbCr(From2Color, n, m);
                            watch.Stop();
                            break;
                        case ColorModel.LCH99:
                            watch.Start();
                            conv.ToLCH99(From2Color);
                            watch.Stop();
                            break;
                        case ColorModel.LCH99b:
                            watch.Start();
                            conv.ToLCH99b(From2Color);
                            watch.Stop();
                            break;
                        case ColorModel.LCH99c:
                            watch.Start();
                            conv.ToLCH99c(From2Color);
                            watch.Stop();
                            break;
                        case ColorModel.LCH99d:
                            watch.Start();
                            conv.ToLCH99d(From2Color);
                            watch.Stop();
                            break;

                        default:
                            watch.Start();
                            conv.ToICC(conv.ToICC_PCS(From2Color, ToICC), ToICC);
                            watch.Stop();
                            break;
                    }
                }

                progress++;
                time += watch.ElapsedTicks;
                if (progress % 100 == 0) MainWorker.ReportProgress(progress * 100 / (end - 1));
            }
        }