Exemple #1
0
        private void insertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tileList1.SelectedIndex == -1)
            {
                return;
            }
            OpenFileDialog a = new OpenFileDialog()
            {
                DefaultExt       = "png",
                Filter           = "Image Files|*.bmp;*.png;*.jpg;*.gif",
                Multiselect      = true,
                RestoreDirectory = true
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                int i = tileList1.SelectedIndex;
                foreach (string item in a.FileNames)
                {
                    sprites[curpal].Insert(i++, BitmapBits.FromBitmap(new Bitmap(a.FileName)));
                }
                tileList1.SelectedIndex = i;
                tileList1.ChangeSize();
            }
        }
Exemple #2
0
 private static void LoadBitmap8BppIndexed(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             bmp[x, y] = (byte)(Bits[srcaddr + x] & 0x3F);
         }
     }
 }
Exemple #3
0
 private static void LoadBitmap64BppArgb(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             bmp[x, y] = (byte)Array.IndexOf(MainForm.palslice, Color.FromArgb(BitConverter.ToUInt16(Bits, srcaddr + (x * 8) + 6) / 255, BitConverter.ToUInt16(Bits, srcaddr + (x * 8) + 4) / 255, BitConverter.ToUInt16(Bits, srcaddr + (x * 8) + 2) / 255, BitConverter.ToUInt16(Bits, srcaddr + (x * 8)) / 255).FindNearestMatch(MainForm.palslice));
         }
     }
 }
Exemple #4
0
 private static void LoadBitmap32BppRgb(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             bmp[x, y] = (byte)Array.IndexOf(MainForm.palslice, Color.FromArgb(Bits[srcaddr + (x * 4) + 2], Bits[srcaddr + (x * 4) + 1], Bits[srcaddr + (x * 4)]).FindNearestMatch(MainForm.palslice));
         }
     }
 }
Exemple #5
0
        public void DrawBitmap(BitmapBits source, Point location)
        {
            int dstx = location.X; int dsty = location.Y;

            for (int i = 0; i < source.Height; i++)
            {
                int di = ((dsty + i) * Width) + dstx;
                int si = i * source.Width;
                Array.Copy(source.Bits, si, Bits, di, source.Width);
            }
        }
Exemple #6
0
 private static void LoadBitmap32BppArgb(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             Color col = Color.FromArgb(BitConverter.ToInt32(Bits, srcaddr + (x * 4)));
             bmp[x, y] = (byte)Array.IndexOf(MainForm.palslice, col.FindNearestMatch(MainForm.palslice));
         }
     }
 }
Exemple #7
0
 private static void LoadBitmap16BppGrayScale(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             ushort pix = BitConverter.ToUInt16(Bits, srcaddr + (x * 2));
             bmp[x, y] = (byte)Array.IndexOf(MainForm.palslice, Color.FromArgb(pix >> 8, pix >> 8, pix >> 8).FindNearestMatch(MainForm.palslice));
         }
     }
 }
Exemple #8
0
        public BitmapBits Scale(int factor)
        {
            BitmapBits res = new BitmapBits(Width * factor, Height * factor);

            for (int y = 0; y < res.Height; y++)
            {
                for (int x = 0; x < res.Width; x++)
                {
                    res[x, y] = this[(x / factor), (y / factor)];
                }
            }
            return(res);
        }
Exemple #9
0
 private static void LoadBitmap1BppIndexed(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x += 8)
         {
             bmp[x + 0, y] = (byte)((Bits[srcaddr + (x / 8)] >> 7) & 1);
             bmp[x + 1, y] = (byte)((Bits[srcaddr + (x / 8)] >> 6) & 1);
             bmp[x + 2, y] = (byte)((Bits[srcaddr + (x / 8)] >> 5) & 1);
             bmp[x + 3, y] = (byte)((Bits[srcaddr + (x / 8)] >> 4) & 1);
             bmp[x + 4, y] = (byte)((Bits[srcaddr + (x / 8)] >> 3) & 1);
             bmp[x + 5, y] = (byte)((Bits[srcaddr + (x / 8)] >> 2) & 1);
             bmp[x + 6, y] = (byte)((Bits[srcaddr + (x / 8)] >> 1) & 1);
             bmp[x + 7, y] = (byte)(Bits[srcaddr + (x / 8)] & 1);
         }
     }
 }
