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

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

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Change behavior on failure during decoding or parsing. Created 4 years, 1 month 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/PNGImageDecoder.h
diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h
index 7ce6aa0faf83c7c6d2ece1ce6cc94ea5d07f7427..141540931e38004948f7807d187f25c89d363595 100644
--- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h
@@ -43,26 +43,74 @@ class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder {
size_t offset = 0);
~PNGImageDecoder() override;
+ enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery };
+
// ImageDecoder:
String filenameExtension() const override { return "png"; }
+ int repetitionCount() const override;
+ bool frameIsCompleteAtIndex(size_t) const override;
+ float frameDurationAtIndex(size_t) const override;
+ size_t clearCacheExceptFrame(size_t) override;
+ // Failures are handled differently, based on the image and state of the
+ // decoder:
+ //
+ // 1) When a non-animated PNG, or the first frame of an animated PNG, can't
scroggo_chromium 2016/11/29 16:30:52 nit: these commas are unnecessary
joostouwerling 2016/12/02 16:08:42 Done.
+ // be decoded or parsed, set the decoder to the failed state, because there
+ // are no frames we can show to the client. Also set the state to failed if
scroggo_chromium 2016/11/29 16:30:52 For a partial first frame (or partial only frame,
joostouwerling 2016/12/02 16:08:42 Yes, the current behavior is that any failure inva
+ // a parse error occurs before any frames were received.
+ // 2) When a decoding failure occurs for non-first frames, we still want to
+ // show earlier frames. This means the frame count needs to be adjusted.
+ // 3) When a parsing failure occurs, the frame count is adjusted to the number
+ // of successfully parsed frames, since we can still show those.
+ //
+ // In cases 2 and 3, we have to prevent parse() from adjusting the frame
+ // count to pre-failure values by setting |m_failedWithCorrectFrames| to true.
+ bool setFailed() override;
// Callbacks from libpng
void headerAvailable();
void rowAvailable(unsigned char* row, unsigned rowIndex, int);
void complete();
+ // Additional methods used for APNG
+ void setRepetitionCount(size_t);
+
private:
// ImageDecoder:
- void decodeSize() override { decode(true); }
- void decode(size_t) override { decode(false); }
+ void decodeSize() override { parse(PNGParseQuery::PNGSizeQuery); }
+ void decode(size_t) override;
+ size_t decodeFrameCount() override;
+ void initializeNewFrame(size_t) override;
+ void clearFrameBuffer(size_t) override;
- // Decodes the image. If |onlySize| is true, stops decoding after
- // calculating the image size. If decoding fails but there is no more
- // data coming, sets the "decode failure" flag.
- void decode(bool onlySize);
+ bool initFrameBuffer(size_t);
+ void parse(PNGParseQuery);
+ // Used by clearCacheExceptFrame if two frames need to be kept in cache.
+ size_t clearCacheExceptTwoFrames(size_t, size_t);
std::unique_ptr<PNGImageReader> m_reader;
const unsigned m_offset;
+ size_t m_frameCount;
+ size_t m_currentFrame;
+ // m_repetitionCount is set to cAnimationLoopOnce by default, so the
+ // DeferredImageDecoder takes into account that this may be an animated
+ // image, but we don't know for sure yet.
+ int m_repetitionCount;
+ // This flag is set to true if the color space has been set. This is used to
+ // prevent setting the color space in each frame, which is unnecessary since
+ // frames don't have their own color space.
+ bool m_colorSpaceSet;
+ bool m_hasAlphaChannel;
+ bool m_currentBufferSawAlpha;
+
+ // This flag is set to true while PNGImageReader is parsing. This is used by
+ // setFailed() to determine how to handle a failure.
+ bool m_isParsing;
+ // This flag is set to true when a failure has occured, but there are earlier
+ // frames that can still be shown. In that case, the frame count is lowered.
+ // This flag prevents from calling parse() again, which could change the frame
+ // count back to the pre-failure value.
+ bool m_failedWithCorrectFrames;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698