Exemplo n.º 1
0
        private ColorPlus GetLinkColor(ThreadLink link)
        {
            ColorPlus color;

            if (!link.Started)
            {
                color = ColorPlus.GetVeryLight(Color.Purple);
            }
            else if (link.Ended)
            {
                color = Color.LightGray;
            }
            else if (link.Cancelled)
            {
                color = ColorPlus.GetVeryLight(Color.Red);
            }
            else if (link.LoopPaused)
            {
                color = ColorPlus.GetVeryLight(Color.Orange);
            }
            else
            {
                color = ColorPlus.GetVeryLight(Color.Green);
            }

            return(color);
        }
Exemplo n.º 2
0
        void AskValues()
        {
            Robots.MainRobot.ReadAnalogicPins(Carte, true);

            if (Robots.MainRobot.AnalogicPinsValue[Carte] != null)
            {
                this.InvokeAuto(() =>
                {
                    List <double> values = Robots.MainRobot.AnalogicPinsValue[Carte];
                    lblAN1.Text          = values[0].ToString("0.0000") + " V";
                    lblAN2.Text          = values[1].ToString("0.0000") + " V";
                    lblAN3.Text          = values[2].ToString("0.0000") + " V";
                    lblAN4.Text          = values[3].ToString("0.0000") + " V";
                    lblAN5.Text          = values[4].ToString("0.0000") + " V";
                    lblAN6.Text          = values[5].ToString("0.0000") + " V";
                    lblAN7.Text          = values[6].ToString("0.0000") + " V";
                    lblAN8.Text          = values[7].ToString("0.0000") + " V";
                    lblAN9.Text          = values[8].ToString("0.0000") + " V";

                    ctrlGraphique.AddPoint("AN1", values[0], ColorPlus.FromHsl(360 / 9 * 0, 1, 0.4));
                    ctrlGraphique.AddPoint("AN2", values[1], ColorPlus.FromHsl(360 / 9 * 1, 1, 0.4));
                    ctrlGraphique.AddPoint("AN3", values[2], ColorPlus.FromHsl(360 / 9 * 2, 1, 0.4));
                    ctrlGraphique.AddPoint("AN4", values[3], ColorPlus.FromHsl(360 / 9 * 3, 1, 0.4));
                    ctrlGraphique.AddPoint("AN5", values[4], ColorPlus.FromHsl(360 / 9 * 4, 1, 0.4));
                    ctrlGraphique.AddPoint("AN6", values[5], ColorPlus.FromHsl(360 / 9 * 5, 1, 0.4));
                    ctrlGraphique.AddPoint("AN7", values[6], ColorPlus.FromHsl(360 / 9 * 6, 1, 0.4));
                    ctrlGraphique.AddPoint("AN8", values[7], ColorPlus.FromHsl(360 / 9 * 7, 1, 0.4));
                    ctrlGraphique.AddPoint("AN9", values[8], ColorPlus.FromHsl(360 / 9 * 8, 1, 0.4));
                });
            }
        }
Exemplo n.º 3
0
        private Image MakeColorBar2(Size sz, ColorPlus colorBottom, ColorPlus colorTop, float value)
        {
            Bitmap   bmp = new Bitmap(sz.Width, sz.Height);
            Graphics g   = Graphics.FromImage(bmp);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            LinearGradientBrush brush = new LinearGradientBrush(new Point(0, bmp.Height), new Point(0, 0), colorBottom, colorTop);

            int       margin = 2;
            int       height = (int)(sz.Height - margin * 2);
            Rectangle rect   = new Rectangle(margin, sz.Height - margin - height, sz.Width - margin * 2, height);

            GraphicsPath path = CreateMixRect(rect, new List <int> {
                Math.Min(2, height), Math.Min(2, height), Math.Min(2, height), Math.Min(2, height)
            });

            g.FillPath(brush, path);
            g.DrawPath(Pens.Black, path);

            height = (int)((sz.Height - margin * 2 - 2) * (1 - value / 255.0)) + 2;
            g.DrawLine(Pens.Black, 0, height - 1, bmp.Width, height - 1);
            g.DrawLine(Pens.White, 0, height, bmp.Width, height);
            g.DrawLine(Pens.Black, 0, height + 1, bmp.Width, height + 1);

            brush.Dispose();

            return(bmp);
        }
