private static Bitmap FromTile8bit(byte* GBAGraphics, int length, Color[] palette, int width, out int emptyGraphicBlocks) { int heigth = length / width; if (heigth % 8 != 0) heigth += 8 - (heigth % 8); while ((emptyGraphicBlocks = heigth * width - length) < 0) heigth += 8; emptyGraphicBlocks /= 64; Bitmap result = new Bitmap(width, heigth, PixelFormat.Format8bppIndexed); result.InsertColorsToPalette(palette); BitmapData bData = result.LockBits(new Rectangle(new Point(), result.Size), ImageLockMode.WriteOnly, result.PixelFormat); for (int i = 0; i < length; i++) { byte pixel = GBAGraphics[i]; int position = bitmapPosition(tiledCoordinate(i, width, 8), width); ((byte*)bData.Scan0)[position] = pixel; } result.UnlockBits(bData); return result; }
private CanCauseError<Bitmap> GetNormalFormat(byte[] rawPortrait, byte[] rawMini, byte[] rawMouth, Color[] palette) { int temp; var result = new Bitmap(FormatSizePixels.Width, FormatSizePixels.Height, PixelFormat.Format8bppIndexed); result.InsertColorsToPalette(palette); Bitmap mainPortrait = GBAGraphics.ToBitmap( rawPortrait, rawPortrait.Length, 0, palette, this.PortraitSize.Width * TileSize.Width, GraphicsMode.Tile4bit, out temp); if (temp != this.BlockAdd) return CanCauseError<Bitmap>.Error("Raw mainportrait is wrong size"); Bitmap miniPortrait; if (rawMini != null) { miniPortrait = GBAGraphics.ToBitmap( rawMini, rawMini.Length, 0, palette, this.MiniSize.Width * TileSize.Width, GraphicsMode.Tile4bit, out temp); if (temp != 0) return CanCauseError<Bitmap>.Error("Raw miniportrait is wrong size"); } else miniPortrait = null; Bitmap mouthPortrait; if (this.SeparateMouthFrames) { mouthPortrait = GBAGraphics.ToBitmap( rawMouth, rawMouth.Length, 0, palette, this.MouthSize.Width * TileSize.Width, GraphicsMode.Tile4bit, out temp); if (temp != 0) return CanCauseError<Bitmap>.Error("Raw mouth is wrong size"); } else { mouthPortrait = mainPortrait; } Move(mainPortrait, result, ReverseMapping(this.PictureMapping)); Move(mouthPortrait, result, ReverseMapping(this.MouthMapping)); Move(mainPortrait, result, ReverseMapping(this.MiniMapping)); return result; }
private static Bitmap FromBitmapIndexed(byte* GBAGraphics, int length, Color[] palette, int width, out int emptyGraphicBlocks) { int heigth = length / width; while (heigth * width < length) heigth++; emptyGraphicBlocks = length - heigth * width; Bitmap result = new Bitmap(width, heigth, PixelFormat.Format8bppIndexed); result.InsertColorsToPalette(palette); BitmapData bData = result.LockBits(new Rectangle(new Point(), result.Size), ImageLockMode.WriteOnly, result.PixelFormat); byte* bitmap = (byte*)bData.Scan0; for (int i = 0; i < length; i++) bitmap[i] = GBAGraphics[i]; result.UnlockBits(bData); emptyGraphicBlocks = 0; return result; }