From 798f6ea5bbda00574531de8fce30b277cb42c727 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 18 Jan 2022 15:41:37 -0600 Subject: [PATCH] Added support for additional formats Signed-off-by: Chris Galvan --- .../RPI.Reflect/Image/StreamingImageAsset.cpp | 109 ++++++++---------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp index e21dd1f2c5..4e664ad3e2 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp @@ -51,58 +51,29 @@ namespace AZ return 0; } - template <> - AZ::u32 RetrieveUintValue(const AZ::u8* mem, size_t index) - { - return mem[index] / static_cast(std::numeric_limits::max()); - } - - template <> - AZ::u32 RetrieveUintValue(const AZ::u8* mem, size_t index) - { - // 16 bits per channel - auto actualMem = reinterpret_cast(mem); - - return actualMem[index] / static_cast(std::numeric_limits::max()); - } - - template <> - AZ::s32 RetrieveIntValue(const AZ::u8* mem, size_t index) - { - // 16 bits per channel - auto actualMem = reinterpret_cast(mem); - - return actualMem[index] / static_cast(std::numeric_limits::max()); - } - - template <> - float RetrieveFloatValue(const AZ::u8* mem, size_t index) - { - // 32 bits per channel - auto actualMem = reinterpret_cast(mem); - actualMem += index; - - return *actualMem; - } - - template <> - float RetrieveFloatValue(const AZ::u8* mem, size_t index) - { - // 32 bits per channel - auto actualMem = reinterpret_cast(mem); - actualMem += index; - - return *actualMem; - } - float RetrieveFloatValue(const AZ::u8* mem, size_t index, AZ::RHI::Format format) { switch (format) { - case AZ::RHI::Format::R32_UINT: - return RetrieveFloatValue(mem, index); + case AZ::RHI::Format::R8_UNORM: + case AZ::RHI::Format::R8_SNORM: + case AZ::RHI::Format::A8_UNORM: + { + return mem[index] / static_cast(std::numeric_limits::max()); + } + case AZ::RHI::Format::R16_FLOAT: + case AZ::RHI::Format::D16_UNORM: + case AZ::RHI::Format::R16_UNORM: + case AZ::RHI::Format::R16_SNORM: + { + return mem[index] / static_cast(std::numeric_limits::max()); + } + case AZ::RHI::Format::D32_FLOAT: case AZ::RHI::Format::R32_FLOAT: - return RetrieveFloatValue(mem, index); + { + auto actualMem = reinterpret_cast(mem); + return actualMem[index]; + } default: return RetrieveFloatValue(mem, index); } @@ -112,10 +83,20 @@ namespace AZ { switch (format) { - case AZ::RHI::Format::R8_UNORM: - return RetrieveUintValue(mem, index); - case AZ::RHI::Format::R16_UNORM: - return RetrieveUintValue(mem, index); + case AZ::RHI::Format::R8_UINT: + { + return mem[index] / static_cast(std::numeric_limits::max()); + } + case AZ::RHI::Format::R16_UINT: + { + auto actualMem = reinterpret_cast(mem); + return actualMem[index] / static_cast(std::numeric_limits::max()); + } + case AZ::RHI::Format::R32_UINT: + { + auto actualMem = reinterpret_cast(mem); + return actualMem[index]; + } default: return RetrieveUintValue(mem, index); } @@ -125,8 +106,20 @@ namespace AZ { switch (format) { + case AZ::RHI::Format::R8_SINT: + { + return mem[index] / static_cast(std::numeric_limits::max()); + } case AZ::RHI::Format::R16_SINT: - return RetrieveIntValue(mem, index); + { + auto actualMem = reinterpret_cast(mem); + return actualMem[index] / static_cast(std::numeric_limits::max()); + } + case AZ::RHI::Format::R32_SINT: + { + auto actualMem = reinterpret_cast(mem); + return actualMem[index]; + } default: return RetrieveIntValue(mem, index); } @@ -292,9 +285,9 @@ namespace AZ auto width = imageDescriptor.m_size.m_width; size_t outValuesIndex = 0; - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { size_t imageDataIndex = (y * width) + x; @@ -318,9 +311,9 @@ namespace AZ auto width = imageDescriptor.m_size.m_width; size_t outValuesIndex = 0; - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { size_t imageDataIndex = (y * width) + x; @@ -344,9 +337,9 @@ namespace AZ auto width = imageDescriptor.m_size.m_width; size_t outValuesIndex = 0; - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { size_t imageDataIndex = (y * width) + x;