Пример #1
0
        public List <PaletteItem> Find(Color color1, Color color2, ColorSearchWidth width, bool addSimilar, int maxCount)
        {
            int mask;
            SortedDictionary <int, int> colors = this.FindColors(color1, color2, width, out mask);

            if (colors.Count == 0)
            {
                return(null);
            }
            return(this.LoadForColors(colors, mask, addSimilar, maxCount));
        }
Пример #2
0
        protected string RenderComparisonList()
        {
            HtmlRenderer html = new HtmlRenderer();

            ColorSearchWidth opt = (ColorSearchWidth)this.parameters.Get("Comparison", (long)ColorSearchWidth.Wide);

            html.SelectItem("Exact", ((int)ColorSearchWidth.Exact).ToString(), opt == ColorSearchWidth.Exact);
            html.SelectItem("Narrow", ((int)ColorSearchWidth.Narrow).ToString(), opt == ColorSearchWidth.Narrow);
            html.SelectItem("Wide", ((int)ColorSearchWidth.Wide).ToString(), opt == ColorSearchWidth.Wide);
            html.SelectItem("Very wide", ((int)ColorSearchWidth.VeryWide).ToString(), opt == ColorSearchWidth.VeryWide);
            html.SelectItem("Widest", ((int)ColorSearchWidth.Widest).ToString(), opt == ColorSearchWidth.Widest);

            return(html.ToString());
        }
Пример #3
0
        private SortedDictionary <int, int> FindColors(Color color1, Color color2, ColorSearchWidth width, out int mask)
        {
            mask = 0;
            SortedDictionary <int, int> l = new SortedDictionary <int, int>();

            using (SqlConnection conn = this.GetConnection())
            {
                if (color1 != Color.Transparent)
                {
                    this.FindAddColors(conn, l, color1.ToArgb() & 0xffffff, width, 0x1);
                    mask |= 0x1;
                }
                if (color2 != Color.Transparent)
                {
                    this.FindAddColors(conn, l, color2.ToArgb() & 0xffffff, width, 0x2);
                    mask |= 0x2;
                }
            }
            return(l);
        }
Пример #4
0
        public Color[] FindColor(Color color, ColorSearchWidth width)
        {
            SortedDictionary <int, int> l = new SortedDictionary <int, int>();

            using (SqlConnection conn = this.GetConnection())
            {
                this.FindAddColors(conn, l, color.ToArgb() & 0xffffff, width, 0x1);
            }
            if (l.Count == 0)
            {
                return(null);
            }
            Color[] r = new Color[l.Count];
            int     i = 0;

            foreach (KeyValuePair <int, int> p in l)
            {
                r[i++] = PaletteManager.ColorFromInt(p.Key);
            }
            l = null;
            return(r);
        }
Пример #5
0
        private static string ColorSearchSql(int color, ColorSearchWidth width, out LabColor lab)
        {
            lab = ColorTransform.RgbToLab(PaletteManager.ColorFromInt(color));

            StringBuilder sb = new StringBuilder();

            int w = (int)width;

            sb.Append(@"SELECT c.RGB, c.L, c.A, c.B
FROM COLOR c, COLOR_INDEX_L l, COLOR_INDEX_A a, COLOR_INDEX_B b
WHERE (l.RGB = c.RGB) AND (a.RGB = c.RGB) AND (b.RGB = l.RGB)");

            sb.Append("AND (l.[HASH] ");
            int h = lab.HashL;

            if (w > 0)
            {
                sb.Append("IN (");

                int c = 0;
                for (int i = -w; i <= w; i++)
                {
                    if (c++ > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append((h + i).ToString());
                }

                sb.Append(')');
            }
            else
            {
                sb.Append("= ");
                sb.Append(h.ToString());
            }
            sb.Append(')');

            sb.Append(" AND (a.[HASH] ");
            h = lab.HashA;
            if (w > 0)
            {
                sb.Append("IN (");
                int c = 0;
                for (int i = -w; i <= w; i++)
                {
                    if (c++ > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append((h + i).ToString());
                }

                sb.Append(')');
            }
            else
            {
                sb.Append("= ");
                sb.Append(h.ToString());
            }
            sb.Append(')');

            sb.Append(" AND (b.[HASH] ");
            h = lab.HashB;
            if (w > 0)
            {
                sb.Append("IN (");
                int c = 0;
                for (int i = -w; i <= w; i++)
                {
                    if (c++ > 0)
                    {
                        sb.Append(',');
                    }
                    sb.Append((h + i).ToString());
                }

                sb.Append(')');
            }
            else
            {
                sb.Append("= ");
                sb.Append(h.ToString());
            }
            sb.Append(')');

            return(sb.ToString());
        }
Пример #6
0
        private void FindAddColors(SqlConnection conn, SortedDictionary <int, int> list, int color, ColorSearchWidth width, int mask)
        {
            LabColor      lab;
            string        sql = PaletteManager.ColorSearchSql(color, width, out lab);
            SqlCommand    cmd = new SqlCommand(sql, conn);
            SqlDataReader r   = cmd.ExecuteReader();

            while (r.Read())
            {
                int c = r.GetInt32(0);
                if (!list.ContainsKey(c))
                {
                    list.Add(c, mask);
                }
                else
                {
                    list[c] |= mask;
                }
            }
            r.Close();
            r   = null;
            cmd = null;
        }