From c090ad6a5697f1ee58b08f744825d4d2d2fbb796 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Thu, 20 Jan 2022 16:10:42 -0600 Subject: [PATCH] Account for the pixel size when computing the image data index Signed-off-by: Chris Galvan --- .../Source/RPI.Reflect/Image/StreamingImageAsset.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 aaf232d4f0..e2268dbdd8 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp @@ -376,13 +376,14 @@ namespace AZ { const AZ::RHI::ImageDescriptor imageDescriptor = GetImageDescriptor(); auto width = imageDescriptor.m_size.m_width; + const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); size_t outValuesIndex = 0; for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - size_t imageDataIndex = (y * width) + x; + size_t imageDataIndex = (y * width * pixelSize) + (x * pixelSize); auto& outValue = const_cast(outValues[outValuesIndex++]); outValue = Internal::RetrieveFloatValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); @@ -402,13 +403,14 @@ namespace AZ { const AZ::RHI::ImageDescriptor imageDescriptor = GetImageDescriptor(); auto width = imageDescriptor.m_size.m_width; + const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); size_t outValuesIndex = 0; for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - size_t imageDataIndex = (y * width) + x; + size_t imageDataIndex = (y * width * pixelSize) + (x * pixelSize); auto& outValue = const_cast(outValues[outValuesIndex++]); outValue = Internal::RetrieveUintValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); @@ -428,13 +430,14 @@ namespace AZ { const AZ::RHI::ImageDescriptor imageDescriptor = GetImageDescriptor(); auto width = imageDescriptor.m_size.m_width; + const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); size_t outValuesIndex = 0; for (uint32_t y = topLeft.second; y <= bottomRight.second; ++y) { for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) { - size_t imageDataIndex = (y * width) + x; + size_t imageDataIndex = (y * width * pixelSize) + (x * pixelSize); auto& outValue = const_cast(outValues[outValuesIndex++]); outValue = Internal::RetrieveIntValue(imageData.data(), imageDataIndex, imageDescriptor.m_format);