OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 GammaAndColorProfileApplied, | 94 GammaAndColorProfileApplied, |
95 GammaAndColorProfileIgnored | 95 GammaAndColorProfileIgnored |
96 }; | 96 }; |
97 | 97 |
98 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption
s, size_t maxDecodedBytes) | 98 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption
s, size_t maxDecodedBytes) |
99 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) | 99 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) |
100 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor
ed) | 100 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor
ed) |
101 , m_maxDecodedBytes(maxDecodedBytes) | 101 , m_maxDecodedBytes(maxDecodedBytes) |
102 , m_sizeAvailable(false) | 102 , m_sizeAvailable(false) |
103 , m_isAllDataReceived(false) | 103 , m_isAllDataReceived(false) |
| 104 , m_haveUpdatedFrameCount(true) |
104 , m_failed(false) { } | 105 , m_failed(false) { } |
105 | 106 |
106 virtual ~ImageDecoder() { } | 107 virtual ~ImageDecoder() { } |
107 | 108 |
108 // Returns a caller-owned decoder of the appropriate type. Returns 0 if | 109 // Returns a caller-owned decoder of the appropriate type. Returns 0 if |
109 // we can't sniff a supported type from the provided data (possibly | 110 // we can't sniff a supported type from the provided data (possibly |
110 // because there isn't enough data yet). | 111 // because there isn't enough data yet). |
111 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 112 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). |
112 static PassOwnPtr<ImageDecoder> create(const char* data, size_t length, Alph
aOption, GammaAndColorProfileOption); | 113 static PassOwnPtr<ImageDecoder> create(const char* data, size_t length, Alph
aOption, GammaAndColorProfileOption); |
113 static PassOwnPtr<ImageDecoder> create(const SharedBuffer&, AlphaOption, Gam
maAndColorProfileOption); | 114 static PassOwnPtr<ImageDecoder> create(const SharedBuffer&, AlphaOption, Gam
maAndColorProfileOption); |
114 static PassOwnPtr<ImageDecoder> create(const SegmentReader&, AlphaOption, Ga
mmaAndColorProfileOption); | 115 static PassOwnPtr<ImageDecoder> create(const SegmentReader&, AlphaOption, Ga
mmaAndColorProfileOption); |
115 | 116 |
116 virtual String filenameExtension() const = 0; | 117 virtual String filenameExtension() const = 0; |
117 | 118 |
118 bool isAllDataReceived() const { return m_isAllDataReceived; } | 119 bool isAllDataReceived() const { return m_isAllDataReceived; } |
119 | 120 |
120 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) | 121 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) |
121 { | 122 { |
122 if (m_failed) | 123 if (m_failed) |
123 return; | 124 return; |
124 m_data = data; | 125 m_data = data; |
125 m_isAllDataReceived = allDataReceived; | 126 m_isAllDataReceived = allDataReceived; |
| 127 m_haveUpdatedFrameCount = false; |
126 onSetData(m_data.get()); | 128 onSetData(m_data.get()); |
127 } | 129 } |
128 | 130 |
129 void setData(PassRefPtr<SharedBuffer> data, bool allDataReceived) | 131 void setData(PassRefPtr<SharedBuffer> data, bool allDataReceived) |
130 { | 132 { |
131 setData(SegmentReader::createFromSharedBuffer(data), allDataReceived); | 133 setData(SegmentReader::createFromSharedBuffer(data), allDataReceived); |
132 } | 134 } |
133 | 135 |
134 virtual void onSetData(SegmentReader* data) { } | 136 virtual void onSetData(SegmentReader* data) { } |
135 | 137 |
136 bool isSizeAvailable() | 138 bool isSizeAvailable() |
137 { | 139 { |
138 if (m_failed) | 140 if (m_failed) |
139 return false; | 141 return false; |
140 if (!m_sizeAvailable) | 142 if (!m_sizeAvailable) |
141 decodeSize(); | 143 decodeSize(); |
142 return isDecodedSizeAvailable(); | 144 return isDecodedSizeAvailable(); |
143 } | 145 } |
144 | 146 |
145 bool isDecodedSizeAvailable() const | 147 bool isDecodedSizeAvailable() const |
146 { | 148 { |
147 return !m_failed && m_sizeAvailable; | 149 return !m_failed && m_sizeAvailable; |
148 } | 150 } |
149 | 151 |
| 152 // Whether the requested frame is fully decoded. |
| 153 inline bool frameIsCompleteAtIndex(size_t frameIndex) const |
| 154 { |
| 155 return (frameIndex < m_frameBufferCache.size()) && (m_frameBufferCache[f
rameIndex].getStatus() == ImageFrame::FrameComplete); |
| 156 } |
| 157 |
150 virtual IntSize size() const { return m_size; } | 158 virtual IntSize size() const { return m_size; } |
151 | 159 |
152 // Decoders which downsample images should override this method to | 160 // Decoders which downsample images should override this method to |
153 // return the actual decoded size. | 161 // return the actual decoded size. |
154 virtual IntSize decodedSize() const { return size(); } | 162 virtual IntSize decodedSize() const { return size(); } |
155 | 163 |
156 // Image decoders that support YUV decoding must override this to | 164 // Image decoders that support YUV decoding must override this to |
157 // provide the size of each component. | 165 // provide the size of each component. |
158 virtual IntSize decodedYUVSize(int component) const | 166 virtual IntSize decodedYUVSize(int component) const |
159 { | 167 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // decoding the individual frames. Resizes m_frameBufferCache to the | 203 // decoding the individual frames. Resizes m_frameBufferCache to the |
196 // correct size and returns its size. | 204 // correct size and returns its size. |
197 size_t frameCount(); | 205 size_t frameCount(); |
198 | 206 |
199 virtual int repetitionCount() const { return cAnimationNone; } | 207 virtual int repetitionCount() const { return cAnimationNone; } |
200 | 208 |
201 // Decodes as much of the requested frame as possible, and returns an | 209 // Decodes as much of the requested frame as possible, and returns an |
202 // ImageDecoder-owned pointer. | 210 // ImageDecoder-owned pointer. |
203 ImageFrame* frameBufferAtIndex(size_t); | 211 ImageFrame* frameBufferAtIndex(size_t); |
204 | 212 |
205 // Whether the requested frame has alpha. | |
206 virtual bool frameHasAlphaAtIndex(size_t) const; | |
207 | |
208 // Whether or not the frame is fully received. | 213 // Whether or not the frame is fully received. |
209 virtual bool frameIsCompleteAtIndex(size_t) const; | 214 virtual bool frameIsFullyReceivedAtIndex(size_t) const; |
210 | 215 |
211 // Duration for displaying a frame in seconds. This method is only used by | 216 // Duration for displaying a frame in seconds. This method is only used by |
212 // animated images. | 217 // animated images. |
213 virtual float frameDurationAtIndex(size_t) const { return 0; } | 218 virtual float frameDurationAtIndex(size_t) const { return 0; } |
214 | 219 |
215 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 220 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't |
216 // have this frame cached (either because it hasn't been decoded, or because | 221 // have this frame cached (either because it hasn't been decoded, or because |
217 // it has been cleared). | 222 // it has been cleared). |
218 virtual size_t frameBytesAtIndex(size_t) const; | 223 virtual size_t frameBytesAtIndex(size_t) const; |
219 | 224 |
| 225 // Whether the requested frame has alpha. |
| 226 bool frameHasAlphaAtIndex(size_t) const; |
| 227 |
220 ImageOrientation orientation() const { return m_orientation; } | 228 ImageOrientation orientation() const { return m_orientation; } |
221 | 229 |
222 void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile
= flag; } | 230 void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile
= flag; } |
223 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi
le; } | 231 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi
le; } |
224 | 232 |
225 bool hasColorProfile() const; | 233 bool hasColorProfile() const; |
226 | 234 |
227 #if USE(QCMSLIB) | 235 #if USE(QCMSLIB) |
228 void setColorProfileAndTransform(const char* iccData, unsigned iccLength, bo
ol hasAlpha, bool useSRGB); | 236 void setColorProfileAndTransform(const char* iccData, unsigned iccLength, bo
ol hasAlpha, bool useSRGB); |
229 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo
rm.get(); } | 237 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo
rm.get(); } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 bool m_ignoreGammaAndColorProfile; | 316 bool m_ignoreGammaAndColorProfile; |
309 ImageOrientation m_orientation; | 317 ImageOrientation m_orientation; |
310 | 318 |
311 // The maximum amount of memory a decoded image should require. Ideally, | 319 // The maximum amount of memory a decoded image should require. Ideally, |
312 // image decoders should downsample large images to fit under this limit | 320 // image decoders should downsample large images to fit under this limit |
313 // (and then return the downsampled size from decodedSize()). Ignoring | 321 // (and then return the downsampled size from decodedSize()). Ignoring |
314 // this limit can cause excessive memory use or even crashes on low- | 322 // this limit can cause excessive memory use or even crashes on low- |
315 // memory devices. | 323 // memory devices. |
316 size_t m_maxDecodedBytes; | 324 size_t m_maxDecodedBytes; |
317 | 325 |
| 326 // Whether frameCount() was called to update frame count after setData(). |
| 327 bool haveUpdatedFrameCount() const { return m_haveUpdatedFrameCount; } |
| 328 |
318 private: | 329 private: |
319 // Some code paths compute the size of the image as "width * height * 4" | 330 // Some code paths compute the size of the image as "width * height * 4" |
320 // and return it as a (signed) int. Avoid overflow. | 331 // and return it as a (signed) int. Avoid overflow. |
321 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) | 332 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) |
322 { | 333 { |
323 unsigned long long total_size = static_cast<unsigned long long>(width) | 334 unsigned long long total_size = static_cast<unsigned long long>(width) |
324 * static_cast<unsigned long long>(height); | 335 * static_cast<unsigned long long>(height); |
325 return total_size > ((1 << 29) - 1); | 336 return total_size > ((1 << 29) - 1); |
326 } | 337 } |
327 | 338 |
328 IntSize m_size; | 339 IntSize m_size; |
329 bool m_sizeAvailable; | 340 bool m_sizeAvailable; |
330 bool m_isAllDataReceived; | 341 bool m_isAllDataReceived; |
| 342 bool m_haveUpdatedFrameCount; |
331 bool m_failed; | 343 bool m_failed; |
332 | 344 |
333 #if USE(QCMSLIB) | 345 #if USE(QCMSLIB) |
334 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; | 346 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; |
335 #endif | 347 #endif |
336 }; | 348 }; |
337 | 349 |
338 } // namespace blink | 350 } // namespace blink |
339 | 351 |
340 #endif | 352 #endif |
OLD | NEW |