Exemple #10
0
 private static void LoadBitmap16BppRgb565(BitmapBits bmp, byte[] Bits, int Stride)
 {
     for (int y = 0; y < bmp.Height; y++)
     {
         int srcaddr = y * Math.Abs(Stride);
         for (int x = 0; x < bmp.Width; x++)
         {
             ushort pix = BitConverter.ToUInt16(Bits, srcaddr + (x * 2));
             int    R   = (pix >> 11) & 0x1F;
             R = R << 3 | R >> 2;
             int G = (pix >> 5) & 0x3F;
             G = G << 2 | G >> 4;
             int B = pix & 0x1F;
             B         = B << 3 | B >> 2;
             bmp[x, y] = (byte)Array.IndexOf(MainForm.palslice, Color.FromArgb(R, G, B).FindNearestMatch(MainForm.palslice));
         }
     }
 }
Exemple #11
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tileList1.SelectedIndex == -1)
            {
                return;
            }
            OpenFileDialog a = new OpenFileDialog()
            {
                DefaultExt       = "png",
                Filter           = "Image Files|*.bmp;*.png;*.jpg;*.gif",
                FileName         = tileList1.SelectedIndex + ".png",
                RestoreDirectory = true
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                sprites[curpal][tileList1.SelectedIndex] = BitmapBits.FromBitmap(new Bitmap(a.FileName));
                tileList1.Invalidate();
                SpritePicture.Invalidate();
            }
        }
Exemple #12
0
        public void DrawBitmapComposited(BitmapBits source, Point location)
        {
            int srcl = 0;

            if (location.X < 0)
            {
                srcl = -location.X;
            }
            int srct = 0;

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

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

            if (srcb > Height - location.Y)
            {
                srcb = Height - location.Y;
            }
            for (int i = srct; i < srcb; i++)
            {
                for (int x = srcl; x < srcr; x++)
                {
                    if (source[x, i] != 0)
                    {
                        this[location.X + x, location.Y + i] = source[x, i];
                    }
                }
            }
        }
Exemple #13
0
        public static BitmapBits FromBitmap(Bitmap bmp)
        {
            BitmapBits bmpbits = new BitmapBits(8, 8);
            BitmapData bmpd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);

            byte[] Bits = new byte[Math.Abs(bmpd.Stride) * bmpd.Height];
            System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, Bits, 0, Bits.Length);
            bmp.UnlockBits(bmpd);
            switch (bmpd.PixelFormat)
            {
            case PixelFormat.Format16bppArgb1555:
                LoadBitmap16BppArgb1555(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format16bppGrayScale:
                LoadBitmap16BppGrayScale(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format16bppRgb555:
                LoadBitmap16BppRgb555(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format16bppRgb565:
                LoadBitmap16BppRgb565(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format1bppIndexed:
                LoadBitmap1BppIndexed(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format24bppRgb:
                LoadBitmap24BppRgb(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format32bppArgb:
                LoadBitmap32BppArgb(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format32bppPArgb:
                throw new NotImplementedException();

            case PixelFormat.Format32bppRgb:
                LoadBitmap32BppRgb(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format48bppRgb:
                LoadBitmap48BppRgb(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format4bppIndexed:
                LoadBitmap4BppIndexed(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format64bppArgb:
                LoadBitmap64BppArgb(bmpbits, Bits, bmpd.Stride);
                break;

            case PixelFormat.Format64bppPArgb:
                throw new NotImplementedException();

            case PixelFormat.Format8bppIndexed:
                LoadBitmap8BppIndexed(bmpbits, Bits, bmpd.Stride);
                break;
            }
            return(bmpbits);
        }