Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h

Issue 2523943002: Explicitly specify target color space to ImageDecoder at creation (Closed)
Patch Set: More const, better enums Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
ccameron 2016/11/23 06:30:01 This (and below) is the core of the change -- rena
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) {
ccameron 2016/11/23 06:30:01 Adding this argument to create and the constructor
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
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 // This returns the color space that will be included in the SkImageInfo of
218 // color profile, this will return sRGB. Returns nullptr if color correct 240 // SkImages created from this decoder. This will be nullptr unless the
219 // rendering is not enabled. 241 // decoder was created with the option ColorSpaceTagged.
220 sk_sp<SkColorSpace> colorSpace() const; 242 sk_sp<SkColorSpace> colorSpaceForSkImages() const;
221 243
222 // This returns whether or not the image included a not-ignored embedded 244 // 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 245 // color space. This is independent of whether or not that space's transform
224 // has been baked into the pixel values. 246 // has been baked into the pixel values.
225 bool hasEmbeddedColorSpace() const { return m_embeddedColorSpace.get(); } 247 bool hasEmbeddedColorSpace() const { return m_embeddedColorSpace.get(); }
226 248
227 // Set the embedded color space directly or via ICC profile. 249 // Set the embedded color space directly or via ICC profile.
228 void setEmbeddedColorProfile(const char* iccData, unsigned iccLength); 250 void setEmbeddedColorProfile(const char* iccData, unsigned iccLength);
229 void setEmbeddedColorSpace(sk_sp<SkColorSpace> srcSpace); 251 void setEmbeddedColorSpace(sk_sp<SkColorSpace> srcSpace);
230 252
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 m_frameBufferCache[0].setMemoryAllocator(allocator); 284 m_frameBufferCache[0].setMemoryAllocator(allocator);
263 } 285 }
264 286
265 virtual bool canDecodeToYUV() { return false; } 287 virtual bool canDecodeToYUV() { return false; }
266 virtual bool decodeToYUV() { return false; } 288 virtual bool decodeToYUV() { return false; }
267 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} 289 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {}
268 290
269 protected: 291 protected:
270 ImageDecoder(AlphaOption alphaOption, 292 ImageDecoder(AlphaOption alphaOption,
271 ColorSpaceOption colorOptions, 293 ColorSpaceOption colorOptions,
294 sk_sp<SkColorSpace> targetColorSpace,
272 size_t maxDecodedBytes) 295 size_t maxDecodedBytes)
273 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), 296 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied),
274 m_ignoreColorSpace(colorOptions == ColorSpaceIgnored), 297 m_colorSpaceOption(colorOptions),
298 m_targetColorSpace(std::move(targetColorSpace)),
275 m_maxDecodedBytes(maxDecodedBytes), 299 m_maxDecodedBytes(maxDecodedBytes),
276 m_purgeAggressively(false) {} 300 m_purgeAggressively(false) {}
277 301
278 // Calculates the most recent frame whose image data may be needed in 302 // Calculates the most recent frame whose image data may be needed in
279 // order to decode frame |frameIndex|, based on frame disposal methods 303 // order to decode frame |frameIndex|, based on frame disposal methods
280 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether 304 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether
281 // the rectangle of frame at |frameIndex| is known to be opaque. 305 // the rectangle of frame at |frameIndex| is known to be opaque.
282 // If no previous frame's data is required, returns WTF::kNotFound. 306 // If no previous frame's data is required, returns WTF::kNotFound.
283 // 307 //
284 // This function requires that the previous frame's 308 // This function requires that the previous frame's
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 352
329 // This is called by decode() after decoding a frame in an animated image. 353 // 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. 354 // Before calling this method, the caller must verify that the frame exists.
331 // @return true if the frame was fully decoded, 355 // @return true if the frame was fully decoded,
332 // false otherwise. 356 // false otherwise.
333 bool postDecodeProcessing(size_t); 357 bool postDecodeProcessing(size_t);
334 358
335 RefPtr<SegmentReader> m_data; // The encoded data. 359 RefPtr<SegmentReader> m_data; // The encoded data.
336 Vector<ImageFrame, 1> m_frameBufferCache; 360 Vector<ImageFrame, 1> m_frameBufferCache;
337 const bool m_premultiplyAlpha; 361 const bool m_premultiplyAlpha;
338 const bool m_ignoreColorSpace; 362 const ColorSpaceOption m_colorSpaceOption;
363 const sk_sp<SkColorSpace> m_targetColorSpace;
339 ImageOrientation m_orientation; 364 ImageOrientation m_orientation;
340 365
341 // The maximum amount of memory a decoded image should require. Ideally, 366 // The maximum amount of memory a decoded image should require. Ideally,
342 // image decoders should downsample large images to fit under this limit 367 // image decoders should downsample large images to fit under this limit
343 // (and then return the downsampled size from decodedSize()). Ignoring 368 // (and then return the downsampled size from decodedSize()). Ignoring
344 // this limit can cause excessive memory use or even crashes on low- 369 // this limit can cause excessive memory use or even crashes on low-
345 // memory devices. 370 // memory devices.
346 const size_t m_maxDecodedBytes; 371 const size_t m_maxDecodedBytes;
347 372
348 // While decoding, we may learn that there are so many animation frames that 373 // While decoding, we may learn that there are so many animation frames that
(...skipping 24 matching lines...) Expand all
373 // Called by initFrameBuffer to determine if it can take the bitmap of the 398 // Called by initFrameBuffer to determine if it can take the bitmap of the
374 // previous frame. This condition is different for GIF and WEBP. 399 // previous frame. This condition is different for GIF and WEBP.
375 virtual bool canReusePreviousFrameBuffer(size_t) const { return false; } 400 virtual bool canReusePreviousFrameBuffer(size_t) const { return false; }
376 401
377 IntSize m_size; 402 IntSize m_size;
378 bool m_sizeAvailable = false; 403 bool m_sizeAvailable = false;
379 bool m_isAllDataReceived = false; 404 bool m_isAllDataReceived = false;
380 bool m_failed = false; 405 bool m_failed = false;
381 bool m_hasHistogrammedColorSpace = false; 406 bool m_hasHistogrammedColorSpace = false;
382 407
383 sk_sp<SkColorSpace> m_targetColorSpace = nullptr;
384 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; 408 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr;
385 bool m_sourceToTargetColorTransformNeedsUpdate = false; 409 bool m_sourceToTargetColorTransformNeedsUpdate = false;
386 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; 410 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform;
387 }; 411 };
388 412
389 } // namespace blink 413 } // namespace blink
390 414
391 #endif 415 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698