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.

105 lines
2.5KB

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