public Schematic ConvertSchematic(Schematic schematic) { Console.WriteLine("[INFO] Started to convert all colors of blocks to match the palette"); Schematic newSchematic = new Schematic(GetPaletteUint()); List <uint> colors = schematic.UsedColors; Dictionary <uint, int> paletteDictionary = new Dictionary <uint, int>(); foreach (uint color in colors) { int index = ColorComparison.CompareColorRGB(_colors, color.UIntToColor()); paletteDictionary[color] = index; } using (ProgressBar progressbar = new ProgressBar()) { int i = 0; List <Voxel> allVoxels = schematic.GetAllVoxels(); foreach (Voxel block in allVoxels) { newSchematic.AddVoxel(block.X, block.Y, block.Z, _colors[paletteDictionary[block.Color]].ColorToUInt()); progressbar.Report(i++ / (float)allVoxels.Count); } } Console.WriteLine("[INFO] Done."); return(newSchematic); }
public Schematic ConvertSchematic(Schematic schematic) { Console.WriteLine("[LOG] Started to convert all colors of blocks to match the palette"); Schematic newSchematic = new Schematic(schematic.Width, schematic.Height, schematic.Length, new HashSet <Block>()); List <uint> colors = schematic.Colors; Dictionary <uint, int> paletteDictionary = new Dictionary <uint, int>(); foreach (uint color in colors) { int index = ColorComparison.CompareColorRGB(_colors, color.UIntToColor()); paletteDictionary[color] = index; } using (ProgressBar progressbar = new ProgressBar()) { int i = 0; foreach (Block block in schematic.Blocks) { newSchematic.Blocks.Add(new Block(block.X, block.Y, block.Z, _colors[paletteDictionary[block.Color]].ColorToUInt(), paletteDictionary[block.Color])); progressbar.Report(i++ / (float)schematic.Blocks.Count); } } Console.WriteLine("[LOG] Done."); return(newSchematic); }
private Color GetFromARGB(List <Color> systemColors, Color target) { double Diff = 0; List <ColorComparison> comparisons = new List <ColorComparison>(); ColorComparison bestMatch = null; for (int c = 0; c < systemColors.Count; c++) { var color = systemColors[c]; ColorComparison cp = new ColorComparison(); cp.systemColor = color; cp.dR = Math.Abs(target.R - color.R); cp.dG = Math.Abs(target.G - color.G); cp.dB = Math.Abs(target.B - color.B); cp.distance = cp.dR + cp.dB + cp.dG; comparisons.Add(cp); if (bestMatch == null || cp.distance < bestMatch.distance) { bestMatch = cp; } } return(bestMatch.systemColor); }