diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Image/StreamingImageAsset.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Image/StreamingImageAsset.h index 93d0392e38..2e01f99cd9 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Image/StreamingImageAsset.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Image/StreamingImageAsset.h @@ -91,12 +91,15 @@ namespace AZ T GetSubImagePixelValue(uint32_t x, uint32_t y, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); //! Retrieve a region of image pixel values (float) for specified mip and slice + //! NOTE: The topLeft coordinate is inclusive, whereas the bottomRight is exclusive void GetSubImagePixelValues(AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); //! Retrieve a region of image pixel values (uint) for specified mip and slice + //! NOTE: The topLeft coordinate is inclusive, whereas the bottomRight is exclusive void GetSubImagePixelValues(AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); //! Retrieve a region of image pixel values (int) for specified mip and slice + //! NOTE: The topLeft coordinate is inclusive, whereas the bottomRight is exclusive void GetSubImagePixelValues(AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); //! Returns streaming image pool asset id of the pool that will be used to create the streaming image. 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 a3cfc581b6..286b259696 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Image/StreamingImageAsset.cpp @@ -315,9 +315,10 @@ namespace AZ { AZStd::array values = { aznumeric_cast(0) }; - auto position = AZStd::make_pair(x, y); + auto topLeft = AZStd::make_pair(x, y); + auto bottomRight = AZStd::make_pair(x + 1, y + 1); AZStd::span valueSpan(values.begin(), values.size()); - GetSubImagePixelValues(position, position, valueSpan, componentIndex, mip, slice); + GetSubImagePixelValues(topLeft, bottomRight, valueSpan, componentIndex, mip, slice); return values[0]; } @@ -354,9 +355,9 @@ namespace AZ 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 y = topLeft.second; y < bottomRight.second; ++y) { - for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) { size_t imageDataIndex = (y * width + x) * pixelSize; @@ -381,9 +382,9 @@ namespace AZ 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 y = topLeft.second; y < bottomRight.second; ++y) { - for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) { size_t imageDataIndex = (y * width + x) * pixelSize; @@ -408,9 +409,9 @@ namespace AZ 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 y = topLeft.second; y < bottomRight.second; ++y) { - for (uint32_t x = topLeft.first; x <= bottomRight.first; ++x) + for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) { size_t imageDataIndex = (y * width + x) * pixelSize; diff --git a/Gems/Atom/RPI/Code/Tests/Image/StreamingImageTests.cpp b/Gems/Atom/RPI/Code/Tests/Image/StreamingImageTests.cpp index 28e5dbd9fe..5efab95818 100644 --- a/Gems/Atom/RPI/Code/Tests/Image/StreamingImageTests.cpp +++ b/Gems/Atom/RPI/Code/Tests/Image/StreamingImageTests.cpp @@ -752,7 +752,7 @@ namespace UnitTest // Validate retrieving a region of pixels AZStd::vector pixelValues(size.m_width * size.m_height); auto topLeft = AZStd::make_pair(0, 0); - auto bottomRight = AZStd::make_pair(size.m_width - 1, size.m_height - 1); + auto bottomRight = AZStd::make_pair(size.m_width, size.m_height); streamingImageAsset->GetSubImagePixelValues(topLeft, bottomRight, pixelValues); for (uint32_t index = 0; index < pixelValues.size(); ++index) {