public void ReadInfo(IContainer resource, LoaderFlags flags) { var ffprobeCommand = FFprobeCommand.Create(resource) .AddSetting(new PrintFormat(PrintFormat.JsonFormat)); if (flags.HasFlag(LoaderFlags.ShowFormat)) { ffprobeCommand.AddSetting(new ShowFormat()); } if (flags.HasFlag(LoaderFlags.ShowStreams)) { ffprobeCommand.AddSetting(new ShowStreams()); } if (flags.HasFlag(LoaderFlags.ShowFrames)) { ffprobeCommand.AddSetting(new ShowFrames()); } var commandProcessor = ffprobeCommand.Execute(null); var containerMetadata = FFprobeSerializer.Serialize(commandProcessor); HasAudio = containerMetadata.Streams != null && containerMetadata.Streams.OfType<AudioStreamMetadata>().Any(); HasVideo = containerMetadata.Streams != null && containerMetadata.Streams.OfType<VideoStreamMetadata>().Any(); HasData = containerMetadata.Streams != null && containerMetadata.Streams.OfType<DataStreamMetadata>().Any(); HasFrames = containerMetadata.Frames != null && containerMetadata.Frames.Any(); BaseData = containerMetadata; }
/// <summary> /// Create a DDS texture from a strean /// </summary> /// <param name="stream">The stream to create from</param> /// <param name="mipMapMaxSize">The largest size a mipmap can be (all larger will be discarded)</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the DDS texture</returns> public static FormatTexture CreateDdsTexture( Stream stream, uint mipMapMaxSize = default, LoaderFlags loaderFlags = LoaderFlags.None ) { if (stream is null) { ThrowHelper.ThrowArgumentNullException(nameof(stream)); } long streamSize = stream !.Length; if (streamSize > int.MaxValue) { ThrowHelper.ThrowArgumentException("File too large"); } var data = new byte[streamSize]; stream.Read(data); return(CreateDdsTexture( data, mipMapMaxSize, loaderFlags )); }
/// <summary> /// Create a TGA texture from a strean /// </summary> /// <param name="stream">The stream to create from</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the texture</returns> public static TextureDescription CreateTgaTexture( Stream stream, LoaderFlags loaderFlags = LoaderFlags.None ) { if (stream is null) { ThrowHelper.ThrowArgumentNullException(nameof(stream)); } long streamSize = stream !.Length; if (streamSize > int.MaxValue) { ThrowHelper.ThrowArgumentException("File too large"); } var data = new byte[streamSize]; stream.Read(data); return(CreateTgaTexture( data, loaderFlags )); }
/// <summary> /// Create a texture from a stream /// </summary> /// <param name="stream">The stream that contains the texture</param> /// <param name="type">The type of the texture to create, or <see cref="TexType.RuntimeDetect"/> to automatically detect</param> /// <param name="loaderFlags">The flags passed to the texture loader</param> /// <param name="maxMipMapSize">The maximum permitted size of a mipmap, or 0 to indicate the maximum size permitted by hardware</param> /// <returns>A texture description</returns> public static FormatTexture LoadTextureDesc( Stream stream, TexType type = TexType.RuntimeDetect, LoaderFlags loaderFlags = LoaderFlags.None, uint maxMipMapSize = 0 ) { if (stream is null) { ThrowHelper.ThrowArgumentNullException(nameof(stream)); } long streamSize = stream !.Length; if (streamSize > int.MaxValue) { ThrowHelper.ThrowArgumentException($"File too large (only files up to {int.MaxValue} bytes are supported)"); } var data = new byte[streamSize]; var read = stream.Read(data); return(LoadTextureDesc( data, type, loaderFlags, maxMipMapSize )); }
internal TextureDescription( Memory <byte> bitData, D3D12_RESOURCE_DIMENSION resourceDimension, Size3 size, uint mipCount, uint arraySize, DXGI_FORMAT format, LoaderFlags loaderFlags, bool isCubeMap, Memory <ManagedSubresourceData> subresourceData, AlphaMode alphaMode, TexType underlyingTextureType) { BitData = bitData; ResourceDimension = resourceDimension; _size = size; MipCount = mipCount; ArraySize = arraySize; Format = format; LoaderFlags = loaderFlags; IsCubeMap = isCubeMap; SubresourceData = subresourceData; AlphaMode = alphaMode; UnderlyingTextureType = underlyingTextureType; }
public void ReadInfo(IContainer resource, LoaderFlags flags) { var ffprobeCommand = FFprobeCommand.Create(resource) .AddSetting(new PrintFormat(PrintFormat.JsonFormat)); if (flags.HasFlag(LoaderFlags.ShowFormat)) { ffprobeCommand.AddSetting(new ShowFormat()); } if (flags.HasFlag(LoaderFlags.ShowStreams)) { ffprobeCommand.AddSetting(new ShowStreams()); } if (flags.HasFlag(LoaderFlags.ShowFrames)) { ffprobeCommand.AddSetting(new ShowFrames()); } var commandProcessor = ffprobeCommand.Execute(); var containerMetadata = FFprobeSerializer.Serialize(commandProcessor); HasAudio = containerMetadata.Streams != null && containerMetadata.Streams.OfType <AudioStreamMetadata>().Any(); HasVideo = containerMetadata.Streams != null && containerMetadata.Streams.OfType <VideoStreamMetadata>().Any(); HasData = containerMetadata.Streams != null && containerMetadata.Streams.OfType <DataStreamMetadata>().Any(); HasFrames = containerMetadata.Frames != null && containerMetadata.Frames.Any(); BaseData = containerMetadata; }
/// <summary> /// Create a DDS texture from a file /// </summary> /// <param name="fileName">The file to create from</param> /// <param name="mipMapMaxSize">The largest size a mipmap can be (all larger will be discarded)</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the DDS texture</returns> public static DdsTextureDescription CreateDdsTexture( string fileName, uint mipMapMaxSize = default, LoaderFlags loaderFlags = LoaderFlags.None) { if (fileName is null) { ThrowHelper.ThrowArgumentNullException(nameof(fileName)); } using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); return(CreateDdsTexture(stream, mipMapMaxSize, loaderFlags)); }
/// <summary> /// Create a TGA texture from memory /// </summary> /// <param name="tgaData">The memory where the TGA data is stored </param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the texture</returns> public static TextureDescription CreateTgaTexture( Memory <byte> tgaData, LoaderFlags loaderFlags = LoaderFlags.None ) { if (tgaData.Length < sizeof(TGAHeader)) { ThrowHelper.ThrowArgumentException("Data too small to be a valid DDS file"); } return(TGAImplementationFunctions.CreateTgaTexture( tgaData, loaderFlags )); }
/// <summary> /// Create a TGA texture from a file /// </summary> /// <param name="fileName">The file to create from</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the texture</returns> public static FormatTexture CreateTgaTexture( string fileName, LoaderFlags loaderFlags = LoaderFlags.None ) { if (fileName is null) { ThrowHelper.ThrowArgumentNullException(nameof(fileName)); } using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); return(CreateTgaTexture( stream, loaderFlags )); }
/// <summary> /// Create a DDS texture from memory /// </summary> /// <param name="ddsData">The memory where the DDS data is stored </param> /// <param name="mipMapMaxSize">The largest size a mipmap can be (all larger will be discarded)</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the DDS texture</returns> public static DdsTextureDescription CreateDdsTexture( Memory <byte> ddsData, uint mipMapMaxSize = default, LoaderFlags loaderFlags = LoaderFlags.None) { if (ddsData.Length < sizeof(DdsHeader) + sizeof(uint)) { ThrowHelper.ThrowArgumentException("Data too small to be a valid DDS file"); } var metadata = FileMetadata.FromMemory(ddsData); return(ImplementationFunctions.CreateTextureFromDds12( metadata, mipMapMaxSize, loaderFlags )); }
internal FormatTexture( ReadOnlyMemory <byte> bitData, TextureDesc desc, uint mipCount, LoaderFlags loaderFlags, bool isCubeMap, ReadOnlyMemory <SubresourceData> subresourceData, AlphaMode alphaMode, TexType underlyingTextureType) { Data = bitData; Desc = desc; MipCount = mipCount; LoaderFlags = loaderFlags; IsCubeMap = isCubeMap; SubresourceData = subresourceData; AlphaMode = alphaMode; UnderlyingTextureType = underlyingTextureType; }
/// <summary> /// Create a texture from a file /// </summary> /// <param name="fileName">The file that contains the texture</param> /// <param name="type">The type of the texture to create, or <see cref="TexType.RuntimeDetect"/> to automatically detect</param> /// <param name="loaderFlags">The flags passed to the texture loader</param> /// <param name="maxMipMapSize">The maximum permitted size of a mipmap, or 0 to indicate the maximum size permitted by hardware</param> /// <returns>A texture description</returns> public static FormatTexture LoadTextureDesc( string fileName, TexType type = TexType.RuntimeDetect, LoaderFlags loaderFlags = LoaderFlags.None, uint maxMipMapSize = 0 ) { if (fileName is null) { ThrowHelper.ThrowArgumentNullException(nameof(fileName)); } using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); return(LoadTextureDesc( stream, type, loaderFlags, maxMipMapSize )); }
/// <summary> /// Create a texture from memory /// </summary> /// <param name="data">The data that contains the texture in memory</param> /// <param name="type">The type of the texture to create, or <see cref="TexType.RuntimeDetect"/> to automatically detect</param> /// <param name="loaderFlags">The flags passed to the texture loader</param> /// <param name="maxMipMapSize">The maximum permitted size of a mipmap, or 0 to indicate the maximum size permitted by hardware</param> /// <returns>A texture description</returns> public static FormatTexture LoadTextureDesc( ReadOnlyMemory <byte> data, TexType type = TexType.RuntimeDetect, LoaderFlags loaderFlags = LoaderFlags.None, uint maxMipMapSize = 0 ) { if (type == TexType.RuntimeDetect && !TryResolveTexture(data, out type)) { ThrowHelper.ThrowArgumentException("Could not recognise texture format"); } switch (type) { case TexType.RuntimeDetect: ThrowHelper.NeverReached(); break; case TexType.DirectDrawSurface: return(CreateDdsTexture(data, maxMipMapSize, loaderFlags)); case TexType.Bitmap: ThrowHelper.Todo(); break; case TexType.TruevisionGraphicsAdapter: return(CreateTgaTexture(data, loaderFlags)); case TexType.PortableNetworkGraphics: ThrowHelper.Todo(); break; default: ThrowHelper.ThrowArgumentOutOfRangeException(nameof(type), type); return(default); } return(default);
/// <summary> /// Create a DDS texture from a strean /// </summary> /// <param name="stream">The stream to create from</param> /// <param name="mipMapMaxSize">The largest size a mipmap can be (all larger will be discarded)</param> /// <param name="loaderFlags">The flags used by the loader</param> /// <returns>A descriptor struct of the DDS texture</returns> public static DdsTextureDescription CreateDdsTexture( Stream stream, uint mipMapMaxSize = default, LoaderFlags loaderFlags = LoaderFlags.None) { if (stream is null) { ThrowHelper.ThrowArgumentNullException(nameof(stream)); } var streamSize = stream.Length; if (streamSize > int.MaxValue) { ThrowHelper.ThrowArgumentException("File too large"); } byte[]? data = null; try { data = ArrayPool <byte> .Shared.Rent((int)streamSize); stream.Read(data); return(CreateDdsTexture( data !, mipMapMaxSize, loaderFlags )); } finally { if (data is object) { ArrayPool <byte> .Shared.Return(data); } } }
public CoffWindowsFields32Plus(BinaryReader rdr) { ImageBase = rdr.ReadUInt64(); SectionAlignment = rdr.ReadUInt32(); FileAlignment = rdr.ReadUInt32(); MajorOperatingSystemVersion = rdr.ReadUInt16(); MinorOperatingSystemVersion = rdr.ReadUInt16(); MajorImageVersion = rdr.ReadUInt16(); MinorImageVersion = rdr.ReadUInt16(); MajorSubsystemVersion = rdr.ReadUInt16(); MinorSubsystemVersion = rdr.ReadUInt16(); Win32VersionValue = rdr.ReadUInt32(); SizeOfImage = rdr.ReadUInt32(); SizeOfHeaders = rdr.ReadUInt32(); CheckSum = rdr.ReadUInt32(); Subsystem = (PESubsystem)rdr.ReadUInt16(); Characteristics = (DllCharacteristics)rdr.ReadUInt16(); SizeOfStackReserve = rdr.ReadUInt64(); SizeOfStackCommit = rdr.ReadUInt64(); SizeOfHeapReserve = rdr.ReadUInt64(); SizeOfHeapCommit = rdr.ReadUInt64(); LoaderFlags = (LoaderFlags)rdr.ReadUInt32(); NumberOfRvaAndSizes = rdr.ReadUInt32(); }
public static FormatTexture CreateTextureFromDds12( DDSFileMetadata metadata, uint maxsize, LoaderFlags loaderFlags) { ref readonly DDSHeader header = ref metadata.DdsHeader;
public static TextureDescription CreateTgaTexture(Memory <byte> tgaData, LoaderFlags loaderFlags = LoaderFlags.None) { if (tgaData.Length < sizeof(TGAHeader)) { ThrowHelper.ThrowInvalidDataException("Too small"); } Span <byte> span = tgaData.Span; TGAHeader header = MemoryMarshal.Read <TGAHeader>(span); if (IsCompressed(header.DataTypeCode)) { ThrowHelper.ThrowNotSupportedException("Compressed TGA textures are TODO"); // TODO } int size = header.Height * header.Width * (header.BitsPerPixel / 8); var data = new byte[size]; var buff = data; DXGI_FORMAT format = loaderFlags.HasFlag(LoaderFlags.ForceSrgb) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; switch (header.BitsPerPixel) { case 24: RbgToRgba(span.Slice(sizeof(TGAHeader)), buff); break; case 32: ArbgToRgba(span.Slice(sizeof(TGAHeader)), buff); break; case 16: Rgba16ToRgba(span.Slice(sizeof(TGAHeader)), buff); break; default: ThrowHelper.ThrowNotSupportedException("Unsupported format"); break; } var subresources = new ManagedSubresourceData[1]; subresources[0] = new ManagedSubresourceData(); return(new TextureDescription( data, D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_TEXTURE2D, new Size3((uint)header.Height, (uint)header.Width, 0), 1, 1, format, loaderFlags, false, subresources, header.BitsPerPixel == 24 ? AlphaMode.Opaque : AlphaMode.Unknown, TexType.Tga )); }
public static FormatTexture CreateTgaTexture( ReadOnlyMemory <byte> tgaData, LoaderFlags loaderFlags = LoaderFlags.None ) { if (tgaData.Length < sizeof(TGAHeader)) { ThrowHelper.ThrowInvalidDataException("Too small"); } ReadOnlySpan <byte> span = tgaData.Span; TGAHeader header = MemoryMarshal.Read <TGAHeader>(span); if (IsCompressed(header.DataTypeCode)) { ThrowHelper.ThrowNotSupportedException("Compressed TGA textures are TODO"); // TODO } int size = header.Height * header.Width * (header.BitsPerPixel / 8); var data = new byte[size]; var buff = data; DXGI_FORMAT format = loaderFlags.HasFlag(LoaderFlags.ForceSrgb) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; switch (header.BitsPerPixel) { case 24: RbgToRgba(span.Slice(sizeof(TGAHeader)), buff); break; case 32: ArbgToRgba(span.Slice(sizeof(TGAHeader)), buff); break; case 16: Rgba16ToRgba(span.Slice(sizeof(TGAHeader)), buff); break; default: ThrowHelper.ThrowNotSupportedException("Unsupported format"); break; } var subresources = new SubresourceData[1]; subresources[0] = new SubresourceData(); var desc = new TextureDesc { Width = (uint)header.Width, Height = (uint)header.Height, DepthOrArraySize = 0, // is this right? Format = (DataFormat)format, Dimension = TextureDimension.Tex2D }; return(new FormatTexture( data, desc, 1, loaderFlags, false, subresources, header.BitsPerPixel == 24 ? AlphaMode.Opaque : AlphaMode.Unknown, TexType.Tga )); }
public LoaderAttribute(int level, LoaderFlags flag) { _lev = level; _tag = flag; }
public static DdsTextureDescription CreateTextureFromDds12( FileMetadata metadata, uint maxsize, LoaderFlags loaderFlags) { ref DdsHeader header = ref metadata.DdsHeader;