| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 class PLATFORM_EXPORT ImageDecoder { | 79 class PLATFORM_EXPORT ImageDecoder { |
| 80 WTF_MAKE_NONCOPYABLE(ImageDecoder); | 80 WTF_MAKE_NONCOPYABLE(ImageDecoder); |
| 81 USING_FAST_MALLOC(ImageDecoder); | 81 USING_FAST_MALLOC(ImageDecoder); |
| 82 | 82 |
| 83 public: | 83 public: |
| 84 static const size_t noDecodedImageByteLimit = | 84 static const size_t noDecodedImageByteLimit = |
| 85 Platform::noDecodedImageByteLimit; | 85 Platform::noDecodedImageByteLimit; |
| 86 | 86 |
| 87 enum AlphaOption { AlphaPremultiplied, AlphaNotPremultiplied }; | 87 enum AlphaOption { AlphaPremultiplied, AlphaNotPremultiplied }; |
| 88 | 88 |
| 89 enum GammaAndColorProfileOption { | 89 enum ColorSpaceOption { ColorSpaceApplied, ColorSpaceIgnored }; |
| 90 GammaAndColorProfileApplied, | |
| 91 GammaAndColorProfileIgnored | |
| 92 }; | |
| 93 | 90 |
| 94 virtual ~ImageDecoder() {} | 91 virtual ~ImageDecoder() {} |
| 95 | 92 |
| 96 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if | 93 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if |
| 97 // we can't sniff a supported type from the provided data (possibly | 94 // we can't sniff a supported type from the provided data (possibly |
| 98 // because there isn't enough data yet). | 95 // because there isn't enough data yet). |
| 99 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 96 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). |
| 100 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SegmentReader> data, | 97 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SegmentReader> data, |
| 101 bool dataComplete, | 98 bool dataComplete, |
| 102 AlphaOption, | 99 AlphaOption, |
| 103 GammaAndColorProfileOption); | 100 ColorSpaceOption); |
| 104 static std::unique_ptr<ImageDecoder> create( | 101 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SharedBuffer> data, |
| 105 PassRefPtr<SharedBuffer> data, | 102 bool dataComplete, |
| 106 bool dataComplete, | 103 AlphaOption alphaoption, |
| 107 AlphaOption alphaoption, | 104 ColorSpaceOption colorOptions) { |
| 108 GammaAndColorProfileOption colorOptions) { | |
| 109 return create(SegmentReader::createFromSharedBuffer(std::move(data)), | 105 return create(SegmentReader::createFromSharedBuffer(std::move(data)), |
| 110 dataComplete, alphaoption, colorOptions); | 106 dataComplete, alphaoption, colorOptions); |
| 111 } | 107 } |
| 112 | 108 |
| 113 virtual String filenameExtension() const = 0; | 109 virtual String filenameExtension() const = 0; |
| 114 | 110 |
| 115 bool isAllDataReceived() const { return m_isAllDataReceived; } | 111 bool isAllDataReceived() const { return m_isAllDataReceived; } |
| 116 | 112 |
| 117 // Returns true if the buffer holds enough data to instantiate a decoder. | 113 // Returns true if the buffer holds enough data to instantiate a decoder. |
| 118 // This is useful for callers to determine whether a decoder instantiation | 114 // This is useful for callers to determine whether a decoder instantiation |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // animated images. | 199 // animated images. |
| 204 virtual float frameDurationAtIndex(size_t) const { return 0; } | 200 virtual float frameDurationAtIndex(size_t) const { return 0; } |
| 205 | 201 |
| 206 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 202 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't |
| 207 // have this frame cached (either because it hasn't been decoded, or because | 203 // have this frame cached (either because it hasn't been decoded, or because |
| 208 // it has been cleared). | 204 // it has been cleared). |
| 209 virtual size_t frameBytesAtIndex(size_t) const; | 205 virtual size_t frameBytesAtIndex(size_t) const; |
| 210 | 206 |
| 211 ImageOrientation orientation() const { return m_orientation; } | 207 ImageOrientation orientation() const { return m_orientation; } |
| 212 | 208 |
| 213 bool ignoresGammaAndColorProfile() const { | 209 bool ignoresColorSpace() const { return m_ignoreColorSpace; } |
| 214 return m_ignoreGammaAndColorProfile; | |
| 215 } | |
| 216 static void setTargetColorProfile(const WebVector<char>&); | 210 static void setTargetColorProfile(const WebVector<char>&); |
| 217 | 211 |
| 218 // Note that hasColorProfile refers to the existence of a not-ignored | 212 // Note that hasColorSpace refers to the existence of a not-ignored |
| 219 // embedded color profile, and is independent of whether or not that | 213 // embedded color space, and is independent of whether or not that |
| 220 // profile's transform has been baked into the pixel values. | 214 // space's transform has been baked into the pixel values. |
| 221 bool hasColorProfile() const { return m_hasColorProfile; } | 215 bool hasColorSpace() const { return m_srcSpace.get(); } |
| 222 void setColorSpaceAndComputeTransform(const char* iccData, | 216 void setColorSpaceAndComputeTransform(const char* iccData, |
| 223 unsigned iccLength, | 217 unsigned iccLength); |
| 224 bool useSRGB); | 218 void setColorSpaceAndComputeTransform(sk_sp<SkColorSpace> srcSpace); |
| 225 | 219 |
| 226 // Transformation from encoded color space to target color space. | 220 // Transformation from encoded color space to target color space. |
| 227 SkColorSpaceXform* colorTransform() { | 221 SkColorSpaceXform* colorTransform() { |
| 228 return m_sourceToOutputDeviceColorTransform.get(); | 222 return m_sourceToOutputDeviceColorTransform.get(); |
| 229 } | 223 } |
| 230 | 224 |
| 231 // Sets the "decode failure" flag. For caller convenience (since so | 225 // Sets the "decode failure" flag. For caller convenience (since so |
| 232 // many callers want to return false after calling this), returns false | 226 // many callers want to return false after calling this), returns false |
| 233 // to enable easy tailcalling. Subclasses may override this to also | 227 // to enable easy tailcalling. Subclasses may override this to also |
| 234 // clean up any local data. | 228 // clean up any local data. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 258 } | 252 } |
| 259 m_frameBufferCache[0].setMemoryAllocator(allocator); | 253 m_frameBufferCache[0].setMemoryAllocator(allocator); |
| 260 } | 254 } |
| 261 | 255 |
| 262 virtual bool canDecodeToYUV() { return false; } | 256 virtual bool canDecodeToYUV() { return false; } |
| 263 virtual bool decodeToYUV() { return false; } | 257 virtual bool decodeToYUV() { return false; } |
| 264 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} | 258 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} |
| 265 | 259 |
| 266 protected: | 260 protected: |
| 267 ImageDecoder(AlphaOption alphaOption, | 261 ImageDecoder(AlphaOption alphaOption, |
| 268 GammaAndColorProfileOption colorOptions, | 262 ColorSpaceOption colorOptions, |
| 269 size_t maxDecodedBytes) | 263 size_t maxDecodedBytes) |
| 270 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), | 264 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), |
| 271 m_ignoreGammaAndColorProfile(colorOptions == | 265 m_ignoreColorSpace(colorOptions == ColorSpaceIgnored), |
| 272 GammaAndColorProfileIgnored), | |
| 273 m_maxDecodedBytes(maxDecodedBytes), | 266 m_maxDecodedBytes(maxDecodedBytes), |
| 274 m_purgeAggressively(false) {} | 267 m_purgeAggressively(false) {} |
| 275 | 268 |
| 276 // Calculates the most recent frame whose image data may be needed in | 269 // Calculates the most recent frame whose image data may be needed in |
| 277 // order to decode frame |frameIndex|, based on frame disposal methods | 270 // order to decode frame |frameIndex|, based on frame disposal methods |
| 278 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether | 271 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether |
| 279 // the rectangle of frame at |frameIndex| is known to be opaque. | 272 // the rectangle of frame at |frameIndex| is known to be opaque. |
| 280 // If no previous frame's data is required, returns WTF::kNotFound. | 273 // If no previous frame's data is required, returns WTF::kNotFound. |
| 281 // | 274 // |
| 282 // This function requires that the previous frame's | 275 // This function requires that the previous frame's |
| (...skipping 18 matching lines...) Expand all Loading... |
| 301 // returns that number. | 294 // returns that number. |
| 302 virtual size_t decodeFrameCount() { return 1; } | 295 virtual size_t decodeFrameCount() { return 1; } |
| 303 | 296 |
| 304 // Performs any additional setup of the requested frame after it has been | 297 // Performs any additional setup of the requested frame after it has been |
| 305 // initially created, e.g. setting a duration or disposal method. | 298 // initially created, e.g. setting a duration or disposal method. |
| 306 virtual void initializeNewFrame(size_t) {} | 299 virtual void initializeNewFrame(size_t) {} |
| 307 | 300 |
| 308 // Decodes the requested frame. | 301 // Decodes the requested frame. |
| 309 virtual void decode(size_t) = 0; | 302 virtual void decode(size_t) = 0; |
| 310 | 303 |
| 311 // Returns the embedded image color profile. | 304 // Returns the embedded image color space. |
| 312 const ImageFrame::ICCProfile& colorProfile() const { return m_colorProfile; } | 305 sk_sp<SkColorSpace> colorSpace() const { return m_srcSpace; } |
| 313 | 306 |
| 314 RefPtr<SegmentReader> m_data; // The encoded data. | 307 RefPtr<SegmentReader> m_data; // The encoded data. |
| 315 Vector<ImageFrame, 1> m_frameBufferCache; | 308 Vector<ImageFrame, 1> m_frameBufferCache; |
| 316 const bool m_premultiplyAlpha; | 309 const bool m_premultiplyAlpha; |
| 317 const bool m_ignoreGammaAndColorProfile; | 310 const bool m_ignoreColorSpace; |
| 318 ImageOrientation m_orientation; | 311 ImageOrientation m_orientation; |
| 319 | 312 |
| 320 // The maximum amount of memory a decoded image should require. Ideally, | 313 // The maximum amount of memory a decoded image should require. Ideally, |
| 321 // image decoders should downsample large images to fit under this limit | 314 // image decoders should downsample large images to fit under this limit |
| 322 // (and then return the downsampled size from decodedSize()). Ignoring | 315 // (and then return the downsampled size from decodedSize()). Ignoring |
| 323 // this limit can cause excessive memory use or even crashes on low- | 316 // this limit can cause excessive memory use or even crashes on low- |
| 324 // memory devices. | 317 // memory devices. |
| 325 const size_t m_maxDecodedBytes; | 318 const size_t m_maxDecodedBytes; |
| 326 | 319 |
| 327 // While decoding, we may learn that there are so many animation frames that | 320 // While decoding, we may learn that there are so many animation frames that |
| (...skipping 14 matching lines...) Expand all Loading... |
| 342 unsigned long long total_size = static_cast<unsigned long long>(width) * | 335 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 343 static_cast<unsigned long long>(height); | 336 static_cast<unsigned long long>(height); |
| 344 return total_size > ((1 << 29) - 1); | 337 return total_size > ((1 << 29) - 1); |
| 345 } | 338 } |
| 346 | 339 |
| 347 IntSize m_size; | 340 IntSize m_size; |
| 348 bool m_sizeAvailable = false; | 341 bool m_sizeAvailable = false; |
| 349 bool m_isAllDataReceived = false; | 342 bool m_isAllDataReceived = false; |
| 350 bool m_failed = false; | 343 bool m_failed = false; |
| 351 | 344 |
| 352 bool m_hasColorProfile = false; | 345 sk_sp<SkColorSpace> m_srcSpace = nullptr; |
| 353 ImageFrame::ICCProfile m_colorProfile; | |
| 354 | |
| 355 std::unique_ptr<SkColorSpaceXform> m_sourceToOutputDeviceColorTransform; | 346 std::unique_ptr<SkColorSpaceXform> m_sourceToOutputDeviceColorTransform; |
| 356 }; | 347 }; |
| 357 | 348 |
| 358 } // namespace blink | 349 } // namespace blink |
| 359 | 350 |
| 360 #endif | 351 #endif |
| OLD | NEW |