private (List <Palette> colors, int numVectors) GetPalette(int paletteSize, Color?exclude, int error = 0, bool ignoreGrey = false) { foreach (var cp in image.GetColors()) { var isExcluded = exclude != null && exclude.Value.R - error < cp.color.R && cp.color.R < (exclude.Value.R + error) && exclude.Value.G - error < cp.color.G && cp.color.G < (exclude.Value.G + error) && exclude.Value.B - error < cp.color.B && cp.color.B < (exclude.Value.B + error); if (!isExcluded) { var excludeGrey = ignoreGrey && Math.Abs(cp.color.R - cp.color.G) < error && Math.Abs(cp.color.R - cp.color.B) < error && Math.Abs(cp.color.G - cp.color.B) < error; if (!excludeGrey) { octree.InsertVector(new byte[] { cp.color.R, cp.color.G, cp.color.B }, cp.position); } } } var numVectors = octree.NumVectors; return(octree.ReduceToSize(paletteSize), numVectors); }