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
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
23 ==============================================================================
29 struct DefaultImageFormats
31 static ImageFileFormat
** get()
33 static DefaultImageFormats formats
;
34 return formats
.formats
;
38 DefaultImageFormats() noexcept
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
);
69 ImageFileFormat
* ImageFileFormat::findImageFormatForFileExtension (const File
& file
)
71 for (ImageFileFormat
** i
= DefaultImageFormats::get(); *i
!= nullptr; ++i
)
72 if ((*i
)->usesFileExtension (file
))
78 //==============================================================================
79 Image
ImageFileFormat::loadFrom (InputStream
& input
)
81 if (ImageFileFormat
* format
= findImageFormatForStream (input
))
82 return format
->decodeImage (input
);
87 Image
ImageFileFormat::loadFrom (const File
& file
)
89 FileInputStream
stream (file
);
91 if (stream
.openedOk())
93 BufferedInputStream
b (stream
, 8192);
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
);