/// <summary> /// コンス /// </summary> public Xbm() { ColorResolver = new Fallback原色(); }
/// <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); }