Exemplo n.º 1
0
        public AC.Palette GetAsPalette()
        {
            AC.Palette palette = new AC.Palette();
            for (int i = 0; i < paletteControl.Items.Length; i++)
                palette.SetColor(i, AC.Palette.ColorPalette[paletteControl.Items[i]]);

            return palette;
        }
Exemplo n.º 2
0
        public Pattern()
        {
            Data = new byte[Width, Height];

            Author = new User();
            Title = "Untitled";

            Type = PatternType.Normal;

            ColorPalette = new Palette();
        }
Exemplo n.º 3
0
        public void Clear()
        {
            for (int i = 0; i < pixels.GetLength(0); i++)
                for (int j = 0; j < pixels.GetLength(1); j++)
                    pixels[i, j] = 12;

            palette = new AC.Palette();

            Invalidate();
        }
Exemplo n.º 4
0
        public void LoadPattern(AC.Pattern pattern)
        {
            for (int i = 0; i < pixels.GetLength(0); i++)
                for (int j = 0; j < pixels.GetLength(1); j++)
                    pixels[i, j] = pattern.Data[i, j];

            palette = new AC.Palette();
            Array.Copy(pattern.ColorPalette.Colors, palette.Colors, pattern.ColorPalette.Colors.Length);

            Refresh();
        }
Exemplo n.º 5
0
        private void LoadFromStream(Stream stream)
        {
            BinaryReader binaryReader = new BinaryReader(stream);
            NibbleReader nibbleReader = new NibbleReader(binaryReader);

            byte type = nibbleReader.ReadByte();
            if (type != 0x40)
                throw new NotImplementedException();

            int size = nibbleReader.ReadByte();
            size = (size << 4) | nibbleReader.ReadNibble();
            if (size != 0x26C)
                throw new InvalidDataException("Size is invalid.");

            Title = nibbleReader.ReadString(42);
            Author = new User(nibbleReader);

            ColorPalette = new Palette(nibbleReader);

            nibbleReader.ReadByte(); // Unknown
            nibbleReader.ReadByte(); // Unknown, 0x0A
            Type = (PatternType)nibbleReader.ReadByte();
            nibbleReader.ReadByte(); // Unknown, 0x00
            nibbleReader.ReadByte(); // Unknown, 0x00

            for (int j = 0; j < Data.GetLength(1); j++)
                for (int i = 0; i < Data.GetLength(0); i += 2)
                {
                    Data[i + 1, j] = nibbleReader.ReadNibble();
                    Data[i, j] = nibbleReader.ReadNibble();
                }
        }
Exemplo n.º 6
0
        private void LoadFromPixelData(byte[] data)
        {
            Title = "Untitled";
            Author = new User("Someone", "Nowhere", new byte[] { 0, 0, 0, 0, 0, 0 });
            Type = PatternType.Normal;

            Color[,] sourceImage = new Color[Width, Height];
            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    sourceImage[i, j] = new Color(data[(j * Height + i) * 3 + 2], data[(j * Height + i) * 3 + 1], data[(j * Height + i) * 3 + 0]);

            HashSet<Color> bestPalette = CreateBestPalette(sourceImage);
            ColorPalette = new Palette();
            int k = 0;
            foreach (Color c in bestPalette)
                ColorPalette.SetColor(k++, c);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    Data[i, j] = ColorPalette.GetNearestColorIndex(sourceImage[i, j]);
        }
Exemplo n.º 7
0
        private void LoadFromPixelData(byte[] data)
        {
            Color[,] sourceImage = new Color[Width, Height];
            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    sourceImage[i, j] = new Color(
                        data[(j * Height + i) * 4 + 2],
                        data[(j * Height + i) * 4 + 1],
                        data[(j * Height + i) * 4 + 0],
                        data[(j * Height + i) * 4 + 3]);

            HashSet<Color> bestPalette = CreateBestPalette(sourceImage);
            ColorPalette = new Palette();
            int k = 0;
            foreach (Color c in bestPalette)
                ColorPalette.SetColor(k++, c);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    Data[i, j] = ColorPalette.GetNearestColorIndex(sourceImage[i, j]);
        }