Added unit test for single pixel and pixel regions API usage
Signed-off-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
@@ -433,12 +433,12 @@ namespace UnitTest
|
||||
return poolAsset;
|
||||
}
|
||||
|
||||
AZ::Data::Asset<AZ::RPI::StreamingImageAsset> BuildTestImage()
|
||||
AZ::Data::Asset<AZ::RPI::StreamingImageAsset> BuildTestImage(AZ::RHI::Format format = AZ::RHI::Format::R8G8B8A8_UNORM)
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
const uint32_t arraySize = 2;
|
||||
const uint32_t pixelSize = 4;
|
||||
const uint32_t pixelSize = RHI::GetFormatSize(format);
|
||||
const uint32_t mipCountHead = 1;
|
||||
const uint32_t mipCountMiddle = 2;
|
||||
const uint32_t mipCountTail = 3;
|
||||
@@ -453,7 +453,7 @@ namespace UnitTest
|
||||
RPI::StreamingImageAssetCreator assetCreator;
|
||||
assetCreator.Begin(Data::AssetId(Uuid::CreateRandom()));
|
||||
|
||||
RHI::ImageDescriptor imageDesc = RHI::ImageDescriptor::Create2DArray(RHI::ImageBindFlags::ShaderRead, imageWidth, imageHeight, arraySize, RHI::Format::R8G8B8A8_UNORM);
|
||||
RHI::ImageDescriptor imageDesc = RHI::ImageDescriptor::Create2DArray(RHI::ImageBindFlags::ShaderRead, imageWidth, imageHeight, arraySize, format);
|
||||
imageDesc.m_mipLevels = static_cast<uint16_t>(mipCountTotal);
|
||||
|
||||
assetCreator.SetImageDescriptor(imageDesc);
|
||||
@@ -726,4 +726,41 @@ namespace UnitTest
|
||||
|
||||
RPI::ImageSystemInterface::Get()->Update();
|
||||
}
|
||||
|
||||
TEST_F(StreamingImageTests, GetSubImagePixelValues)
|
||||
{
|
||||
using namespace AZ;
|
||||
|
||||
Data::Asset<RPI::StreamingImageAsset> imageAsset = BuildTestImage(AZ::RHI::Format::R8_UNORM);
|
||||
|
||||
auto streamingImageAsset = imageAsset.Get();
|
||||
EXPECT_NE(streamingImageAsset, nullptr);
|
||||
|
||||
// Validate retrieving one pixel at a time
|
||||
auto size = streamingImageAsset->GetImageDescriptor().m_size;
|
||||
for (uint32_t y = 0; y < size.m_height; ++y)
|
||||
{
|
||||
for (uint32_t x = 0; x < size.m_width; ++x)
|
||||
{
|
||||
auto pixelDataValue = imageAsset->GetSubImagePixelValue<float>(x, y);
|
||||
auto pixelExpectedValue = static_cast<uint8_t>(y * size.m_width + x) / static_cast<float>(std::numeric_limits<AZ::u8>::max());
|
||||
|
||||
EXPECT_TRUE(AZ::IsClose(pixelDataValue, pixelExpectedValue));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate retrieving a region of pixels
|
||||
AZStd::vector<float> pixelValues(size.m_width * size.m_height);
|
||||
auto topLeft = AZStd::make_pair<uint32_t, uint32_t>(0, 0);
|
||||
auto bottomRight = AZStd::make_pair<uint32_t, uint32_t>(size.m_width - 1, size.m_height - 1);
|
||||
AZStd::span<float> valueSpan(pixelValues.begin(), pixelValues.size());
|
||||
streamingImageAsset->GetSubImagePixelValues(topLeft, bottomRight, valueSpan);
|
||||
for (uint32_t index = 0; index < pixelValues.size(); ++index)
|
||||
{
|
||||
auto pixelDataValue = valueSpan[index];
|
||||
auto pixelExpectedValue = static_cast<uint8_t>(index) / static_cast<float>(std::numeric_limits<AZ::u8>::max());
|
||||
|
||||
EXPECT_TRUE(AZ::IsClose(pixelDataValue, pixelExpectedValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user