From 53deac91e7253cdd7810d452463778c1c690db6a Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 5 Aug 2024 17:45:35 -0700 Subject: [PATCH] Additional code review for OpenEXR --- Auxiliary/DirectXTexEXR.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Auxiliary/DirectXTexEXR.cpp b/Auxiliary/DirectXTexEXR.cpp index ee3b5a54..cd4655b2 100644 --- a/Auxiliary/DirectXTexEXR.cpp +++ b/Auxiliary/DirectXTexEXR.cpp @@ -265,14 +265,25 @@ HRESULT DirectX::GetMetadataFromEXRFile(const wchar_t* szFile, TexMetadata& meta const auto dw = file.dataWindow(); const int width = dw.max.x - dw.min.x + 1; - const int height = dw.max.y - dw.min.y + 1; + int height = dw.max.y - dw.min.y + 1; + size_t arraySize = 1; if (width < 1 || height < 1) return E_FAIL; + if (file.header().find("envmap") != file.header().end()) + { + if (width == height / 6) + { + height = width; + arraySize = 6; + } + } + metadata.width = static_cast(width); metadata.height = static_cast(height); - metadata.depth = metadata.arraySize = metadata.mipLevels = 1; + metadata.depth = metadata.mipLevels = 1; + metadata.arraySize = arraySize; metadata.format = DXGI_FORMAT_R16G16B16A16_FLOAT; metadata.dimension = TEX_DIMENSION_TEXTURE2D; } @@ -371,7 +382,7 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S auto const dw = file.dataWindow(); - int width = dw.max.x - dw.min.x + 1; + const int width = dw.max.x - dw.min.x + 1; int height = dw.max.y - dw.min.y + 1; size_t arraySize = 1; @@ -383,8 +394,8 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S if (width == height / 6) { height = width; + arraySize = 6; } - arraySize = 6; } if (metadata)