Exemplo n.º 4
0
    /// <summary>
    /// Créée une couleur depuis les paramètres de transparence, rouge, bleu et vert.
    /// </summary>
    /// <param name="alpha">Transparence, de 0 à 255.</param>
    /// <param name="r">Composante rouge, de 0 à 255.</param>
    /// <param name="g">Composante verte, de 0 à 255.</param>
    /// <param name="b">Composante bleue, de 0 à 255.</param>
    /// <returns>Couleur correspondante.</returns>
    public static ColorPlus FromArgb(int alpha, int r, int g, int b)
    {
        if (0 > alpha || 255 < alpha)
        {
            throw new ArgumentOutOfRangeException(nameof(alpha));
        }
        if (0 > r || 255 < r)
        {
            throw new ArgumentOutOfRangeException(nameof(r));
        }
        if (0 > g || 255 < g)
        {
            throw new ArgumentOutOfRangeException(nameof(g));
        }
        if (0 > b || 255 < b)
        {
            throw new ArgumentOutOfRangeException(nameof(b));
        }

        ColorPlus color = new ColorPlus();

        color._innerColor = Color.FromArgb(alpha, r, g, b);

        return(color);
    }
Exemplo n.º 5
0
    /// <summary>
    /// Calcule la différence angulaire en degrés de la teinte entre deux couleurs.
    /// </summary>
    /// <param name="c1">Première couleur.</param>
    /// <param name="c2">Deuxième couleur.</param>
    /// <returns>Différence angulaire.</returns>
    public static double HueDelta(ColorPlus c1, ColorPlus c2)
    {
        double d1 = Math.Abs(c1.Hue - c2.Hue);
        double d2 = Math.Abs(c1.Hue - (c2.Hue - 360));
        double d3 = Math.Abs(c1.Hue - (c2.Hue + 360));

        return(new double[] { d1, d2, d3 }.Min());
    }
Exemplo n.º 6
0
    public static Cell CreateWaterCell(ref Random random)
    {
        var color = ColorPlus.LerpInLch(WaterStartColor, WaterEndColor, random.NextFloat());

        return(new Cell
        {
            type = CellType.Water,
            color = color,
        });
    }
Exemplo n.º 7
0
    public static Cell CreateSandCell(ref Random random)
    {
        var color = ColorPlus.LerpInLch(SandStartColor, SandEndColor, random.NextFloat());

        return(new Cell
        {
            type = CellType.Sand,
            color = color,
        });
    }
Exemplo n.º 8
0
        private void PaintBuoy(Graphics g, PointF center, ColorPlus color, float scale)
        {
            if (color.Alpha != 0)
            {
                List <PointF> pts = BuoyPoints(center, scale);

                Brush bsh = new LinearGradientBrush(new PointF(pts.Min(o => o.X), pts.Min(o => o.Y)), new PointF(pts.Max(o => o.X), pts.Min(o => o.Y)), ColorPlus.FromAhsl(color.Alpha, color.Hue, color.Saturation, Math.Min(color.Lightness * 2, 1)), color);
                g.FillPolygon(bsh, pts.ToArray());
                bsh.Dispose();

                g.DrawPolygon(Pens.Black, pts.ToArray());
            }
        }
