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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Implement frame meta data decoding, include tests Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..15aa86b1e61e273f8db7e37b2ffc20fc05a1ecea
--- /dev/null
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageReader.h
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "platform/image-decoders/SegmentReader.h"
+#include "platform/image-decoders/png/PNGImageDecoder.h"
+#include "platform/PlatformExport.h"
+#include "png.h"
+#include "wtf/Allocator.h"
+#include "wtf/PtrUtil.h"
+
+#ifndef PNGImageReader_h
+#define PNGImageReader_h
+
+namespace blink {
+
+class FastSharedBufferReader;
+
+class PLATFORM_EXPORT PNGImageReader final {
+ USING_FAST_MALLOC(PNGImageReader);
+ WTF_MAKE_NONCOPYABLE(PNGImageReader);
+public:
+ PNGImageReader(PNGImageDecoder*, size_t readOffset);
+ ~PNGImageReader();
+
+ struct FrameInfo {
+ size_t readOffset;
+ size_t byteLength;
+ size_t duration;
+ IntPoint offset;
scroggo_chromium 2016/10/11 20:13:11 Why not combine offset and size into an IntRect?
+ IntSize size;
+ ImageFrame::DisposalMethod disposalMethod;
+ ImageFrame::AlphaBlendSource alphaBlend;
+ };
+
+ /*
+ * This method tries to parse the data stream in the SegmentReader, up to
+ * the point where the PNGParseQuery can be answered. It returns true when
scroggo_chromium 2016/10/11 20:13:11 I think some better formatting will make this easi
+ * the query is fulfilled. It returns false when 1) there is not enough data
+ * provided, or 2) when the data processing by libpng fails. In the case of
+ * 2), it also calls setFailed() at the m_decoder.
scroggo_chromium 2016/10/11 20:13:11 nit: "on m_decoder"
+ */
+ bool parse(SegmentReader&, PNGImageDecoder::PNGParseQuery);
+
+ void decode(SegmentReader&, size_t);
+ const FrameInfo& frameInfo(size_t) const;
+
+ /*
+ * This will return the number of frames that have been detected in the
+ * stream so far. If an incomplete stream is provided, this number is not
+ * final. However, all frame info for the frames up to this number is
+ * available so it can be used by the client if it wants to.
+ */
+ size_t frameCount() const;
+
+ // This is a callback for libpng, when it encounters an unknown chunk.
+ void parseAnimationChunk(const char* tag, const void* dataChunk, size_t length);
+
+ 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; }
+ 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]); }
+#if USE(QCMSLIB)
+ png_bytep rowBuffer() const { return m_rowBuffer.get(); }
+ void createRowBuffer(int size) { m_rowBuffer = wrapArrayUnique(new png_byte[size]); }
+#endif
+
+
+private:
+ png_structp m_png;
+ png_infop m_info;
+ PNGImageDecoder* m_decoder;
+ size_t m_readOffset;
+ bool m_hasAlpha;
+ bool m_idatPartOfAnimation;
scroggo_chromium 2016/10/11 20:13:11 nit: I think this is more clear if you insert the
+ bool m_parsedSignature;
+ std::unique_ptr<png_byte[]> m_interlaceBuffer;
+
+ Vector<FrameInfo, 1> m_frameInfo;
+ FrameInfo m_newFrame;
+
+ // Before using this method, see the remarks at the definition.
+ png_byte* readAsPngBytep(const FastSharedBufferReader&, size_t offset, size_t length);
+ char m_readBuffer[26];
+
+ bool processData(SegmentReader&, size_t offset, size_t length);
+ bool parseSize(SegmentReader&);
+ void parseAnimationControl(const png_byte* data);
+ void parseFrameInfo(const png_byte* data);
+
+#if USE(QCMSLIB)
+ std::unique_ptr<png_byte[]> m_rowBuffer;
+#endif
+};
+
+};
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698