Exemplo n.º 1
0
        public void TestGenerateGraphics3()
        {
            // Ensure that when a sub-palette (4-color palette) doesn't have a first color
            // that matches the theme BackColor (ie: the first color of the first palette),
            // then the graphics generation still works as expected, using the theme BackColor
            // rather than the first sub-palette color.
            byte[] palData =
            {
                0x00, 0x00, 0xFF, 0x7F, 0x55, 0x62, 0xB0, 0x49,
                0xF0, 0xF0, 0x5A, 0x73, 0xB0, 0x49, 0x2C, 0x39, // Sub-palette used
                0x00, 0x00, 0xD3, 0x7E, 0x20, 0x78, 0x00, 0x3C,
                0x00, 0x00, 0xDE, 0x3F, 0x9E, 0x02, 0x1B, 0x00
            };

            byte[] gfx =
            {
                0x00, 0x00, 0x00, 0x07, 0x07, 0x18, 0x0F, 0x30,
                0x0B, 0x20, 0x0B, 0x60, 0x0B, 0x60, 0x3F, 0x40
            };

            Tile2bppProperties properties = new Tile2bppProperties {
                SubPaletteIndex = 4
            };

            this.TestGenerateGraphics(palData, gfx, properties);
        }
Exemplo n.º 2
0
        private void TestGenerateGraphics(byte[] palData, byte[] gfx, Tile2bppProperties properties)
        {
            byte[] palsData = new byte[512];
            Buffer.BlockCopy(palData, 0, palsData, 0, palData.Length);

            Palettes pals = new Palettes(palsData);

            byte     props = properties.GetByte();
            Tile2bpp tile  = new Tile2bpp(gfx, pals, props);
            Tile2bpp tile2 = new Tile2bpp(new byte[gfx.Length], pals, props);

            tile2.Bitmap = tile.Bitmap; // Trigger graphics update

            Assert.AreEqual(gfx, tile2.Graphics);
        }
Exemplo n.º 3
0
 public void TestPropertiesGetByte()
 {
     for (int i = 0; i <= 0xFF; i++)
     {
         byte value = (byte)i;
         if ((value & 0x3) != 0)
         {
             Assert.Throws(typeof(ArgumentOutOfRangeException), delegate { new Tile2bppProperties(value); });
         }
         else
         {
             Tile2bppProperties properties = new Tile2bppProperties(value);
             Assert.AreEqual(i, properties.GetByte());
         }
     }
 }
Exemplo n.º 4
0
        public static Bitmap GetBitmapFrom2bppPlanar(byte[] gfx, Palettes palettes, Tile2bppProperties properties)
        {
            // Each tile is made up of 8x8 pixels, coded on 16 bytes (2 bits per pixel)

            Palette    palette     = palettes[properties.PaletteIndex];
            int        subPalIndex = properties.SubPaletteIndex;
            TileFlip   flip        = properties.Flip;
            Bitmap     bitmap      = new Bitmap(Tile.Size, Tile.Size, PixelFormat.Format32bppPArgb);
            FastBitmap fBitmap     = new FastBitmap(bitmap);

            for (int y = 0; y < Tile.Size; y++)
            {
                byte val1 = gfx[y * 2];
                byte val2 = gfx[y * 2 + 1];
                for (int x = 0; x < Tile.Size; x++)
                {
                    int mask       = 1 << x;
                    int colorIndex = ((val1 & mask) >> x) + (((val2 & mask) >> x) << 1);

                    if (colorIndex > 0) // If pixel is not transparent
                    {
                        int xPos = (flip & TileFlip.X) != 0 ?
                                   x : (Tile.Size - 1) - x;

                        int yPos = (flip & TileFlip.Y) == 0 ?
                                   y : (Tile.Size - 1) - y;

                        Color color = palette[subPalIndex + colorIndex];

                        fBitmap.SetPixel(xPos, yPos, color);
                    }
                }
            }

            fBitmap.Release();
            return(bitmap);
        }