Beispiel #1
0
        public static SymbolsImage Combine(SymbolsImage bottom, SymbolsImage top)
        {
            if (bottom.Width != top.Width || bottom.Height != top.Height)
            {
                throw new ArgumentException($"Cannot combine images {bottom.Width}x{bottom.Height} and {top.Width}x{top.Height}");
            }

            var result = new SymbolsImage(bottom.Width, bottom.Height);

            for (var x = 0; x < bottom.Width; x++)
            {
                for (var y = 0; y < bottom.Height; y++)
                {
                    var pixel       = result[x, y];
                    var bottomPixel = bottom[x, y];
                    var topPixel    = top[x, y];

                    pixel.Symbol          = topPixel.Symbol ?? bottomPixel.Symbol;
                    pixel.Color           = topPixel.Symbol.HasValue ? topPixel.Color : bottomPixel.Color;
                    pixel.BackgroundColor = topPixel.BackgroundColor ?? bottomPixel.BackgroundColor;
                }
            }

            return(result);
        }
Beispiel #2
0
        public static SymbolsImage Recolor(SymbolsImage image, Dictionary <Color, Color> palette)
        {
            var result = new SymbolsImage(image.Width, image.Height);

            for (var x = 0; x < image.Width; x++)
            {
                for (var y = 0; y < image.Height; y++)
                {
                    var pixel         = result[x, y];
                    var originalPixel = image[x, y];

                    pixel.Symbol = originalPixel.Symbol;

                    if (originalPixel.Color.HasValue)
                    {
                        pixel.Color = palette.ContainsKey(originalPixel.Color.Value)
                        ? palette[originalPixel.Color.Value]
                        : originalPixel.Color;
                    }
                    else
                    {
                        pixel.Color = null;
                    }

                    if (originalPixel.BackgroundColor.HasValue)
                    {
                        pixel.BackgroundColor = palette.ContainsKey(originalPixel.BackgroundColor.Value)
                        ? palette[originalPixel.BackgroundColor.Value]
                        : originalPixel.BackgroundColor;
                    }
                    else
                    {
                        pixel.BackgroundColor = null;
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        public static void SaveToFile(SymbolsImage image, Stream fileStream)
        {
            var savingManager = new XmlSavingManager();

            savingManager.SaveToFile(image.Width, image.Height, image.pixels, fileStream);
        }