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

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

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Rebase master on top of CL Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 26 matching lines...) Expand all
37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder); 37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder);
38 38
39 public: 39 public:
40 PNGImageDecoder(AlphaOption, 40 PNGImageDecoder(AlphaOption,
41 ColorSpaceOption, 41 ColorSpaceOption,
42 sk_sp<SkColorSpace>, 42 sk_sp<SkColorSpace>,
43 size_t maxDecodedBytes, 43 size_t maxDecodedBytes,
44 size_t offset = 0); 44 size_t offset = 0);
45 ~PNGImageDecoder() override; 45 ~PNGImageDecoder() override;
46 46
47 enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery };
48
47 // ImageDecoder: 49 // ImageDecoder:
48 String filenameExtension() const override { return "png"; } 50 String filenameExtension() const override { return "png"; }
51 int repetitionCount() const override;
52 bool frameIsCompleteAtIndex(size_t) const override;
53 float frameDurationAtIndex(size_t) const override;
54 // Failures are handled differently, based on the image and state of the
55 // decoder:
56 //
57 // 1) When a non-animated PNG or the first frame of an animated PNG can't be
58 // decoded or parsed, set the decoder to the failed state, because there
59 // are no frames we can show to the client. Also set the state to failed if
60 // a parse error occurs before any frames were received.
61 // 2) When a decoding failure occurs for non-first frames, we still want to
62 // show earlier frames. This means the frame count needs to be adjusted.
63 // 3) When a parsing failure occurs, the frame count is adjusted to the number
64 // of successfully parsed frames, since we can still show those.
65 //
66 // In cases 2 and 3, we have to prevent parse() from adjusting the frame
67 // count to pre-failure values by setting |m_failedWithCorrectFrames| to true.
68 bool setFailed() override;
49 69
50 // Callbacks from libpng 70 // Callbacks from libpng
51 void headerAvailable(); 71 void headerAvailable();
52 void rowAvailable(unsigned char* row, unsigned rowIndex, int); 72 void rowAvailable(unsigned char* row, unsigned rowIndex, int);
53 void complete(); 73 void complete();
54 74
75 // Additional methods used for APNG
76 void setRepetitionCount(size_t);
77
55 private: 78 private:
56 // ImageDecoder: 79 // ImageDecoder:
57 void decodeSize() override { decode(true); } 80 void decodeSize() override { parse(PNGParseQuery::PNGSizeQuery); }
58 void decode(size_t) override { decode(false); } 81 void decode(size_t) override;
82 size_t decodeFrameCount() override;
83 void initializeNewFrame(size_t) override;
84 void clearFrameBuffer(size_t) override;
59 85
60 // Decodes the image. If |onlySize| is true, stops decoding after 86 // Create an interlacing buffer when the frame is encoded with interlacing.
61 // calculating the image size. If decoding fails but there is no more 87 void onInitFrameBuffer(size_t) override;
62 // data coming, sets the "decode failure" flag. 88
63 void decode(bool onlySize); 89 // When the disposal method of the frame is DisposeOverwritePrevious, the
scroggo_chromium 2016/12/07 13:44:44 Is this not already explained in the base class? C
joostouwerling 2016/12/07 16:49:10 The base class explains how this method is used (i
90 // next frame will use the previous frame's buffer as its starting state, so
91 // we can't take over the data in that case. Before calling this method, the
92 // caller must verify that the frame exists.
93 bool canReusePreviousFrameBuffer(size_t index) const override;
94
95 void parse(PNGParseQuery);
96 // Used by clearCacheExceptFrame if two frames need to be kept in cache.
97 size_t clearCacheExceptTwoFrames(size_t, size_t);
scroggo_chromium 2016/12/07 13:44:44 I thought this was moved to the base class?
joostouwerling 2016/12/07 16:49:10 Yes. Removed it.
64 98
65 std::unique_ptr<PNGImageReader> m_reader; 99 std::unique_ptr<PNGImageReader> m_reader;
66 const unsigned m_offset; 100 const unsigned m_offset;
101 size_t m_frameCount;
102 size_t m_currentFrame;
103 // m_repetitionCount is set to cAnimationLoopOnce by default, so the
104 // DeferredImageDecoder takes into account that this may be an animated
105 // image, but we don't know for sure yet.
106 int m_repetitionCount;
107 bool m_hasAlphaChannel;
108 bool m_currentBufferSawAlpha;
109
110 // This flag is set to true while PNGImageReader is parsing. This is used by
111 // setFailed() to determine how to handle a failure.
112 bool m_isParsing;
113 // This flag is set to true when a failure has occured, but there are earlier
114 // frames that can still be shown. In that case, the frame count is lowered.
115 // This flag prevents from calling parse() again, which could change the frame
scroggo_chromium 2016/12/07 13:44:44 What if instead we set the reader's m_parseComplet
joostouwerling 2016/12/07 16:49:10 That'd work for parsing errors, but not for decodi
116 // count back to the pre-failure value.
117 bool m_failedWithCorrectFrames;
67 }; 118 };
68 119
69 } // namespace blink 120 } // namespace blink
70 121
71 #endif 122 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698