Example #1
0
 public Sprite(BitmapBits lowImg, BitmapBits highImg, int xoff, int yoff)
 {
     strips = new List <PixelStrip>();
     LoadBitmap(lowImg, false, xoff, yoff);
     LoadBitmap(highImg, true, xoff, yoff);
     CalculateBounds();
 }
Example #2
0
        public BitmapBits GetBitmapHigh()
        {
            BitmapBits result = new BitmapBits(Size);

            result.DrawSpriteHigh(this, -X, -Y);
            return(result);
        }
Example #3
0
 public BitmapBits(BitmapBits source)
 {
     Width  = source.Width;
     Height = source.Height;
     Bits   = new byte[source.Bits.Length];
     Array.Copy(source.Bits, Bits, Bits.Length);
     OriginalFormat = PixelFormat.Format8bppIndexed;
 }
Example #4
0
 public static void IncrementIndexes(this BitmapBits bmp, int amount)
 {
     for (int i = 0; i < bmp.Bits.Length; i++)
     {
         if (bmp.Bits[i] > 0)
         {
             bmp.Bits[i] = (byte)(bmp.Bits[i] + amount);
         }
     }
 }
Example #5
0
        public BitmapBits GetSection(int x, int y, int width, int height)
        {
            BitmapBits result = new BitmapBits(width, height);

            for (int v = 0; v < height; v++)
            {
                Array.Copy(this.Bits, GetPixelIndex(x, y + v), result.Bits, v * width, width);
            }
            return(result);
        }
Example #6
0
 public void DrawBitmap(BitmapBits source, int x, int y)
 {
     if (x == 0 && source.Width == Width)
     {
         source.Bits.CopyTo(Bits, GetPixelIndex(0, y));
         return;
     }
     for (int i = 0; i < source.Height; i++)
     {
         int di = GetPixelIndex(x, y + i);
         int si = i * source.Width;
         Array.Copy(source.Bits, si, Bits, di, source.Width);
     }
 }
Example #7
0
        public static BitmapBits FromTileInterlaced(byte[] art, int index)
        {
            BitmapBits bmp = new BitmapBits(8, 16);

            if (index * 32 + 64 <= art.Length)
            {
                for (int i = 0; i < 64; i++)
                {
                    bmp.Bits[i * 2]       = (byte)(art[i + (index * 32)] >> 4);
                    bmp.Bits[(i * 2) + 1] = (byte)(art[i + (index * 32)] & 0xF);
                }
            }
            return(bmp);
        }
Example #8
0
        public static BitmapBits ReadPCX(Stream stream, out Color[] palette)
        {
            BinaryReader br = new BinaryReader(stream);

            stream.Seek(8, SeekOrigin.Current);
            BitmapBits pix = new BitmapBits(br.ReadUInt16() + 1, br.ReadUInt16() + 1);

            stream.Seek(0x36, SeekOrigin.Current);
            int stride = br.ReadUInt16();

            byte[] buffer = new byte[stride];
            stream.Seek(0x3C, SeekOrigin.Current);
            for (int y = 0; y < pix.Height; y++)
            {
                int i = 0;
                while (i < stride)
                {
                    int  run = 1;
                    byte val = br.ReadByte();
                    if ((val & 0xC0) == 0xC0)
                    {
                        run = val & 0x3F;
                        val = br.ReadByte();
                    }
                    for (int r = 0; r < run; r++)
                    {
                        buffer[i++] = val;
                    }
                }
                for (int x = 0; x < pix.Width; x++)
                {
                    pix[x, y] = buffer[x];
                }
            }
            palette = new Color[256];
            if (br.ReadByte() != 0xC)
            {
                return(pix);
            }
            for (int i = 0; i < 256; i++)
            {
                palette[i] = Color.FromArgb(br.ReadByte(), br.ReadByte(), br.ReadByte());
            }
            return(pix);
        }
Example #9
0
        public override bool Equals(object obj)
        {
            if (base.Equals(obj))
            {
                return(true);
            }
            BitmapBits other = obj as BitmapBits;

            if (other == null)
            {
                return(false);
            }
            if (Width != other.Width | Height != other.Height)
            {
                return(false);
            }
            return(Bits.FastArrayEqual(other.Bits));
        }
Example #10
0
        public static void FixUIColors(this BitmapBits bmp)
        {
            for (int i = 0; i < bmp.Bits.Length; i++)
            {
                switch (bmp.Bits[i])
                {
                case 1:
                    bmp.Bits[i] = LevelData.ColorWhite;
                    break;

                case 2:
                    bmp.Bits[i] = LevelData.ColorYellow;
                    break;

                case 3:
                    bmp.Bits[i] = LevelData.ColorBlack;
                    break;
                }
            }
        }
Example #11
0
        public static void UnfixUIColors(this BitmapBits bmp)
        {
            for (int i = 0; i < bmp.Bits.Length; i++)
            {
                switch (bmp.Bits[i])
                {
                case LevelData.ColorWhite:
                    bmp.Bits[i] = 1;
                    break;

                case LevelData.ColorYellow:
                    bmp.Bits[i] = 2;
                    break;

                case LevelData.ColorBlack:
                    bmp.Bits[i] = 3;
                    break;
                }
            }
        }
