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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 public: | 84 public: |
| 85 static const size_t noDecodedImageByteLimit = Platform::noDecodedImageByteLi mit; | 85 static const size_t noDecodedImageByteLimit = Platform::noDecodedImageByteLi mit; |
| 86 | 86 |
| 87 enum AlphaOption { | 87 enum AlphaOption { |
| 88 AlphaPremultiplied, | 88 AlphaPremultiplied, |
| 89 AlphaNotPremultiplied | 89 AlphaNotPremultiplied |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 enum GammaAndColorProfileOption { | 92 enum GammaAndColorProfileOption { |
| 93 GammaAndColorProfileApplied, | 93 GammaAndColorProfileApplied, |
| 94 GammaAndColorProfileIgnored | 94 GammaAndColorProfileNotApplied |
|
Justin Novosad
2016/08/02 22:49:13
You still need to keep the "Ignore" option IMHO.
| |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 enum class SniffResult { | 97 enum class SniffResult { |
| 98 JPEG, | 98 JPEG, |
| 99 PNG, | 99 PNG, |
| 100 GIF, | 100 GIF, |
| 101 WEBP, | 101 WEBP, |
| 102 ICO, | 102 ICO, |
| 103 BMP, | 103 BMP, |
| 104 InsufficientData, | 104 InsufficientData, |
| 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) | |
| 115 , m_maxDecodedBytes(maxDecodedBytes) | 114 , m_maxDecodedBytes(maxDecodedBytes) |
| 116 , m_sizeAvailable(false) | 115 , m_bakeColorTransformToPixels(colorOptions == GammaAndColorProfileAppli ed) { } |
| 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; } | 231 static void setTargetColorProfile(const WebVector<char>&); |
| 235 bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfi le; } | |
| 236 | 232 |
| 237 static void setTargetColorProfile(const WebVector<char>&); | 233 // Note that hasColorProfile refers to the existence of an embedded color |
| 238 bool hasColorProfile() const; | 234 // profile, and is independent of whether or not that profile's transform |
| 235 // has been baked into the pixel values. | |
| 236 bool hasColorProfile() const { return m_hasColorProfile; } | |
| 237 void setColorProfileAndComputeTransform(const char* iccData, unsigned iccLen gth, bool hasAlpha, bool useSRGB); | |
| 239 | 238 |
| 240 #if USE(QCMSLIB) | 239 #if USE(QCMSLIB) |
| 241 void setColorProfileAndTransform(const char* iccData, unsigned iccLength, bo ol hasAlpha, bool useSRGB); | 240 // In contrast with hasColorProfile, this refers to the transform that has |
| 241 // been baked into the pixels. | |
| 242 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo rm.get(); } | 242 qcms_transform* colorTransform() { return m_sourceToOutputDeviceColorTransfo rm.get(); } |
| 243 #endif | 243 #endif |
| 244 | 244 |
| 245 // Sets the "decode failure" flag. For caller convenience (since so | 245 // Sets the "decode failure" flag. For caller convenience (since so |
| 246 // many callers want to return false after calling this), returns false | 246 // many callers want to return false after calling this), returns false |
| 247 // to enable easy tailcalling. Subclasses may override this to also | 247 // to enable easy tailcalling. Subclasses may override this to also |
| 248 // clean up any local data. | 248 // clean up any local data. |
| 249 virtual bool setFailed() | 249 virtual bool setFailed() |
| 250 { | 250 { |
| 251 m_failed = true; | 251 m_failed = true; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 // returns that number. | 308 // returns that number. |
| 309 virtual size_t decodeFrameCount() { return 1; } | 309 virtual size_t decodeFrameCount() { return 1; } |
| 310 | 310 |
| 311 // Performs any additional setup of the requested frame after it has been | 311 // Performs any additional setup of the requested frame after it has been |
| 312 // initially created, e.g. setting a duration or disposal method. | 312 // initially created, e.g. setting a duration or disposal method. |
| 313 virtual void initializeNewFrame(size_t) { } | 313 virtual void initializeNewFrame(size_t) { } |
| 314 | 314 |
| 315 // Decodes the requested frame. | 315 // Decodes the requested frame. |
| 316 virtual void decode(size_t) = 0; | 316 virtual void decode(size_t) = 0; |
| 317 | 317 |
| 318 // Returns the embedded image color profile. | |
| 319 const ImageFrame::ICCProfile& colorProfile() const { return m_colorProfile; } | |
| 320 | |
| 318 RefPtr<SegmentReader> m_data; // The encoded data. | 321 RefPtr<SegmentReader> m_data; // The encoded data. |
| 319 Vector<ImageFrame, 1> m_frameBufferCache; | 322 Vector<ImageFrame, 1> m_frameBufferCache; |
| 320 bool m_premultiplyAlpha; | 323 bool m_premultiplyAlpha; |
| 321 bool m_ignoreGammaAndColorProfile; | |
| 322 ImageOrientation m_orientation; | 324 ImageOrientation m_orientation; |
| 323 | 325 |
| 324 // The maximum amount of memory a decoded image should require. Ideally, | 326 // The maximum amount of memory a decoded image should require. Ideally, |
| 325 // image decoders should downsample large images to fit under this limit | 327 // image decoders should downsample large images to fit under this limit |
| 326 // (and then return the downsampled size from decodedSize()). Ignoring | 328 // (and then return the downsampled size from decodedSize()). Ignoring |
| 327 // this limit can cause excessive memory use or even crashes on low- | 329 // this limit can cause excessive memory use or even crashes on low- |
| 328 // memory devices. | 330 // memory devices. |
| 329 size_t m_maxDecodedBytes; | 331 size_t m_maxDecodedBytes; |
| 330 | 332 |
| 331 private: | 333 private: |
| 332 // Some code paths compute the size of the image as "width * height * 4" | 334 // Some code paths compute the size of the image as "width * height * 4" |
| 333 // and return it as a (signed) int. Avoid overflow. | 335 // and return it as a (signed) int. Avoid overflow. |
| 334 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) | 336 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) |
| 335 { | 337 { |
| 336 unsigned long long total_size = static_cast<unsigned long long>(width) | 338 unsigned long long total_size = static_cast<unsigned long long>(width) |
| 337 * static_cast<unsigned long long>(height); | 339 * static_cast<unsigned long long>(height); |
| 338 return total_size > ((1 << 29) - 1); | 340 return total_size > ((1 << 29) - 1); |
| 339 } | 341 } |
| 340 | 342 |
| 341 IntSize m_size; | 343 IntSize m_size; |
| 342 bool m_sizeAvailable; | 344 bool m_sizeAvailable = false; |
| 343 bool m_isAllDataReceived; | 345 bool m_isAllDataReceived = false; |
| 344 bool m_failed; | 346 bool m_failed = false; |
| 347 | |
| 348 const bool m_bakeColorTransformToPixels = false; | |
| 349 | |
| 350 bool m_hasColorProfile = false; | |
| 351 ImageFrame::ICCProfile m_colorProfile; | |
| 345 | 352 |
| 346 #if USE(QCMSLIB) | 353 #if USE(QCMSLIB) |
| 347 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; | 354 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; |
| 348 #endif | 355 #endif |
| 349 }; | 356 }; |
| 350 | 357 |
| 351 } // namespace blink | 358 } // namespace blink |
| 352 | 359 |
| 353 #endif | 360 #endif |
| OLD | NEW |