JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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{
31 static ImageFileFormat** get()
32 {
33 static DefaultImageFormats formats;
34 return formats.formats;
35 }
36
37private:
38 DefaultImageFormats() noexcept
39 {
40 formats[0] = &png;
41 formats[1] = &jpg;
42 formats[2] = &gif;
43 formats[3] = nullptr;
44 }
45
49
50 ImageFileFormat* formats[4];
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{
81 if (ImageFileFormat* format = findImageFormatForStream (input))
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
Wraps another input stream, and reads from it using an intermediate buffer.
An input stream that reads from a local file.
bool openedOk() const noexcept
Returns true if the stream opened without problems.
Represents a local file or directory.
Definition juce_File.h:45
A subclass of ImageFileFormat for reading GIF files.
Base-class for codecs that can read and write image file formats such as PNG, JPEG,...
static Image loadFrom(InputStream &input)
Tries to load an image from a stream.
static ImageFileFormat * findImageFormatForStream(InputStream &input)
Tries the built-in formats to see if it can find one to read this stream.
static ImageFileFormat * findImageFormatForFileExtension(const File &file)
Looks for a format that can handle the given file extension.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
The base class for streams that read data.
virtual int64 getPosition()=0
Returns the offset of the next byte that will be read from the stream.
virtual bool setPosition(int64 newPosition)=0
Tries to move the current read position of the stream.
A subclass of ImageFileFormat for reading and writing JPEG files.
Allows a block of data to be accessed as a stream.
A subclass of ImageFileFormat for reading and writing PNG files.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.