Added API for retrieving region of streaming image asset pixel values
Signed-off-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
@@ -85,10 +85,13 @@ namespace AZ
|
||||
//! Get image data for specified mip and slice. It may return empty array if its mipchain assets are not loaded
|
||||
AZStd::array_view<uint8_t> GetSubImageData(uint32_t mip, uint32_t slice);
|
||||
|
||||
//! Get image pixel value for specified mip and slice
|
||||
//! Get single image pixel value for specified mip and slice
|
||||
template<typename T>
|
||||
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
|
||||
void GetSubImagePixelValues(AZStd::pair<uint32_t, uint32_t> topLeft, AZStd::pair<uint32_t, uint32_t> bottomRight, AZStd::array_view<float> 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.
|
||||
const Data::AssetId& GetPoolAssetId() const;
|
||||
|
||||
|
||||
@@ -18,13 +18,19 @@ namespace AZ
|
||||
template <AZ::RHI::Format>
|
||||
float RetrieveFloatValue(const AZ::u8* mem, size_t index)
|
||||
{
|
||||
AZ_Assert(false, "Unsupported pixel format");
|
||||
static_assert(false, "Unsupported pixel format");
|
||||
}
|
||||
|
||||
template <AZ::RHI::Format>
|
||||
AZ::u32 RetrieveUintValue(const AZ::u8* mem, size_t index)
|
||||
{
|
||||
AZ_Assert(false, "Unsupported pixel format");
|
||||
static_assert(false, "Unsupported pixel format");
|
||||
}
|
||||
|
||||
template <AZ::RHI::Format>
|
||||
AZ::s32 RetrieveIntValue(const AZ::u8* mem, size_t index)
|
||||
{
|
||||
static_assert(false, "Unsupported pixel format");
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -217,18 +223,14 @@ namespace AZ
|
||||
template<>
|
||||
float StreamingImageAsset::GetSubImagePixelValue<float>(uint32_t x, uint32_t y, uint32_t componentIndex, uint32_t mip, uint32_t slice)
|
||||
{
|
||||
// TODO: Use the component index
|
||||
(void)componentIndex;
|
||||
AZStd::vector<float> values;
|
||||
auto position = AZStd::make_pair(x, y);
|
||||
|
||||
auto imageData = GetSubImageData(mip, slice);
|
||||
GetSubImagePixelValues(position, position, values, componentIndex, mip, slice);
|
||||
|
||||
if (!imageData.empty())
|
||||
if (values.size() == 1)
|
||||
{
|
||||
const AZ::RHI::ImageDescriptor imageDescriptor = GetImageDescriptor();
|
||||
auto width = imageDescriptor.m_size.m_width;
|
||||
size_t index = (y * width) + x;
|
||||
|
||||
return Internal::RetrieveFloatValue(imageData.data(), index, imageDescriptor.m_format);
|
||||
return values[0];
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
@@ -253,5 +255,31 @@ namespace AZ
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StreamingImageAsset::GetSubImagePixelValues(AZStd::pair<uint32_t, uint32_t> topLeft, AZStd::pair<uint32_t, uint32_t> bottomRight, AZStd::array_view<float> outValues, uint32_t componentIndex, uint32_t mip, uint32_t slice)
|
||||
{
|
||||
// TODO: Use the component index
|
||||
(void)componentIndex;
|
||||
|
||||
auto imageData = GetSubImageData(mip, slice);
|
||||
|
||||
if (!imageData.empty())
|
||||
{
|
||||
const AZ::RHI::ImageDescriptor imageDescriptor = GetImageDescriptor();
|
||||
auto width = imageDescriptor.m_size.m_width;
|
||||
|
||||
size_t outValuesIndex = 0;
|
||||
for (uint32_t x = topLeft.first; x < bottomRight.first; ++x)
|
||||
{
|
||||
for (uint32_t y = topLeft.second; y < bottomRight.second; ++y)
|
||||
{
|
||||
size_t imageDataIndex = (y * width) + x;
|
||||
|
||||
auto& outValue = const_cast<float&>(outValues[outValuesIndex++]);
|
||||
outValue = Internal::RetrieveFloatValue(imageData.data(), imageDataIndex, imageDescriptor.m_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user