diff --git a/sources/editor/Stride.Assets.Presentation/AssetEditors/SpriteEditor/Services/SpriteEditorImageCache.cs b/sources/editor/Stride.Assets.Presentation/AssetEditors/SpriteEditor/Services/SpriteEditorImageCache.cs index 328b80d390..63dcb67ab3 100644 --- a/sources/editor/Stride.Assets.Presentation/AssetEditors/SpriteEditor/Services/SpriteEditorImageCache.cs +++ b/sources/editor/Stride.Assets.Presentation/AssetEditors/SpriteEditor/Services/SpriteEditorImageCache.cs @@ -92,7 +92,7 @@ public BitmapImage RetrieveImage(UFile filePath) using (var texTool = new TextureTool()) { texImage = texTool.Load(filePath, false); - texTool.Decompress(texImage, texImage.Format.IsSRgb); + texTool.Decompress(texImage, texImage.Format.IsSRgb()); if (texImage.Format == PixelFormat.R16G16B16A16_UNorm) texTool.Convert(texImage, PixelFormat.R8G8B8A8_UNorm); var image = texTool.ConvertToStrideImage(texImage); diff --git a/sources/editor/Stride.Editor/Thumbnails/StaticThumbnailCommand.cs b/sources/editor/Stride.Editor/Thumbnails/StaticThumbnailCommand.cs index 8820dc4df9..77eec73481 100644 --- a/sources/editor/Stride.Editor/Thumbnails/StaticThumbnailCommand.cs +++ b/sources/editor/Stride.Editor/Thumbnails/StaticThumbnailCommand.cs @@ -51,7 +51,7 @@ protected override Task DoCommandOverride(ICommandContext commandC using (var texImage = texTool.Load(image, Parameters.SRgb)) { // Rescale image so that it fits the thumbnail asked resolution - texTool.Decompress(texImage, texImage.Format.IsSRgb); + texTool.Decompress(texImage, texImage.Format.IsSRgb()); texTool.Resize(texImage, thumbnailSize.X, thumbnailSize.Y, Filter.Rescaling.Lanczos3); // Save diff --git a/sources/engine/Stride.Assets.Tests/TexturePackerTests.cs b/sources/engine/Stride.Assets.Tests/TexturePackerTests.cs index ba28932e28..5a150cd2fb 100644 --- a/sources/engine/Stride.Assets.Tests/TexturePackerTests.cs +++ b/sources/engine/Stride.Assets.Tests/TexturePackerTests.cs @@ -748,7 +748,7 @@ public void TestImageCreationGetAndSet() var source = Image.New2D(width, height, 1, PixelFormat.R8G8B8A8_UNorm); - Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes * width * height); + Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes() * width * height); Assert.Equal(1, source.PixelBuffer.Count); Assert.Equal(1, source.Description.MipLevels); @@ -777,7 +777,7 @@ public void TestImageDataPointerManipulation() var source = Image.New2D(width, height, 1, PixelFormat.R8G8B8A8_UNorm); - Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes * width * height); + Assert.Equal(source.TotalSizeInBytes, PixelFormat.R8G8B8A8_UNorm.SizeInBytes() * width * height); Assert.Equal(1, source.PixelBuffer.Count); Assert.Equal(1, source.Description.MipLevels); diff --git a/sources/engine/Stride.Assets/Skyboxes/SkyboxGenerator.cs b/sources/engine/Stride.Assets/Skyboxes/SkyboxGenerator.cs index 6369ae9617..9ae949b864 100644 --- a/sources/engine/Stride.Assets/Skyboxes/SkyboxGenerator.cs +++ b/sources/engine/Stride.Assets/Skyboxes/SkyboxGenerator.cs @@ -146,7 +146,7 @@ public static SkyboxResult Compile(SkyboxAsset asset, SkyboxGeneratorContext con if (textureSize < 64) textureSize = 64; // TODO: Add support for HDR 32bits - var filteringTextureFormat = skyboxTexture.Format.IsHDR ? skyboxTexture.Format : PixelFormat.R8G8B8A8_UNorm; + var filteringTextureFormat = skyboxTexture.Format.IsHDR() ? skyboxTexture.Format : PixelFormat.R8G8B8A8_UNorm; //var outputTexture = Texture.New2D(graphicsDevice, 256, 256, skyboxTexture.Format, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess, 6); using (var outputTexture = Texture.New2D(context.GraphicsDevice, textureSize, textureSize, true, filteringTextureFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget, 6)) diff --git a/sources/engine/Stride.Assets/Textures/TextureHelper.cs b/sources/engine/Stride.Assets/Textures/TextureHelper.cs index c8de023d51..db2895fc1a 100644 --- a/sources/engine/Stride.Assets/Textures/TextureHelper.cs +++ b/sources/engine/Stride.Assets/Textures/TextureHelper.cs @@ -205,7 +205,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz { case PlatformType.Android: case PlatformType.iOS: - if (inputImageFormat.IsHDR) + if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } @@ -304,7 +304,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz { outputFormat = PixelFormat.BC4_UNorm; } - else if (inputImageFormat.IsHDR) + else if (inputImageFormat.IsHDR()) { // BC6H is too slow to compile //outputFormat = parameters.GraphicsProfile >= GraphicsProfile.Level_11_0 && alphaMode == AlphaFormat.None ? PixelFormat.BC6H_Uf16 : inputImageFormat; @@ -314,7 +314,7 @@ public static PixelFormat DetermineOutputFormat(ImportParameters parameters, Siz } break; case GraphicsPlatform.OpenGLES: // OpenGLES on Windows - if (inputImageFormat.IsHDR) + if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } @@ -452,7 +452,7 @@ public static ResultStatus ImportTextureImageRaw(TextureTool textureTool, TexIma return ResultStatus.Cancelled; // Pre-multiply alpha only for relevant formats - if (parameters.PremultiplyAlpha && texImage.Format.Is32bppWithAlpha) + if (parameters.PremultiplyAlpha && texImage.Format.Is32bppWithAlpha()) textureTool.PreMultiplyAlpha(texImage); if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded @@ -462,7 +462,7 @@ public static ResultStatus ImportTextureImageRaw(TextureTool textureTool, TexIma // Generate mipmaps if (parameters.GenerateMipmaps) { - var boxFilteringIsSupported = !texImage.Format.IsSRgb || (MathUtil.IsPow2(targetSize.Width) && MathUtil.IsPow2(targetSize.Height)); + var boxFilteringIsSupported = !texImage.Format.IsSRgb() || (MathUtil.IsPow2(targetSize.Width) && MathUtil.IsPow2(targetSize.Height)); textureTool.GenerateMipMaps(texImage, boxFilteringIsSupported? Filter.MipMapGeneration.Box: Filter.MipMapGeneration.Linear); } diff --git a/sources/engine/Stride.Engine/Rendering/Skyboxes/CubemapFromTextureRenderer.cs b/sources/engine/Stride.Engine/Rendering/Skyboxes/CubemapFromTextureRenderer.cs index 65421f3432..518054b134 100644 --- a/sources/engine/Stride.Engine/Rendering/Skyboxes/CubemapFromTextureRenderer.cs +++ b/sources/engine/Stride.Engine/Rendering/Skyboxes/CubemapFromTextureRenderer.cs @@ -43,7 +43,7 @@ protected override void DrawImpl() public static Texture GenerateCubemap(IServiceRegistry services, RenderDrawContext renderDrawContext, Texture input, int outputSize) { - var pixelFormat = input.Format.IsHDR ? PixelFormat.R16G16B16A16_Float : input.Format.IsSRgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm; + var pixelFormat = input.Format.IsHDR() ? PixelFormat.R16G16B16A16_Float : input.Format.IsSRgb() ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm; return GenerateCubemap(new CubemapFromTextureRenderer(services, renderDrawContext, input, outputSize, pixelFormat), Vector3.Zero); } } diff --git a/sources/engine/Stride.Graphics.Regression/ImageTester.cs b/sources/engine/Stride.Graphics.Regression/ImageTester.cs index 80e0054994..10eba5704f 100644 --- a/sources/engine/Stride.Graphics.Regression/ImageTester.cs +++ b/sources/engine/Stride.Graphics.Regression/ImageTester.cs @@ -65,7 +65,7 @@ public static bool CompareImage(Image image, string testFilename) || buffer.RowStride != referenceBuffer.RowStride) return false; - var swapBGR = buffer.Format.IsBgraOrder != referenceBuffer.Format.IsBgraOrder; + var swapBGR = buffer.Format.IsBGRAOrder() != referenceBuffer.Format.IsBGRAOrder(); // For now, we handle only those specific cases if ((buffer.Format != PixelFormat.R8G8B8A8_UNorm_SRgb && buffer.Format != PixelFormat.B8G8R8A8_UNorm_SRgb) || referenceBuffer.Format != PixelFormat.B8G8R8A8_UNorm) @@ -74,7 +74,7 @@ public static bool CompareImage(Image image, string testFilename) return false; } - bool checkAlpha = buffer.Format.AlphaSizeInBits > 0; + bool checkAlpha = buffer.Format.AlphaSizeInBits() > 0; // Compare remaining bytes. int allowedDiff = 2; diff --git a/sources/engine/Stride.Graphics.Tests/TestTexture.cs b/sources/engine/Stride.Graphics.Tests/TestTexture.cs index 992caebaf2..fddba94ee2 100644 --- a/sources/engine/Stride.Graphics.Tests/TestTexture.cs +++ b/sources/engine/Stride.Graphics.Tests/TestTexture.cs @@ -553,7 +553,7 @@ public void TestCopy(GraphicsProfile profile, GraphicsResourceUsage usageSource) { foreach (var pixelFormat in pixelFormats) { - ColorComputer colorComputer = pixelFormat.SizeInBytes == 1 + ColorComputer colorComputer = pixelFormat.SizeInBytes() == 1 ? ColorComputerR8 : DefaultColorComputer; @@ -592,7 +592,7 @@ public void TestCopy(GraphicsProfile profile, GraphicsResourceUsage usageSource) /// A byte array containing the generated Texture data. private static byte[] CreateDebugTextureData(int width, int height, int mipmaps, int arraySize, PixelFormat format, ColorComputer dataComputer) { - var formatSize = format.SizeInBytes; + var formatSize = format.SizeInBytes(); var mipmapSize = 0; for (int i = 0; i < mipmaps; i++) @@ -650,7 +650,7 @@ private static byte[] CreateDebugTextureData(int width, int height, int mipmaps, /// private unsafe Texture CreateDebugTexture(GraphicsDevice device, byte[] data, int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage) { - var sizeInBytes = format.SizeInBytes; + var sizeInBytes = format.SizeInBytes(); var offset = 0; var dataBoxes = new DataBox[arraySize * mipmaps]; @@ -701,7 +701,7 @@ private void CheckDebugTextureData(GraphicsContext graphicsContext, Texture debu int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage, ColorComputer dataComputer) { - var pixelSize = format.SizeInBytes; + var pixelSize = format.SizeInBytes(); for (int arraySlice = 0; arraySlice < arraySize; arraySlice++) for (int mipLevel = 0; mipLevel < mipmaps; mipLevel++) diff --git a/sources/engine/Stride.Graphics/Buffer.Typed.cs b/sources/engine/Stride.Graphics/Buffer.Typed.cs index 725771156e..59f096943c 100644 --- a/sources/engine/Stride.Graphics/Buffer.Typed.cs +++ b/sources/engine/Stride.Graphics/Buffer.Typed.cs @@ -57,7 +57,7 @@ public static class Typed /// A new instance of . public static Buffer New(GraphicsDevice device, int elementCount, PixelFormat elementFormat, bool unorderedAccess = false, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { - return Buffer.New(device, bufferSize: elementCount * elementFormat.SizeInBytes, BufferFlags.ShaderResource | (unorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), elementFormat, usage); + return Buffer.New(device, bufferSize: elementCount * elementFormat.SizeInBytes(), BufferFlags.ShaderResource | (unorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), elementFormat, usage); } /// diff --git a/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs b/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs index e32db5e384..d7fec7460a 100644 --- a/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs +++ b/sources/engine/Stride.Graphics/Data/TextureSerializationData.cs @@ -79,7 +79,7 @@ public void Write(SerializationStream stream) // Determine whether we can store initial image StorageHeader.InitialImage = true; - if (Image.Description.Format.IsCompressed) + if (Image.Description.Format.IsCompressed()) { // Compressed: mips need to be multiple of 4, otherwise we can't do it var initialImageWidth = Image.PixelBuffers[skippedMipCount].Width; diff --git a/sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs b/sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs index 4ee16a55ae..1194a3fa24 100644 --- a/sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs +++ b/sources/engine/Stride.Graphics/Direct3D/SwapChainGraphicsPresenter.Direct3D.cs @@ -144,7 +144,7 @@ public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters // Texture.InitializeFromImpl also increments the reference count when storing the COM pointer; // compensate with Release() to return the reference count to its previous value - backBuffer.InitializeFromImpl(nativeBackBuffer, Description.BackBufferFormat.IsSRgb); + backBuffer.InitializeFromImpl(nativeBackBuffer, Description.BackBufferFormat.IsSRgb()); nativeBackBuffer.Release(); // Reload should get Back-Buffer from Swap-Chain as well @@ -395,7 +395,7 @@ public override void Present() // Texture.InitializeFromImpl also increments the reference count when storing the COM pointer; // compensate with Release() to return the reference count to its previous value - backBuffer.InitializeFromImpl(nextBackBuffer, Description.BackBufferFormat.IsSRgb); + backBuffer.InitializeFromImpl(nextBackBuffer, Description.BackBufferFormat.IsSRgb()); nextBackBuffer.Release(); #endif } @@ -440,7 +440,7 @@ public override void OnRecreated() // Put it in our Back-Buffer Texture // Texture.InitializeFromImpl also increments the reference count when storing the COM pointer; // compensate with Release() to return the reference count to its previous value - backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb); + backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb()); backBufferTexture.Release(); backBuffer.LifetimeState = GraphicsResourceLifetimeState.Active; @@ -506,7 +506,7 @@ protected override void ResizeBackBuffer(int width, int height, PixelFormat form // Put it in our Back-Buffer Texture // Texture.InitializeFromImpl also increments the reference count when storing the COM pointer; // compensate with Release() to return the reference count to its previous value - backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb); + backBuffer.InitializeFromImpl(backBufferTexture, Description.BackBufferFormat.IsSRgb()); backBufferTexture.Release(); foreach (var childTexture in childrenTextures) diff --git a/sources/engine/Stride.Graphics/Direct3D11/Buffer.Direct3D11.cs b/sources/engine/Stride.Graphics/Direct3D11/Buffer.Direct3D11.cs index e54ed35c79..edab9a5ba3 100644 --- a/sources/engine/Stride.Graphics/Direct3D11/Buffer.Direct3D11.cs +++ b/sources/engine/Stride.Graphics/Direct3D11/Buffer.Direct3D11.cs @@ -149,7 +149,7 @@ void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat) { // TODO: The way to calculate the count is not always correct depending on the ViewFlags...etc. count = ViewFlags.HasFlag(BufferFlags.RawBuffer) ? Description.SizeInBytes / sizeof(int) : - ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes : + ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes() : 0; } else @@ -298,7 +298,7 @@ internal ComPtr GetRenderTargetView(PixelFormat pixelFor Buffer = new() { - ElementWidth = (uint) (pixelFormat.SizeInBytes * width), + ElementWidth = (uint) (pixelFormat.SizeInBytes() * width), ElementOffset = 0 } }; diff --git a/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs b/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs index 9949fcc052..d2bd31c012 100644 --- a/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs +++ b/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs @@ -42,7 +42,7 @@ public unsafe partial class Texture private const int TextureRowPitchAlignment = 1; private const int TextureSubresourceAlignment = 1; - private int TexturePixelSize => Format.SizeInBytes; + private int TexturePixelSize => Format.SizeInBytes(); private ID3D11RenderTargetView* renderTargetView; private ID3D11DepthStencilView* depthStencilView; @@ -1109,7 +1109,7 @@ private Texture3DDesc ConvertToNativeDescription3D() private static TextureDescription CheckMipLevels(GraphicsDevice device, ref TextureDescription description) { if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && - description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed) + description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed()) { description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount); } diff --git a/sources/engine/Stride.Graphics/Direct3D12/Buffer.Direct3D12.cs b/sources/engine/Stride.Graphics/Direct3D12/Buffer.Direct3D12.cs index 558eb2e18d..cb69cc6b90 100644 --- a/sources/engine/Stride.Graphics/Direct3D12/Buffer.Direct3D12.cs +++ b/sources/engine/Stride.Graphics/Direct3D12/Buffer.Direct3D12.cs @@ -99,7 +99,7 @@ void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat) { // TODO: The way to calculate the count is not always correct depending on the ViewFlags...etc. count = ViewFlags.HasFlag(BufferFlags.RawBuffer) ? Description.SizeInBytes / sizeof(int) : - ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes : + ViewFlags.HasFlag(BufferFlags.ShaderResource) ? Description.SizeInBytes / viewFormat.SizeInBytes() : 0; } else diff --git a/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs b/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs index fc742bd8a8..b6f8388ad0 100644 --- a/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs +++ b/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs @@ -44,7 +44,7 @@ public unsafe partial class Texture private const int TextureRowPitchAlignment = D3D12.TextureDataPitchAlignment; private const int TextureSubresourceAlignment = D3D12.TextureDataPlacementAlignment; - private int TexturePixelSize => Format.SizeInBytes; + private int TexturePixelSize => Format.SizeInBytes(); /// /// A handle to the CPU-accessible Render Target View (RTV) Descriptor. @@ -1052,7 +1052,7 @@ private static TextureDescription CheckMipLevels(GraphicsDevice device, ref Text // TODO: Stale comment? if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && - !description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed) + !description.Flags.HasFlag(TextureFlags.DepthStencil) && description.Format.IsCompressed()) { description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount); } diff --git a/sources/engine/Stride.Graphics/MeshExtension.cs b/sources/engine/Stride.Graphics/MeshExtension.cs index ae1f49eac0..ed80c50edf 100644 --- a/sources/engine/Stride.Graphics/MeshExtension.cs +++ b/sources/engine/Stride.Graphics/MeshExtension.cs @@ -58,7 +58,7 @@ public static bool TryGetElement(this VertexDeclaration declaration, string vert if (currentElementOffset != VertexElement.AppendAligned) offset = currentElementOffset; - var elementSize = element.Format.SizeInBytes; + var elementSize = element.Format.SizeInBytes(); if (vertexElementUsage == element.SemanticName && semanticIndex == element.SemanticIndex) { result = new VertexElementWithOffset(element, offset, elementSize); diff --git a/sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs b/sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs index 23ced5e5b5..16a797eb24 100644 --- a/sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs +++ b/sources/engine/Stride.Graphics/OpenGL/CommandList.OpenGL.cs @@ -508,7 +508,7 @@ internal unsafe void CopyScaler2D(Texture sourceTexture, Texture destTexture, Re // TODO find a better way to detect if sRGB conversion is needed (need to detect if main frame buffer is sRGB or not at init time) #if STRIDE_GRAPHICS_API_OPENGLES // If we are copying from an SRgb texture to a non SRgb texture, we use a special SRGb copy shader - bool needSRgbConversion = sourceTexture.Description.Format.IsSRgb && destTexture == GraphicsDevice.WindowProvidedRenderTexture; + bool needSRgbConversion = sourceTexture.Description.Format.IsSRgb() && destTexture == GraphicsDevice.WindowProvidedRenderTexture; #else bool needSRgbConversion = false; #endif diff --git a/sources/engine/Stride.Graphics/Texture.cs b/sources/engine/Stride.Graphics/Texture.cs index 86a3467959..686bedea37 100644 --- a/sources/engine/Stride.Graphics/Texture.cs +++ b/sources/engine/Stride.Graphics/Texture.cs @@ -274,7 +274,7 @@ public TextureDimension ViewDimension /// Gets a value indicating if the Texture is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). /// /// - public bool IsBlockCompressed => Description.Format.IsCompressed; + public bool IsBlockCompressed => Description.Format.IsCompressed(); /// /// Gets the largestSize of the Texture or Texture View. @@ -830,7 +830,7 @@ public unsafe int CalculateWidth(int mipLevel = 0) where TData : unmanage { var mipWidth = CalculateMipSize(Width, mipLevel); - var rowStride = mipWidth * Format.SizeInBytes; + var rowStride = mipWidth * Format.SizeInBytes(); var dataStrideInBytes = mipWidth * sizeof(TData); var (width, rem) = Math.DivRem(rowStride * mipWidth, dataStrideInBytes); @@ -1453,7 +1453,7 @@ public unsafe void SetData(CommandList commandList, ReadOnlySpan f depth = regionToCheck.Depth; } - var sizePerElement = Format.SizeInBytes; + var sizePerElement = Format.SizeInBytes(); // Compute actual pitch Image.ComputePitch(Format, width, height, out var rowStride, out var textureDepthStride, out width, out height); diff --git a/sources/engine/Stride.Graphics/VertexDeclaration.cs b/sources/engine/Stride.Graphics/VertexDeclaration.cs index e1028084cd..85a99f9478 100644 --- a/sources/engine/Stride.Graphics/VertexDeclaration.cs +++ b/sources/engine/Stride.Graphics/VertexDeclaration.cs @@ -100,7 +100,7 @@ public IEnumerable EnumerateWithOffsets() if (currentElementOffset != VertexElement.AppendAligned) offset = currentElementOffset; - var elementSize = element.Format.SizeInBytes; + var elementSize = element.Format.SizeInBytes(); yield return new VertexElementWithOffset(element, offset, elementSize); // Compute next offset (if automatic) @@ -123,7 +123,7 @@ public int CalculateSize() if (currentElementOffset != VertexElement.AppendAligned) offset = currentElementOffset; - var elementSize = element.Format.SizeInBytes; + var elementSize = element.Format.SizeInBytes(); // Compute next offset (if automatic) offset += elementSize; diff --git a/sources/engine/Stride.Graphics/VertexElementValidator.cs b/sources/engine/Stride.Graphics/VertexElementValidator.cs index 94cd237d1b..ff430e489f 100644 --- a/sources/engine/Stride.Graphics/VertexElementValidator.cs +++ b/sources/engine/Stride.Graphics/VertexElementValidator.cs @@ -26,7 +26,7 @@ internal static int GetVertexStride(VertexElement[] elements) int stride = 0; for (int i = 0; i < elements.Length; i++) - stride += elements[i].Format.SizeInBytes; + stride += elements[i].Format.SizeInBytes(); return stride; } @@ -76,12 +76,12 @@ internal static void Validate(int vertexStride, VertexElement[] elements) int elementOffset = elements[elementIndex].AlignedByteOffset; if (elementOffset == VertexElement.AppendAligned) { - elementOffset = elementIndex == 0 ? 0 : totalOffset + elements[elementIndex - 1].Format.SizeInBytes; + elementOffset = elementIndex == 0 ? 0 : totalOffset + elements[elementIndex - 1].Format.SizeInBytes(); } totalOffset = elementOffset; // Validate the element offset - int typeSize = elements[elementIndex].Format.SizeInBytes; + int typeSize = elements[elementIndex].Format.SizeInBytes(); if (elementOffset == VertexElement.AppendAligned || (elementOffset + typeSize) > vertexStride) { throw new ArgumentException($"The {nameof(VertexElement)}'s offset and size makes it extend beyond the vertex stride", nameof(elements)); diff --git a/sources/engine/Stride.Graphics/VertexHelper.cs b/sources/engine/Stride.Graphics/VertexHelper.cs index a9fc812238..f37c242492 100644 --- a/sources/engine/Stride.Graphics/VertexHelper.cs +++ b/sources/engine/Stride.Graphics/VertexHelper.cs @@ -141,7 +141,7 @@ public static unsafe VertexTransformResult GenerateMultiTextureCoordinates(Verte // Use R16G16_SNorm as it is supported from HW Level 9.1 // See https://msdn.microsoft.com/en-us/library/windows/desktop/ff471324%28v=vs.85%29.aspx const PixelFormat DefaultUVFormat = PixelFormat.R16G16_SNorm; - var newUvSize = DefaultUVFormat.SizeInBytes; + var newUvSize = DefaultUVFormat.SizeInBytes(); for (int i = 0; i <= maxTexcoord; i++) { diff --git a/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs index 0e43a74d2b..52abd51829 100644 --- a/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs @@ -274,7 +274,7 @@ private void InitCountAndViewFormat(out int count, ref PixelFormat viewFormat) } else if ((ViewFlags & BufferFlags.ShaderResource) != 0) { - count = Description.SizeInBytes / viewFormat.SizeInBytes; + count = Description.SizeInBytes / viewFormat.SizeInBytes(); } else { diff --git a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs index a30f53bf40..07bc9686d2 100644 --- a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs @@ -1317,7 +1317,7 @@ internal unsafe partial void UpdateSubResource(GraphicsResource resource, int su if (texture != null) { lengthInBytes = databox.SlicePitch * (region.Back - region.Front); - blockSize = texture.Format.BlockSize; + blockSize = texture.Format.BlockSize(); } else { @@ -1350,8 +1350,8 @@ internal unsafe partial void UpdateSubResource(GraphicsResource resource, int su { bufferOffset = (ulong) (uploadOffset + alignment), imageSubresource = new VkImageSubresourceLayers { aspectMask = VkImageAspectFlags.Color, baseArrayLayer = (uint) arraySlice, layerCount = 1, mipLevel = (uint) mipSlice }, - bufferRowLength = (uint) (databox.RowPitch * texture.Format.BlockWidth / texture.Format.BlockSize), - bufferImageHeight = (uint) (databox.SlicePitch * texture.Format.BlockHeight / databox.RowPitch), + bufferRowLength = (uint) (databox.RowPitch * texture.Format.BlockWidth() / texture.Format.BlockSize()), + bufferImageHeight = (uint) (databox.SlicePitch * texture.Format.BlockHeight() / databox.RowPitch), imageOffset = new VkOffset3D(region.Left, region.Top, region.Front), imageExtent = new VkExtent3D(region.Right - region.Left, region.Bottom - region.Top, region.Back - region.Front) }; diff --git a/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs index fdc835757e..44633824f6 100644 --- a/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs @@ -10,7 +10,7 @@ namespace Stride.Graphics public partial class Texture { // Note: block size for compressed formats - internal int TexturePixelSize => Format.SizeInBytes; + internal int TexturePixelSize => Format.SizeInBytes(); internal const int TextureSubresourceAlignment = 4; internal const int TextureRowPitchAlignment = 1; @@ -291,7 +291,7 @@ private unsafe void InitializeData(DataBox[] dataBoxes) if (dataBoxes != null && dataBoxes.Length > 0) { // Buffer-to-image copies need to be aligned to the pixel size and 4 (always a power of 2) - var blockSize = Format.BlockSize; + var blockSize = Format.BlockSize(); var alignmentMask = (blockSize < 4 ? 4 : blockSize) - 1; int totalSize = dataBoxes.Length * alignmentMask; @@ -351,8 +351,8 @@ private unsafe void InitializeData(DataBox[] dataBoxes) { bufferOffset = (ulong) uploadOffset, imageSubresource = new VkImageSubresourceLayers(VkImageAspectFlags.Color, (uint) mipSlice, (uint) arraySlice, layerCount: 1), - bufferRowLength = (uint) (dataBoxes[i].RowPitch * Format.BlockWidth / Format.BlockSize), - bufferImageHeight = (uint) (dataBoxes[i].SlicePitch * Format.BlockHeight / dataBoxes[i].RowPitch), + bufferRowLength = (uint) (dataBoxes[i].RowPitch * Format.BlockWidth() / Format.BlockSize()), + bufferImageHeight = (uint) (dataBoxes[i].SlicePitch * Format.BlockHeight() / dataBoxes[i].RowPitch), imageOffset = new VkOffset3D(0, 0, 0), imageExtent = new VkExtent3D(mipMapDescription.Width, mipMapDescription.Height, mipMapDescription.Depth) }; @@ -641,7 +641,7 @@ internal static PixelFormat ComputeShaderResourceFormatFromDepthFormat(PixelForm /// The updated texture description. private static TextureDescription CheckMipLevels(GraphicsDevice device, ref TextureDescription description) { - if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && (description.Flags & TextureFlags.DepthStencil) == 0 && description.Format.IsCompressed) + if (device.Features.CurrentProfile < GraphicsProfile.Level_10_0 && (description.Flags & TextureFlags.DepthStencil) == 0 && description.Format.IsCompressed()) { description.MipLevelCount = Math.Min(CalculateMipCount(description.Width, description.Height), description.MipLevelCount); } diff --git a/sources/engine/Stride.Particles/VertexLayouts/ParticleVertexBuilder.cs b/sources/engine/Stride.Particles/VertexLayouts/ParticleVertexBuilder.cs index 0fed13f750..6cd38abb63 100644 --- a/sources/engine/Stride.Particles/VertexLayouts/ParticleVertexBuilder.cs +++ b/sources/engine/Stride.Particles/VertexLayouts/ParticleVertexBuilder.cs @@ -101,7 +101,7 @@ public void UpdateVertexLayout() DefaultTexCoords = attrDesc; } - var stride = vertexElement.Format.SizeInBytes; + var stride = vertexElement.Format.SizeInBytes(); var attrAccs = new AttributeAccessor { Offset = totalOffset, Size = stride }; totalOffset += stride; diff --git a/sources/engine/Stride.Rendering/Rendering/ComputeEffect/LambertianPrefiltering/LambertianPrefilteringSH.cs b/sources/engine/Stride.Rendering/Rendering/ComputeEffect/LambertianPrefiltering/LambertianPrefilteringSH.cs index cfc0ec2d77..7d9735edf3 100644 --- a/sources/engine/Stride.Rendering/Rendering/ComputeEffect/LambertianPrefiltering/LambertianPrefilteringSH.cs +++ b/sources/engine/Stride.Rendering/Rendering/ComputeEffect/LambertianPrefiltering/LambertianPrefilteringSH.cs @@ -131,7 +131,7 @@ protected override void DrawCore(RenderDrawContext context) prefilteredLambertianSH = new SphericalHarmonics(HarmonicOrder); // Get the data out of the final buffer - var sizeResult = coefficientsCount * sumsToPerfomRemaining * PixelFormat.R32G32B32A32_Float.SizeInBytes; + var sizeResult = coefficientsCount * sumsToPerfomRemaining * PixelFormat.R32G32B32A32_Float.SizeInBytes(); var stagedBuffer = NewScopedBuffer(new BufferDescription(sizeResult, BufferFlags.None, GraphicsResourceUsage.Staging)); context.CommandList.CopyRegion(secondPassInputBuffer, 0, new ResourceRegion(0, 0, 0, sizeResult, 1, 1), stagedBuffer, 0); var finalsValues = stagedBuffer.GetData(context.CommandList); diff --git a/sources/engine/Stride.Rendering/Rendering/Images/LuminanceEffect/LuminanceEffect.cs b/sources/engine/Stride.Rendering/Rendering/Images/LuminanceEffect/LuminanceEffect.cs index f56ef37d76..8e58e11a1b 100644 --- a/sources/engine/Stride.Rendering/Rendering/Images/LuminanceEffect/LuminanceEffect.cs +++ b/sources/engine/Stride.Rendering/Rendering/Images/LuminanceEffect/LuminanceEffect.cs @@ -63,7 +63,7 @@ public PixelFormat LuminanceFormat get => luminanceFormat; set { - if (value.IsCompressed || value.IsPacked || value.IsTypeless || value == PixelFormat.None) + if (value.IsCompressed() || value.IsPacked() || value.IsTypeless() || value == PixelFormat.None) { throw new ArgumentOutOfRangeException(nameof(value), "Unsupported format [{0}] (must be not none, compressed, packed or typeless)".ToFormat(value)); } diff --git a/sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs b/sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs index 92b7f9df09..979faf4e6b 100644 --- a/sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs +++ b/sources/engine/Stride.Rendering/Rendering/RendererCoreBase.cs @@ -168,7 +168,7 @@ protected Buffer NewScopedBuffer(BufferDescription description, PixelFormat view /// A new instance of texture. protected Buffer NewScopedTypedBuffer(int count, PixelFormat viewFormat, bool isUnorderedAccess, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) { - return NewScopedBuffer(new BufferDescription(count * viewFormat.SizeInBytes, BufferFlags.ShaderResource | (isUnorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), usage), viewFormat); + return NewScopedBuffer(new BufferDescription(count * viewFormat.SizeInBytes(), BufferFlags.ShaderResource | (isUnorderedAccess ? BufferFlags.UnorderedAccess : BufferFlags.None), usage), viewFormat); } /// diff --git a/sources/engine/Stride.Rendering/Streaming/StreamingTexture.cs b/sources/engine/Stride.Rendering/Streaming/StreamingTexture.cs index 5ceca64cac..3b5cdbfe0c 100644 --- a/sources/engine/Stride.Rendering/Streaming/StreamingTexture.cs +++ b/sources/engine/Stride.Rendering/Streaming/StreamingTexture.cs @@ -140,7 +140,7 @@ public override int CalculateTargetResidency(StreamingQuality quality) var result = Math.Max(1, (int)(TotalMipLevels * quality)); // Compressed formats have aligment restrictions on the dimensions of the texture (minimum size must be 4) - if (Format.IsCompressed && TotalMipLevels >= 3) + if (Format.IsCompressed() && TotalMipLevels >= 3) result = MathUtil.Clamp(result, 3, TotalMipLevels); return result; diff --git a/sources/engine/Stride/Graphics/DDSHelper.cs b/sources/engine/Stride/Graphics/DDSHelper.cs index 462a751719..f6d989e9c5 100644 --- a/sources/engine/Stride/Graphics/DDSHelper.cs +++ b/sources/engine/Stride/Graphics/DDSHelper.cs @@ -331,7 +331,7 @@ private static unsafe bool DecodeDDSHeader(IntPtr headerPtr, int size, DDSFlags throw new InvalidOperationException("Unexpected ArraySize == 0 from DDS HeaderDX10 "); description.Format = headerDX10.DXGIFormat; - if (!description.Format.IsValid) + if (!description.Format.IsValid()) throw new InvalidOperationException("Invalid Format from DDS HeaderDX10 "); switch (headerDX10.ResourceDimension) @@ -676,7 +676,7 @@ private static unsafe void EncodeDDSHeader( ImageDescription description, DDSFla int newHeight; Image.ComputePitch(description.Format, description.Width, description.Height, out rowPitch, out slicePitch, out newWidth, out newHeight); - if (description.Format.IsCompressed) + if (description.Format.IsCompressed()) { header->Flags |= DDS.HeaderFlags.LinearSize; header->PitchOrLinearSize = slicePitch; @@ -1144,7 +1144,7 @@ private static unsafe Image CreateImageFromDDS(IntPtr pDDS, int offset, int size if (checkSize < 0) throw new InvalidOperationException("Unexpected end of buffer"); - if (metadata.Format.IsCompressed) + if (metadata.Format.IsCompressed()) { MemoryUtilities.CopyWithAlignmentFallback((void*)pDest, (void*)pSrc, (uint)Math.Min(images[index].BufferStride, imagesDst[index].BufferStride)); } diff --git a/sources/engine/Stride/Graphics/Image.cs b/sources/engine/Stride/Graphics/Image.cs index 7c5b57d0fb..33825a3a5b 100644 --- a/sources/engine/Stride/Graphics/Image.cs +++ b/sources/engine/Stride/Graphics/Image.cs @@ -763,7 +763,7 @@ static Image() internal unsafe void Initialize(ImageDescription description, IntPtr dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable, PitchFlags pitchFlags = PitchFlags.None, int rowStride = 0) { - if (!description.Format.IsValid || description.Format.IsVideoFormat) + if (!description.Format.IsValid() || description.Format.IsVideo()) throw new InvalidOperationException("Unsupported DXGI Format"); if (rowStride > 0 && description.MipLevels != 1) @@ -886,7 +886,7 @@ internal static void ComputePitch(PixelFormat format, int width, int height, out widthPacked = width; heightPacked = height; - if (format.IsCompressed) + if (format.IsCompressed()) { int minWidth = 1; int minHeight = 1; @@ -912,7 +912,7 @@ or PixelFormat.ETC2_RGB slicePitch = rowPitch * heightPacked; } - else if (format.IsPacked) + else if (format.IsPacked()) { rowPitch = ((width + 1) >> 1) * 4; @@ -929,7 +929,7 @@ or PixelFormat.ETC2_RGB else if (flags.HasFlag(PitchFlags.Bpp8)) bitsPerPixel = 8; else - bitsPerPixel = format.SizeInBits; + bitsPerPixel = format.SizeInBits(); if (flags.HasFlag(PitchFlags.LegacyDword)) { diff --git a/sources/engine/Stride/Graphics/PixelBuffer.cs b/sources/engine/Stride/Graphics/PixelBuffer.cs index fe314078f2..5c6b0d9890 100644 --- a/sources/engine/Stride/Graphics/PixelBuffer.cs +++ b/sources/engine/Stride/Graphics/PixelBuffer.cs @@ -71,7 +71,7 @@ public PixelBuffer(int width, int height, PixelFormat format, int rowStride, int this.rowStride = rowStride; this.bufferStride = bufferStride; this.dataPointer = dataPointer; - this.pixelSize = format.SizeInBytes; + this.pixelSize = format.SizeInBytes(); this.isStrictRowStride = (pixelSize * width) == rowStride; } diff --git a/sources/engine/Stride/Graphics/PixelFormatExtensions.cs b/sources/engine/Stride/Graphics/PixelFormatExtensions.cs index ea7df982ea..d1ae3b416d 100644 --- a/sources/engine/Stride/Graphics/PixelFormatExtensions.cs +++ b/sources/engine/Stride/Graphics/PixelFormatExtensions.cs @@ -45,7 +45,7 @@ public static class PixelFormatExtensions /// This property returns the size of each block in bytes. /// For non-compressed formats, this value corresponds to the size of a single pixel. /// - public int BlockSize => sizeInfos[GetIndex(format)].BlockSize; + public int BlockSize() => sizeInfos[GetIndex(format)].BlockSize; /// /// Gets the width, in pixels, of a single block for the . @@ -55,7 +55,7 @@ public static class PixelFormatExtensions /// This property returns the width of each block in pixels. /// For non-compressed formats, this value is always 1. /// - public int BlockWidth => sizeInfos[GetIndex(format)].BlockWidth; + public int BlockWidth() => sizeInfos[GetIndex(format)].BlockWidth; /// /// Gets the height, in pixels, of a single block for the . /// @@ -64,30 +64,24 @@ public static class PixelFormatExtensions /// This property returns the height of each block in pixels. /// For non-compressed formats, this value is always 1. /// - public int BlockHeight => sizeInfos[GetIndex(format)].BlockHeight; + public int BlockHeight() => sizeInfos[GetIndex(format)].BlockHeight; /// /// Gets the size of the in bytes. /// - public int SizeInBytes + public int SizeInBytes() { - get - { - var sizeInfo = sizeInfos[GetIndex(format)]; - return sizeInfo.BlockSize / (sizeInfo.BlockWidth * sizeInfo.BlockHeight); - } + var sizeInfo = sizeInfos[GetIndex(format)]; + return sizeInfo.BlockSize / (sizeInfo.BlockWidth * sizeInfo.BlockHeight); } /// /// Gets the size of the in bits. /// - public int SizeInBits + public int SizeInBits() { - get - { - var sizeInfo = sizeInfos[GetIndex(format)]; - return sizeInfo.BlockSize * 8 / (sizeInfo.BlockWidth * sizeInfo.BlockHeight); - } + var sizeInfo = sizeInfos[GetIndex(format)]; + return sizeInfo.BlockSize * 8 / (sizeInfo.BlockWidth * sizeInfo.BlockHeight); } /// @@ -97,7 +91,7 @@ public int SizeInBits /// The size of the alpha channel in bits. /// If the format does not have an alpha channel, this value is 0. /// - public int AlphaSizeInBits => format switch + public int AlphaSizeInBits() => format switch { R32G32B32A32_Typeless or R32G32B32A32_Float or R32G32B32A32_UInt or R32G32B32A32_SInt => 32, @@ -127,7 +121,7 @@ B8G8R8A8_UNorm or B8G8R8A8_Typeless or B8G8R8A8_UNorm_SRgb or /// /// Gets a value indicating if the is a compressed format. /// - public bool IsCompressed => sizeInfos[GetIndex(format)].IsCompressed; + public bool IsCompressed() => sizeInfos[GetIndex(format)].IsCompressed; /// /// Gets a value indicating if the is a valid pixel format. @@ -136,21 +130,30 @@ B8G8R8A8_UNorm or B8G8R8A8_Typeless or B8G8R8A8_UNorm_SRgb or /// if the format is valid, i.e., recognized by Stride; /// otherwise. /// - public bool IsValid + public bool IsValid() => ((int) format >= 1 && (int) format <= 115) // DirectX formats || ((int) format >= 1088 && (int) format <= 1097); // ETC formats + /// + /// Returns true if the is an uncompressed 32-bit color with an Alpha channel. + /// + /// True if the is an uncompressed 32-bit color with an Alpha channel + public bool HasAlpha32Bits() + { + return format.Is32bppWithAlpha(); + } + /// /// Gets a value indicating if the is an /// uncompressed 32-bit-per-pixel (8-bit per channel) color format /// with an Alpha channel. /// - public bool Is32bppWithAlpha => alpha32Formats[GetIndex(format)]; + public bool Is32bppWithAlpha() => alpha32Formats[GetIndex(format)]; /// /// Gets a value indicating if the has an Alpha channel. /// - public bool HasAlpha => format.AlphaSizeInBits != 0; + public bool HasAlpha() => format.AlphaSizeInBits() != 0; /// /// Gets a value indicating if the uses packed color channels. @@ -160,7 +163,7 @@ public bool IsValid /// which can affect how pixel data is accessed and processed. /// Use this property to determine if special handling is required for reading or writing pixel values. /// - public bool IsPacked => format is R8G8_B8G8_UNorm or G8R8_G8B8_UNorm; + public bool IsPacked() => format is R8G8_B8G8_UNorm or G8R8_G8B8_UNorm; /// /// Gets a value indicating if the is a video format. @@ -170,42 +173,39 @@ public bool IsValid /// This property helps identify formats that may have specific requirements or optimizations, /// and may not be suitable for rendering by the 3D pipeline. /// - public bool IsVideoFormat + public bool IsVideo() { - get - { #if DIRECTX11_1 - switch (format) - { - case PixelFormat.AYUV: - case PixelFormat.Y410: - case PixelFormat.Y416: - case PixelFormat.NV12: - case PixelFormat.P010: - case PixelFormat.P016: - case PixelFormat.YUY2: - case PixelFormat.Y210: - case PixelFormat.Y216: - case PixelFormat.NV11: - // These video formats can be used with the 3D pipeline through special view mappings - return true; - - case PixelFormat.Opaque420: - case PixelFormat.AI44: - case PixelFormat.IA44: - case PixelFormat.P8: - case PixelFormat.A8P8: - // These are limited use video formats not usable in any way by the 3D pipeline - return true; - - default: - return false; - } + switch (format) + { + case PixelFormat.AYUV: + case PixelFormat.Y410: + case PixelFormat.Y416: + case PixelFormat.NV12: + case PixelFormat.P010: + case PixelFormat.P016: + case PixelFormat.YUY2: + case PixelFormat.Y210: + case PixelFormat.Y216: + case PixelFormat.NV11: + // These video formats can be used with the 3D pipeline through special view mappings + return true; + + case PixelFormat.Opaque420: + case PixelFormat.AI44: + case PixelFormat.IA44: + case PixelFormat.P8: + case PixelFormat.A8P8: + // These are limited use video formats not usable in any way by the 3D pipeline + return true; + + default: + return false; + } #else - // !DXGI_1_2_FORMATS - return false; + // !DXGI_1_2_FORMATS + return false; #endif - } } /// @@ -217,7 +217,7 @@ public bool IsVideoFormat /// These kind of formats are typically used for Textures and Images that are displayed on screen, /// but not for Render Targets or Buffers involved in intermediate rendering calculations. /// - public bool IsSRgb => srgbFormats[GetIndex(format)]; + public bool IsSRgb() => srgbFormats[GetIndex(format)]; /// /// Gets a value indicating if the is an HDR format @@ -228,7 +228,7 @@ public bool IsVideoFormat /// These formats are typically used in high-dynamic-range rendering scenarios, /// such as when rendering scenes with significant contrast between light and dark areas. /// - public bool IsHDR => hdrFormats[GetIndex(format)]; + public bool IsHDR() => hdrFormats[GetIndex(format)]; /// /// Gets a value indicating if the is a typeless format. @@ -239,7 +239,7 @@ public bool IsVideoFormat /// as different types depending on the context, such as when creating /// a resource that can be viewed in multiple ways. /// - public bool IsTypeless => typelessFormats[GetIndex(format)]; + public bool IsTypeless() => typelessFormats[GetIndex(format)]; /// /// Gets a value indicating if the has an equivalent sRGB format. @@ -251,8 +251,8 @@ public bool IsVideoFormat /// /// The provided pixel format is already an sRGB format. /// - public bool HasSRgbEquivalent - => format.IsSRgb + public bool HasSRgbEquivalent() + => format.IsSRgb() ? throw new ArgumentException($"'{format}' is already an sRGB pixel format", nameof(format)) : sRgbConversion.ContainsKey(format); @@ -266,8 +266,8 @@ public bool HasSRgbEquivalent /// /// The provided pixel format is not an sRGB format. /// - public bool HasNonSRgbEquivalent - => !format.IsSRgb + public bool HasNonSRgbEquivalent() + => !format.IsSRgb() ? throw new ArgumentException($"'{format}' is not a sRGB format", nameof(format)) : sRgbConversion.ContainsKey(format); @@ -278,7 +278,7 @@ public bool HasNonSRgbEquivalent /// The equivalent sRGB format if it exists, or the provided pixel format otherwise. /// public PixelFormat ToSRgb() - => format.IsSRgb || !sRgbConversion.TryGetValue(format, out var srgbFormat) + => format.IsSRgb() || !sRgbConversion.TryGetValue(format, out var srgbFormat) ? format : srgbFormat; @@ -289,7 +289,7 @@ public PixelFormat ToSRgb() /// The equivalent non-sRGB format if it exists, or the provided pixel format otherwise. /// public PixelFormat ToNonSRgb() - => !format.IsSRgb || !sRgbConversion.TryGetValue(format, out var nonSrgbFormat) + => !format.IsSRgb() || !sRgbConversion.TryGetValue(format, out var nonSrgbFormat) ? format : nonSrgbFormat; @@ -316,7 +316,7 @@ public void ComputePitch(int width, int height, out int rowPitch, out int sliceP /// /// Gets a value indicating if the has its components in the RGBA order. /// - public bool IsRgbaOrder => format switch + public bool IsRGBAOrder() => format switch { R32G32B32A32_Typeless or R32G32B32A32_Float or R32G32B32A32_UInt or R32G32B32A32_SInt or R32G32B32_Typeless or R32G32B32_Float or R32G32B32_UInt or R32G32B32_SInt or @@ -333,7 +333,7 @@ R11G11B10_Float or /// /// Gets a value indicating if the has its components in the BGRA order. /// - public bool IsBgraOrder => format switch + public bool IsBGRAOrder() => format switch { B8G8R8A8_UNorm or B8G8R8X8_UNorm or B8G8R8A8_Typeless or B8G8R8A8_UNorm_SRgb or B8G8R8X8_Typeless or B8G8R8X8_UNorm_SRgb => true, _ => false, diff --git a/sources/tests/tools/Stride.TextureConverter.Tests/TexLibraryTest.cs b/sources/tests/tools/Stride.TextureConverter.Tests/TexLibraryTest.cs index eb7b39f127..b250ce52ad 100644 --- a/sources/tests/tools/Stride.TextureConverter.Tests/TexLibraryTest.cs +++ b/sources/tests/tools/Stride.TextureConverter.Tests/TexLibraryTest.cs @@ -66,9 +66,9 @@ public static void FixedRescaleTest(TexImage image, ITexLibrary library, Filter. public static void SwitchChannelsTest(TexImage image, ITexLibrary library) { - var isInRgbaOrder = image.Format.IsRgbaOrder; + var isInRgbaOrder = image.Format.IsRGBAOrder(); library.Execute(image, new SwitchingBRChannelsRequest()); - Assert.True(image.Format.IsRgbaOrder != isInRgbaOrder); + Assert.True(image.Format.IsRGBAOrder() != isInRgbaOrder); //Console.WriteLine("SwitchChannelsTest_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize)); Assert.Equal(TestTools.GetInstance().Checksum["SwitchChannelsTest_" + image.Name], TestTools.ComputeSHA1(image.Data, image.DataSize)); @@ -84,7 +84,7 @@ public static void FlipTest(TexImage image, ITexLibrary library, Orientation ori public static void DecompressTest(TexImage image, ITexLibrary library) { - Assert.True(image.Format.IsCompressed); + Assert.True(image.Format.IsCompressed()); library.Execute(image, new DecompressingRequest(false)); Assert.True(image.Format == PixelFormat.R8G8B8A8_UNorm); Assert.Equal(TestTools.GetInstance().Checksum["DecompressTest_" + image.Name], TestTools.ComputeSHA1(image.Data, image.DataSize)); @@ -93,7 +93,7 @@ public static void DecompressTest(TexImage image, ITexLibrary library) public static void CompressTest(TexImage image, ITexLibrary library, PixelFormat format) { - Assert.True(!image.Format.IsCompressed); + Assert.True(!image.Format.IsCompressed()); library.Execute(image, new CompressingRequest(format)); Assert.True(image.Format == format); @@ -104,7 +104,7 @@ public static void CompressTest(TexImage image, ITexLibrary library, PixelFormat public static void GenerateMipMapTest(TexImage image, ITexLibrary library, Filter.MipMapGeneration filter) { Assert.True(image.MipmapCount == 1); - if (image.Format.IsCompressed) library.Execute(image, new DecompressingRequest(false)); + if (image.Format.IsCompressed()) library.Execute(image, new DecompressingRequest(false)); library.Execute(image, new MipMapsGenerationRequest(filter)); Assert.True(image.MipmapCount > 1); Assert.Equal(TestTools.GetInstance().Checksum["GenerateMipMapTest_" + filter + "_" + image.Name], TestTools.ComputeSHA1(image.Data, image.DataSize)); diff --git a/sources/tests/tools/Stride.TextureConverter.Tests/TextureToolTest.cs b/sources/tests/tools/Stride.TextureConverter.Tests/TextureToolTest.cs index d3aea686db..3217dfd3d1 100644 --- a/sources/tests/tools/Stride.TextureConverter.Tests/TextureToolTest.cs +++ b/sources/tests/tools/Stride.TextureConverter.Tests/TextureToolTest.cs @@ -245,12 +245,12 @@ public void ResizeTest(string file) public void SwitchChannelTest(string file) { var image = texTool.Load(Module.PathToInputImages + file); - var isInBgraOrder = image.Format.IsBgraOrder; + var isInBgraOrder = image.Format.IsBGRAOrder(); texTool.SwitchChannel(image); image.Update(); - Assert.True(isInBgraOrder != image.Format.IsBgraOrder); + Assert.True(isInBgraOrder != image.Format.IsBGRAOrder()); Assert.Equal(TestTools.GetInstance().Checksum["TextureTool_SwitchChannel_" + image.Name], TestTools.ComputeSHA1(image.Data, image.DataSize)); //Console.WriteLine("TextureTool_SwitchChannel_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize)); diff --git a/sources/tools/Stride.TextureConverter/Backend/Requests/DecompressingRequest.cs b/sources/tools/Stride.TextureConverter/Backend/Requests/DecompressingRequest.cs index de6ce590c5..17ba6851a9 100644 --- a/sources/tools/Stride.TextureConverter/Backend/Requests/DecompressingRequest.cs +++ b/sources/tools/Stride.TextureConverter/Backend/Requests/DecompressingRequest.cs @@ -24,7 +24,7 @@ internal class DecompressingRequest : IRequest /// Input pixel format. public DecompressingRequest(bool isSRgb, PixelFormat pixelFormat = PixelFormat.None) { - if (pixelFormat.IsHDR) + if (pixelFormat.IsHDR()) DecompressedFormat = PixelFormat.R16G16B16A16_Float; else DecompressedFormat = isSRgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm; diff --git a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs index ead3419e1a..b0538b9fb8 100644 --- a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs +++ b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs @@ -290,12 +290,12 @@ private void Load(TexImage image, LoadingRequest loader) UpdateImage(image, libraryData); var alphaSize = DDSHeader.GetAlphaDepth(loader.FilePath); - image.OriginalAlphaDepth = alphaSize != -1 ? alphaSize : image.Format.AlphaSizeInBits; + image.OriginalAlphaDepth = alphaSize != -1 ? alphaSize : image.Format.AlphaSizeInBits(); } private static void ChangeDxtImageType(DxtTextureLibraryData libraryData, DXGI_FORMAT dxgiFormat) { - if (((PixelFormat)libraryData.Metadata.format).SizeInBits != ((PixelFormat)dxgiFormat).SizeInBits) + if (((PixelFormat)libraryData.Metadata.format).SizeInBits() != ((PixelFormat)dxgiFormat).SizeInBits()) throw new ArgumentException("Impossible to change image data format. The two formats '{0}' and '{1}' are not compatibles.".ToFormat(libraryData.Metadata.format, dxgiFormat)); libraryData.Metadata.format = dxgiFormat; @@ -320,7 +320,7 @@ private void Compress(TexImage image, DxtTextureLibraryData libraryData, Compres ScratchImage scratchImage = new ScratchImage(); HRESULT hr; - if (request.Format.IsCompressed) + if (request.Format.IsCompressed()) { var topImage = libraryData.DxtImages[0]; if (topImage.Width % 4 != 0 || topImage.Height % 4 != 0) @@ -422,7 +422,7 @@ private void Rescale(TexImage image, DxtTextureLibraryData libraryData, Rescalin private void Convert(TexImage image, DxtTextureLibraryData libraryData, ConvertingRequest request) { // TODO: temp if request format is SRGB we force it to non-srgb to perform the conversion. Will not work if texture input is SRGB - var outputFormat = request.Format.IsSRgb ? request.Format.ToNonSRgb() : request.Format; + var outputFormat = request.Format.IsSRgb() ? request.Format.ToNonSRgb() : request.Format; Log.Verbose($"Converting texture from {(PixelFormat)libraryData.Metadata.format} to {outputFormat}"); @@ -461,7 +461,7 @@ private void Decompress(TexImage image, DxtTextureLibraryData libraryData, Decom Log.Verbose("Decompressing texture ..."); // determine the output format to avoid any sRGB/RGB conversions (only decompression, no conversion) - var outputFormat = !((PixelFormat)libraryData.Metadata.format).IsSRgb ? request.DecompressedFormat.ToNonSRgb() : request.DecompressedFormat.ToSRgb(); + var outputFormat = !((PixelFormat)libraryData.Metadata.format).IsSRgb() ? request.DecompressedFormat.ToNonSRgb() : request.DecompressedFormat.ToSRgb(); var scratchImage = new ScratchImage(); var hr = Utilities.Decompress(libraryData.DxtImages, libraryData.DxtImages.Length, ref libraryData.Metadata, (DXGI_FORMAT)outputFormat, scratchImage); @@ -784,7 +784,7 @@ private void UpdateImage(TexImage image, DxtTextureLibraryData libraryData) image.MipmapCount = libraryData.Metadata.MipLevels; image.ArraySize = libraryData.Metadata.ArraySize; image.SlicePitch = libraryData.DxtImages[0].SlicePitch; - image.OriginalAlphaDepth = Math.Min(image.OriginalAlphaDepth, image.Format.AlphaSizeInBits); + image.OriginalAlphaDepth = Math.Min(image.OriginalAlphaDepth, image.Format.AlphaSizeInBits()); } diff --git a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/FITexLib.cs b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/FITexLib.cs index fc782b9d97..651fa86fb7 100644 --- a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/FITexLib.cs +++ b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/FITexLib.cs @@ -55,7 +55,7 @@ public void Dispose(TexImage image) public void StartLibrary(TexImage image) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Error("FreeImage can't process compressed texture."); throw new TextureToolsException("FreeImage can't process compressed texture."); @@ -380,7 +380,7 @@ private void SwitchChannels(TexImage image, FreeImageTextureLibraryData libraryD FreeImage.Unload(redChannel); } - if (image.Format.IsBgraOrder) + if (image.Format.IsBGRAOrder()) image.Format = Graphics.PixelFormat.R8G8B8A8_UNorm; else image.Format = Graphics.PixelFormat.B8G8R8A8_UNorm; @@ -506,7 +506,7 @@ private void Export(TexImage image, FreeImageTextureLibraryData libraryData, Exp throw new TextureToolsException("Not implemented."); } - if (!image.Format.IsBgraOrder) + if (!image.Format.IsBGRAOrder()) { SwitchChannels(image, libraryData, new SwitchingBRChannelsRequest()); } diff --git a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/PvrttTexLib.cs b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/PvrttTexLib.cs index 1f22c4f1fc..44ea81a27d 100644 --- a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/PvrttTexLib.cs +++ b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/PvrttTexLib.cs @@ -916,7 +916,7 @@ private Stride.Graphics.PixelFormat RetrieveFormatFromNativeData(PVRTextureHeade private EPVRTColourSpace RetrieveNativeColorSpace(Stride.Graphics.PixelFormat format) { - return format.IsSRgb ? EPVRTColourSpace.SRgb : EPVRTColourSpace.Linear; + return format.IsSRgb() ? EPVRTColourSpace.SRgb : EPVRTColourSpace.Linear; } } } diff --git a/sources/tools/Stride.TextureConverter/Backend/Tools.cs b/sources/tools/Stride.TextureConverter/Backend/Tools.cs index f6d4d2816b..0f5c211d7e 100644 --- a/sources/tools/Stride.TextureConverter/Backend/Tools.cs +++ b/sources/tools/Stride.TextureConverter/Backend/Tools.cs @@ -25,9 +25,9 @@ public static void ComputePitch(PixelFormat fmt, int width, int height, out int int widthCount = width; int heightCount = height; - int bpp = fmt.SizeInBits; + int bpp = fmt.SizeInBits(); - if (fmt.IsCompressed) + if (fmt.IsCompressed()) { widthCount = Math.Max(1, (width + 3) / 4); heightCount = Math.Max(1, (height + 3) / 4); @@ -35,7 +35,7 @@ public static void ComputePitch(PixelFormat fmt, int width, int height, out int slicePitch = rowPitch * heightCount; } - else if (fmt.IsPacked) + else if (fmt.IsPacked()) { rowPitch = ((width + 1) >> 1) * 4; @@ -44,7 +44,7 @@ public static void ComputePitch(PixelFormat fmt, int width, int height, out int else { if (bpp == 0) - bpp = fmt.SizeInBits; + bpp = fmt.SizeInBits(); rowPitch = (width * bpp + 7) / 8; slicePitch = rowPitch * height; @@ -61,7 +61,7 @@ public static void ComputePitch(PixelFormat fmt, int width, int height, out int /// public static bool IsInSameChannelOrder(PixelFormat format1, PixelFormat format2) { - return format1.IsBgraOrder && format2.IsBgraOrder || format1.IsRgbaOrder && format2.IsRgbaOrder; + return format1.IsBGRAOrder() && format2.IsBGRAOrder() || format1.IsRGBAOrder() && format2.IsRGBAOrder(); } } } diff --git a/sources/tools/Stride.TextureConverter/Frontend/TexImage.cs b/sources/tools/Stride.TextureConverter/Frontend/TexImage.cs index 4e7b22e91d..6174955106 100644 --- a/sources/tools/Stride.TextureConverter/Frontend/TexImage.cs +++ b/sources/tools/Stride.TextureConverter/Frontend/TexImage.cs @@ -373,7 +373,7 @@ public bool IsPowerOfTwo() public int GetAlphaDepth() { // TODO: Improve this function so that it checks that actual data (will probably need to add the region to check as parameter) - int alphaDepth = Format.AlphaSizeInBits; + int alphaDepth = Format.AlphaSizeInBits(); if (OriginalAlphaDepth == -1) return alphaDepth; diff --git a/sources/tools/Stride.TextureConverter/Frontend/TextureTool.cs b/sources/tools/Stride.TextureConverter/Frontend/TextureTool.cs index 69d9266703..f4a3e2ac0e 100644 --- a/sources/tools/Stride.TextureConverter/Frontend/TextureTool.cs +++ b/sources/tools/Stride.TextureConverter/Frontend/TextureTool.cs @@ -390,7 +390,7 @@ private TexImage Load(LoadingRequest request) /// Indicate is the image to decompress is an sRGB image public void Decompress(TexImage image, bool isSRgb) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { ExecuteRequest(image, new DecompressingRequest(isSRgb, image.Format)); } @@ -427,10 +427,10 @@ public void Save(TexImage image, String fileName, int minimumMipMapSize=1) var request = new ExportRequest(fileName, minimumMipMapSize); - if (FindLibrary(image, request) == null && image.Format.IsCompressed) + if (FindLibrary(image, request) == null && image.Format.IsCompressed()) { Log.Warning("No library can export this texture with the actual compression format. We will try to decompress it first."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, request); @@ -458,17 +458,17 @@ public void Save(TexImage image, String fileName, PixelFormat format, int minimu throw new TextureToolsException("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain."); } - if (image.Format != format && format.IsCompressed && !image.Format.IsCompressed) + if (image.Format != format && format.IsCompressed() && !image.Format.IsCompressed()) { TexImage workingImage = (TexImage)image.Clone(); Compress(workingImage, format); ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize)); workingImage.Dispose(); } - else if (image.Format != format && format.IsCompressed) + else if (image.Format != format && format.IsCompressed()) { TexImage workingImage = (TexImage)image.Clone(); - Decompress(workingImage, image.Format.IsSRgb); + Decompress(workingImage, image.Format.IsSRgb()); Compress(workingImage, format); ExecuteRequest(workingImage, new ExportRequest(fileName, minimumMipMapSize)); workingImage.Dispose(); @@ -490,10 +490,10 @@ public void Save(TexImage image, String fileName, PixelFormat format, int minimu /// The image. public void SwitchChannel(TexImage image) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't switch channels of a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, new SwitchingBRChannelsRequest()); @@ -513,10 +513,10 @@ public void Compress(TexImage image, PixelFormat format, TextureQuality quality { if (image.Format == format) return; - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't compress an already compressed texture. It will be decompressed first.."); - Decompress(image, format.IsSRgb); + Decompress(image, format.IsSRgb()); } var request = new CompressingRequest(format, quality); @@ -531,10 +531,10 @@ public void Compress(TexImage image, PixelFormat format, TextureQuality quality /// The color key. public void ColorKey(TexImage image, Color colorKey) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't compress an already compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } if (image.Format != PixelFormat.R8G8B8A8_UNorm && image.Format != PixelFormat.B8G8R8A8_UNorm @@ -558,10 +558,10 @@ public void ColorKey(TexImage image, Color colorKey) /// The filter. public void GenerateMipMaps(TexImage image, Filter.MipMapGeneration filter) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't generate mipmaps for a compressed texture. It will be decompressed first."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, new MipMapsGenerationRequest(filter)); @@ -592,10 +592,10 @@ public void Resize(TexImage image, int width, int height, Filter.Rescaling filte return; } - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't resize a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, new FixedRescalingRequest(width, height, filter)); @@ -627,10 +627,10 @@ public void Rescale(TexImage image, float widthFactor, float heightFactor, Filte return; } - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't rescale a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, new FactorRescalingRequest(widthFactor, heightFactor, filter)); @@ -651,10 +651,10 @@ public TexImage GenerateNormalMap(TexImage heightMap, float amplitude) throw new TextureToolsException("The amplitude must be a positive float."); } - if (heightMap.Format.IsCompressed) + if (heightMap.Format.IsCompressed()) { Log.Warning("You can't generate a normal map from a compressed height hmap. It will be decompressed first.."); - Decompress(heightMap, heightMap.Format.IsSRgb); + Decompress(heightMap, heightMap.Format.IsSRgb()); } var request = new NormalMapGenerationRequest(amplitude); @@ -671,10 +671,10 @@ public TexImage GenerateNormalMap(TexImage heightMap, float amplitude) /// The image. public void PreMultiplyAlpha(TexImage image) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't premultiply alpha on a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } ExecuteRequest(image, new PreMultiplyAlphaRequest()); @@ -687,7 +687,7 @@ public void PreMultiplyAlpha(TexImage image) /// The containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image. public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage) { - if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed) + if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed()) throw new NotImplementedException(); var alphaImage = (TexImage)texImage.Clone(true); @@ -761,8 +761,8 @@ public unsafe AlphaLevels GetAlphaLevels(TexImage texture, Rectangle region, Col // check that we support the format var format = texture.Format; - var pixelSize = format.SizeInBytes; - if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRgbaOrder || format.IsBgraOrder || pixelSize != 4)) + var pixelSize = format.SizeInBytes(); + if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || pixelSize != 4)) { var guessedAlphaLevel = alphaDepth > 0 ? AlphaLevels.InterpolatedAlpha : AlphaLevels.NoAlpha; logger?.Debug($"Unable to find alpha levels for texture type {format}. Returning default alpha level '{guessedAlphaLevel}'."); @@ -780,7 +780,7 @@ public unsafe AlphaLevels GetAlphaLevels(TexImage texture, Rectangle region, Col if (tranparencyColor.HasValue) // specific case when using a transparency color { - var transparencyValue = format.IsRgbaOrder ? tranparencyColor.Value.ToRgba() : tranparencyColor.Value.ToBgra(); + var transparencyValue = format.IsRGBAOrder() ? tranparencyColor.Value.ToRgba() : tranparencyColor.Value.ToBgra(); for (int y = 0; y < region.Height; ++y) { @@ -837,7 +837,7 @@ public unsafe Color PickColor(TexImage texture, Int2 pixel) if (texture == null) throw new ArgumentNullException(nameof(texture)); var format = texture.Format; - if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRgbaOrder || format.IsBgraOrder || format.SizeInBytes != 4)) + if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || format.SizeInBytes() != 4)) throw new NotImplementedException(); // check that the pixel is inside the texture @@ -849,7 +849,7 @@ public unsafe Color PickColor(TexImage texture, Int2 pixel) var stride = texture.RowPitch / 4; var pixelColorInt = ptr[stride*pixel.Y + pixel.X]; - var pixelColor = format.IsRgbaOrder ? Color.FromRgba(pixelColorInt) : Color.FromBgra(pixelColorInt); + var pixelColor = format.IsRGBAOrder() ? Color.FromRgba(pixelColorInt) : Color.FromBgra(pixelColorInt); return pixelColor; } @@ -868,12 +868,12 @@ public unsafe Rectangle FindSpriteRegion(TexImage texture, Int2 pixel, Color? se if (texture == null) throw new ArgumentNullException(nameof(texture)); var format = texture.Format; - if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRgbaOrder || format.IsBgraOrder || format.SizeInBytes != 4)) + if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || format.SizeInBytes() != 4)) throw new NotImplementedException(); // adjust the separator color the mask depending on the color format. var separator = (uint)(separatorColor ?? Color.Transparent).ToRgba(); - if (texture.Format.IsBgraOrder) + if (texture.Format.IsBGRAOrder()) { separator = RgbaToBgra(separator); separatorMask = RgbaToBgra(separatorMask); @@ -968,7 +968,7 @@ public unsafe Rectangle FindSpriteRegion(TexImage texture, Int2 pixel, Color? se /// The extracted region . Note: it is the user responsibility to dispose the returned image. public unsafe Image CreateImageFromRegion(TexImage texImage, Rectangle region) { - if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed) + if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed()) throw new NotImplementedException(); Log.Info("Extracting region and exporting to Stride Image ..."); @@ -1043,10 +1043,10 @@ public void CorrectGamma(TexImage image, double gamma) throw new TextureToolsException("The gamma must be a positive float."); } - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't correct gamme on a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } var request = new GammaCorrectionRequest(gamma); @@ -1062,10 +1062,10 @@ public void CorrectGamma(TexImage image, double gamma) /// The orientation . public void Flip(TexImage image, Orientation orientation) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't flip a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } var request = new FlippingRequest(orientation); @@ -1081,10 +1081,10 @@ public void Flip(TexImage image, Orientation orientation) /// The orientation . public void FlipSub(TexImage image, int index, Orientation orientation) { - if (image.Format.IsCompressed) + if (image.Format.IsCompressed()) { Log.Warning("You can't flip a compressed texture. It will be decompressed first.."); - Decompress(image, image.Format.IsSRgb); + Decompress(image, image.Format.IsSRgb()); } var request = new FlippingSubRequest(index, orientation); @@ -1173,9 +1173,9 @@ public TexImage Extract(TexAtlas atlas, string name, int minimumMipmapSize = 1) var request = new AtlasExtractionRequest(name, minimumMipmapSize); - if (atlas.Format.IsCompressed) + if (atlas.Format.IsCompressed()) { - Decompress(atlas, atlas.Format.IsSRgb); + Decompress(atlas, atlas.Format.IsSRgb()); } ExecuteRequest(atlas, request); @@ -1235,10 +1235,10 @@ public List ExtractAll(TexAtlas atlas, int minimumMipmapSize = 1) var request = new AtlasExtractionRequest(minimumMipmapSize); - if (atlas.Format.IsCompressed) + if (atlas.Format.IsCompressed()) { Log.Warning("You can't extract a texture from a compressed atlas. The atlas will be decompressed first.."); - Decompress(atlas, atlas.Format.IsSRgb); + Decompress(atlas, atlas.Format.IsSRgb()); } ExecuteRequest(atlas, request); @@ -1264,9 +1264,9 @@ public List ExtractAll(TexImage array, int minimumMipmapSize = 1) var request = new ArrayExtractionRequest(minimumMipmapSize); - if (array.Format.IsCompressed) + if (array.Format.IsCompressed()) { - Decompress(array, array.Format.IsSRgb); + Decompress(array, array.Format.IsSRgb()); } ExecuteRequest(array, request); @@ -1410,14 +1410,14 @@ private void CheckConformity(TexImage model, TexImage candidate) if (candidate.Format != model.Format) { Log.Warning("The given texture format isn't correct. The texture will be converted.."); - if (model.Format.IsCompressed) + if (model.Format.IsCompressed()) { - if (candidate.Format.IsCompressed) Decompress(candidate, candidate.Format.IsSRgb); + if (candidate.Format.IsCompressed()) Decompress(candidate, candidate.Format.IsSRgb()); Compress(candidate, model.Format); } else { - Decompress(candidate, candidate.Format.IsSRgb); + Decompress(candidate, candidate.Format.IsSRgb()); if (candidate.Format != model.Format) Compress(candidate, model.Format); } } @@ -1442,7 +1442,7 @@ private void ExecuteRequest(TexImage image, IRequest request) ITexLibrary library; if ((library = FindLibrary(image, request)) != null) { - if (image.Format.IsBgraOrder && !library.SupportBGRAOrder()) + if (image.Format.IsBGRAOrder() && !library.SupportBGRAOrder()) { SwitchChannel(image); } @@ -1487,7 +1487,7 @@ private void ExecuteRequest(TexImage image, IRequest request) } // Both libraries for intermediate processing were found, preceeding with the request - if (image.Format.IsBgraOrder && !library.SupportBGRAOrder()) + if (image.Format.IsBGRAOrder() && !library.SupportBGRAOrder()) { SwitchChannel(image); }