Exemplo n.º 9
0
        public override Color ReadSensorColor(SensorColorID sensor, bool wait = true)
        {
            ColorPlus c   = Color.White;
            int       i   = DateTime.Now.Millisecond + DateTime.Now.Second * 1000 + DateTime.Now.Minute * 60 * 1000 + DateTime.Now.Hour * 60 * 60 * 1000;
            int       max = 999 + 59 * 1000 + 59 * 60 * 1000 + 23 * 60 * 60 * 1000;

            i   %= (15 * 1000);
            max %= (15 * 1000);

            int steps    = 10;
            int maxColor = 255 * steps;

            i = (int)Math.Floor(i / (max / (float)maxColor));

            switch (i / 255)
            {
            case 0:
                c = ColorPlus.FromRgb(255, i % 255, 0); break;

            case 1:
                c = ColorPlus.FromRgb(255 - i % 255, 255, 0); break;

            case 2:
                c = ColorPlus.FromRgb(0, 255, i % 255); break;

            case 3:
                c = ColorPlus.FromRgb(0, 255 - i % 255, 255); break;

            case 4:
                c = ColorPlus.FromRgb(i % 255, 0, 255); break;

            case 5:
                c = ColorPlus.FromRgb(255, 0, 255 - i % 255); break;

            case 6:
                c = ColorPlus.FromRgb(255 - i % 255, 0, 0); break;

            case 7:
                c = ColorPlus.FromRgb(i % 255, i % 255, i % 255); break;

            case 8:
                c = ColorPlus.FromRgb(255 - i % 255 / 2, 255 - i % 255 / 2, 255 - i % 255 / 2); break;

            case 9:
                c = ColorPlus.FromHsl(0, i % 255 / 255f, 0.5); break;
            }

            OnSensorColorChanged(sensor, c);
            return(SensorsColorValue[sensor]);
        }
Exemplo n.º 10
0
        private void GameBoard_MyColorChange(object sender, EventArgs e)
        {
            Rectangle r = new Rectangle(8, 8, 78, 78);

            Bitmap   img   = new Bitmap(picColor.Width, picColor.Height);
            Graphics g     = Graphics.FromImage(img);
            Brush    brush = new LinearGradientBrush(r, ColorPlus.GetIntense(GameBoard.MyColor), ColorPlus.GetPastel(GameBoard.MyColor), 24);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillEllipse(brush, r);
            g.DrawImage(Properties.Resources.Circle96, 0, 0, 96, 96);

            brush.Dispose();
            g.Dispose();

            picColor.Image = img;
        }
Exemplo n.º 11
0
 public bool Equals(ColorPlus a, Color32 b)
 {
     if (a.red != b.r)
     {
         return(false);
     }
     if (a.green != b.g)
     {
         return(false);
     }
     if (a.blue != b.b)
     {
         return(false);
     }
     if (a.alpha != b.a)
     {
         return(false);
     }
     return(true);
 }
 public static bool Equals(this Color32 c1, ColorPlus c2)
 {
     if (c1.r != c2.red)
     {
         return(false);
     }
     if (c1.g != c2.green)
     {
         return(false);
     }
     if (c1.b != c2.blue)
     {
         return(false);
     }
     if (c1.a != c2.alpha)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Détermine la couleur actuellement affichée
        /// </summary>
        /// <param name="color">Couleur affichée</param>
        public void SetColor(Color c)
        {
            this.InvokeAuto(() =>
            {
                ColorPlus color = c;
                lblR.Text       = color.Red.ToString();
                lblG.Text       = color.Green.ToString();
                lblB.Text       = color.Blue.ToString();

                lblH.Text = ((int)(color.Hue)).ToString();
                lblS.Text = ((int)(color.Saturation * 255)).ToString();
                lblL.Text = ((int)(color.Lightness * 255)).ToString();

                picColor.Image = MakeColorZone(picColor.Size, color);

                picR.Image = MakeColorBar(picR.Size, Color.Red, color.Red);
                picG.Image = MakeColorBar(picG.Size, Color.FromArgb(44, 208, 0), color.Green);
                picB.Image = MakeColorBar(picB.Size, Color.FromArgb(10, 104, 199), color.Blue);

                picH.Image = MakeColorBarRainbow(picR.Size, color.Hue);
                picS.Image = MakeColorBar2(picG.Size, ColorPlus.FromHsl(color.Hue, 0, 0.5), ColorPlus.FromHsl(color.Hue, 1, 0.5), (int)(color.Saturation * 255));
                picL.Image = MakeColorBar2(picB.Size, ColorPlus.FromHsl(color.Hue, 1, 0), ColorPlus.FromHsl(color.Hue, 1, 1), (int)(color.Lightness * 255));
            });
        }
Exemplo n.º 14
0
 /// <summary>
 /// Retourne la couleur pastel équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur pastel.</returns>
 public static ColorPlus GetPastel(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 1, 0.85));
 }
Exemplo n.º 15
0
    private void PopulatePalettes()
    {
        // copy original state in case user hits cancel
        orig_input_palette.AddRange(ImageUtilities.input_palette);
        orig_output_palette.AddRange(ImageUtilities.output_palette);

        // ensure we have a valid input palette
        if (ImageUtilities.input_palette.Count == 0)
        {
            return;
        }

        ColorPlus[] input_palette = new ColorPlus[ImageUtilities.input_palette.Count];
        ColorPlus[] output_palette;

        if (ImageUtilities.sort_saved_palette)
        {
            ImageUtilities.StepSort(ImageUtilities.input_palette).CopyTo(input_palette);
        }
        else
        {
            ImageUtilities.input_palette.CopyTo(input_palette);
        }

        // figure out if an output palette has been defined or not (use input as default)
        if (ImageUtilities.output_palette.Count == 0)
        {
            output_palette = new ColorPlus[input_palette.Length];
            input_palette.CopyTo(output_palette, 0);
        }
        else
        {
            output_palette = new ColorPlus[ImageUtilities.output_palette.Count];
            if (ImageUtilities.sort_saved_palette)
            {
                ImageUtilities.StepSort(ImageUtilities.output_palette).CopyTo(output_palette);
            }
            else
            {
                ImageUtilities.output_palette.CopyTo(output_palette);
            }
        }

        // tell all the tiles they are input colors
        GameObject[] temp_objs  = new GameObject[input_palette.Length];
        ColorTile[]  temp_tiles = new ColorTile[input_palette.Length];
        int          index      = 0;

        for (int i = 0; i != input_palette.Length; i++)
        {
            // don't list transparent colors
            if (input_palette[i].alpha < ImageUtilities.transparent_threshhold)
            {
                continue;
            }

            // new color tile
            temp_objs[index]      = Instantiate(prefab, input_viewport.transform) as GameObject;
            temp_objs[index].name = "input_color_" + index.ToString();

            // set color tile color
            temp_tiles[index] = temp_objs[index].GetComponent(typeof(ColorTile)) as ColorTile;
            temp_tiles[index].Setup(true, input_palette[i].color32, input_palette[i].match, ref temp_objs[index]);

            index++;
        }

        GameObject[] temp1 = new GameObject[index];
        Array.Copy(temp_objs, temp1, index);
        input_colors.AddRange(temp1);

        ColorTile[] temp2 = new ColorTile[index];
        Array.Copy(temp_tiles, temp2, index);
        input_tiles.AddRange(temp2);

        temp_objs  = new GameObject[output_palette.Length];
        temp_tiles = new ColorTile[output_palette.Length];
        index      = 0;

        for (int i = 0; i != output_palette.Length; i++)
        {
            // don't list transparent colors
            if (output_palette[i].alpha < ImageUtilities.transparent_threshhold)
            {
                continue;
            }

            // new color tile
            temp_objs[index]      = Instantiate(prefab, output_viewport.transform) as GameObject;
            temp_objs[index].name = "output_color_" + index.ToString();

            // set color tile color
            temp_tiles[index] = temp_objs[index].GetComponent(typeof(ColorTile)) as ColorTile;
            temp_tiles[index].Setup(false, output_palette[i].color32, output_palette[i].match, ref temp_objs[index]);

            index++;
        }

        temp1 = new GameObject[index];
        Array.Copy(temp_objs, temp1, index);
        output_colors.AddRange(temp1);

        temp2 = new ColorTile[index];
        Array.Copy(temp_tiles, temp2, index);
        output_tiles.AddRange(temp2);
    }
