Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. struct DefaultImageFormats
  21. {
  22. static ImageFileFormat** get()
  23. {
  24. static DefaultImageFormats formats;
  25. return formats.formats;
  26. }
  27. private:
  28. DefaultImageFormats() noexcept
  29. {
  30. formats[0] = &png;
  31. formats[1] = &jpg;
  32. formats[2] = &gif;
  33. formats[3] = nullptr;
  34. }
  35. PNGImageFormat png;
  36. JPEGImageFormat jpg;
  37. GIFImageFormat gif;
  38. ImageFileFormat* formats[4];
  39. };
  40. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  41. {
  42. const int64 streamPos = input.getPosition();
  43. for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
  44. {
  45. const bool found = (*i)->canUnderstand (input);
  46. input.setPosition (streamPos);
  47. if (found)
  48. return *i;
  49. }
  50. return nullptr;
  51. }
  52. ImageFileFormat* ImageFileFormat::findImageFormatForFileExtension (const File& file)
  53. {
  54. for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
  55. if ((*i)->usesFileExtension (file))
  56. return *i;
  57. return nullptr;
  58. }
  59. //==============================================================================
  60. Image ImageFileFormat::loadFrom (InputStream& input)
  61. {
  62. if (ImageFileFormat* format = findImageFormatForStream (input))
  63. return format->decodeImage (input);
  64. return Image();
  65. }
  66. Image ImageFileFormat::loadFrom (const File& file)
  67. {
  68. FileInputStream stream (file);
  69. if (stream.openedOk())
  70. {
  71. BufferedInputStream b (stream, 8192);
  72. return loadFrom (b);
  73. }
  74. return Image();
  75. }
  76. Image ImageFileFormat::loadFrom (const void* rawData, const size_t numBytes)
  77. {
  78. if (rawData != nullptr && numBytes > 4)
  79. {
  80. MemoryInputStream stream (rawData, numBytes, false);
  81. return loadFrom (stream);
  82. }
  83. return Image();
  84. }
  85. } // namespace juce