protected override System.Drawing.Bitmap GetImageFromIsoInner(System.IO.Stream iso) { List <byte> pixels = GetAllPixelBytes(iso); //var palette = GetPalette( iso ); PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, 0); Palette palette = new Palette(newPalettePosition.ReadIso(iso), FFTPatcher.SpriteEditor.Palette.ColorDepth._16bit, true); Bitmap result = new Bitmap(Width, Height); var mypixels = new List <byte>(); foreach (byte p in pixels) { mypixels.Add(p.GetLowerNibble()); mypixels.Add(p.GetUpperNibble()); } pixels = mypixels; for (int i = 0; i < Width * Height; i++) { result.SetPixel(i % Width, i / Width, palette[pixels[i]]); } return(result); }
public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false) { using (System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap(image)) { Set <System.Drawing.Color> colors = GetColors(sourceBitmap); if (colors.Count > NumColors) { ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(NumColors, 8); using (var newBmp = q.Quantize(sourceBitmap)) { WriteImageToIsoInner(iso, newBmp); } } else { byte[] imageBytes = GetImageBytes(sourceBitmap, isDest4bpp); IList <byte> bytes = PixelsToBytes(imageBytes); byte[] originalPaletteBytes = PalettePosition.ReadIso(iso); PalettePosition.PatchIso(iso, GetPaletteBytes(image.Palette.Entries, originalPaletteBytes)); int currentIndex = 0; foreach (var kp in PixelPositions) { var bb = bytes.Sub(currentIndex, currentIndex + kp.Length - 1); kp.PatchIso(iso, bb); currentIndex += kp.Length; } } } }
protected StupidTM2Image Get8BitPalettedBitmap() { PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, PalettePosition.Length * 15); StupidTM2Image image = new StupidTM2Image(Name, Width, Height, newPalettePosition, PixelPositions.ToArray()); image.ImportFilename = ImportFilename; return(image); }
protected override PalettedImage8bpp Get8BitPalettedBitmap() { PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, PalettePosition.Length * 15); PalettedImage8bppSectioned image = new PalettedImage8bppSectioned(Name, Width, Height, NumPalettes, Depth, position, newPalettePosition, true); image.ImportFilename = ImportFilename; image.NumBytesBetweenRows = NumBytesBetweenRows; return(image); }
public override void SaveImage(System.IO.Stream iso, System.IO.Stream output) { if (ImportExport8bpp) { SaveImage8bpp(iso, output); return; } List <byte> imageBytes = GetAllPixelBytes(iso); int imageByteIndex = 0; bool useHighNibble = false; PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, 0); Palette p = new Palette(newPalettePosition.ReadIso(iso), FFTPatcher.SpriteEditor.Palette.ColorDepth._16bit, true); using (Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format4bppIndexed)) { System.Drawing.Imaging.ColorPalette pal = bmp.Palette; for (int i = 0; i < p.Colors.Length; i++) { pal.Entries[i] = p.Colors[i]; } bmp.Palette = pal; System.Drawing.Imaging.BitmapData bmd = bmp.LockBits(new Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format4bppIndexed); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { byte currentByte = imageBytes[imageByteIndex]; int index = useHighNibble ? currentByte.GetUpperNibble() : currentByte.GetLowerNibble(); bmd.SetPixel4bpp(x, y, index); useHighNibble = !useHighNibble; imageByteIndex = useHighNibble ? imageByteIndex : (imageByteIndex + 1); } } bmp.UnlockBits(bmd); // Write that shit bmp.Save(output, System.Drawing.Imaging.ImageFormat.Bmp); } }
public void SaveImageSpecific(System.IO.Stream iso, System.IO.Stream output, bool isSource4bpp = false) { IList <byte> imageBytes = GetAllPixelBytes(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 Palette p = new Palette(PalettePosition.ReadIso(iso), FFTPatcher.SpriteEditor.Palette.ColorDepth._16bit, true); // Convert colors to indices using (Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed)) { System.Drawing.Imaging.ColorPalette pal = bmp.Palette; for (int i = 0; i < p.Colors.Length; i++) { pal.Entries[i] = p.Colors[i]; } 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.Bmp); } }
protected override void WriteImageToIsoInner(System.IO.Stream iso, System.Drawing.Image image) { if (ImportExport8bpp) { WriteImageToIsoInner8bpp(iso, image); return; } using (Bitmap bmp = new Bitmap(image)) { Set <Color> colors = GetColors(bmp); IList <Color> myColors = new List <Color>(colors); if (myColors.Count > 16) { ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(16, 8); using (var newBmp = q.Quantize(bmp)) { WriteImageToIsoInner(iso, newBmp); } } else { PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, 0); IList <Byte> originalPaletteBytes = newPalettePosition.ReadIso(iso); byte[] imageBytes = GetImageBytes(bmp); List <Byte> paletteBytes = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes); newPalettePosition.PatchIso(iso, paletteBytes); int currentIndex = 0; foreach (PatcherLib.Iso.KnownPosition kp in PixelPositions) { IList <byte> bb = imageBytes.Sub(currentIndex, currentIndex + kp.Length - 1); kp.PatchIso(iso, bb); currentIndex += kp.Length; } //PatchIsoBytes(iso, imageBytes); } } }
protected Palette GetPalette(System.IO.Stream iso) { return(new Palette(PalettePosition.ReadIso(iso))); }