private void WriteImageFile(Stream output, ImageInfo imageInfo) { using var bw = new BinaryWriterX(output); // Calculate offsets var unkRegion1Offset = HeaderSize; var unkRegion2Offset = unkRegion1Offset + _unkRegion1.Length; var tileIndexOffset = unkRegion2Offset + _unkRegion2.Length; // Split tiles var tileBitDepth = GtxtSupport.IndexFormats[_ltHeader.indexFormat].BitDepth; var(imageData, tileData) = SplitTiles(new MemoryStream(imageInfo.ImageData), tileBitDepth); var imageDataOffset = tileIndexOffset + tileData.Length; // Write image data output.Position = imageDataOffset; imageData.CopyTo(output); // Write tile data output.Position = tileIndexOffset; tileData.CopyTo(output); // Write unknown regions output.Position = unkRegion1Offset; bw.Write(_unkRegion1); bw.Write(_unkRegion2); // Update header _ltHeader.indexFormat = (byte)imageInfo.ImageFormat; _ltHeader.width = (short)imageInfo.ImageSize.Width; _ltHeader.height = (short)imageInfo.ImageSize.Height; _ltHeader.paddedWidth = (short)GtxtSupport.ToPowerOfTwo(imageInfo.ImageSize.Width); _ltHeader.paddedHeight = (short)((imageInfo.ImageSize.Height + 7) & ~7); _ltHeader.unkOffset1 = (short)unkRegion1Offset; _ltHeader.unkOffset2 = (short)unkRegion2Offset; _ltHeader.indexOffset = (short)tileIndexOffset; _ltHeader.dataOffset = (short)imageDataOffset; _ltHeader.unkCount1 = (short)(_unkRegion1.Length / 8); _ltHeader.unkCount2 = (short)(_unkRegion2.Length / 3); _ltHeader.indexCount = (short)(tileData.Length / 2); _ltHeader.tileCount = (short)(imageData.Length / (64 * tileBitDepth / 8)); // Write header output.Position = 0; bw.WriteType(_ltHeader); }
public GtxtState() { _img = new Gtxt(); EncodingDefinition = GtxtSupport.GetEncodingDefinition(); }