public Bitmap Read(byte[] data) { int width; int height; byte[] pixelData; width = WordHelpers.GetInt16Le(data, 0); height = WordHelpers.GetInt16Le(data, 2); pixelData = new byte[width * height]; // doom images seem to use index // 255 for transparency, so we'll // set the image data to transparent // by default for the entire image for (int i = 0; i < pixelData.Length; i++) { pixelData[i] = 255; } // each column is represented by one or // more sub columns, called "posts" in the // DOOM FAQ. Each post has a starting row, // and a height, followed by a seemly unused // value, the pixel data and then another // unused value for (int column = 0; column < width; column++) { int pointer; pointer = WordHelpers.GetInt32Le(data, (column * 4) + 8); do { int row; int postHeight; row = data[pointer]; if (row != 255 && (postHeight = data[++pointer]) != 255) { pointer++; // unused value for (int i = 0; i < postHeight; i++) { if (row + i < height && pointer < data.Length - 1) { pixelData[((row + i) * width) + column] = data[++pointer]; } } pointer++; // unused value } else { break; } } while (pointer < data.Length - 1 && data[++pointer] != 255); } return(this.CreateIndexedBitmap(width, height, pixelData)); }
public void AddRanges(HexViewer control, byte[] buffer) { control.Clear(); if (buffer.Length > 8) { int[] pointer; short width; short height; width = WordHelpers.GetInt16Le(buffer, 0); height = WordHelpers.GetInt16Le(buffer, 2); // do some basic sanity checking if (width > 0 && width <= 320 && height > 0 && height <= 200) { control.AddRange(0, 2, Color.MediumSeaGreen, Color.White, "Width"); // width control.AddRange(2, 2, Color.SeaGreen, Color.White, "Height"); // height control.AddRange(4, 2, Color.DeepPink, Color.White, "X-Offset"); // x offset control.AddRange(6, 2, Color.HotPink, Color.White, "Y-Offset"); // y offset pointer = new int[width]; for (int i = 0; i < width; i++) { int index; index = 8 + (i * 4); pointer[i] = WordHelpers.GetInt32Le(buffer, index); control.AddRange(new HexViewer.ByteGroup { Start = index, Length = 4, ForeColor = Color.White, BackColor = Color.Orange, Pointer = pointer[i], Type = "Pointer #" + i.ToString() }); // column pointer } for (int i = 0; i < width; i++) { int index; byte length; int sourceIndex; index = pointer[i]; length = buffer[index + 1]; sourceIndex = 8 + (i * 4); // post if (_showPrimaryPosts) { this.AddPost(control, index, length, sourceIndex, true); } if (length != 255) { index = this.IncrementColumn(buffer, index + 3, length); //index += length + 4; // row, length, 2xunused, pixel data if (buffer[index] == 255) { this.AddColumnEndMarker(control, index, pointer[i]); } else { while (true) { length = buffer[index + 1]; if (length == 255 || index + length + 4 > buffer.Length) { break; } else if (_showSecondaryPosts) { this.AddPost(control, index, length, sourceIndex, false); } index = this.IncrementColumn(buffer, index + 3, length); // index += length + 4; if (buffer[index] == 255) { this.AddColumnEndMarker(control, index, pointer[i]); break; } } } } } } } control.Invalidate(); }