Chromium Code Reviews| Index: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h |
| diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h |
| index a44d261b49b45e02fd25415aa1f76c59c2551f42..bedc7d3d1dc3340b946e47a87de11feb6b94a65c 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h |
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h |
| @@ -94,38 +94,29 @@ public: |
| GammaAndColorProfileIgnored |
| }; |
| - enum class SniffResult { |
| - JPEG, |
| - PNG, |
| - GIF, |
| - WEBP, |
| - ICO, |
| - BMP, |
| - InsufficientData, |
| - Invalid |
| - }; |
| - |
| - static SniffResult determineImageType(const char* data, size_t length); |
| - static SniffResult determineImageType(const SharedBuffer&); |
| - static SniffResult determineImageType(const SegmentReader&); |
| - |
| - ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOptions, size_t maxDecodedBytes) |
| - : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) |
| - , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnored) |
| - , m_maxDecodedBytes(maxDecodedBytes) { } |
| - |
| virtual ~ImageDecoder() { } |
| - // Returns a caller-owned decoder of the appropriate type. Returns 0 if |
| + // Returns a caller-owned decoder of the appropriate type. Returns nullptr if |
| // we can't sniff a supported type from the provided data (possibly |
| // because there isn't enough data yet). |
| // Sets m_maxDecodedBytes to Platform::maxImageDecodedBytes(). |
| - static std::unique_ptr<ImageDecoder> create(SniffResult, AlphaOption, GammaAndColorProfileOption); |
| + static std::unique_ptr<ImageDecoder> create(PassRefPtr<SegmentReader> data, bool dataComplete, |
| + AlphaOption, GammaAndColorProfileOption); |
| + static std::unique_ptr<ImageDecoder> create(PassRefPtr<SharedBuffer> data, bool dataComplete, |
| + AlphaOption alphaoption, GammaAndColorProfileOption colorOptions) |
| + { |
| + return create(SegmentReader::createFromSharedBuffer(data), dataComplete, alphaoption, colorOptions); |
| + } |
| + |
| virtual String filenameExtension() const = 0; |
| bool isAllDataReceived() const { return m_isAllDataReceived; } |
| + // Returns true if the buffer holds enough data to instantiate a decoder. This is useful for |
| + // callers to determine whether a decoder instantiation failure is due to insufficient or bad data. |
|
Peter Kasting
2016/08/19 23:04:58
Nit: Seems like most of this file prefers to wrap
f(malita)
2016/08/22 01:51:16
Done.
|
| + static bool isSufficientData(const SharedBuffer&); |
|
Peter Kasting
2016/08/19 23:04:58
Nit: I'm not a big fan of this function name. Som
f(malita)
2016/08/22 01:51:16
Changed to hasSufficientDataToSniffImageType().
|
| + |
| void setData(PassRefPtr<SegmentReader> data, bool allDataReceived) |
| { |
| if (m_failed) |
| @@ -282,6 +273,11 @@ public: |
| virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) { } |
| protected: |
| + ImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption colorOptions, size_t maxDecodedBytes) |
| + : m_premultiplyAlpha(alphaOption == AlphaPremultiplied) |
| + , m_ignoreGammaAndColorProfile(colorOptions == GammaAndColorProfileIgnored) |
| + , m_maxDecodedBytes(maxDecodedBytes) { } |
| + |
| // Calculates the most recent frame whose image data may be needed in |
| // order to decode frame |frameIndex|, based on frame disposal methods |
| // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether |
| @@ -334,6 +330,18 @@ protected: |
| const size_t m_maxDecodedBytes; |
| private: |
| + enum class SniffResult { |
| + JPEG, |
| + PNG, |
| + GIF, |
| + WEBP, |
| + ICO, |
| + BMP, |
| + Invalid |
| + }; |
| + |
| + static SniffResult determineImageType(const char* data, size_t length); |
| + |
| // Some code paths compute the size of the image as "width * height * 4" |
| // and return it as a (signed) int. Avoid overflow. |
| static bool sizeCalculationMayOverflow(unsigned width, unsigned height) |