public BitmapBits Scale(int factor) { if (factor < 1) { throw new ArgumentOutOfRangeException("factor", "Scaling factor must be 1 or greater."); } if (factor == 1) { return(new BitmapBits(this)); } BitmapBits res = new BitmapBits(Width * factor, Height * factor); int srcaddr = 0; int dstaddr = 0; for (int y = 0; y < Height; y++) { int linestart = dstaddr; for (int x = 0; x < Width; x++) { res.Bits.FastFill(Bits[srcaddr++], dstaddr, factor); dstaddr += factor; } for (int i = 1; i < factor; i++) { Array.Copy(res.Bits, linestart, res.Bits, dstaddr, res.Width); dstaddr += res.Width; } } return(res); }
public void ScrollHV(BitmapBits destination, int dstY, int srcY, params int[] srcX) { if (dstY < 0 || dstY >= destination.Height) { return; } for (int i = 0; i < srcX.Length; i++) { srcX[i] %= Width; if (srcX[i] < 0) { srcX[i] += Width; } } srcY %= Height; if (srcY < 0) { srcY += Height; } int rowSrc = GetPixelIndex(0, srcY); int rowDst = destination.GetPixelIndex(0, dstY); for (int y = 0; y < destination.Height - dstY; y++) { int amount = srcX[(srcY + y) % srcX.Length]; Array.Copy(Bits, rowSrc + amount, destination.Bits, rowDst, Math.Min(Width - amount, destination.Width)); if (amount != 0 && Width - amount < destination.Width) { Array.Copy(Bits, rowSrc, destination.Bits, rowDst + Width - amount, Math.Min(amount, destination.Width - (Width - amount))); } rowSrc = (rowSrc + Width) % Bits.Length; rowDst += destination.Width; } }
public static BitmapBits DrawLayout(LayoutData layout, int gridsize, Rectangle?bounds = null) { BitmapBits layoutbmp = DrawLayout(layout.Layout, gridsize, bounds); int off = (gridsize - 24) / 2; layoutbmp.DrawBitmapComposited(StartBmps[layout.Angle], (layout.StartX - bounds?.X ?? 0) * gridsize + off, (layout.StartY - bounds?.Y ?? 0) * gridsize + off); return(layoutbmp); }
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; }
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); }
public static void Init() { using (Bitmap tmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed)) Palette = tmp.Palette; Bitmap[] bmplist = { Properties.Resources.blue, Properties.Resources.red, Properties.Resources.bumper, Properties.Resources.yellow, Properties.Resources.green, Properties.Resources.pink, Properties.Resources.ring }; int palind = 1; for (int i = 0; i < bmplist.Length; i++) { bmplist[i].Palette.Entries.CopyTo(Palette.Entries, palind); BitmapBits bmp = new BitmapBits(bmplist[i]); bmp.IncrementIndexes(palind); SphereBmps[(SphereType)(i + 1)] = bmp; palind += 16; } for (int i = 0; i < bmplist.Length; i++) { BitmapBits bmp = new BitmapBits(SphereBmps[(SphereType)(i + 1)]); bmp.DrawBitmapComposited(SphereBmps[SphereType.Ring], 0, 0); SphereBmps[(SphereType)(i + 1) | SphereType.RingFlag] = bmp; } Palette.Entries[0] = Palette.Entries[1] = Color.Transparent; Bitmap face; switch (System.DateTime.Now.Second % 3) { case 1: face = Properties.Resources.tails; break; case 2: face = Properties.Resources.knuckles; break; default: face = Properties.Resources.sonic; break; } face.Palette.Entries.CopyTo(Palette.Entries, palind); BitmapBits facebmp = new BitmapBits(face); facebmp.IncrementIndexes(palind); palind += 16; bmplist = new[] { Properties.Resources.north, Properties.Resources.west, Properties.Resources.south, Properties.Resources.east }; bmplist[0].Palette.Entries.CopyTo(Palette.Entries, palind); for (int i = 0; i < bmplist.Length; i++) { BitmapBits bmp = new BitmapBits(bmplist[i]); bmp.IncrementIndexes(palind); bmp.DrawBitmapBehind(facebmp, 0, 0); StartBmps[i] = bmp; } }
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); }
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); } }
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); }
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)); }
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); } }
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]; } } } }
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); }
public void DrawBitmapBounded(BitmapBits source, Point location) { DrawBitmapComposited(source, location.X, location.Y); }
public void DrawBitmapBehind(BitmapBits source, Point location) { DrawBitmapBehind(source, location.X, location.Y); }