Exemplo n.º 16
0
 /// <summary>
 /// Retourne la couleur fluo équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur fluo.</returns>
 public static ColorPlus GetFluo(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 1, 0.6));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Retourne la couleur connue la plus similaire à la couleur inconnue.
 /// </summary>
 /// <param name="unknown">Couleur inconnue.</param>
 /// <param name="knowns">Couleurs connues.</param>
 /// <returns>Couleur connue la plus proche de la couleur inconnue.</returns>
 public static ColorPlus GuessColor(ColorPlus unknown, IEnumerable <ColorPlus> knowns)
 {
     return(knowns.OrderBy(known => HueDelta(unknown, known)).First());
 }
Exemplo n.º 18
0
 /// <summary>
 /// Retourne la couleur terne équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur terne.</returns>
 public static ColorPlus GetDull(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 0.2, 0.75));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Retourne la couleur très estompée équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur très estompée.</returns>
 public static ColorPlus GetVeryLight(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 1, 0.93));
 }
Exemplo n.º 20
0
    // cycles through colors lists and set lowest LAB distance between each
    public static void FindClosest()
    {
        // ensure we received a valid colors array
        if (!auto_color_match || input_palette.Count == 0 || output_palette.Count == 0)
        {
            return;
        }

        Color32 transparent = new Color32((byte)255, (byte)255, (byte)255, (byte)0);

        Parallel.For(0, input_palette.Count, i =>
        {
            // some working varialbes
            double distance = 0, last = 0;
            int j;

            // short reference to this color
            ColorPlus in_color = input_palette[i];
            ColorPlus closest  = new ColorPlus();

            bool not_done = true;

            // check if transparent
            if (in_color.alpha <= transparent_threshhold)
            {
                // set this pixel to transparent
                in_color.match   = transparent;
                input_palette[i] = in_color;
                not_done         = false;
            }

            // check if color is gray
            if (not_done && in_color.achromatic)
            {
                // max possible difference between two gray colors (black -> white)
                distance = 255;

                // cycle through output palette
                for (j = 0; j < output_palette.Count; j++)
                {
                    // skip colors that aren't gray
                    if (!output_palette[j].achromatic)
                    {
                        continue;
                    }

                    // calculate absolute difference between grays
                    if (in_color.brightness > output_palette[j].brightness)
                    {
                        last = in_color.brightness - output_palette[j].brightness;
                    }
                    else
                    {
                        last = output_palette[j].brightness - in_color.brightness;
                    }

                    if (distance > last)
                    {
                        closest  = output_palette[j];
                        distance = last;
                    }
                }

                // check if source gray is sufficiently close to the nearest match
                if (distance <= achromatic_match)
                {
                    // best possible match is saved
                    in_color.match = new Color32((byte)closest.red, (byte)closest.green, (byte)closest.blue, (byte)in_color.alpha);

                    // assign data to input palette
                    input_palette[i] = in_color;

                    // stop calculating for this color
                    not_done = false;
                }
            }

            if (not_done)
            {
                // take first output_palette color as nearest match
                closest = output_palette[0];
                last    = CIE2000(in_color, output_palette[0]);

                // see if another color is closer than the first one
                for (j = 1; j < output_palette.Count; j++)
                {
                    distance = CIE2000(in_color, output_palette[j]);
                    if (last > distance)
                    {
                        last    = distance;
                        closest = output_palette[j];
                    }
                }

                // best possible match is saved
                in_color.match = new Color32((byte)closest.red, (byte)closest.green, (byte)closest.blue, (byte)in_color.alpha);

                // ensure data is kept
                input_palette[i] = in_color;
            }
        });
    }
    public ColorPlus GetColorPlus()
    {
        ColorPlus cp = this;

        return(cp);
    }
