public void Save(Stream output, ImageInfo imageInfo) { using var bw = new BinaryWriterX(output); // Calculate offsets var texDataOffset = (HeaderSize + 0x7F) & ~0x7F; // Write image data output.Position = texDataOffset; output.Write(imageInfo.ImageData); // Write header var paddedSize = imageInfo.PadSize.Build(imageInfo.ImageSize); var header = new RawJtexHeader { dataOffset = (uint)texDataOffset, format = imageInfo.ImageFormat, width = imageInfo.ImageSize.Width, height = imageInfo.ImageSize.Height, paddedWidth = paddedSize.Width, paddedHeight = paddedSize.Height }; output.Position = 0; bw.WriteType(header); }
public void Save(Stream output, ImageInfo imageInfo) { using var bw = new BinaryWriterX(output, true); // Calculate offsets var texDataOffset = _shouldAlign ? (HeaderSize + 0x7F) & ~0x7F : HeaderSize; // Write image data output.Position = texDataOffset; output.Write(imageInfo.ImageData); // Update header var paddedSize = imageInfo.PadSize.Build(imageInfo.ImageSize); var header = new RawJtexHeader { format = imageInfo.ImageFormat, width = imageInfo.ImageSize.Width, height = imageInfo.ImageSize.Height, paddedWidth = paddedSize.Width, paddedHeight = paddedSize.Height }; // Write header output.Position = 0; if (_shouldAlign) { bw.Write(texDataOffset); } bw.WriteType(header); }