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 a7df4e6f786d26b16e0ca90ded65cb65937418c0..181b6bd1f3a6ae65bca304a66b4e870607401e85 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h |
@@ -27,9 +27,12 @@ |
#define PNGImageReader_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/PtrUtil.h" |
+#include "wtf/Vector.h" |
#if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) |
#error version error: compile against a versioned libpng. |
@@ -44,6 +47,7 @@ |
namespace blink { |
+class FastSharedBufferReader; |
class PNGImageDecoder; |
class SegmentReader; |
@@ -52,34 +56,102 @@ class PLATFORM_EXPORT PNGImageReader final { |
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 ParseQuery { Size, MetaData }; |
+ |
+ bool parse(SegmentReader&, ParseQuery); |
+ |
+ // 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; |
Noel Gordon
2017/03/06 05:21:48
Minor comment fix, we should just in-line this fun
scroggo_chromium
2017/03/07 20:25:38
Done.
|
+ |
+ 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; |
Noel Gordon
2017/03/06 05:21:48
In-line this function? To do that, you could add
scroggo_chromium
2017/03/07 20:25:38
Done.
|
+ |
+ 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]); |
} |
+ 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; |
+ |
+ 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); |
}; |
} // namespace blink |