Exemplo n.º 22
0
    /// <summary>
    /// Créée une couleur depuis les paramètres de transparence, teinte, saturation et luminosité.
    /// </summary>
    /// <param name="alpha">Transparence, de 0 à 255.</param>
    /// <param name="hue">Teinte de 0° à 360°.</param>
    /// <param name="saturation">Saturation de 0 à 1.</param>
    /// <param name="lighting">Luminosité de 0 à 1.</param>
    /// <returns>Couleur correspondante.</returns>
    public static ColorPlus FromAhsl(int alpha, double hue, double saturation, double lighting)
    {
        if (0 > alpha || 255 < alpha)
        {
            throw new ArgumentOutOfRangeException(nameof(alpha));
        }
        if (0f > hue || 360f < hue)
        {
            throw new ArgumentOutOfRangeException(nameof(hue));
        }
        if (0f > saturation || 1f < saturation)
        {
            throw new ArgumentOutOfRangeException(nameof(saturation));
        }
        if (0f > lighting || 1f < lighting)
        {
            throw new ArgumentOutOfRangeException(nameof(lighting));
        }

        if (0 == saturation)
        {
            return(Color.FromArgb(alpha, Convert.ToInt32(lighting * 255), Convert.ToInt32(lighting * 255), Convert.ToInt32(lighting * 255)));
        }

        double fMax, fMid, fMin;
        int    sextant, iMax, iMid, iMin;

        if (0.5 < lighting)
        {
            fMax = lighting - (lighting * saturation) + saturation;
            fMin = lighting + (lighting * saturation) - saturation;
        }
        else
        {
            fMax = lighting + (lighting * saturation);
            fMin = lighting - (lighting * saturation);
        }

        sextant = (int)Math.Floor(hue / 60f);

        if (300f <= hue)
        {
            hue -= 360f;
        }

        hue /= 60f;
        hue -= 2f * (double)Math.Floor(((sextant + 1f) % 6f) / 2f);

        if (0 == sextant % 2)
        {
            fMid = hue * (fMax - fMin) + fMin;
        }
        else
        {
            fMid = fMin - hue * (fMax - fMin);
        }

        iMax = Convert.ToInt32(fMax * 255);
        iMid = Convert.ToInt32(fMid * 255);
        iMin = Convert.ToInt32(fMin * 255);

        ColorPlus color = new ColorPlus();

        switch (sextant)
        {
        case 1:
            color._innerColor = Color.FromArgb(alpha, iMid, iMax, iMin);
            break;

        case 2:
            color._innerColor = Color.FromArgb(alpha, iMin, iMax, iMid);
            break;

        case 3:
            color._innerColor = Color.FromArgb(alpha, iMin, iMid, iMax);
            break;

        case 4:
            color._innerColor = Color.FromArgb(alpha, iMid, iMin, iMax);
            break;

        case 5:
            color._innerColor = Color.FromArgb(alpha, iMax, iMin, iMid);
            break;

        default:
            color._innerColor = Color.FromArgb(alpha, iMax, iMid, iMin);
            break;
        }

        return(color);
    }
Exemplo n.º 23
0
    private void ProcessHex(string text)
    {
        // remove comments
        text = (Regex.Replace(text, "//[.]*$", ""));

        // strip all characters except 0-9, a-f, greater than symbol, and newline
        text = (Regex.Replace(text, "[^0-9a-f>\n]", "")).Trim();

        // replace multiple lines with single line
        text = (Regex.Replace(text, "[\n]+", "\n"));

        // remove example line at the end
        text = text.Replace("\nc0ffee00>c00c000", "");

        // break into rows
        string[] line, rows = text.Split('\n');

        // these are assigned empty values to make the compiler stop complaining
        ColorPlus in_color = transparent, out_color = transparent, test_color = transparent;
        bool      is_color_map;
        int       i, j;

        for (i = 0; i < rows.Length; i++)
        {
            is_color_map = false;
            // split line into values
            line = rows[i].Split('>');

            // left side of arrow
            if (line[0].Length >= 8)
            {
                in_color = int.Parse(line[0].Substring(0, 8), System.Globalization.NumberStyles.HexNumber);
            }
            else if (line[0].Length >= 6)
            {
                in_color = int.Parse(line[0].Substring(0, 6), System.Globalization.NumberStyles.HexNumber) << 8 | 255;
            }
            else
            {
                continue;
            }

            // right side of arrow
            if (line.Length > 1)
            {
                is_color_map = true;
                if (line[1].Length >= 8)
                {
                    out_color = int.Parse(line[1].Substring(0, 8), System.Globalization.NumberStyles.HexNumber);
                }
                else if (line[1].Length >= 6)
                {
                    out_color = int.Parse(line[1].Substring(0, 6), System.Globalization.NumberStyles.HexNumber) << 8 | 255;
                }
                else
                {
                    continue;
                }
            }

            // is this a color mapping ?
            if (is_color_map)
            {
                j = ImageUtilities.input_palette.IndexOf(in_color);
                if (j != -1)
                {
                    // found the color, map it
                    test_color       = ImageUtilities.input_palette[j];
                    test_color.match = out_color.color32;
                    ImageUtilities.input_palette[j] = test_color;
                }
                // add output color to the list
                color_list.Add(out_color);
            }
            else
            {
                // only adding this color, no mapping
                find_closest = true;
                color_list.Add(in_color);
            }
        }
    }
