summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/image-decoders/ImageDecoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/image-decoders/ImageDecoder.h')
-rw-r--r--WebCore/platform/image-decoders/ImageDecoder.h269
1 files changed, 139 insertions, 130 deletions
diff --git a/WebCore/platform/image-decoders/ImageDecoder.h b/WebCore/platform/image-decoders/ImageDecoder.h
index 17756ac..ca27b37 100644
--- a/WebCore/platform/image-decoders/ImageDecoder.h
+++ b/WebCore/platform/image-decoders/ImageDecoder.h
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef IMAGE_DECODER_H_
-#define IMAGE_DECODER_H_
+#ifndef ImageDecoder_h
+#define ImageDecoder_h
#include "IntRect.h"
#include "ImageSource.h"
@@ -34,136 +34,145 @@
namespace WebCore {
-typedef Vector<unsigned> RGBA32Array;
-
-// The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
-// decoders write a single frame into. Frames are then instantiated for drawing by being handed this buffer.
-class RGBA32Buffer
-{
-public:
- enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
- enum FrameDisposalMethod {
- // If you change the numeric values of these, make sure you audit all
- // users, as some users may cast raw values to/from these constants.
- DisposeNotSpecified = 0, // Leave frame in framebuffer
- DisposeKeep = 1, // Leave frame in framebuffer
- DisposeOverwriteBgcolor = 2, // Clear frame to transparent
- DisposeOverwritePrevious = 3, // Clear frame to previous framebuffer contents
- };
+ typedef Vector<unsigned> RGBA32Array;
+
+ // The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
+ // decoders write a single frame into. Frames are then instantiated for drawing by being handed this buffer.
+ class RGBA32Buffer {
+ public:
+ enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
+
+ enum FrameDisposalMethod {
+ // If you change the numeric values of these, make sure you audit all
+ // users, as some users may cast raw values to/from these constants.
+ DisposeNotSpecified, // Leave frame in framebuffer
+ DisposeKeep, // Leave frame in framebuffer
+ DisposeOverwriteBgcolor, // Clear frame to transparent
+ DisposeOverwritePrevious, // Clear frame to previous framebuffer contents
+ };
+
+ RGBA32Buffer()
+ : m_height(0)
+ , m_status(FrameEmpty)
+ , m_duration(0)
+ , m_disposalMethod(DisposeNotSpecified)
+ , m_hasAlpha(false)
+ {
+ }
+
+ void clear() {
+ m_bytes.clear();
+ m_status = FrameEmpty;
+ // NOTE: Do not reset other members here; clearFrameBufferCache() calls
+ // this to free the bitmap data, but other functions like
+ // initFrameBuffer() and frameComplete() may still need to read other
+ // metadata out of this frame later.
+ }
- RGBA32Buffer() : m_height(0), m_status(FrameEmpty), m_duration(0),
- m_disposalMethod(DisposeNotSpecified), m_hasAlpha(false)
- {}
-
- void clear() {
- m_bytes.clear();
- m_status = FrameEmpty;
- // NOTE: Do not reset other members here; clearFrameBufferCache() calls
- // this to free the bitmap data, but other functions like
- // initFrameBuffer() and frameComplete() may still need to read other
- // metadata out of this frame later.
- }
-
- const RGBA32Array& bytes() const { return m_bytes; }
- RGBA32Array& bytes() { return m_bytes; }
- const IntRect& rect() const { return m_rect; }
- unsigned height() const { return m_height; }
- FrameStatus status() const { return m_status; }
- unsigned duration() const { return m_duration; }
- FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
- bool hasAlpha() const { return m_hasAlpha; }
-
- void setRect(const IntRect& r) { m_rect = r; }
- void ensureHeight(unsigned rowIndex) { if (rowIndex > m_height) m_height = rowIndex; }
- void setStatus(FrameStatus s) { m_status = s; }
- void setDuration(unsigned duration) { m_duration = duration; }
- void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
- void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
-
- static void setRGBA(unsigned& pos, unsigned r, unsigned g, unsigned b, unsigned a)
- {
- // We store this data pre-multiplied.
- if (a == 0)
- pos = 0;
- else {
- if (a < 255) {
- float alphaPercent = a / 255.0f;
- r = static_cast<unsigned>(r * alphaPercent);
- g = static_cast<unsigned>(g * alphaPercent);
- b = static_cast<unsigned>(b * alphaPercent);
+ const RGBA32Array& bytes() const { return m_bytes; }
+ RGBA32Array& bytes() { return m_bytes; }
+ const IntRect& rect() const { return m_rect; }
+ unsigned height() const { return m_height; }
+ FrameStatus status() const { return m_status; }
+ unsigned duration() const { return m_duration; }
+ FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
+ bool hasAlpha() const { return m_hasAlpha; }
+
+ void setRect(const IntRect& r) { m_rect = r; }
+ void ensureHeight(unsigned rowIndex) { if (rowIndex > m_height) m_height = rowIndex; }
+ void setStatus(FrameStatus s) { m_status = s; }
+ void setDuration(unsigned duration) { m_duration = duration; }
+ void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
+ void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
+
+ static void setRGBA(unsigned& pos, unsigned r, unsigned g, unsigned b, unsigned a)
+ {
+ // We store this data pre-multiplied.
+ if (a == 0)
+ pos = 0;
+ else {
+ if (a < 255) {
+ float alphaPercent = a / 255.0f;
+ r = static_cast<unsigned>(r * alphaPercent);
+ g = static_cast<unsigned>(g * alphaPercent);
+ b = static_cast<unsigned>(b * alphaPercent);
+ }
+ pos = (a << 24 | r << 16 | g << 8 | b);
}
- pos = (a << 24 | r << 16 | g << 8 | b);
}
- }
-
-private:
- RGBA32Array m_bytes;
- IntRect m_rect; // The rect of the original specified frame within the overall buffer.
- // This will always just be the entire buffer except for GIF frames
- // whose original rect was smaller than the overall image size.
- unsigned m_height; // The height (the number of rows we've fully decoded).
- FrameStatus m_status; // Whether or not this frame is completely finished decoding.
- unsigned m_duration; // The animation delay.
- FrameDisposalMethod m_disposalMethod; // What to do with this frame's data when initializing the next frame.
- bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
-};
-
-// The ImageDecoder class represents a base class for specific image format decoders
-// (e.g., GIF, JPG, PNG, ICO) to derive from. All decoders decode into RGBA32 format
-// and the base class manages the RGBA32 frame cache.
-class ImageDecoder
-{
-public:
- ImageDecoder() :m_sizeAvailable(false), m_failed(false) {}
- virtual ~ImageDecoder() {}
-
- // The the filename extension usually associated with an undecoded image of this type.
- virtual String filenameExtension() const = 0;
-
- // All specific decoder plugins must do something with the data they are given.
- virtual void setData(SharedBuffer* data, bool allDataReceived) { m_data = data; }
-
- // Whether or not the size information has been decoded yet.
- virtual bool isSizeAvailable() const = 0;
-
- // Requests the size.
- virtual IntSize size() const { return m_size; }
-
- // The total number of frames for the image. Classes that support multiple frames
- // will scan the image data for the answer if they need to (without necessarily
- // decoding all of the individual frames).
- virtual int frameCount() { return 1; }
-
- // The number of repetitions to perform for an animation loop.
- virtual int repetitionCount() const { return cAnimationNone; }
-
- // Called to obtain the RGBA32Buffer full of decoded data for rendering. The
- // decoder plugin will decode as much of the frame as it can before handing
- // back the buffer.
- virtual RGBA32Buffer* frameBufferAtIndex(size_t index) = 0;
-
- // Whether or not the underlying image format even supports alpha transparency.
- virtual bool supportsAlpha() const { return true; }
-
- bool failed() const { return m_failed; }
- void setFailed() { m_failed = true; }
-
- // Wipe out frames in the frame buffer cache before |clearBeforeFrame|,
- // assuming this can be done without breaking decoding. Different decoders
- // place different restrictions on what frames are safe to destroy, so this
- // is left to them to implement.
- // For convenience's sake, we provide a default (empty) implementation,
- // since in practice only GIFs will ever use this.
- virtual void clearFrameBufferCache(size_t clearBeforeFrame) { }
-
-protected:
- RefPtr<SharedBuffer> m_data; // The encoded data.
- Vector<RGBA32Buffer> m_frameBufferCache;
- bool m_sizeAvailable;
- mutable bool m_failed;
- IntSize m_size;
-};
-
-}
+
+ private:
+ RGBA32Array m_bytes;
+ IntRect m_rect; // The rect of the original specified frame within the overall buffer.
+ // This will always just be the entire buffer except for GIF frames
+ // whose original rect was smaller than the overall image size.
+ unsigned m_height; // The height (the number of rows we've fully decoded).
+ FrameStatus m_status; // Whether or not this frame is completely finished decoding.
+ unsigned m_duration; // The animation delay.
+ FrameDisposalMethod m_disposalMethod; // What to do with this frame's data when initializing the next frame.
+ bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
+ };
+
+ // The ImageDecoder class represents a base class for specific image format decoders
+ // (e.g., GIF, JPG, PNG, ICO) to derive from. All decoders decode into RGBA32 format
+ // and the base class manages the RGBA32 frame cache.
+ class ImageDecoder {
+ public:
+ ImageDecoder()
+ : m_sizeAvailable(false)
+ , m_failed(false)
+ {
+ }
+
+ virtual ~ImageDecoder() {}
+
+ // The the filename extension usually associated with an undecoded image of this type.
+ virtual String filenameExtension() const = 0;
+
+ // All specific decoder plugins must do something with the data they are given.
+ virtual void setData(SharedBuffer* data, bool allDataReceived) { m_data = data; }
+
+ // Whether or not the size information has been decoded yet.
+ virtual bool isSizeAvailable() const = 0;
+
+ // Requests the size.
+ virtual IntSize size() const { return m_size; }
+
+ // The total number of frames for the image. Classes that support multiple frames
+ // will scan the image data for the answer if they need to (without necessarily
+ // decoding all of the individual frames).
+ virtual int frameCount() { return 1; }
+
+ // The number of repetitions to perform for an animation loop.
+ virtual int repetitionCount() const { return cAnimationNone; }
+
+ // Called to obtain the RGBA32Buffer full of decoded data for rendering. The
+ // decoder plugin will decode as much of the frame as it can before handing
+ // back the buffer.
+ virtual RGBA32Buffer* frameBufferAtIndex(size_t index) = 0;
+
+ // Whether or not the underlying image format even supports alpha transparency.
+ virtual bool supportsAlpha() const { return true; }
+
+ bool failed() const { return m_failed; }
+ void setFailed() { m_failed = true; }
+
+ // Wipe out frames in the frame buffer cache before |clearBeforeFrame|,
+ // assuming this can be done without breaking decoding. Different decoders
+ // place different restrictions on what frames are safe to destroy, so this
+ // is left to them to implement.
+ // For convenience's sake, we provide a default (empty) implementation,
+ // since in practice only GIFs will ever use this.
+ virtual void clearFrameBufferCache(size_t clearBeforeFrame) { }
+
+ protected:
+ RefPtr<SharedBuffer> m_data; // The encoded data.
+ Vector<RGBA32Buffer> m_frameBufferCache;
+ bool m_sizeAvailable;
+ mutable bool m_failed;
+ IntSize m_size;
+ };
+
+} // namespace WebCore
#endif