| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 Invalid | 105 Invalid |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 static SniffResult determineImageType(const char* data, size_t length); | 108 static SniffResult determineImageType(const char* data, size_t length); |
| 109 static SniffResult determineImageType(const SharedBuffer&); | 109 static SniffResult determineImageType(const SharedBuffer&); |
| 110 static SniffResult determineImageType(const SegmentReader&); | 110 static SniffResult determineImageType(const SegmentReader&); |
| 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) | |
| 117 , m_isAllDataReceived(false) | |
| 118 , m_failed(false) { } | |
| 119 | 116 |
| 120 virtual ~ImageDecoder() { } | 117 virtual ~ImageDecoder() { } |
| 121 | 118 |
| 122 // Returns a caller-owned decoder of the appropriate type. Returns 0 if | 119 // 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 | 120 // we can't sniff a supported type from the provided data (possibly |
| 124 // because there isn't enough data yet). | 121 // because there isn't enough data yet). |
| 125 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 122 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). |
| 126 static std::unique_ptr<ImageDecoder> create(SniffResult, AlphaOption, GammaA
ndColorProfileOption); | 123 static std::unique_ptr<ImageDecoder> create(SniffResult, AlphaOption, GammaA
ndColorProfileOption); |
| 127 | 124 |
| 128 virtual String filenameExtension() const = 0; | 125 virtual String filenameExtension() const = 0; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // animated images. | 221 // animated images. |
| 225 virtual float frameDurationAtIndex(size_t) const { return 0; } | 222 virtual float frameDurationAtIndex(size_t) const { return 0; } |
| 226 | 223 |
| 227 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 224 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't |
| 228 // have this frame cached (either because it hasn't been decoded, or because | 225 // have this frame cached (either because it hasn't been decoded, or because |
| 229 // it has been cleared). | 226 // it has been cleared). |
| 230 virtual size_t frameBytesAtIndex(size_t) const; | 227 virtual size_t frameBytesAtIndex(size_t) const; |
| 231 | 228 |
| 232 ImageOrientation orientation() const { return m_orientation; } | 229 ImageOrientation orientation() const { return m_orientation; } |
| 233 | 230 |
| 234 void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile
= flag; } | |
| 235 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi
le; } | 231 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi
le; } |
| 232 static void setTargetColorProfile(const WebVector<char>&); |
| 236 | 233 |
| 237 static void setTargetColorProfile(const WebVector<char>&); | 234 |
| 238 bool hasColorProfile() const; | 235 // Note that hasColorProfile refers to the existence of a not-ignored |
| 236 // embedded color profile, and is independent of whether or not that |
| 237 // profile's transform has been baked into the pixel values. |
| 238 bool hasColorProfile() const { return m_hasColorProfile; } |
| 239 void setColorProfileAndComputeTransform(const char* iccData, unsigned iccLen
gth, bool hasAlpha, bool useSRGB); |
| 239 | 240 |
| 240 #if USE(QCMSLIB) | 241 #if USE(QCMSLIB) |
| 241 void setColorProfileAndTransform(const char* iccData, unsigned iccLength, bo
ol hasAlpha, bool useSRGB); | 242 // In contrast with hasColorProfile, this refers to the transform that has |
| 243 // been baked into the pixels. |
| 242 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo
rm.get(); } | 244 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo
rm.get(); } |
| 243 #endif | 245 #endif |
| 244 | 246 |
| 245 // Sets the "decode failure" flag. For caller convenience (since so | 247 // Sets the "decode failure" flag. For caller convenience (since so |
| 246 // many callers want to return false after calling this), returns false | 248 // many callers want to return false after calling this), returns false |
| 247 // to enable easy tailcalling. Subclasses may override this to also | 249 // to enable easy tailcalling. Subclasses may override this to also |
| 248 // clean up any local data. | 250 // clean up any local data. |
| 249 virtual bool setFailed() | 251 virtual bool setFailed() |
| 250 { | 252 { |
| 251 m_failed = true; | 253 m_failed = true; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // returns that number. | 310 // returns that number. |
| 309 virtual size_t decodeFrameCount() { return 1; } | 311 virtual size_t decodeFrameCount() { return 1; } |
| 310 | 312 |
| 311 // Performs any additional setup of the requested frame after it has been | 313 // Performs any additional setup of the requested frame after it has been |
| 312 // initially created, e.g. setting a duration or disposal method. | 314 // initially created, e.g. setting a duration or disposal method. |
| 313 virtual void initializeNewFrame(size_t) { } | 315 virtual void initializeNewFrame(size_t) { } |
| 314 | 316 |
| 315 // Decodes the requested frame. | 317 // Decodes the requested frame. |
| 316 virtual void decode(size_t) = 0; | 318 virtual void decode(size_t) = 0; |
| 317 | 319 |
| 320 // Returns the embedded image color profile. |
| 321 const ImageFrame::ICCProfile& colorProfile() const { return m_colorProfile;
} |
| 322 |
| 318 RefPtr<SegmentReader> m_data; // The encoded data. | 323 RefPtr<SegmentReader> m_data; // The encoded data. |
| 319 Vector<ImageFrame, 1> m_frameBufferCache; | 324 Vector<ImageFrame, 1> m_frameBufferCache; |
| 320 bool m_premultiplyAlpha; | 325 const bool m_premultiplyAlpha; |
| 321 bool m_ignoreGammaAndColorProfile; | 326 const bool m_ignoreGammaAndColorProfile; |
| 322 ImageOrientation m_orientation; | 327 ImageOrientation m_orientation; |
| 323 | 328 |
| 324 // The maximum amount of memory a decoded image should require. Ideally, | 329 // The maximum amount of memory a decoded image should require. Ideally, |
| 325 // image decoders should downsample large images to fit under this limit | 330 // image decoders should downsample large images to fit under this limit |
| 326 // (and then return the downsampled size from decodedSize()). Ignoring | 331 // (and then return the downsampled size from decodedSize()). Ignoring |
| 327 // this limit can cause excessive memory use or even crashes on low- | 332 // this limit can cause excessive memory use or even crashes on low- |
| 328 // memory devices. | 333 // memory devices. |
| 329 size_t m_maxDecodedBytes; | 334 const size_t m_maxDecodedBytes; |
| 330 | 335 |
| 331 private: | 336 private: |
| 332 // Some code paths compute the size of the image as "width * height * 4" | 337 // Some code paths compute the size of the image as "width * height * 4" |
| 333 // and return it as a (signed) int. Avoid overflow. | 338 // and return it as a (signed) int. Avoid overflow. |
| 334 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) | 339 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) |
| 335 { | 340 { |
| 336 unsigned long long total_size = static_cast<unsigned long long>(width) | 341 unsigned long long total_size = static_cast<unsigned long long>(width) |
| 337 * static_cast<unsigned long long>(height); | 342 * static_cast<unsigned long long>(height); |
| 338 return total_size > ((1 << 29) - 1); | 343 return total_size > ((1 << 29) - 1); |
| 339 } | 344 } |
| 340 | 345 |
| 341 IntSize m_size; | 346 IntSize m_size; |
| 342 bool m_sizeAvailable; | 347 bool m_sizeAvailable = false; |
| 343 bool m_isAllDataReceived; | 348 bool m_isAllDataReceived = false; |
| 344 bool m_failed; | 349 bool m_failed = false; |
| 350 |
| 351 bool m_hasColorProfile = false; |
| 352 ImageFrame::ICCProfile m_colorProfile; |
| 345 | 353 |
| 346 #if USE(QCMSLIB) | 354 #if USE(QCMSLIB) |
| 347 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; | 355 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; |
| 348 #endif | 356 #endif |
| 349 }; | 357 }; |
| 350 | 358 |
| 351 } // namespace blink | 359 } // namespace blink |
| 352 | 360 |
| 353 #endif | 361 #endif |
| OLD | NEW |