Chromium Code Reviews| Index: third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
| diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
| index 4144201a9b66088d12704bdf2d64feb9eac6c822..26ba4fc92f66a48095446195aaa673083c77a955 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
| +++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
| @@ -26,8 +26,20 @@ |
| #ifndef PNGImageReader_h |
| #define PNGImageReader_h |
| -#include "platform/image-decoders/png/PNGImageDecoder.h" |
| +#include "platform/PlatformExport.h" |
| +#include "platform/geometry/IntRect.h" |
| +#include "platform/image-decoders/ImageFrame.h" |
| #include "png.h" |
| +#include "wtf/Allocator.h" |
| +#include "wtf/Noncopyable.h" |
| +#include "wtf/PtrUtil.h" |
| +#include "wtf/Vector.h" |
| + |
| +namespace blink { |
| + |
| +class SegmentReader; |
| +class PNGImageDecoder; |
| +class FastSharedBufferReader; |
| #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) |
|
Noel Gordon
2017/02/21 13:53:57
nit: this #if-defy section @44-53 got moved into t
scroggo_chromium
2017/02/23 22:09:56
Done.
|
| #error version error: compile against a versioned libpng. |
| @@ -40,45 +52,108 @@ |
| #define JMPBUF(png_ptr) png_ptr->jmpbuf |
| #endif |
| -namespace blink { |
| - |
| -class SegmentReader; |
| - |
| class PLATFORM_EXPORT PNGImageReader final { |
| USING_FAST_MALLOC(PNGImageReader); |
| WTF_MAKE_NONCOPYABLE(PNGImageReader); |
| public: |
| - PNGImageReader(PNGImageDecoder*, size_t offset); |
| + PNGImageReader(PNGImageDecoder*, size_t initialOffset); |
| ~PNGImageReader(); |
| - bool decode(const SegmentReader&, bool sizeOnly); |
| + struct FrameInfo { |
| + // The offset where the frame data of this frame starts. |
| + size_t startOffset; |
| + // The number of bytes that contain frame data, starting at startOffset. |
| + size_t byteLength; |
| + size_t duration; |
| + IntRect frameRect; |
| + ImageFrame::DisposalMethod disposalMethod; |
| + ImageFrame::AlphaBlendSource alphaBlend; |
| + }; |
| + |
| + enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery }; |
|
Noel Gordon
2017/02/21 13:53:57
PNG prefix is somewhat redundant. Make this:
enu
scroggo_chromium
2017/02/23 22:09:55
Done.
|
| + |
| + bool parse(SegmentReader&, PNGParseQuery); |
|
Noel Gordon
2017/02/21 13:53:57
bool parse(SegmentReader&, ParseQuery);
scroggo_chromium
2017/02/23 22:09:56
Done.
|
| + |
| + // Returns false on a fatal error. |
| + bool decode(SegmentReader&, size_t); |
| + const FrameInfo& frameInfo(size_t) const; |
| + |
| + // Number of complete frames parsed so far, included frame zero if it is |
| + // partial. |
| + size_t frameCount() const; |
| + |
| + bool parseCompleted() const { return m_parseCompleted; }; |
| + |
| + // This method indicates for *animated* PNGs whether the first frame is fully |
| + // received. That is, when the fcTL chunk of the next frame has been received. |
| + bool firstFrameFullyReceived() const; |
| + |
| + void clearDecodeState(size_t frameIndex); |
| + |
| png_structp pngPtr() const { return m_png; } |
| png_infop infoPtr() const { return m_info; } |
| - size_t getReadOffset() const { return m_readOffset; } |
| - void setReadOffset(size_t offset) { m_readOffset = offset; } |
| - size_t currentBufferSize() const { return m_currentBufferSize; } |
| - bool decodingSizeOnly() const { return m_decodingSizeOnly; } |
| - void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } |
| - bool hasAlpha() const { return m_hasAlpha; } |
| - |
| png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } |
| void createInterlaceBuffer(int size) { |
| m_interlaceBuffer = wrapArrayUnique(new png_byte[size]); |
|
Noel Gordon
2017/02/21 13:53:57
does wrapArrayUnique need a WTF:: prefix?
scroggo_chromium
2017/02/23 22:09:55
No. None of the instances I see in code search use
|
| } |
| + void clearInterlaceBuffer() { m_interlaceBuffer.reset(); } |
| private: |
| png_structp m_png; |
| png_infop m_info; |
| + png_uint_32 m_width; |
| + png_uint_32 m_height; |
| + |
| PNGImageDecoder* m_decoder; |
| + |
| + // The offset in the stream where the PNG image starts. |
| + const size_t m_initialOffset; |
| + // How many bytes have been read during parsing. |
| size_t m_readOffset; |
| - size_t m_currentBufferSize; |
| - bool m_decodingSizeOnly; |
| - bool m_hasAlpha; |
| + size_t m_progressiveDecodeOffset; |
| + size_t m_idatOffset; |
| + |
| + bool m_idatIsPartOfAnimation; |
| + // All IDAT chunks must precede the first fdAT chunk, and all fdAT chunks |
| + // should be separated from the IDAT chunks by an fcTL chunk. So this is true |
| + // until the first fcTL chunk after an IDAT chunk. After that, only fdAT |
| + // chunks are expected. |
| + bool m_expectIdats; |
| + bool m_isAnimated; |
| + bool m_parsedSignature; |
| + bool m_parsedIHDR; |
| + bool m_parseCompleted; |
| + uint32_t m_reportedFrameCount; |
| + uint32_t m_nextSequenceNumber; |
| + // True when an fcTL has been parsed but not its corresponding fdAT or IDAT |
| + // chunk. Consecutive fcTLs is an error. |
| + bool m_fctlNeedsDatChunk; |
| + bool m_ignoreAnimation; |
| + |
| std::unique_ptr<png_byte[]> m_interlaceBuffer; |
| -}; |
| -} // namespace blink |
| + Vector<FrameInfo, 1> m_frameInfo; |
| + // This is used to temporarily store frame information, until it is pushed to |
| + // |m_frameInfo|, when all frame data has been seen in the stream. |
| + FrameInfo m_newFrame; |
| + |
| + size_t processData(const FastSharedBufferReader&, |
| + size_t offset, |
| + size_t length); |
| + // Returns false on a fatal error. |
| + bool parseSize(const FastSharedBufferReader&); |
| + // Returns false on an error. |
| + bool parseFrameInfo(const png_byte* data); |
| + void startFrameDecoding(const FastSharedBufferReader&, size_t); |
| + // Returns whether the frame was completely decoded. |
| + bool progressivelyDecodeFirstFrame(const FastSharedBufferReader&); |
| + void decodeFrame(const FastSharedBufferReader&, size_t); |
| + void processFdatChunkAsIdat(png_uint_32 fdatLength); |
| + // Returns false on a fatal error. |
| + bool checkSequenceNumber(const png_byte* position); |
| +}; |
| +}; |
|
Noel Gordon
2017/02/21 13:53:57
}: ? If this ends a namespace, then make it
} /
scroggo_chromium
2017/02/23 22:09:55
Done.
|
| #endif |