LMMS
Loading...
Searching...
No Matches
juce_ImageFileFormat.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
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.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
32 {
34 return formats.formats;
35 }
36
37private:
39 {
40 formats[0] = &png;
41 formats[1] = &jpg;
42 formats[2] = &gif;
43 formats[3] = nullptr;
44 }
45
49
51};
52
54{
55 const int64 streamPos = input.getPosition();
56
57 for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
58 {
59 const bool found = (*i)->canUnderstand (input);
60 input.setPosition (streamPos);
61
62 if (found)
63 return *i;
64 }
65
66 return nullptr;
67}
68
70{
71 for (ImageFileFormat** i = DefaultImageFormats::get(); *i != nullptr; ++i)
72 if ((*i)->usesFileExtension (file))
73 return *i;
74
75 return nullptr;
76}
77
78//==============================================================================
80{
82 return format->decodeImage (input);
83
84 return Image();
85}
86
88{
89 FileInputStream stream (file);
90
91 if (stream.openedOk())
92 {
93 BufferedInputStream b (stream, 8192);
94 return loadFrom (b);
95 }
96
97 return Image();
98}
99
100Image ImageFileFormat::loadFrom (const void* rawData, const size_t numBytes)
101{
102 if (rawData != nullptr && numBytes > 4)
103 {
104 MemoryInputStream stream (rawData, numBytes, false);
105 return loadFrom (stream);
106 }
107
108 return Image();
109}
110
111} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_BufferedInputStream.h:37
Definition juce_File.h:45
Definition juce_FileInputStream.h:35
bool openedOk() const noexcept
Definition juce_FileInputStream.h:67
Definition juce_ImageFileFormat.h:209
Definition juce_ImageFileFormat.h:42
static Image loadFrom(InputStream &input)
Definition juce_ImageFileFormat.cpp:79
static ImageFileFormat * findImageFormatForStream(InputStream &input)
Definition juce_ImageFileFormat.cpp:53
static ImageFileFormat * findImageFormatForFileExtension(const File &file)
Definition juce_ImageFileFormat.cpp:69
Definition juce_Image.h:58
Definition juce_InputStream.h:37
virtual int64 getPosition()=0
virtual bool setPosition(int64 newPosition)=0
Definition juce_ImageFileFormat.h:175
Definition juce_MemoryInputStream.h:36
Definition juce_ImageFileFormat.h:151
register unsigned i
Definition inflate.c:1575
Definition carla_juce.cpp:31
long long int64
Definition juce_MathsFunctions.h:54
static ImageFileFormat ** get()
Definition juce_ImageFileFormat.cpp:31
PNGImageFormat png
Definition juce_ImageFileFormat.cpp:46
DefaultImageFormats() noexcept
Definition juce_ImageFileFormat.cpp:38
ImageFileFormat * formats[4]
Definition juce_ImageFileFormat.cpp:50
JPEGImageFormat jpg
Definition juce_ImageFileFormat.cpp:47
GIFImageFormat gif
Definition juce_ImageFileFormat.cpp:48
b
Definition crypt.c:628
struct zdirent * file
Definition win32.c:1500
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263