ScriptReporter_Windows.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Automation/ScriptReporter.h>
  9. #include <AzCore/Utils/Utils.h>
  10. #include <Atom/Utils/PngFile.h>
  11. namespace AtomSampleViewer
  12. {
  13. bool ScriptReporter::LoadPngData(ImageComparisonResult& imageComparisonResult, const AZStd::string& path, AZStd::vector<uint8_t>& buffer, AZ::RHI::Size& size, AZ::RHI::Format& format, TraceLevel traceLevel)
  14. {
  15. using namespace AZ;
  16. using namespace AZ::Utils;
  17. const auto errorHandler = [path, traceLevel, &imageComparisonResult](const char* errorMessage)
  18. {
  19. ReportScriptIssue(AZStd::string::format("Failed to load PNG file '%s' with error '%s'", path.c_str(), errorMessage),
  20. traceLevel);
  21. imageComparisonResult.m_resultCode = ImageComparisonResult::ResultCode::FileNotLoaded;
  22. };
  23. PngFile::LoadSettings loadSettings;
  24. loadSettings.m_stripAlpha = false;
  25. loadSettings.m_errorHandler = errorHandler;
  26. PngFile file = PngFile::Load(path.c_str(), loadSettings);
  27. if (file.IsValid())
  28. {
  29. size = RHI::Size(file.GetWidth(), file.GetHeight(), 1);
  30. format = AZ::RHI::Format::R8G8B8A8_UNORM;
  31. buffer = file.TakeBuffer();
  32. return true;
  33. }
  34. else
  35. {
  36. return false;
  37. }
  38. }
  39. }