Chromium Code Reviews| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 GammaAndColorProfileApplied, | 108 GammaAndColorProfileApplied, | 
| 109 GammaAndColorProfileIgnored | 109 GammaAndColorProfileIgnored | 
| 110 }; | 110 }; | 
| 111 | 111 | 
| 112 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption s, size_t maxDecodedBytes) | 112 ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOption s, size_t maxDecodedBytes) | 
| 113 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) | 113 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) | 
| 114 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor ed) | 114 , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnor ed) | 
| 115 , m_maxDecodedBytes(maxDecodedBytes) | 115 , m_maxDecodedBytes(maxDecodedBytes) | 
| 116 , m_sizeAvailable(false) | 116 , m_sizeAvailable(false) | 
| 117 , m_isAllDataReceived(false) | 117 , m_isAllDataReceived(false) | 
| 118 , m_haveUpdatedFrameCount(true) | |
| 118 , m_failed(false) { } | 119 , m_failed(false) { } | 
| 119 | 120 | 
| 120 virtual ~ImageDecoder() { } | 121 virtual ~ImageDecoder() { } | 
| 121 | 122 | 
| 122 // Returns a caller-owned decoder of the appropriate type. Returns 0 if | 123 // Returns a caller-owned decoder of the appropriate type. Returns 0 if | 
| 123 // we can't sniff a supported type from the provided data (possibly | 124 // we can't sniff a supported type from the provided data (possibly | 
| 124 // because there isn't enough data yet). | 125 // because there isn't enough data yet). | 
| 125 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 126 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 
| 126 static PassOwnPtr<ImageDecoder> create(const char* data, size_t length, Alph aOption, GammaAndColorProfileOption); | 127 static PassOwnPtr<ImageDecoder> create(const char* data, size_t length, Alph aOption, GammaAndColorProfileOption); | 
| 127 static PassOwnPtr<ImageDecoder> create(const SharedBuffer&, AlphaOption, Gam maAndColorProfileOption); | 128 static PassOwnPtr<ImageDecoder> create(const SharedBuffer&, AlphaOption, Gam maAndColorProfileOption); | 
| 128 static PassOwnPtr<ImageDecoder> create(const SegmentReader&, AlphaOption, Ga mmaAndColorProfileOption); | 129 static PassOwnPtr<ImageDecoder> create(const SegmentReader&, AlphaOption, Ga mmaAndColorProfileOption); | 
| 129 | 130 | 
| 130 virtual String filenameExtension() const = 0; | 131 virtual String filenameExtension() const = 0; | 
| 131 | 132 | 
| 132 bool isAllDataReceived() const { return m_isAllDataReceived; } | 133 bool isAllDataReceived() const { return m_isAllDataReceived; } | 
| 133 | 134 | 
| 134 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) | 135 void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) | 
| 135 { | 136 { | 
| 136 if (m_failed) | 137 if (m_failed) | 
| 137 return; | 138 return; | 
| 138 m_data = data; | 139 m_data = data; | 
| 139 m_isAllDataReceived = allDataReceived; | 140 m_isAllDataReceived = allDataReceived; | 
| 141 m_haveUpdatedFrameCount = false; | |
| 140 onSetData(m_data.get()); | 142 onSetData(m_data.get()); | 
| 141 } | 143 } | 
| 142 | 144 | 
| 143 void setData(PassRefPtr<SharedBuffer> data, bool allDataReceived) | 145 void setData(PassRefPtr<SharedBuffer> data, bool allDataReceived) | 
| 144 { | 146 { | 
| 145 setData(SegmentReader::createFromSharedBuffer(data), allDataReceived); | 147 setData(SegmentReader::createFromSharedBuffer(data), allDataReceived); | 
| 146 } | 148 } | 
| 147 | 149 | 
| 148 virtual void onSetData(SegmentReader* data) { } | 150 virtual void onSetData(SegmentReader* data) { } | 
| 149 | 151 | 
| 150 bool isSizeAvailable() | 152 bool isSizeAvailable() | 
| 151 { | 153 { | 
| 152 if (m_failed) | 154 if (m_failed) | 
| 153 return false; | 155 return false; | 
| 154 if (!m_sizeAvailable) | 156 if (!m_sizeAvailable) | 
| 155 decodeSize(); | 157 decodeSize(); | 
| 156 return isDecodedSizeAvailable(); | 158 return isDecodedSizeAvailable(); | 
| 157 } | 159 } | 
| 158 | 160 | 
| 159 bool isDecodedSizeAvailable() const | 161 bool isDecodedSizeAvailable() const | 
| 160 { | 162 { | 
| 161 return !m_failed && m_sizeAvailable; | 163 return !m_failed && m_sizeAvailable; | 
| 162 } | 164 } | 
| 163 | 165 | 
| 166 // Whether the requested frame is fully decoded. | |
| 167 inline bool frameIsCompleteAtIndex(size_t frameIndex) const | |
| 168 { | |
| 169 return (frameIndex < m_frameBufferCache.size()) && (m_frameBufferCache[f rameIndex].getStatus() == ImageFrame::FrameComplete); | |
| 170 } | |
| 171 | |
| 164 virtual IntSize size() const { return m_size; } | 172 virtual IntSize size() const { return m_size; } | 
| 165 | 173 | 
| 166 // Decoders which downsample images should override this method to | 174 // Decoders which downsample images should override this method to | 
| 167 // return the actual decoded size. | 175 // return the actual decoded size. | 
| 168 virtual IntSize decodedSize() const { return size(); } | 176 virtual IntSize decodedSize() const { return size(); } | 
| 169 | 177 | 
| 170 // Image decoders that support YUV decoding must override this to | 178 // Image decoders that support YUV decoding must override this to | 
| 171 // provide the size of each component. | 179 // provide the size of each component. | 
| 172 virtual IntSize decodedYUVSize(int component) const | 180 virtual IntSize decodedYUVSize(int component) const | 
| 173 { | 181 { | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // decoding the individual frames. Resizes m_frameBufferCache to the | 217 // decoding the individual frames. Resizes m_frameBufferCache to the | 
| 210 // correct size and returns its size. | 218 // correct size and returns its size. | 
| 211 size_t frameCount(); | 219 size_t frameCount(); | 
| 212 | 220 | 
| 213 virtual int repetitionCount() const { return cAnimationNone; } | 221 virtual int repetitionCount() const { return cAnimationNone; } | 
| 214 | 222 | 
| 215 // Decodes as much of the requested frame as possible, and returns an | 223 // Decodes as much of the requested frame as possible, and returns an | 
| 216 // ImageDecoder-owned pointer. | 224 // ImageDecoder-owned pointer. | 
| 217 ImageFrame* frameBufferAtIndex(size_t); | 225 ImageFrame* frameBufferAtIndex(size_t); | 
| 218 | 226 | 
| 219 // Whether the requested frame has alpha. | |
| 220 virtual bool frameHasAlphaAtIndex(size_t) const; | |
| 221 | |
| 222 // Whether or not the frame is fully received. | 227 // Whether or not the frame is fully received. | 
| 223 virtual bool frameIsCompleteAtIndex(size_t) const; | 228 virtual bool frameIsFullyReceivedAtIndex(size_t) const; | 
| 224 | 229 | 
| 225 // Duration for displaying a frame in seconds. This method is only used by | 230 // Duration for displaying a frame in seconds. This method is only used by | 
| 226 // animated images. | 231 // animated images. | 
| 227 virtual float frameDurationAtIndex(size_t) const { return 0; } | 232 virtual float frameDurationAtIndex(size_t) const { return 0; } | 
| 228 | 233 | 
| 229 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 234 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 
| 230 // have this frame cached (either because it hasn't been decoded, or because | 235 // have this frame cached (either because it hasn't been decoded, or because | 
| 231 // it has been cleared). | 236 // it has been cleared). | 
| 232 virtual size_t frameBytesAtIndex(size_t) const; | 237 virtual size_t frameBytesAtIndex(size_t) const; | 
| 233 | 238 | 
| 239 // Whether the requested frame has alpha. | |
| 240 bool frameHasAlphaAtIndex(size_t) const; | |
| 241 | |
| 234 ImageOrientation orientation() const { return m_orientation; } | 242 ImageOrientation orientation() const { return m_orientation; } | 
| 235 | 243 | 
| 236 static bool deferredImageDecodingEnabled(); | 244 static bool deferredImageDecodingEnabled(); | 
| 237 | 245 | 
| 238 void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; } | 246 void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; } | 
| 239 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi le; } | 247 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi le; } | 
| 240 | 248 | 
| 241 bool hasColorProfile() const; | 249 bool hasColorProfile() const; | 
| 242 | 250 | 
| 243 #if USE(QCMSLIB) | 251 #if USE(QCMSLIB) | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 bool m_ignoreGammaAndColorProfile; | 332 bool m_ignoreGammaAndColorProfile; | 
| 325 ImageOrientation m_orientation; | 333 ImageOrientation m_orientation; | 
| 326 | 334 | 
| 327 // The maximum amount of memory a decoded image should require. Ideally, | 335 // The maximum amount of memory a decoded image should require. Ideally, | 
| 328 // image decoders should downsample large images to fit under this limit | 336 // image decoders should downsample large images to fit under this limit | 
| 329 // (and then return the downsampled size from decodedSize()). Ignoring | 337 // (and then return the downsampled size from decodedSize()). Ignoring | 
| 330 // this limit can cause excessive memory use or even crashes on low- | 338 // this limit can cause excessive memory use or even crashes on low- | 
| 331 // memory devices. | 339 // memory devices. | 
| 332 size_t m_maxDecodedBytes; | 340 size_t m_maxDecodedBytes; | 
| 333 | 341 | 
| 342 // Whether frameCount() was called to update frame count after setData(). | |
| 
 
