2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "platform/PlatformExport.h"
30 #include "platform/graphics/ImageOrientation.h"
31 #include "wtf/Forward.h"
32 #include "wtf/Noncopyable.h"
33 #include "wtf/OwnPtr.h"
37 class DeferredImageDecoder;
38 class ImageOrientation;
41 class NativeImageSkia;
44 // GIF and WebP support animation. The explanation below is in terms of GIF,
45 // but the same constants are used for WebP, too.
46 // GIFs have an optional 16-bit unsigned loop count that describes how an
47 // animated GIF should be cycled. If the loop count is absent, the animation
48 // cycles once; if it is 0, the animation cycles infinitely; otherwise the
49 // animation plays n + 1 cycles (where n is the specified loop count). If the
50 // GIF decoder defaults to cAnimationLoopOnce in the absence of any loop count
51 // and translates an explicit "0" loop count to cAnimationLoopInfinite, then we
52 // get a couple of nice side effects:
53 // * By making cAnimationLoopOnce be 0, we allow the animation cycling code in
54 // BitmapImage.cpp to avoid special-casing it, and simply treat all
55 // non-negative loop counts identically.
56 // * By making the other two constants negative, we avoid conflicts with any
57 // real loop count values.
58 const int cAnimationLoopOnce = 0;
59 const int cAnimationLoopInfinite = -1;
60 const int cAnimationNone = -2;
62 class PLATFORM_EXPORT ImageSource {
63 WTF_MAKE_NONCOPYABLE(ImageSource);
70 enum GammaAndColorProfileOption {
71 GammaAndColorProfileApplied,
72 GammaAndColorProfileIgnored
75 ImageSource(AlphaOption alphaOption = AlphaPremultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileApplied);
78 // Tells the ImageSource that the Image no longer cares about decoded frame
79 // data except for the specified frame. Callers may pass WTF::kNotFound to
82 // In response, the ImageSource should delete cached decoded data for other
83 // frames where possible to keep memory use low. The expectation is that in
84 // the future, the caller may call createFrameAtIndex() with an index larger
85 // than the one passed to this function, and the implementation may then
86 // make use of the preserved frame data here in decoding that frame.
87 // By contrast, callers who call this function and then later ask for an
88 // earlier frame may require more work to be done, e.g. redecoding the image
89 // from the beginning.
91 // Implementations may elect to preserve more frames than the one requested
92 // here if doing so is likely to save CPU time in the future, but will pay
93 // an increased memory cost to do so.
95 // Returns the number of bytes of frame data actually cleared.
96 size_t clearCacheExceptFrame(size_t);
98 bool initialized() const;
100 void setData(SharedBuffer& data, bool allDataReceived);
101 String filenameExtension() const;
103 bool isSizeAvailable();
104 bool hasColorProfile() const;
105 IntSize size(RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
106 IntSize frameSizeAtIndex(size_t, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
108 bool getHotSpot(IntPoint&) const;
110 // Returns one of the cAnimationXXX constants at the top of the file, or
111 // a loop count. In the latter case, the actual number of times the animation
112 // cycles is one more than the loop count. See comment atop the file.
113 int repetitionCount();
115 size_t frameCount() const;
117 PassRefPtr<NativeImageSkia> createFrameAtIndex(size_t);
119 float frameDurationAtIndex(size_t) const;
120 bool frameHasAlphaAtIndex(size_t) const; // Whether or not the frame actually used any alpha.
121 bool frameIsCompleteAtIndex(size_t) const; // Whether or not the frame is fully received.
122 ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
124 // Return the number of bytes in the decoded frame. If the frame is not yet
125 // decoded then return 0.
126 unsigned frameBytesAtIndex(size_t) const;
129 OwnPtr<DeferredImageDecoder> m_decoder;
131 AlphaOption m_alphaOption;
132 GammaAndColorProfileOption m_gammaAndColorProfileOption;