diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/RPIUtils.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/RPIUtils.h index 5b5c642047..546089ab1e 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/RPIUtils.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/RPIUtils.h @@ -66,15 +66,15 @@ namespace AZ //! 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(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, 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(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, 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(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex = 0, uint32_t mip = 0, uint32_t slice = 0); } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp index c36472dd8b..ecca215536 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/RPIUtils.cpp @@ -438,100 +438,109 @@ namespace AZ return Internal::GetSubImagePixelValueInternal(imageAsset, x, y, componentIndex, mip, slice); } - void GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) { // TODO: Use the component index (void)componentIndex; if (!imageAsset.IsReady()) { - return; + return false; } auto imageData = imageAsset->GetSubImageData(mip, slice); - - if (!imageData.empty()) + if (imageData.empty()) { - const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->GetImageDescriptor(); - auto width = imageDescriptor.m_size.m_width; - const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); + return false; + } - size_t outValuesIndex = 0; - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->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) { - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) - { - size_t imageDataIndex = (y * width + x) * pixelSize; + size_t imageDataIndex = (y * width + x) * pixelSize; - auto& outValue = outValues[outValuesIndex++]; - outValue = Internal::RetrieveFloatValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); - } + auto& outValue = outValues[outValuesIndex++]; + outValue = Internal::RetrieveFloatValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); } } + + return true; } - void GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) { // TODO: Use the component index (void)componentIndex; if (!imageAsset.IsReady()) { - return; + return false; } auto imageData = imageAsset->GetSubImageData(mip, slice); - - if (!imageData.empty()) + if (imageData.empty()) { - const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->GetImageDescriptor(); - auto width = imageDescriptor.m_size.m_width; - const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); + return false; + } - size_t outValuesIndex = 0; - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->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) { - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) - { - size_t imageDataIndex = (y * width + x) * pixelSize; + size_t imageDataIndex = (y * width + x) * pixelSize; - auto& outValue = outValues[outValuesIndex++]; - outValue = Internal::RetrieveUintValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); - } + auto& outValue = outValues[outValuesIndex++]; + outValue = Internal::RetrieveUintValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); } } + + return true; } - void GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) + bool GetSubImagePixelValues(const AZ::Data::Asset& imageAsset, AZStd::pair topLeft, AZStd::pair bottomRight, AZStd::span outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice) { // TODO: Use the component index (void)componentIndex; if (!imageAsset.IsReady()) { - return; + return false; } auto imageData = imageAsset->GetSubImageData(mip, slice); - - if (!imageData.empty()) + if (imageData.empty()) { - const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->GetImageDescriptor(); - auto width = imageDescriptor.m_size.m_width; - const uint32_t pixelSize = AZ::RHI::GetFormatSize(imageDescriptor.m_format); + return false; + } - size_t outValuesIndex = 0; - for (uint32_t y = topLeft.second; y < bottomRight.second; ++y) + const AZ::RHI::ImageDescriptor imageDescriptor = imageAsset->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) { - for (uint32_t x = topLeft.first; x < bottomRight.first; ++x) - { - size_t imageDataIndex = (y * width + x) * pixelSize; + size_t imageDataIndex = (y * width + x) * pixelSize; - auto& outValue = outValues[outValuesIndex++]; - outValue = Internal::RetrieveIntValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); - } + auto& outValue = outValues[outValuesIndex++]; + outValue = Internal::RetrieveIntValue(imageData.data(), imageDataIndex, imageDescriptor.m_format); } } + + return true; } } }