private void _GenerateBitmapDecode(Bitmap Bitmap, Func <byte[], int, ARGB_Rev> Decode) { int BytesPerPixel = BitsPerPixel / 8; Bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (BitmapData) => { int WidthHeight = Width * Height; var Stream = SliceStream.Slice(); var Bytes = Stream.ReadBytes(TotalBytes); int m = 0; bool Tiled = this.Tiled; var Base = (ARGB_Rev *)BitmapData.Scan0.ToPointer(); for (int n = 0; n < WidthHeight; n++) { int X, Y; if (Tiled) { Swizzling.XGAddress2DTiledXY(n, Width, BytesPerPixel, out X, out Y); } else { Swizzling.UnswizzledXY(n, Width, BytesPerPixel, out X, out Y); } if (X >= Width || Y >= Height) { Console.Error.WriteLine("(Warning: Outside! ({0}, {1}) - ({2}x{3}))", X, Y, Width, Height); continue; } Base[Y * Width + X] = Decode(Bytes, m); m += BytesPerPixel; } }); }
private void _GenerateBitmapEncode(Bitmap Bitmap, Action <byte[], ARGB_Rev> Encode) { int TotalBytes = Bitmap.Width * Bitmap.Height * BitsPerPixel / 8; int BytesPerPixel = BitsPerPixel / 8; Bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (BitmapData) => { int WidthHeight = Width * Height; var Bytes = new byte[TotalBytes]; bool Tiled = this.Tiled; var PixelBytes = new byte[BytesPerPixel]; var Base = (ARGB_Rev *)BitmapData.Scan0.ToPointer(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int n; if (Tiled) { n = Swizzling.XGAddress2DTiledOffset(x, y, Width, BytesPerPixel); } else { n = Swizzling.UnswizzledOffset(x, y, Width, BytesPerPixel); } Encode(PixelBytes, Base[y * Width + x]); Array.Copy(PixelBytes, 0, Bytes, n * BytesPerPixel, BytesPerPixel); } } SliceStream.Slice().WriteBytes(Bytes).Flush(); }); }
public void WritePointerValue(uint value) { PointerStream.Slice().WriteStruct((uint_be)value); }