|
@@ -8,42 +8,38 @@
|
|
|
|
|
|
#include <Automation/ScriptReporter.h>
|
|
#include <Automation/ScriptReporter.h>
|
|
#include <AzCore/Utils/Utils.h>
|
|
#include <AzCore/Utils/Utils.h>
|
|
-#include <OpenImageIO/imageio.h>
|
|
|
|
|
|
+#include <Atom/Utils/PngFile.h>
|
|
|
|
|
|
namespace AtomSampleViewer
|
|
namespace AtomSampleViewer
|
|
{
|
|
{
|
|
bool ScriptReporter::LoadPngData(ImageComparisonResult& imageComparisonResult, const AZStd::string& path, AZStd::vector<uint8_t>& buffer, AZ::RHI::Size& size, AZ::RHI::Format& format, TraceLevel traceLevel)
|
|
bool ScriptReporter::LoadPngData(ImageComparisonResult& imageComparisonResult, const AZStd::string& path, AZStd::vector<uint8_t>& buffer, AZ::RHI::Size& size, AZ::RHI::Format& format, TraceLevel traceLevel)
|
|
{
|
|
{
|
|
- using namespace OIIO;
|
|
|
|
|
|
+ using namespace AZ;
|
|
|
|
+ using namespace AZ::Utils;
|
|
|
|
|
|
- const size_t maxFileSize = 1024 * 1024 * 25;
|
|
|
|
-
|
|
|
|
- auto readScreenshotFileResult = AZ::Utils::ReadFile<AZStd::vector<uint8_t>>(path, maxFileSize);
|
|
|
|
- if (!readScreenshotFileResult.IsSuccess())
|
|
|
|
|
|
+ const auto errorHandler = [path, traceLevel, &imageComparisonResult](const char* errorMessage)
|
|
{
|
|
{
|
|
- ReportScriptIssue(AZStd::string::format("Screenshot check failed. %s", readScreenshotFileResult.GetError().c_str()), traceLevel);
|
|
|
|
- imageComparisonResult.m_resultCode = ImageComparisonResult::ResultCode::FileNotFound;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ ReportScriptIssue(AZStd::string::format("Failed to load PNG file '%s' with error '%s'", path.c_str(), errorMessage),
|
|
|
|
+ traceLevel);
|
|
|
|
+
|
|
|
|
+ imageComparisonResult.m_resultCode = ImageComparisonResult::ResultCode::FileNotLoaded;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ PngFile::LoadSettings loadSettings;
|
|
|
|
+ loadSettings.m_stripAlpha = false;
|
|
|
|
+ loadSettings.m_errorHandler = errorHandler;
|
|
|
|
|
|
- auto in = ImageInput::open(path.c_str());
|
|
|
|
- if (in)
|
|
|
|
|
|
+ PngFile file = PngFile::Load(path.c_str(), loadSettings);
|
|
|
|
+ if (file.IsValid())
|
|
{
|
|
{
|
|
- const ImageSpec& spec = in->spec();
|
|
|
|
- size.m_width = spec.width;
|
|
|
|
- size.m_height = spec.height;
|
|
|
|
- size.m_depth = spec.depth;
|
|
|
|
|
|
+ size = RHI::Size(file.GetWidth(), file.GetHeight(), 1);
|
|
format = AZ::RHI::Format::R8G8B8A8_UNORM;
|
|
format = AZ::RHI::Format::R8G8B8A8_UNORM;
|
|
- buffer.resize(spec.width * spec.height * spec.nchannels);
|
|
|
|
- if (!in->read_image(TypeDesc::UINT8, &buffer[0]))
|
|
|
|
- {
|
|
|
|
- ReportScriptIssue(AZStd::string::format("Screenshot check failed. Failed to read file '%s'", path.c_str()), traceLevel);
|
|
|
|
- imageComparisonResult.m_resultCode = ImageComparisonResult::ResultCode::FileNotLoaded;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- in->close();
|
|
|
|
|
|
+ buffer = file.TakeBuffer();
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|