mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 05:43:40 +01:00
Update ITextureProvider
This commit is contained in:
parent
8e5a84792e
commit
3fe2920e92
14 changed files with 1222 additions and 498 deletions
20
Dalamud/Plugin/Services/GameIconLookup.cs
Normal file
20
Dalamud/Plugin/Services/GameIconLookup.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a lookup for a game icon.
|
||||
/// </summary>
|
||||
/// <param name="IconId">The icon ID.</param>
|
||||
/// <param name="ItemHq">Whether the HQ icon is requested, where HQ is in the context of items.</param>
|
||||
/// <param name="HiRes">Whether the high-resolution icon is requested.</param>
|
||||
/// <param name="Language">The language of the icon to load.</param>
|
||||
[SuppressMessage(
|
||||
"StyleCop.CSharp.NamingRules",
|
||||
"SA1313:Parameter names should begin with lower-case letter",
|
||||
Justification = "no")]
|
||||
public record struct GameIconLookup(
|
||||
uint IconId,
|
||||
bool ItemHq = false,
|
||||
bool HiRes = true,
|
||||
ClientLanguage? Language = null);
|
||||
98
Dalamud/Plugin/Services/ITextureProvider.Api9.cs
Normal file
98
Dalamud/Plugin/Services/ITextureProvider.Api9.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System.IO;
|
||||
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Utility;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service that grants you access to textures you may render via ImGui.
|
||||
/// </summary>
|
||||
public partial interface ITextureProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags describing the icon you wish to receive.
|
||||
/// </summary>
|
||||
[Obsolete($"Use {nameof(GameIconLookup)}.")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
[Flags]
|
||||
public enum IconFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Low-resolution, standard quality icon.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// If this icon is an item icon, and it has a high-quality variant, receive the high-quality version.
|
||||
/// Null if the item does not have a high-quality variant.
|
||||
/// </summary>
|
||||
ItemHighQuality = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Get the hi-resolution version of the icon, if it exists.
|
||||
/// </summary>
|
||||
HiRes = 1 << 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for a specific icon.
|
||||
/// </summary>
|
||||
/// <param name="iconId">The ID of the icon to load.</param>
|
||||
/// <param name="flags">Options to be considered when loading the icon.</param>
|
||||
/// <param name="language">
|
||||
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
|
||||
/// If null, default to the game's current language.
|
||||
/// </param>
|
||||
/// <param name="keepAlive">
|
||||
/// Not used. This parameter is ignored.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Null, if the icon does not exist in the specified configuration, or a texture wrap that can be used
|
||||
/// to render the icon.
|
||||
/// </returns>
|
||||
[Obsolete($"Use {nameof(ImmediateGetFromGameIcon)} or {nameof(GetFromGameIconAsync)}.")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
public IDalamudTextureWrap? GetIcon(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null, bool keepAlive = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get a path for a specific icon's .tex file.
|
||||
/// </summary>
|
||||
/// <param name="iconId">The ID of the icon to look up.</param>
|
||||
/// <param name="flags">Options to be considered when loading the icon.</param>
|
||||
/// <param name="language">
|
||||
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
|
||||
/// If null, default to the game's current language.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Null, if the icon does not exist in the specified configuration, or the path to the texture's .tex file,
|
||||
/// which can be loaded via IDataManager.
|
||||
/// </returns>
|
||||
[Obsolete($"Use {nameof(TryGetIconPath)} or {nameof(GetIconPath)}({nameof(GameIconLookup)}).")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
public string? GetIconPath(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null);
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for the texture at the specified path.
|
||||
/// You may only specify paths in the game's VFS.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the texture in the game's VFS.</param>
|
||||
/// <param name="keepAlive">Not used. This parameter is ignored.</param>
|
||||
/// <returns>Null, if the icon does not exist, or a texture wrap that can be used to render the texture.</returns>
|
||||
[Obsolete($"Use {nameof(ImmediateGetFromGame)} or {nameof(GetFromGameAsync)}.")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
public IDalamudTextureWrap? GetTextureFromGame(string path, bool keepAlive = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for the image or texture, specified by the passed FileInfo.
|
||||
/// You may only specify paths on the native file system.
|
||||
///
|
||||
/// This API can load .png and .tex files.
|
||||
/// </summary>
|
||||
/// <param name="file">The FileInfo describing the image or texture file.</param>
|
||||
/// <param name="keepAlive">Not used. This parameter is ignored.</param>
|
||||
/// <returns>Null, if the file does not exist, or a texture wrap that can be used to render the texture.</returns>
|
||||
[Obsolete($"Use {nameof(ImmediateGetFromFile)} or {nameof(GetFromFileAsync)}.")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
public IDalamudTextureWrap? GetTextureFromFile(FileInfo file, bool keepAlive = false);
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Interface.Internal;
|
||||
|
||||
using Lumina.Data.Files;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
|
@ -9,86 +11,107 @@ namespace Dalamud.Plugin.Services;
|
|||
/// <summary>
|
||||
/// Service that grants you access to textures you may render via ImGui.
|
||||
/// </summary>
|
||||
public interface ITextureProvider
|
||||
public partial interface ITextureProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags describing the icon you wish to receive.
|
||||
/// <summary>Gets the corresponding game icon for use with the current frame.</summary>
|
||||
/// <param name="lookup">The icon specifier.</param>
|
||||
/// <returns>An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for the current
|
||||
/// frame being drawn.</returns>
|
||||
/// <remarks><see cref="IDisposable.Dispose"/> will be ignored.<br />
|
||||
/// If the file is unavailable, then the returned instance of <see cref="IDalamudTextureWrap"/> will point to an
|
||||
/// empty texture instead.</remarks>
|
||||
/// <exception cref="InvalidOperationException">Thrown when called outside the UI thread.</exception>
|
||||
public IDalamudTextureWrap ImmediateGetFromGameIcon(in GameIconLookup lookup);
|
||||
|
||||
/// <summary>Gets a texture from a file shipped as a part of the game resources for use with the current frame.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum IconFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Low-resolution, standard quality icon.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// If this icon is an item icon, and it has a high-quality variant, receive the high-quality version.
|
||||
/// Null if the item does not have a high-quality variant.
|
||||
/// </summary>
|
||||
ItemHighQuality = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Get the hi-resolution version of the icon, if it exists.
|
||||
/// </summary>
|
||||
HiRes = 1 << 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for a specific icon.
|
||||
/// </summary>
|
||||
/// <param name="iconId">The ID of the icon to load.</param>
|
||||
/// <param name="flags">Options to be considered when loading the icon.</param>
|
||||
/// <param name="language">
|
||||
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
|
||||
/// If null, default to the game's current language.
|
||||
/// </param>
|
||||
/// <param name="keepAlive">
|
||||
/// Not used. This parameter is ignored.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Null, if the icon does not exist in the specified configuration, or a texture wrap that can be used
|
||||
/// to render the icon.
|
||||
/// </returns>
|
||||
public IDalamudTextureWrap? GetIcon(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null, bool keepAlive = false);
|
||||
/// <param name="path">The game-internal path to a .tex, .atex, or an image file such as .png.</param>
|
||||
/// <returns>An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for the current
|
||||
/// frame being drawn.</returns>
|
||||
/// <remarks><see cref="IDisposable.Dispose"/> will be ignored.<br />
|
||||
/// If the file is unavailable, then the returned instance of <see cref="IDalamudTextureWrap"/> will point to an
|
||||
/// empty texture instead.</remarks>
|
||||
/// <exception cref="InvalidOperationException">Thrown when called outside the UI thread.</exception>
|
||||
public IDalamudTextureWrap ImmediateGetFromGame(string path);
|
||||
|
||||
/// <summary>Gets a texture from a file on the filesystem for use with the current frame.</summary>
|
||||
/// <param name="file">The filesystem path to a .tex, .atex, or an image file such as .png.</param>
|
||||
/// <returns>An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for the current
|
||||
/// frame being drawn.</returns>
|
||||
/// <remarks><see cref="IDisposable.Dispose"/> will be ignored.<br />
|
||||
/// If the file is unavailable, then the returned instance of <see cref="IDalamudTextureWrap"/> will point to an
|
||||
/// empty texture instead.</remarks>
|
||||
/// <exception cref="InvalidOperationException">Thrown when called outside the UI thread.</exception>
|
||||
public IDalamudTextureWrap ImmediateGetFromFile(string file);
|
||||
|
||||
/// <summary>Gets the corresponding game icon for use with the current frame.</summary>
|
||||
/// <param name="lookup">The icon specifier.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromGameIconAsync(in GameIconLookup lookup);
|
||||
|
||||
/// <summary>Gets a texture from a file shipped as a part of the game resources.</summary>
|
||||
/// <param name="path">The game-internal path to a .tex, .atex, or an image file such as .png.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromGameAsync(string path);
|
||||
|
||||
/// <summary>Gets a texture from a file on the filesystem.</summary>
|
||||
/// <param name="file">The filesystem path to a .tex, .atex, or an image file such as .png.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromFileAsync(string file);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, trying to interpret it as a .tex file or other well-known image
|
||||
/// files, such as .png.</summary>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromImageAsync(ReadOnlyMemory<byte> bytes);
|
||||
|
||||
/// <summary>Gets a texture from the given stream, trying to interpret it as a .tex file or other well-known image
|
||||
/// files, such as .png.</summary>
|
||||
/// <param name="stream">The stream to load data from.</param>
|
||||
/// <param name="leaveOpen">Whether to leave the stream open once the task completes, sucessfully or not.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromImageAsync(Stream stream, bool leaveOpen = false);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, interpreting it as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <returns>The texture loaded from the supplied raw bitmap. Dispose after use.</returns>
|
||||
public IDalamudTextureWrap GetFromRaw(RawImageSpecification specs, ReadOnlySpan<byte> bytes);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, interpreting it as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromRawAsync(RawImageSpecification specs, ReadOnlyMemory<byte> bytes);
|
||||
|
||||
/// <summary>Gets a texture from the given stream, interpreting the read data as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="stream">The stream to load data from.</param>
|
||||
/// <param name="leaveOpen">Whether to leave the stream open once the task completes, sucessfully or not.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
public Task<IDalamudTextureWrap> GetFromRawAsync(
|
||||
RawImageSpecification specs,
|
||||
Stream stream,
|
||||
bool leaveOpen = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get a path for a specific icon's .tex file.
|
||||
/// </summary>
|
||||
/// <param name="iconId">The ID of the icon to look up.</param>
|
||||
/// <param name="flags">Options to be considered when loading the icon.</param>
|
||||
/// <param name="language">
|
||||
/// The language to be considered when loading the icon, if the icon has versions for multiple languages.
|
||||
/// If null, default to the game's current language.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Null, if the icon does not exist in the specified configuration, or the path to the texture's .tex file,
|
||||
/// which can be loaded via IDataManager.
|
||||
/// </returns>
|
||||
public string? GetIconPath(uint iconId, IconFlags flags = IconFlags.HiRes, ClientLanguage? language = null);
|
||||
|
||||
/// <param name="lookup">The icon lookup.</param>
|
||||
/// <returns>The path to the icon.</returns>
|
||||
/// <exception cref="FileNotFoundException">If a corresponding file could not be found.</exception>
|
||||
public string GetIconPath(in GameIconLookup lookup);
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for the texture at the specified path.
|
||||
/// You may only specify paths in the game's VFS.
|
||||
/// Gets the path of an icon.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the texture in the game's VFS.</param>
|
||||
/// <param name="keepAlive">Not used. This parameter is ignored.</param>
|
||||
/// <returns>Null, if the icon does not exist, or a texture wrap that can be used to render the texture.</returns>
|
||||
public IDalamudTextureWrap? GetTextureFromGame(string path, bool keepAlive = false);
|
||||
/// <param name="lookup">The icon lookup.</param>
|
||||
/// <param name="path">The resolved path.</param>
|
||||
/// <returns><c>true</c> if the corresponding file exists and <paramref name="path"/> has been set.</returns>
|
||||
public bool TryGetIconPath(in GameIconLookup lookup, [NotNullWhen(true)] out string? path);
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for the image or texture, specified by the passed FileInfo.
|
||||
/// You may only specify paths on the native file system.
|
||||
///
|
||||
/// This API can load .png and .tex files.
|
||||
/// </summary>
|
||||
/// <param name="file">The FileInfo describing the image or texture file.</param>
|
||||
/// <param name="keepAlive">Not used. This parameter is ignored.</param>
|
||||
/// <returns>Null, if the file does not exist, or a texture wrap that can be used to render the texture.</returns>
|
||||
public IDalamudTextureWrap? GetTextureFromFile(FileInfo file, bool keepAlive = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get a texture handle for the specified Lumina TexFile.
|
||||
/// Get a texture handle for the specified Lumina <see cref="TexFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="file">The texture to obtain a handle to.</param>
|
||||
/// <returns>A texture wrap that can be used to render the texture.</returns>
|
||||
|
|
|
|||
216
Dalamud/Plugin/Services/RawImageSpecification.cs
Normal file
216
Dalamud/Plugin/Services/RawImageSpecification.cs
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a raw image.
|
||||
/// </summary>
|
||||
/// <param name="Width">The width of the image.</param>
|
||||
/// <param name="Height">The height of the image.</param>
|
||||
/// <param name="Pitch">The pitch of the image.</param>
|
||||
/// <param name="DxgiFormat">The format of the image. See <a href="https://learn.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format">DXGI_FORMAT</a>.</param>
|
||||
[SuppressMessage(
|
||||
"StyleCop.CSharp.NamingRules",
|
||||
"SA1313:Parameter names should begin with lower-case letter",
|
||||
Justification = "no")]
|
||||
public record struct RawImageSpecification(int Width, int Height, int Pitch, int DxgiFormat)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution and pixel
|
||||
/// format. Pitch will be automatically calculated.
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>The new instance.</returns>
|
||||
public static RawImageSpecification From(int width, int height, int format)
|
||||
{
|
||||
int bitsPerPixel;
|
||||
var isBlockCompression = false;
|
||||
switch ((DXGI_FORMAT)format)
|
||||
{
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_SINT:
|
||||
bitsPerPixel = 128;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32B32_SINT:
|
||||
bitsPerPixel = 96;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G32_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
|
||||
bitsPerPixel = 64;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R11G11B10_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16G16_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_D32_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R32_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R24G8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_D24_UNORM_S8_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_X24_TYPELESS_G8_UINT:
|
||||
bitsPerPixel = 32;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_FLOAT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_D16_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R16_SINT:
|
||||
bitsPerPixel = 16;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8_UINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8_SNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8_SINT:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_A8_UNORM:
|
||||
bitsPerPixel = 8;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R1_UNORM:
|
||||
bitsPerPixel = 1;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R8G8_B8G8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_G8R8_G8B8_UNORM:
|
||||
throw new NotSupportedException();
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC1_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB:
|
||||
bitsPerPixel = 4;
|
||||
isBlockCompression = true;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC2_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM_SRGB:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC3_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB:
|
||||
bitsPerPixel = 8;
|
||||
isBlockCompression = true;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC4_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM:
|
||||
bitsPerPixel = 4;
|
||||
isBlockCompression = true;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC5_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM:
|
||||
bitsPerPixel = 8;
|
||||
isBlockCompression = true;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B5G6R5_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM:
|
||||
bitsPerPixel = 16;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||
bitsPerPixel = 32;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC6H_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC6H_SF16:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC7_TYPELESS:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||
bitsPerPixel = 8;
|
||||
isBlockCompression = true;
|
||||
break;
|
||||
case DXGI_FORMAT.DXGI_FORMAT_AYUV:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_Y410:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_Y416:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_NV12:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_P010:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_P016:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_420_OPAQUE:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_YUY2:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_Y210:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_Y216:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_NV11:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_AI44:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_IA44:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_P8:
|
||||
case DXGI_FORMAT.DXGI_FORMAT_A8P8:
|
||||
throw new NotSupportedException();
|
||||
case DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM:
|
||||
bitsPerPixel = 16;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
var pitch = isBlockCompression
|
||||
? Math.Max(1, (width + 3) / 4) * 2 * bitsPerPixel
|
||||
: ((width * bitsPerPixel) + 7) / 8;
|
||||
|
||||
return new(width, height, pitch, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution,
|
||||
/// in B8G8R8A8(BGRA32) UNorm pixel format.
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <returns>The new instance.</returns>
|
||||
public static RawImageSpecification Bgra32(int width, int height) =>
|
||||
new(width, height, width * 4, (int)DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution,
|
||||
/// in R8G8B8A8(RGBA32) UNorm pixel format.
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
/// <returns>The new instance.</returns>
|
||||
public static RawImageSpecification Rgba32(int width, int height) =>
|
||||
new(width, height, width * 4, (int)DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue