2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2007-2008 Torch Mobile, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <wtf/Forward.h>
31 #include <wtf/Noncopyable.h>
32 #include <wtf/Vector.h>
36 class wxGraphicsBitmap;
38 typedef struct CGImageSource* CGImageSourceRef;
39 typedef struct CGImage* CGImageRef;
40 typedef const struct __CFData* CFDataRef;
47 struct _cairo_surface;
48 typedef struct _cairo_surface cairo_surface_t;
51 class NativeImageSkia;
56 #include "SharedBitmap.h"
66 #if USE(WEBKIT_IMAGE_DECODERS)
68 typedef ImageDecoder* NativeImageSourcePtr;
70 typedef CGImageSourceRef NativeImageSourcePtr;
72 typedef CGImageRef NativeImagePtr;
73 #elif PLATFORM(OPENVG)
75 class TiledImageOpenVG;
76 typedef ImageDecoder* NativeImageSourcePtr;
77 typedef TiledImageOpenVG* NativeImagePtr;
80 typedef ImageDecoderQt* NativeImageSourcePtr;
81 typedef QPixmap* NativeImagePtr;
84 typedef ImageDecoder* NativeImageSourcePtr;
87 typedef wxGraphicsBitmap* NativeImagePtr;
89 typedef wxBitmap* NativeImagePtr;
92 typedef cairo_surface_t* NativeImagePtr;
94 typedef WebCore::NativeImageSkia* NativeImagePtr;
96 typedef BBitmap* NativeImagePtr;
98 typedef RefPtr<SharedBitmap> NativeImagePtr;
102 // Right now GIFs are the only recognized image format that supports animation.
103 // The animation system and the constants below are designed with this in mind.
104 // GIFs have an optional 16-bit unsigned loop count that describes how an
105 // animated GIF should be cycled. If the loop count is absent, the animation
106 // cycles once; if it is 0, the animation cycles infinitely; otherwise the
107 // animation plays n + 1 cycles (where n is the specified loop count). If the
108 // GIF decoder defaults to cAnimationLoopOnce in the absence of any loop count
109 // and translates an explicit "0" loop count to cAnimationLoopInfinite, then we
110 // get a couple of nice side effects:
111 // * By making cAnimationLoopOnce be 0, we allow the animation cycling code in
112 // BitmapImage.cpp to avoid special-casing it, and simply treat all
113 // non-negative loop counts identically.
114 // * By making the other two constants negative, we avoid conflicts with any
115 // real loop count values.
116 const int cAnimationLoopOnce = 0;
117 const int cAnimationLoopInfinite = -1;
118 const int cAnimationNone = -2;
121 WTF_MAKE_NONCOPYABLE(ImageSource);
125 AlphaNotPremultiplied
128 enum GammaAndColorProfileOption {
129 GammaAndColorProfileApplied,
130 GammaAndColorProfileIgnored
133 ImageSource(AlphaOption alphaOption = AlphaPremultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileApplied);
136 // Tells the ImageSource that the Image no longer cares about decoded frame
137 // data -- at all (if |destroyAll| is true), or before frame
138 // |clearBeforeFrame| (if |destroyAll| is false). The ImageSource should
139 // delete cached decoded data for these frames where possible to keep memory
140 // usage low. When |destroyAll| is true, the ImageSource should also reset
141 // any local state so that decoding can begin again.
143 // Implementations that delete less than what's specified above waste
144 // memory. Implementations that delete more may burn CPU re-decoding frames
145 // that could otherwise have been cached, or encounter errors if they're
146 // asked to decode frames they can't decode due to the loss of previous
149 // Callers should not call clear(false, n) and subsequently call
150 // createFrameAtIndex(m) with m < n, unless they first call clear(true).
151 // This ensures that stateful ImageSources/decoders will work properly.
153 // The |data| and |allDataReceived| parameters should be supplied by callers
154 // who set |destroyAll| to true if they wish to be able to continue using
155 // the ImageSource. This way implementations which choose to destroy their
156 // decoders in some cases can reconstruct them correctly.
157 void clear(bool destroyAll,
158 size_t clearBeforeFrame = 0,
159 SharedBuffer* data = NULL,
160 bool allDataReceived = false);
162 bool initialized() const;
164 void setData(SharedBuffer* data, bool allDataReceived);
165 String filenameExtension() const;
167 bool isSizeAvailable();
168 IntSize size() const;
169 IntSize frameSizeAtIndex(size_t) const;
170 bool getHotSpot(IntPoint&) const;
172 size_t bytesDecodedToDetermineProperties() const;
174 int repetitionCount();
176 size_t frameCount() const;
178 // Callers should not call this after calling clear() with a higher index;
179 // see comments on clear() above.
180 NativeImagePtr createFrameAtIndex(size_t);
182 float frameDurationAtIndex(size_t);
183 bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
184 bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
186 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
187 static unsigned maxPixelsPerDecodedImage() { return s_maxPixelsPerDecodedImage; }
188 static void setMaxPixelsPerDecodedImage(unsigned maxPixels) { s_maxPixelsPerDecodedImage = maxPixels; }
192 NativeImageSourcePtr m_decoder;
193 AlphaOption m_alphaOption;
194 GammaAndColorProfileOption m_gammaAndColorProfileOption;
195 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
196 static unsigned s_maxPixelsPerDecodedImage;