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 <wtf/Noncopyable.h>
30 #include <wtf/Vector.h>
35 typedef struct CGImageSource
* CGImageSourceRef
;
36 typedef struct CGImage
* CGImageRef
;
37 typedef const struct __CFData
* CFDataRef
;
44 struct _cairo_surface
;
45 typedef struct _cairo_surface cairo_surface_t
;
47 class NativeImageSkia
;
58 typedef ImageDecoder
* NativeImageSourcePtr
;
59 typedef const Vector
<char>* NativeBytePtr
;
60 typedef wxBitmap
* NativeImagePtr
;
62 typedef CGImageSourceRef NativeImageSourcePtr
;
63 typedef CGImageRef NativeImagePtr
;
66 typedef ImageDecoderQt
* NativeImageSourcePtr
;
67 typedef QPixmap
* NativeImagePtr
;
70 typedef ImageDecoder
* NativeImageSourcePtr
;
71 typedef cairo_surface_t
* NativeImagePtr
;
74 typedef ImageDecoder
* NativeImageSourcePtr
;
75 typedef NativeImageSkia
* NativeImagePtr
;
78 const int cAnimationLoopOnce
= -1;
79 const int cAnimationNone
= -2;
81 class ImageSource
: Noncopyable
{
86 // Tells the ImageSource that the Image no longer cares about decoded frame
87 // data -- at all (if |destroyAll| is true), or before frame
88 // |clearBeforeFrame| (if |destroyAll| is false). The ImageSource should
89 // delete cached decoded data for these frames where possible to keep memory
90 // usage low. When |destroyAll| is true, the ImageSource should also reset
91 // any local state so that decoding can begin again.
93 // Implementations that delete less than what's specified above waste
94 // memory. Implementations that delete more may burn CPU re-decoding frames
95 // that could otherwise have been cached, or encounter errors if they're
96 // asked to decode frames they can't decode due to the loss of previous
99 // Callers should not call clear(false, n) and subsequently call
100 // createFrameAtIndex(m) with m < n, unless they first call clear(true).
101 // This ensures that stateful ImageSources/decoders will work properly.
103 // The |data| and |allDataReceived| parameters should be supplied by callers
104 // who set |destroyAll| to true if they wish to be able to continue using
105 // the ImageSource. This way implementations which choose to destroy their
106 // decoders in some cases can reconstruct them correctly.
107 void clear(bool destroyAll
,
108 size_t clearBeforeFrame
= 0,
109 SharedBuffer
* data
= NULL
,
110 bool allDataReceived
= false);
112 bool initialized() const;
114 void setData(SharedBuffer
* data
, bool allDataReceived
);
115 String
filenameExtension() const;
117 bool isSizeAvailable();
118 IntSize
size() const;
119 IntSize
frameSizeAtIndex(size_t) const;
120 #if ENABLE(RESPECT_EXIF_ORIENTATION)
121 int orientationAtIndex(size_t) const; // EXIF image orientation
124 int repetitionCount();
126 size_t frameCount() const;
128 // Callers should not call this after calling clear() with a higher index;
129 // see comments on clear() above.
130 NativeImagePtr
createFrameAtIndex(size_t, float scaleHint
, float* actualScaleOut
, ssize_t
* bytesOut
);
132 float frameDurationAtIndex(size_t);
133 bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
134 bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
136 // FIXME: This is protected only to allow ImageSourceSkia to set ICO decoder
137 // with a preferred size. See ImageSourceSkia.h for discussion.
139 NativeImageSourcePtr m_decoder
;
140 mutable int m_baseSubsampling
;
141 mutable bool m_isProgressive
;
142 CFDictionaryRef
imageSourceOptions(int subsampling
= 0) const;