/// <summary>色情報を入力する</summary> /// <param name="buf">カラー配列</param> private void SetColor(byte[] buf) { Random rnd = new Random(); List <Point3D>[] colorLists = new List <Point3D> [colors.Length]; for (int i = 0; i < colorLists.Length; i++) { colorLists[i] = new List <Point3D>(); } HashSet <Point3D> hash = new HashSet <Point3D>(); for (int i = 0; i < buf.Length; i += 4) { int n = rnd.Next(0, colors.Length); LAB lab = LAB.FromRGB(buf[i + 0], buf[i + 1], buf[i + 2]); Point3D point = new Point3D(lab.L, lab.A, lab.B); if (hash.Add(point)) { colorLists[n].Add(point); } } for (int i = 0; i < colors.Length; i++) { colors[i] = colorLists[i]; } }
/// <summary>カラー配列の置き換え</summary> /// <param name="buf">カラー配列</param> private void Replace(byte[] buf) { for (int i = 0; i < buf.Length; i += 4) { LAB lab = LAB.FromRGB(buf[i + 0], buf[i + 1], buf[i + 2]); Point3D c = new Point3D(lab.L, lab.A, lab.B); int min = 0; double minR = double.MaxValue; for (int k = 0; k < center.Length; k++) { double r = Range(c, center[k]); if (minR > r) { min = k; minR = r; } } Color color = LAB.ToRGB(LAB.FromLAB(center[min].X, center[min].Y, center[min].Z)); buf[i + 0] = color.R; buf[i + 1] = color.G; buf[i + 2] = color.B; } }