ImageLoaders.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <ImageLoader/ImageLoaders.h>
  9. #include <Processing/ImageFlags.h>
  10. #include <Atom/ImageProcessing/ImageObject.h>
  11. // warning C4251: class QT_Type needs to have dll-interface to be used by clients of class 'QT_Type'
  12. AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option")
  13. #include <QFileInfo>
  14. AZ_POP_DISABLE_WARNING
  15. namespace ImageProcessingAtom
  16. {
  17. IImageObject* LoadImageFromFile(const AZStd::string& filename)
  18. {
  19. QFileInfo fileInfo(filename.c_str());
  20. auto suffix = fileInfo.suffix().toUtf8(); // need to cache the utf8 object so its data can be referenced below
  21. const char* ext = suffix.data();
  22. if (!fileInfo.exists())
  23. {
  24. return nullptr;
  25. }
  26. IImageObject* loadedImage = nullptr;
  27. if (TIFFLoader::IsExtensionSupported(ext))
  28. {
  29. loadedImage = TIFFLoader::LoadImageFromTIFF(filename);
  30. }
  31. else if (DdsLoader::IsExtensionSupported(ext))
  32. {
  33. loadedImage = DdsLoader::LoadImageFromFile(filename);
  34. }
  35. else if (TgaLoader::IsExtensionSupported(ext))
  36. {
  37. loadedImage = TgaLoader::LoadImageFromFile(filename);
  38. }
  39. else if (QtImageLoader::IsExtensionSupported(ext))
  40. {
  41. loadedImage = QtImageLoader::LoadImageFromFile(filename);
  42. }
  43. else if (ExrLoader::IsExtensionSupported(ext))
  44. {
  45. loadedImage = ExrLoader::LoadImageFromFile(filename);
  46. }
  47. else
  48. {
  49. AZ_Warning("ImageProcessing", false, "No proper image loader to load file: %s", filename.c_str());
  50. }
  51. if (loadedImage)
  52. {
  53. if (IsHDRFormat(loadedImage->GetPixelFormat()))
  54. {
  55. loadedImage->AddImageFlags(EIF_HDR);
  56. }
  57. return loadedImage;
  58. }
  59. else
  60. {
  61. AZ_Warning("ImageProcessing", false, "Failed to load image file: %s", filename.c_str());
  62. return nullptr;
  63. }
  64. }
  65. bool IsExtensionSupported(const char* extension)
  66. {
  67. return TIFFLoader::IsExtensionSupported(extension)
  68. || DdsLoader::IsExtensionSupported(extension)
  69. || TgaLoader::IsExtensionSupported(extension)
  70. || QtImageLoader::IsExtensionSupported(extension)
  71. || ExrLoader::IsExtensionSupported(extension);
  72. }
  73. }// namespace ImageProcessingAtom