Example #12
0
        public void DrawBitmapBounded(BitmapBits source, int x, int y)
        {
            if (x >= 0 && y >= 0 && x + source.Width <= Width && y + source.Height <= Height)
            {
                DrawBitmap(source, x, y);
                return;
            }
            int srct = 0;

            if (y < 0)
            {
                srct = -y;
            }
            int srcb = source.Height;

            if (srcb > Height - y)
            {
                srcb = Height - y;
            }
            if (x == 0 && source.Width == Width)
            {
                Array.Copy(source.Bits, source.GetPixelIndex(0, srct), Bits, GetPixelIndex(0, y + srct), GetPixelIndex(0, srcb - srct));
                return;
            }
            int srcl = 0;

            if (x < 0)
            {
                srcl = -x;
            }
            int srcr = source.Width;

            if (srcr > Width - x)
            {
                srcr = Width - x;
            }
            for (int c = srct; c < srcb; c++)
            {
                Array.Copy(source.Bits, source.GetPixelIndex(srcl, c), Bits, GetPixelIndex(x + srcl, y + c), srcr - srcl);
            }
        }
Example #13
0
        public void DrawBitmapBehind(BitmapBits source, int x, int y)
        {
            int srcl = 0;

            if (x < 0)
            {
                srcl = -x;
            }
            int srct = 0;

            if (y < 0)
            {
                srct = -y;
            }
            int srcr = source.Width;

            if (srcr > Width - x)
            {
                srcr = Width - x;
            }
            int srcb = source.Height;

            if (srcb > Height - y)
            {
                srcb = Height - y;
            }
            for (int c = srct; c < srcb; c++)
            {
                for (int r = srcl; r < srcr; r++)
                {
                    if (this[x + r, y + c] == 0)
                    {
                        this[x + r, y + c] = source[r, c];
                    }
                }
            }
        }
Example #14
0
        public static BitmapBits FromTile(byte[] art, int index)
        {
            BitmapBits bmp = new BitmapBits(8, 8);

            if (index * 16 + 16 <= art.Length)
            {
                for (int i = 0; i < 8; i++)
                {
                    ushort val = ByteConverter.ToUInt16(art, index * 16 + i * 2);
                    for (int j = 7; j >= 0; j--, val >>= 2)
                    {
                        if ((val & 0x03) == 0)
                        {
                            bmp.Bits[i * 8 + j] = 0;
                        }
                        else
                        {
                            bmp.Bits[i * 8 + j] = (byte)(val & 0x03);
                        }
                    }
                }
            }
            return(bmp);
        }
Example #15
0
        private void LoadBitmap(BitmapBits source, bool priority, int xoff, int yoff)
        {
            int i = 0;

            for (int y = 0; y < source.Height; y++)
            {
                int?starti = null;
                int startx = 0;
                for (int x = 0; x < source.Width; x++)
                {
                    if (source.Bits[i] != 0)
                    {
                        if (!starti.HasValue)
                        {
                            starti = i;
                            startx = x;
                        }
                    }
                    else if (starti.HasValue)
                    {
                        byte[] pix = new byte[i - starti.Value];
                        Array.Copy(source.Bits, starti.Value, pix, 0, pix.Length);
                        strips.Add(new PixelStrip(pix, priority, startx + xoff, y + yoff));
                        starti = null;
                    }
                    i++;
                }
                if (starti.HasValue)
                {
                    byte[] pix = new byte[i - starti.Value];
                    Array.Copy(source.Bits, starti.Value, pix, 0, pix.Length);
                    strips.Add(new PixelStrip(pix, priority, startx + xoff, y + yoff));
                }
            }
            strips.Sort();
        }
Example #16
0
 public Sprite(BitmapBits lowImg, BitmapBits highImg, Point offset)
     : this(lowImg, highImg, offset.X, offset.Y)
 {
 }
Example #17
0
 public void DrawBitmapBounded(BitmapBits source, Point location)
 {
     DrawBitmapComposited(source, location.X, location.Y);
 }
Example #18
0
 public void DrawBitmapBehind(BitmapBits source, Point location)
 {
     DrawBitmapBehind(source, location.X, location.Y);
 }
Example #19
0
 public Sprite(BitmapBits lowImg, BitmapBits highImg)
     : this(lowImg, highImg, 0, 0)
 {
 }
Example #20
0
 public Sprite(BitmapBits img, bool priority, int xoff, int yoff)
 {
     strips = new List <PixelStrip>();
     LoadBitmap(img, priority, xoff, yoff);
     CalculateBounds();
 }
Example #21
0
 public Sprite(BitmapBits img, bool priority, Point offset)
     : this(img, priority, offset.X, offset.Y)
 {
 }
Example #22
0
 public Sprite(BitmapBits img, bool priority)
     : this(img, priority, 0, 0)
 {
 }