VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_graphics / images / juce_ImageFileFormat.cpp
blob31e825cca93163236eef3e8ea7a2ae889110f955
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 struct DefaultImageFormats
31 static ImageFileFormat** get()
33 static DefaultImageFormats formats;
34 return formats.formats;
37 private:
38 DefaultImageFormats() noexcept
40 formats[0] = &png;
41 formats[1] = &jpg;
42 formats[2] = &gif;
43 formats[3] = nullptr;
46 PNGImageFormat png;
47 JPEGImageFormat jpg;
48 GIFImageFormat gif;
50 ImageFileFormat* formats[4];
53 ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
55 const int64 streamPos = input.getPosition();
57 for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
59 const bool found = (*i)->canUnderstand (input);
60 input.setPosition (streamPos);
62 if (found)
63 return *i;
66 return nullptr;
69 ImageFileFormat* ImageFileFormat::findImageFormatForFileExtension (const File& file)
71 for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
72 if ((*i)->usesFileExtension (file))
73 return *i;
75 return nullptr;
78 //==============================================================================
79 Image ImageFileFormat::loadFrom (InputStream& input)
81 if (ImageFileFormat* format = findImageFormatForStream (input))
82 return format->decodeImage (input);
84 return Image();
87 Image ImageFileFormat::loadFrom (const File& file)
89 FileInputStream stream (file);
91 if (stream.openedOk())
93 BufferedInputStream b (stream, 8192);
94 return loadFrom (b);
97 return Image();
100 Image ImageFileFormat::loadFrom (const void* rawData, const size_t numBytes)
102 if (rawData != nullptr && numBytes > 4)
104 MemoryInputStream stream (rawData, numBytes, false);
105 return loadFrom (stream);
108 return Image();
111 } // namespace juce