Beispiel #1
0
 public void AddColor(総天然色 c)
 {
     if (ColorTable.ContainsKey(c.Char))
     {
         return;
     }
     c.LutIndex = ColorLookupTable.Count;
     ColorTable.Add(c.Char, c);
     ColorLookupTable.Add(c);
 }
        /// <summary>
        /// XPMの色定義から総天然色のインスタンスを作る
        /// </summary>
        /// <param name="xpm">XPM</param>
        /// <param name="src">色定義</param>
        /// <returns>総天然色</returns>
        public static 総天然色 Parse(Xpm xpm, string src)
        {
            var r = new 総天然色(xpm.ColorResolver);

            // CPP分
            r.Char = src.Substring(0, xpm.CharsPerPixel);
            var vs = src.Substring(xpm.CharsPerPixel + 1).Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            r.colors = new ColorRef[vs.Length / 2];
            for (int i = 0, j = 0; i < vs.Length; i += 2, j++)
            {
                r.colors[j] = ParseColorRef(xpm.ColorResolver, vs[i], vs[i + 1]);
                if (r.colors[j].Converted)
                {
                    r.ConvertedIndex = j;
                }
            }

            return(r);
        }
Beispiel #3
0
        /// <summary>
        /// カラーマップ生成
        /// </summary>
        /// <param name="pix">ぉ</param>
        /// <param name="rpp">1ピクセル辺りの文字数(Tupleが公式サポートされたらTupleで返そう)</param>
        /// <returns>色</returns>
        public static Dictionary <string, 総天然色> GenerateColorMap(ぉ[] pix, out int rpp)
        {
            var cmap = new Dictionary <ぉ, int>();

            cmap.Add(new ぉ(0, 0, 0, 0), 0);
            int pi = 1;

            foreach (var c in pix)
            {
                if (!cmap.ContainsKey(c))
                {
                    cmap.Add(c, pi++);
                }
            }
            var dik = XPMCHARS.Length - 1;
            // 桁数
            int cn = cmap.Count < dik ? 1 : (cmap.Count / (XPMCHARS.Length * XPMCHARS.Length)) + 2;

            rpp = cn;

            var keys = new string[cmap.Count];

            int[] ack = new int[cn];
            int   vc  = 0;

            for (int j = 0; j < cn; j++)
            {
                ack[j] = j;
            }
            int cni = 0;

            for (int i = 0; i < cmap.Count; i++)
            {
                keys[i] = XPMCHARS[vc].ToString();
                for (int j = 1; j < cn; j++)
                {
                    keys[i] += XPMCHARS[ack[j - 1]];
                }
                vc++;
                if (vc > dik)
                {
                    vc = 0;
                    if (++ack[cni] >= dik)
                    {
                        cni++;
                    }
                }
            }
            var 原色 = new Fallback原色();

            var ret = new Dictionary <string, 総天然色>();

            foreach (var c in cmap.Keys)
            {
                var k = keys[cmap[c]];
                var g = new 総天然色(原色);
                g.Alloc(1);
                if (cmap[c] == 0)
                {
                    g.Char             = k;
                    g.Color[0]         = new 総天然色.ColorRef();
                    g.Color[0].Context = 色種別.Color;
                    g.Color[0].Format  = ColorFormat.Name;
                    g.Color[0].Color   = "None";
                }
                else
                {
                    g.Char             = k;
                    g.Color[0]         = new 総天然色.ColorRef();
                    g.Color[0].Context = 色種別.Color;
                    g.Color[0].Format  = ColorFormat.RGB;
                    g.Color[0].Color   = c.ToXRGB16();
                }
                ret.Add(k, g);
            }
            return(ret);
        }