2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
27 #define __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
29 #include "juce_Image.h"
30 #include "../../../io/files/juce_File.h"
31 #include "../../../io/streams/juce_InputStream.h"
32 #include "../../../io/streams/juce_OutputStream.h"
35 //==============================================================================
37 Base-class for codecs that can read and write image file formats such
40 This class also contains static methods to make it easy to load images
41 from files, streams or from memory.
43 @see Image, ImageCache
45 class JUCE_API ImageFileFormat
48 //==============================================================================
49 /** Creates an ImageFormat. */
54 virtual ~ImageFileFormat() {}
56 //==============================================================================
57 /** Returns a description of this file format.
61 virtual String
getFormatName() = 0;
63 /** Returns true if the given stream seems to contain data that this format
66 The format class should only read the first few bytes of the stream and sniff
67 for header bytes that it understands.
71 virtual bool canUnderstand (InputStream
& input
) = 0;
73 /** Tries to decode and return an image from the given stream.
75 This will be called for an image format after calling its canUnderStand() method
76 to see if it can handle the stream.
78 @param input the stream to read the data from. The stream will be positioned
79 at the start of the image data (but this may not necessarily
81 @returns the image that was decoded, or an invalid image if it fails.
84 virtual Image
decodeImage (InputStream
& input
) = 0;
86 //==============================================================================
87 /** Attempts to write an image to a stream.
89 To specify extra information like encoding quality, there will be appropriate parameters
90 in the subclasses of the specific file types.
92 @returns true if it nothing went wrong.
94 virtual bool writeImageToStream (const Image
& sourceImage
,
95 OutputStream
& destStream
) = 0;
97 //==============================================================================
98 /** Tries the built-in decoders to see if it can find one to read this stream.
100 There are currently built-in decoders for PNG, JPEG and GIF formats.
102 The object that is returned should not be deleted by the caller.
104 @see canUnderstand, decodeImage, loadFrom
106 static ImageFileFormat
* findImageFormatForStream (InputStream
& input
);
108 //==============================================================================
109 /** Tries to load an image from a stream.
111 This will use the findImageFormatForStream() method to locate a suitable
112 codec, and use that to load the image.
114 @returns the image that was decoded, or an invalid image if it fails.
116 static Image
loadFrom (InputStream
& input
);
118 /** Tries to load an image from a file.
120 This will use the findImageFormatForStream() method to locate a suitable
121 codec, and use that to load the image.
123 @returns the image that was decoded, or an invalid image if it fails.
125 static Image
loadFrom (const File
& file
);
127 /** Tries to load an image from a block of raw image data.
129 This will use the findImageFormatForStream() method to locate a suitable
130 codec, and use that to load the image.
132 @returns the image that was decoded, or an invalid image if it fails.
134 static Image
loadFrom (const void* rawData
,
135 const int numBytesOfData
);
139 //==============================================================================
141 A subclass of ImageFileFormat for reading and writing PNG files.
143 @see ImageFileFormat, JPEGImageFormat
145 class JUCE_API PNGImageFormat
: public ImageFileFormat
148 //==============================================================================
152 //==============================================================================
153 String
getFormatName();
154 bool canUnderstand (InputStream
& input
);
155 Image
decodeImage (InputStream
& input
);
156 bool writeImageToStream (const Image
& sourceImage
, OutputStream
& destStream
);
160 //==============================================================================
162 A subclass of ImageFileFormat for reading and writing JPEG files.
164 @see ImageFileFormat, PNGImageFormat
166 class JUCE_API JPEGImageFormat
: public ImageFileFormat
169 //==============================================================================
173 //==============================================================================
174 /** Specifies the quality to be used when writing a JPEG file.
176 @param newQuality a value 0 to 1.0, where 0 is low quality, 1.0 is best, or
177 any negative value is "default" quality
179 void setQuality (float newQuality
);
181 //==============================================================================
182 String
getFormatName();
183 bool canUnderstand (InputStream
& input
);
184 Image
decodeImage (InputStream
& input
);
185 bool writeImageToStream (const Image
& sourceImage
, OutputStream
& destStream
);
191 //==============================================================================
193 A subclass of ImageFileFormat for reading GIF files.
195 @see ImageFileFormat, PNGImageFormat, JPEGImageFormat
197 class JUCE_API GIFImageFormat
: public ImageFileFormat
200 //==============================================================================
204 //==============================================================================
205 String
getFormatName();
206 bool canUnderstand (InputStream
& input
);
207 Image
decodeImage (InputStream
& input
);
208 bool writeImageToStream (const Image
& sourceImage
, OutputStream
& destStream
);
212 #endif // __JUCE_IMAGEFILEFORMAT_JUCEHEADER__