Ejemplo n.º 1
0
        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);
            }
        }