public override void RoomChanged(Room room) { var roomPtr = room.Image.Data; _roomStrips = GenerateStripTable(roomPtr, room.Header.Width, room.Header.Height); }
/// <summary> /// Create and fill a table with offsets to the graphic and mask strips in the /// given V2 EGA bitmap. /// </summary> /// <returns>The filled strip table.</returns> /// <param name="src">The V2 EGA bitmap.</param> /// <param name="width">The width of the bitmap.</param> /// <param name="height">The height of the bitmap.</param> StripTable GenerateStripTable(byte[] src, int width, int height) { int srcPos = 0; var table = new StripTable(); byte color = 0, data = 0; int x, y, length = 0; byte run = 1; // Decode the graphics strips, and memorize the run/color values // as well as the byte offset. for (x = 0; x < width; x++) { if ((x % 8) == 0) { Debug.Assert(x / 8 < 160); table.run[x / 8] = run; table.color[x / 8] = color; table.offsets[x / 8] = srcPos; } for (y = 0; y < height; y++) { if (--run == 0) { data = src[srcPos++]; if ((data & 0x80) != 0) { run = (byte)(data & 0x7f); } else { run = (byte)(data >> 4); } if (run == 0) { run = src[srcPos++]; } color = (byte)(data & 0x0f); } } } // The mask data follows immediately after the graphics. x = 0; y = height; width /= 8; for (;;) { length = src[srcPos++]; byte runFlag = (byte)(length & 0x80); if (runFlag != 0) { length &= 0x7f; data = src[srcPos++]; } do { if (runFlag == 0) { data = src[srcPos++]; } if (y == height) { Debug.Assert(x < 120); table.zoffsets[x] = srcPos - 1; table.zrun[x] = length | runFlag; } if (--y == 0) { if (--width == 0) { return(table); } x++; y = height; } } while ((--length) != 0); } }
/// <summary> /// Create and fill a table with offsets to the graphic and mask strips in the /// given V2 EGA bitmap. /// </summary> /// <returns>The filled strip table.</returns> /// <param name="src">The V2 EGA bitmap.</param> /// <param name="width">The width of the bitmap.</param> /// <param name="height">The height of the bitmap.</param> StripTable GenerateStripTable(byte[] src, int width, int height) { int srcPos = 0; var table = new StripTable(); byte color = 0, data = 0; int x, y, length = 0; byte run = 1; // Decode the graphics strips, and memorize the run/color values // as well as the byte offset. for (x = 0; x < width; x++) { if ((x % 8) == 0) { Debug.Assert(x / 8 < 160); table.run[x / 8] = run; table.color[x / 8] = color; table.offsets[x / 8] = srcPos; } for (y = 0; y < height; y++) { if (--run == 0) { data = src[srcPos++]; if ((data & 0x80) != 0) { run = (byte)(data & 0x7f); } else { run = (byte)(data >> 4); } if (run == 0) { run = src[srcPos++]; } color = (byte)(data & 0x0f); } } } // The mask data follows immediately after the graphics. x = 0; y = height; width /= 8; for (;;) { length = src[srcPos++]; byte runFlag = (byte)(length & 0x80); if (runFlag != 0) { length &= 0x7f; data = src[srcPos++]; } do { if (runFlag == 0) data = src[srcPos++]; if (y == height) { Debug.Assert(x < 120); table.zoffsets[x] = srcPos - 1; table.zrun[x] = length | runFlag; } if (--y == 0) { if (--width == 0) return table; x++; y = height; } } while ((--length) != 0); } }