//public void SaveImageSpecific( System.IO.Stream iso, System.IO.Stream output, Bitmap originalImage = null, bool isSource4bpp = false ) public void SaveImageSpecific(System.IO.Stream iso, System.IO.Stream output, bool isSource4bpp = false, IList <byte> imageBytes = null) { //imageBytes = imageBytes ?? position.ReadIso(iso); imageBytes = imageBytes ?? GetIsoBytes(iso); if (isSource4bpp) { List <byte> newImageBytes = new List <byte>(); foreach (byte imageByte in imageBytes) { newImageBytes.Add((byte)(imageByte & 0x0F)); newImageBytes.Add((byte)((imageByte & 0xF0) >> 4)); } imageBytes = newImageBytes; } // Get colors //Set<Color> colors = GetColors( iso ); PatcherLib.Iso.KnownPosition newPalettePosition = palettePosition.AddOffset(CurrentPalette * palettePosition.Length, 0); Palette p = new Palette(newPalettePosition.ReadIso(iso), depth, true); // Convert colors to indices //if (originalImage == null) // originalImage = GetImageFromIso(iso); using (Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed)) { ColorPalette pal = bmp.Palette; for (int i = 0; i < p.Colors.Length; i++) { pal.Entries[i] = p.Colors[i]; } for (int i = p.Colors.Length; i < 256; i++) { pal.Entries[i] = Palette.BytesToColor(0x00, 0x00); } bmp.Palette = pal; var bmd = bmp.LockBits(new Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { bmd.SetPixel8bpp(x, y, imageBytes[(y * Width) + x]); } } bmp.UnlockBits(bmd); // Write that shit //bmp.Save( output, System.Drawing.Imaging.ImageFormat.Gif ); bmp.Save(output, System.Drawing.Imaging.ImageFormat.Bmp); } }
protected override System.Drawing.Bitmap GetImageFromIsoInner(System.IO.Stream iso) { IList <byte> bytes = position.ReadIso(iso); IList <Color> pixels = new Color[bytes.Count / 2]; for (int i = 0; i < pixels.Count; i++) { pixels[i] = Palette.BytesToColor(bytes[i * 2], bytes[i * 2 + 1]); } Bitmap result = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { result.SetPixel(x, y, pixels[y * Width + x]); } } return(result); }
public static IList <IList <Color> > ReadBytesAsRawImage(IList <byte> bytes, int width, int height) { Color[][] result = new Color[width][]; for (int i = 0; i < result.Length; i++) { result[i] = new Color[height]; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { byte one = bytes[(y * width + x) * 2]; byte two = bytes[(y * width + x) * 2 + 1]; result[x][y] = Palette.BytesToColor(one, two); } } return(result); }