Exemplo n.º 24
0
 public bool Equals(Color32 b, ColorPlus a)
 {
     return(Equals(a, b));
 }
Exemplo n.º 25
0
    // translated from very good C++ source found at https://github.com/gfiumara/CIEDE2000
    public static double CIE2000(ColorPlus lab1, ColorPlus lab2)
    {
        /*
         * "For these and all other numerical/graphical delta E00 values
         * reported in this article, we set the parametric weighting factors
         * to unity(i.e., k_L = k_C = k_H = 1.0)." (Page 27).
         *
         * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
         */
        double k_L = 1.0, k_C = 1.0, k_H = 1.0;
        double deg360InRad = deg2Rad(360.0);
        double deg180InRad = deg2Rad(180.0);
        double pow25To7    = 6103515625.0;      /* pow(25, 7) */

        /*
         * Step 1
         */
        /* Equation 2 */
        double C1 = Math.Sqrt((lab1.a * lab1.a) + (lab1.b * lab1.b));
        double C2 = Math.Sqrt((lab2.a * lab2.a) + (lab2.b * lab2.b));
        /* Equation 3 */
        double barC = (C1 + C2) / 2.0;
        /* Equation 4 */
        double G = 0.5 * (1 - Math.Sqrt(Math.Pow(barC, 7) / (Math.Pow(barC, 7) + pow25To7)));
        /* Equation 5 */
        double a1Prime = (1.0 + G) * lab1.a;
        double a2Prime = (1.0 + G) * lab2.a;
        /* Equation 6 */
        double CPrime1 = Math.Sqrt((a1Prime * a1Prime) + (lab1.b * lab1.b));
        double CPrime2 = Math.Sqrt((a2Prime * a2Prime) + (lab2.b * lab2.b));
        /* Equation 7 */
        double hPrime1;

        if (lab1.b == 0 && a1Prime == 0)
        {
            hPrime1 = 0.0;
        }
        else
        {
            hPrime1 = Math.Atan2(lab1.b, a1Prime);

            /*
             * This must be converted to a hue angle in degrees between 0
             * and 360 by addition of 2 degrees to negative hue angles.
             */
            if (hPrime1 < 0)
            {
                hPrime1 += deg360InRad;
            }
        }
        double hPrime2;

        if (lab2.b == 0 && a2Prime == 0)
        {
            hPrime2 = 0.0;
        }
        else
        {
            hPrime2 = Math.Atan2(lab2.b, a2Prime);

            /*
             * This must be converted to a hue angle in degrees between 0
             * and 360 by addition of 2 degrees to negative hue angles.
             */
            if (hPrime2 < 0)
            {
                hPrime2 += deg360InRad;
            }
        }

        /*
         * Step 2
         */
        /* Equation 8 */
        double deltaLPrime = lab2.l - lab1.l;
        /* Equation 9 */
        double deltaCPrime = CPrime2 - CPrime1;
        /* Equation 10 */
        double deltahPrime;
        double CPrimeProduct = CPrime1 * CPrime2;

        if (CPrimeProduct == 0)
        {
            deltahPrime = 0;
        }
        else
        {
            /* Avoid the fabs() call */
            deltahPrime = hPrime2 - hPrime1;
            if (deltahPrime < -deg180InRad)
            {
                deltahPrime += deg360InRad;
            }
            else if (deltahPrime > deg180InRad)
            {
                deltahPrime -= deg360InRad;
            }
        }
        /* Equation 11 */
        double deltaHPrime = 2.0 *
                             Math.Sqrt(CPrimeProduct) *
                             Math.Sin(deltahPrime / 2.0);

        /*
         * Step 3
         */
        /* Equation 12 */
        double barLPrime = (lab1.l + lab2.l) / 2.0;
        /* Equation 13 */
        double barCPrime = (CPrime1 + CPrime2) / 2.0;
        /* Equation 14 */
        double barhPrime, hPrimeSum = hPrime1 + hPrime2;

        if (CPrime1 * CPrime2 == 0)
        {
            barhPrime = hPrimeSum;
        }
        else
        {
            if (Math.Abs(hPrime1 - hPrime2) <= deg180InRad)
            {
                barhPrime = hPrimeSum / 2.0;
            }
            else
            {
                if (hPrimeSum < deg360InRad)
                {
                    barhPrime = (hPrimeSum + deg360InRad) / 2.0;
                }
                else
                {
                    barhPrime = (hPrimeSum - deg360InRad) / 2.0;
                }
            }
        }
        /* Equation 15 */
        double T = 1.0 - (0.17 * Math.Cos(barhPrime - deg2Rad(30.0))) +
                   (0.24 * Math.Cos(2.0 * barhPrime)) +
                   (0.32 * Math.Cos((3.0 * barhPrime) + deg2Rad(6.0))) -
                   (0.20 * Math.Cos((4.0 * barhPrime) - deg2Rad(63.0)));
        /* Equation 16 */
        double deltaTheta = deg2Rad(30.0) *
                            Math.Exp(-Math.Pow((barhPrime - deg2Rad(275.0)) / deg2Rad(25.0), 2.0));
        /* Equation 17 */
        double R_C = 2.0 * Math.Sqrt(Math.Pow(barCPrime, 7.0) /
                                     (Math.Pow(barCPrime, 7.0) + pow25To7));
        /* Equation 18 */
        double S_L = 1 + ((0.015 * Math.Pow(barLPrime - 50.0, 2.0)) /
                          Math.Sqrt(20 + Math.Pow(barLPrime - 50.0, 2.0)));
        /* Equation 19 */
        double S_C = 1 + (0.045 * barCPrime);
        /* Equation 20 */
        double S_H = 1 + (0.015 * barCPrime * T);
        /* Equation 21 */
        double R_T = (-Math.Sin(2.0 * deltaTheta)) * R_C;

        /* Equation 22 */
        double deltaE = Math.Sqrt(
            Math.Pow(deltaLPrime / (k_L * S_L), 2.0) +
            Math.Pow(deltaCPrime / (k_C * S_C), 2.0) +
            Math.Pow(deltaHPrime / (k_H * S_H), 2.0) +
            (R_T * (deltaCPrime / (k_C * S_C)) * (deltaHPrime / (k_H * S_H))));

        return(deltaE);
    }
Exemplo n.º 26
0
 /// <summary>
 /// Retourne la couleur intense équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur intense.</returns>
 public static ColorPlus GetIntense(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 1, 0.4));
 }
Exemplo n.º 27
0
 public static string ToGPL(ColorPlus c)
 {
     return(ToGPL(c.color32));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Retourne la couleur sombre équivalente.
 /// </summary>
 /// <param name="color">Couleur d'origine.</param>
 /// <returns>Couleur sombre.</returns>
 public static ColorPlus GetDark(ColorPlus color)
 {
     return(ColorPlus.FromHsl(color.Hue, 1, 0.3));
 }