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 ColorSpaceOption { ColorSpaceApplied, ColorSpaceIgnored }; | 89 enum ColorSpaceOption { |
| 90 // The embedded color profile is ignored entirely. The hasEmbeddedColorSpace |
| 91 // method will always return false. No transformations are applied to the |
| 92 // pixel data. SkImages created will have no assocated SkColorSpace. |
| 93 ColorSpaceIgnored, |
| 94 // The image will be transformed to the specified target color space. The |
| 95 // hasEmbeddedColorSpace method will return the truth. SkImages created by |
| 96 // this decoder will have no associated SkColorSpace. |
| 97 // TODO(ccameron): This transform is applied only if the image has an |
| 98 // embedded color profile, but should be applied always. |
| 99 ColorSpaceTransformed, |
| 100 // The image will not be transformed (to the extent possible). SkImages |
| 101 // created by this decoder will have the SkColorSpace of the embedded |
| 102 // color profile (or sRGB if there was no embedded color profile). |
| 103 ColorSpaceTagged, |
| 104 }; |
90 | 105 |
91 virtual ~ImageDecoder() {} | 106 virtual ~ImageDecoder() {} |
92 | 107 |
93 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if | 108 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if |
94 // we can't sniff a supported type from the provided data (possibly | 109 // we can't sniff a supported type from the provided data (possibly |
95 // because there isn't enough data yet). | 110 // because there isn't enough data yet). |
96 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). | 111 // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). |
97 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SegmentReader> data, | 112 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SegmentReader> data, |
98 bool dataComplete, | 113 bool dataComplete, |
99 AlphaOption, | 114 AlphaOption, |
100 ColorSpaceOption); | 115 ColorSpaceOption, |
101 static std::unique_ptr<ImageDecoder> create(PassRefPtr<SharedBuffer> data, | 116 sk_sp<SkColorSpace>); |
102 bool dataComplete, | 117 static std::unique_ptr<ImageDecoder> create( |
103 AlphaOption alphaoption, | 118 PassRefPtr<SharedBuffer> data, |
104 ColorSpaceOption colorOptions) { | 119 bool dataComplete, |
| 120 AlphaOption alphaoption, |
| 121 ColorSpaceOption colorOptions, |
| 122 sk_sp<SkColorSpace> targetColorSpace) { |
105 return create(SegmentReader::createFromSharedBuffer(std::move(data)), | 123 return create(SegmentReader::createFromSharedBuffer(std::move(data)), |
106 dataComplete, alphaoption, colorOptions); | 124 dataComplete, alphaoption, colorOptions, targetColorSpace); |
107 } | 125 } |
108 | 126 |
109 virtual String filenameExtension() const = 0; | 127 virtual String filenameExtension() const = 0; |
110 | 128 |
111 bool isAllDataReceived() const { return m_isAllDataReceived; } | 129 bool isAllDataReceived() const { return m_isAllDataReceived; } |
112 | 130 |
113 // Returns true if the buffer holds enough data to instantiate a decoder. | 131 // Returns true if the buffer holds enough data to instantiate a decoder. |
114 // This is useful for callers to determine whether a decoder instantiation | 132 // This is useful for callers to determine whether a decoder instantiation |
115 // failure is due to insufficient or bad data. | 133 // failure is due to insufficient or bad data. |
116 static bool hasSufficientDataToSniffImageType(const SharedBuffer&); | 134 static bool hasSufficientDataToSniffImageType(const SharedBuffer&); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // animated images. | 217 // animated images. |
200 virtual float frameDurationAtIndex(size_t) const { return 0; } | 218 virtual float frameDurationAtIndex(size_t) const { return 0; } |
201 | 219 |
202 // 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 |
203 // 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 |
204 // it has been cleared). | 222 // it has been cleared). |
205 virtual size_t frameBytesAtIndex(size_t) const; | 223 virtual size_t frameBytesAtIndex(size_t) const; |
206 | 224 |
207 ImageOrientation orientation() const { return m_orientation; } | 225 ImageOrientation orientation() const { return m_orientation; } |
208 | 226 |
209 bool ignoresColorSpace() const { return m_ignoreColorSpace; } | 227 bool ignoresColorSpace() const { |
| 228 return m_colorSpaceOption == ColorSpaceIgnored; |
| 229 } |
| 230 ColorSpaceOption colorSpaceOption() const { return m_colorSpaceOption; } |
| 231 sk_sp<SkColorSpace> targetColorSpace() const { return m_targetColorSpace; } |
210 | 232 |
211 // Set the target color profile into which all images with embedded color | 233 // Set the target color profile into which all images with embedded color |
212 // profiles should be converted. Note that only the first call to this | 234 // profiles should be converted. Note that only the first call to this |
213 // function in this process has any effect. | 235 // function in this process has any effect. |
214 static void setGlobalTargetColorProfile(const WebVector<char>&); | 236 static void setGlobalTargetColorProfile(const WebVector<char>&); |
215 static sk_sp<SkColorSpace> globalTargetColorSpace(); | 237 static sk_sp<SkColorSpace> globalTargetColorSpace(); |
216 | 238 |
217 // This returns the color space of this image. If the image had no embedded | 239 // A target color space to be used by tests. |
218 // color profile, this will return sRGB. Returns nullptr if color correct | 240 static sk_sp<SkColorSpace> targetColorSpaceForTesting(); |
219 // rendering is not enabled. | 241 |
220 sk_sp<SkColorSpace> colorSpace() const; | 242 // This returns the color space that will be included in the SkImageInfo of |
| 243 // SkImages created from this decoder. This will be nullptr unless the |
| 244 // decoder was created with the option ColorSpaceTagged. |
| 245 sk_sp<SkColorSpace> colorSpaceForSkImages() const; |
221 | 246 |
222 // This returns whether or not the image included a not-ignored embedded | 247 // This returns whether or not the image included a not-ignored embedded |
223 // color space. This is independent of whether or not that space's transform | 248 // color space. This is independent of whether or not that space's transform |
224 // has been baked into the pixel values. | 249 // has been baked into the pixel values. |
225 bool hasEmbeddedColorSpace() const { return m_embeddedColorSpace.get(); } | 250 bool hasEmbeddedColorSpace() const { return m_embeddedColorSpace.get(); } |
226 | 251 |
227 // Set the embedded color space directly or via ICC profile. | 252 // Set the embedded color space directly or via ICC profile. |
228 void setEmbeddedColorProfile(const char* iccData, unsigned iccLength); | 253 void setEmbeddedColorProfile(const char* iccData, unsigned iccLength); |
229 void setEmbeddedColorSpace(sk_sp<SkColorSpace> srcSpace); | 254 void setEmbeddedColorSpace(sk_sp<SkColorSpace> srcSpace); |
230 | 255 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 m_frameBufferCache[0].setMemoryAllocator(allocator); | 287 m_frameBufferCache[0].setMemoryAllocator(allocator); |
263 } | 288 } |
264 | 289 |
265 virtual bool canDecodeToYUV() { return false; } | 290 virtual bool canDecodeToYUV() { return false; } |
266 virtual bool decodeToYUV() { return false; } | 291 virtual bool decodeToYUV() { return false; } |
267 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} | 292 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} |
268 | 293 |
269 protected: | 294 protected: |
270 ImageDecoder(AlphaOption alphaOption, | 295 ImageDecoder(AlphaOption alphaOption, |
271 ColorSpaceOption colorOptions, | 296 ColorSpaceOption colorOptions, |
| 297 sk_sp<SkColorSpace> targetColorSpace, |
272 size_t maxDecodedBytes) | 298 size_t maxDecodedBytes) |
273 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), | 299 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), |
274 m_ignoreColorSpace(colorOptions == ColorSpaceIgnored), | 300 m_colorSpaceOption(colorOptions), |
| 301 m_targetColorSpace(std::move(targetColorSpace)), |
275 m_maxDecodedBytes(maxDecodedBytes), | 302 m_maxDecodedBytes(maxDecodedBytes), |
276 m_purgeAggressively(false) {} | 303 m_purgeAggressively(false) {} |
277 | 304 |
278 // Calculates the most recent frame whose image data may be needed in | 305 // Calculates the most recent frame whose image data may be needed in |
279 // order to decode frame |frameIndex|, based on frame disposal methods | 306 // order to decode frame |frameIndex|, based on frame disposal methods |
280 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether | 307 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether |
281 // the rectangle of frame at |frameIndex| is known to be opaque. | 308 // the rectangle of frame at |frameIndex| is known to be opaque. |
282 // If no previous frame's data is required, returns WTF::kNotFound. | 309 // If no previous frame's data is required, returns WTF::kNotFound. |
283 // | 310 // |
284 // This function requires that the previous frame's | 311 // This function requires that the previous frame's |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 355 |
329 // This is called by decode() after decoding a frame in an animated image. | 356 // This is called by decode() after decoding a frame in an animated image. |
330 // Before calling this method, the caller must verify that the frame exists. | 357 // Before calling this method, the caller must verify that the frame exists. |
331 // @return true if the frame was fully decoded, | 358 // @return true if the frame was fully decoded, |
332 // false otherwise. | 359 // false otherwise. |
333 bool postDecodeProcessing(size_t); | 360 bool postDecodeProcessing(size_t); |
334 | 361 |
335 RefPtr<SegmentReader> m_data; // The encoded data. | 362 RefPtr<SegmentReader> m_data; // The encoded data. |
336 Vector<ImageFrame, 1> m_frameBufferCache; | 363 Vector<ImageFrame, 1> m_frameBufferCache; |
337 const bool m_premultiplyAlpha; | 364 const bool m_premultiplyAlpha; |
338 const bool m_ignoreColorSpace; | 365 const ColorSpaceOption m_colorSpaceOption; |
| 366 const sk_sp<SkColorSpace> m_targetColorSpace; |
339 ImageOrientation m_orientation; | 367 ImageOrientation m_orientation; |
340 | 368 |
341 // The maximum amount of memory a decoded image should require. Ideally, | 369 // The maximum amount of memory a decoded image should require. Ideally, |
342 // image decoders should downsample large images to fit under this limit | 370 // image decoders should downsample large images to fit under this limit |
343 // (and then return the downsampled size from decodedSize()). Ignoring | 371 // (and then return the downsampled size from decodedSize()). Ignoring |
344 // this limit can cause excessive memory use or even crashes on low- | 372 // this limit can cause excessive memory use or even crashes on low- |
345 // memory devices. | 373 // memory devices. |
346 const size_t m_maxDecodedBytes; | 374 const size_t m_maxDecodedBytes; |
347 | 375 |
348 // While decoding, we may learn that there are so many animation frames that | 376 // While decoding, we may learn that there are so many animation frames that |
(...skipping 24 matching lines...) Expand all Loading... |
373 // Called by initFrameBuffer to determine if it can take the bitmap of the | 401 // Called by initFrameBuffer to determine if it can take the bitmap of the |
374 // previous frame. This condition is different for GIF and WEBP. | 402 // previous frame. This condition is different for GIF and WEBP. |
375 virtual bool canReusePreviousFrameBuffer(size_t) const { return false; } | 403 virtual bool canReusePreviousFrameBuffer(size_t) const { return false; } |
376 | 404 |
377 IntSize m_size; | 405 IntSize m_size; |
378 bool m_sizeAvailable = false; | 406 bool m_sizeAvailable = false; |
379 bool m_isAllDataReceived = false; | 407 bool m_isAllDataReceived = false; |
380 bool m_failed = false; | 408 bool m_failed = false; |
381 bool m_hasHistogrammedColorSpace = false; | 409 bool m_hasHistogrammedColorSpace = false; |
382 | 410 |
383 sk_sp<SkColorSpace> m_targetColorSpace = nullptr; | |
384 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; | 411 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; |
385 bool m_sourceToTargetColorTransformNeedsUpdate = false; | 412 bool m_sourceToTargetColorTransformNeedsUpdate = false; |
386 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; | 413 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; |
387 }; | 414 }; |
388 | 415 |
389 } // namespace blink | 416 } // namespace blink |
390 | 417 |
391 #endif | 418 #endif |
OLD | NEW |