private void Export(IExportContainer container, Stream destination, Stream source, long length) { switch (TextureFormat.ToContainerType()) { case ContainerType.None: source.CopyStream(destination, length); break; case ContainerType.DDS: ExportDDS(container, destination, source, length); break; case ContainerType.PVR: ExportPVR(destination, source, length); break; case ContainerType.KTX: ExportKTX(destination, source, length); break; default: throw new NotSupportedException($"Unsupported texture container {TextureFormat.ToContainerType()}"); } }
public override byte[] ExportBinary() { byte[] data = m_imageData; int offset = 0; int length = data.Length; if (IsReadStreamData) { string path = StreamData.Path; if (path != string.Empty) { if (data.Length != 0) { throw new Exception("Texture contains data and resource path"); } const string archivePrefix = "archive:/"; if (path.StartsWith(archivePrefix)) { path = path.Substring(archivePrefix.Length); } ResourcesFile res = AssetsFile.Collection.FindResourcesFile(AssetsFile, path); if (res == null) { Logger.Log(LogType.Warning, LogCategory.Export, $"Can't export '{Name}' because resources file '{path}' hasn't been found"); return(null); } data = res.Data; long longOffset = StreamData.Offset; long longSize = StreamData.Size; if (longOffset > int.MaxValue) { throw new Exception($"Unsupported offset value {longOffset}"); } if (longSize > int.MaxValue) { throw new Exception($"Unsupported size value {longSize}"); } offset = (int)longOffset; length = (int)longSize; } } switch (TextureFormat.ToContainerType()) { case ContainerType.None: return(m_imageData); case ContainerType.DDS: return(ExportDDS(data, offset, length)); case ContainerType.PVR: return(ExportPVR(data, offset, length)); case ContainerType.KTX: return(ExportKTX(data, offset, length)); default: throw new NotSupportedException($"Unsupported texture container {TextureFormat.ToContainerType()}"); } }