void DumpRoomObjectImages(Room room, ObjectData obj, Gdi gdi) { var text = new ScummText(obj.Name); var sb = new StringBuilder(); sb.Append("Object #" + obj.Number).Append(" "); var decoder = new TextDecoder(sb); text.Decode(decoder); sb.AppendFormat(" size: {0}x{1}", obj.Width, obj.Height); Console.WriteLine(sb); var j = 0; foreach (var img in obj.Images) { // try // { var screen = new VirtScreen(0, obj.Width, obj.Height, PixelFormat.Indexed8, 2); if (img.IsBomp) { var bdd = new BompDrawData(); bdd.Src = img.Data; bdd.Dst = new PixelNavigator(screen.Surfaces[0]); bdd.X = 0; bdd.Y = 0; bdd.Width = obj.Width; bdd.Height = obj.Height; bdd.ScaleX = 255; bdd.ScaleY = 255; bdd.DrawBomp(); } else { gdi.DrawBitmap(img, screen, new Point(0, 0), obj.Width, obj.Height & 0xFFF8, 0, obj.Width / 8, room.Header.Width, DrawBitmaps.None, true); } using (var bmp = ToBitmap(room, screen)) { bmp.Save("obj_" + obj.Number + "_" + (++j) + ".png"); } // } // catch (Exception e) // { // Console.ForegroundColor = ConsoleColor.Red; // Console.WriteLine(e); // Console.ResetColor(); // Console.ReadLine(); // } } }
void DumpRoomObjects(Room room, Gdi gdi) { foreach (var obj in room.Objects) { DumpRoomObjectImages(room, obj, gdi); } }
static void DumpZPlanes(Room room, string name) { if (room.Image != null) { for (int i = 0; i < room.Image.ZPlanes.Count; i++) { var zplane = room.Image.ZPlanes[i]; var nStrips = zplane.StripOffsets.Count; var pixels = new byte[nStrips * room.Header.Height]; var pn = new PixelNavigator(pixels, nStrips, 1); using (var ms = new MemoryStream(zplane.Data)) { for (int nStrip = 0; nStrip < nStrips; nStrip++) { var offset = zplane.StripOffsets[nStrip]; if (offset.HasValue) { ms.Seek(offset.Value, SeekOrigin.Begin); pn.GoTo(nStrip, 0); DecompressMaskImg(pn, ms, room.Header.Height); } } } using (var bmpZ = new System.Drawing.Bitmap(nStrips * 8, room.Header.Height)) { for (int j = 0; j < room.Header.Height; j++) { for (int x = 0; x < nStrips; x++) { for (int b = 0; b < 8; b++) { bmpZ.SetPixel(x * 8 + b, j, (pixels[x + j * nStrips] & (0x80 >> b)) != 0 ? System.Drawing.Color.White : System.Drawing.Color.Black); } } } bmpZ.Save(name + "_z" + i + ".png"); } } } }
void DumpRoomImage(Room room, Gdi gdi) { var name = room.Name ?? "room_" + room.Number; var screen = new VirtScreen(0, room.Header.Width, room.Header.Height, PixelFormat.Indexed8, 2); var numStrips = room.Header.Width / 8; gdi.NumStrips = numStrips; gdi.IsZBufferEnabled = false; if (room.Header.Height > 0) { gdi.RoomChanged(room); gdi.DrawBitmap(room.Image, screen, new Point(), room.Header.Width, room.Header.Height, 0, numStrips, room.Header.Width, 0, true); using (var bmpRoom = ToBitmap(room, screen)) { bmpRoom.Save(name + ".png"); } } DumpZPlanes(room, name); }
System.Drawing.Bitmap ToBitmap(Room room, VirtScreen screen) { var bmp = new System.Drawing.Bitmap(screen.Width, screen.Height); // DitherCGA(screen.Surfaces[0].Pixels, screen.Surfaces[0].Pitch, 0, 0, screen.Width, screen.Height); var palette = Game.Features.HasFlag(GameFeatures.SixteenColors) ? Palette.Ega : room.Palette; for (int x = 0; x < screen.Width; x++) { for (int y = 0; y < screen.Height; y++) { bmp.SetPixel(x, y, ToColor(screen.Surfaces[0].Pixels, palette, screen, x, y)); } } return bmp; }
System.Drawing.Color ToColor(Room room, VirtScreen screen, int x, int y) { var index = screen.Surfaces[0].Pixels[y * screen.Width + x]; var c = Game.Features.HasFlag(GameFeatures.SixteenColors) ? Palette.Cga.Colors[index] : room.Palette.Colors[index]; return System.Drawing.Color.FromArgb(c.R, c.G, c.B); }