Peter Kasting
2016/06/10 00:10:02
Nit: update -> update the
 
 | |
| 343 bool haveUpdatedFrameCount() const { return m_haveUpdatedFrameCount; } | |
| 344 | |
| 334 private: | 345 private: | 
| 335 // Some code paths compute the size of the image as "width * height * 4" | 346 // Some code paths compute the size of the image as "width * height * 4" | 
| 336 // and return it as a (signed) int. Avoid overflow. | 347 // and return it as a (signed) int. Avoid overflow. | 
| 337 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) | 348 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) | 
| 338 { | 349 { | 
| 339 unsigned long long total_size = static_cast<unsigned long long>(width) | 350 unsigned long long total_size = static_cast<unsigned long long>(width) | 
| 340 * static_cast<unsigned long long>(height); | 351 * static_cast<unsigned long long>(height); | 
| 341 return total_size > ((1 << 29) - 1); | 352 return total_size > ((1 << 29) - 1); | 
| 342 } | 353 } | 
| 343 | 354 | 
| 344 IntSize m_size; | 355 IntSize m_size; | 
| 345 bool m_sizeAvailable; | 356 bool m_sizeAvailable; | 
| 346 bool m_isAllDataReceived; | 357 bool m_isAllDataReceived; | 
| 358 bool m_haveUpdatedFrameCount; | |
| 347 bool m_failed; | 359 bool m_failed; | 
| 348 | 360 | 
| 349 #if USE(QCMSLIB) | 361 #if USE(QCMSLIB) | 
| 350 OwnPtr<qcms_transform> m_sourceToOutputDeviceColorTransform; | 362 OwnPtr<qcms_transform> m_sourceToOutputDeviceColorTransform; | 
| 351 #endif | 363 #endif | 
| 352 }; | 364 }; | 
| 353 | 365 | 
| 354 } // namespace blink | 366 } // namespace blink | 
| 355 | 367 | 
| 356 #endif | 368 #endif | 
| OLD | NEW |