The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
7.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  19. #define __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  20. #include "juce_Image.h"
  21. //==============================================================================
  22. /**
  23. Base-class for codecs that can read and write image file formats such
  24. as PNG, JPEG, etc.
  25. This class also contains static methods to make it easy to load images
  26. from files, streams or from memory.
  27. @see Image, ImageCache
  28. */
  29. class JUCE_API ImageFileFormat
  30. {
  31. protected:
  32. //==============================================================================
  33. /** Creates an ImageFormat. */
  34. ImageFileFormat() {}
  35. public:
  36. /** Destructor. */
  37. virtual ~ImageFileFormat() {}
  38. //==============================================================================
  39. /** Returns a description of this file format.
  40. E.g. "JPEG", "PNG"
  41. */
  42. virtual String getFormatName() = 0;
  43. /** Returns true if the given stream seems to contain data that this format
  44. understands.
  45. The format class should only read the first few bytes of the stream and sniff
  46. for header bytes that it understands.
  47. @see decodeImage
  48. */
  49. virtual bool canUnderstand (InputStream& input) = 0;
  50. /** Tries to decode and return an image from the given stream.
  51. This will be called for an image format after calling its canUnderStand() method
  52. to see if it can handle the stream.
  53. @param input the stream to read the data from. The stream will be positioned
  54. at the start of the image data (but this may not necessarily
  55. be position 0)
  56. @returns the image that was decoded, or an invalid image if it fails.
  57. @see loadFrom
  58. */
  59. virtual Image decodeImage (InputStream& input) = 0;
  60. //==============================================================================
  61. /** Attempts to write an image to a stream.
  62. To specify extra information like encoding quality, there will be appropriate parameters
  63. in the subclasses of the specific file types.
  64. @returns true if it nothing went wrong.
  65. */
  66. virtual bool writeImageToStream (const Image& sourceImage,
  67. OutputStream& destStream) = 0;
  68. //==============================================================================
  69. /** Tries the built-in decoders to see if it can find one to read this stream.
  70. There are currently built-in decoders for PNG, JPEG and GIF formats.
  71. The object that is returned should not be deleted by the caller.
  72. @see canUnderstand, decodeImage, loadFrom
  73. */
  74. static ImageFileFormat* findImageFormatForStream (InputStream& input);
  75. //==============================================================================
  76. /** Tries to load an image from a stream.
  77. This will use the findImageFormatForStream() method to locate a suitable
  78. codec, and use that to load the image.
  79. @returns the image that was decoded, or an invalid image if it fails.
  80. */
  81. static Image loadFrom (InputStream& input);
  82. /** Tries to load an image from a file.
  83. This will use the findImageFormatForStream() method to locate a suitable
  84. codec, and use that to load the image.
  85. @returns the image that was decoded, or an invalid image if it fails.
  86. */
  87. static Image loadFrom (const File& file);
  88. /** Tries to load an image from a block of raw image data.
  89. This will use the findImageFormatForStream() method to locate a suitable
  90. codec, and use that to load the image.
  91. @returns the image that was decoded, or an invalid image if it fails.
  92. */
  93. static Image loadFrom (const void* rawData,
  94. size_t numBytesOfData);
  95. };
  96. //==============================================================================
  97. /**
  98. A subclass of ImageFileFormat for reading and writing PNG files.
  99. @see ImageFileFormat, JPEGImageFormat
  100. */
  101. class JUCE_API PNGImageFormat : public ImageFileFormat
  102. {
  103. public:
  104. //==============================================================================
  105. PNGImageFormat();
  106. ~PNGImageFormat();
  107. //==============================================================================
  108. String getFormatName();
  109. bool canUnderstand (InputStream& input);
  110. Image decodeImage (InputStream& input);
  111. bool writeImageToStream (const Image& sourceImage, OutputStream& destStream);
  112. };
  113. //==============================================================================
  114. /**
  115. A subclass of ImageFileFormat for reading and writing JPEG files.
  116. @see ImageFileFormat, PNGImageFormat
  117. */
  118. class JUCE_API JPEGImageFormat : public ImageFileFormat
  119. {
  120. public:
  121. //==============================================================================
  122. JPEGImageFormat();
  123. ~JPEGImageFormat();
  124. //==============================================================================
  125. /** Specifies the quality to be used when writing a JPEG file.
  126. @param newQuality a value 0 to 1.0, where 0 is low quality, 1.0 is best, or
  127. any negative value is "default" quality
  128. */
  129. void setQuality (float newQuality);
  130. //==============================================================================
  131. String getFormatName();
  132. bool canUnderstand (InputStream& input);
  133. Image decodeImage (InputStream& input);
  134. bool writeImageToStream (const Image& sourceImage, OutputStream& destStream);
  135. private:
  136. float quality;
  137. };
  138. //==============================================================================
  139. /**
  140. A subclass of ImageFileFormat for reading GIF files.
  141. @see ImageFileFormat, PNGImageFormat, JPEGImageFormat
  142. */
  143. class JUCE_API GIFImageFormat : public ImageFileFormat
  144. {
  145. public:
  146. //==============================================================================
  147. GIFImageFormat();
  148. ~GIFImageFormat();
  149. //==============================================================================
  150. String getFormatName();
  151. bool canUnderstand (InputStream& input);
  152. Image decodeImage (InputStream& input);
  153. bool writeImageToStream (const Image& sourceImage, OutputStream& destStream);
  154. };
  155. #endif // __JUCE_IMAGEFILEFORMAT_JUCEHEADER__