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

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

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Fix feedback on previous patches 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef PNGImageDecoder_h 26 #ifndef PNGImageDecoder_h
27 #define PNGImageDecoder_h 27 #define PNGImageDecoder_h
28 28
29 #include "platform/image-decoders/ImageDecoder.h" 29 #include "platform/image-decoders/ImageDecoder.h"
30 #include "platform/image-decoders/png/PNGImageReader.h"
30 #include <memory> 31 #include <memory>
31 32
32 namespace blink { 33 namespace blink {
33 34
34 class PNGImageReader; 35 class PNGImageReader;
35 36
36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { 37 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder {
37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder); 38 WTF_MAKE_NONCOPYABLE(PNGImageDecoder);
38 39
39 public: 40 public:
40 PNGImageDecoder(AlphaOption, 41 PNGImageDecoder(AlphaOption,
41 const ColorBehavior&, 42 const ColorBehavior&,
42 size_t maxDecodedBytes, 43 size_t maxDecodedBytes,
43 size_t offset = 0); 44 size_t offset = 0);
44 ~PNGImageDecoder() override; 45 ~PNGImageDecoder() override;
45 46
46 // ImageDecoder: 47 // ImageDecoder:
47 String filenameExtension() const override { return "png"; } 48 String filenameExtension() const override { return "png"; }
49 int repetitionCount() const override;
50 bool frameIsCompleteAtIndex(size_t) const override;
51 float frameDurationAtIndex(size_t) const override;
52 // Failures are handled differently, based on the image and state of the
53 // decoder:
54 //
55 // 1) When a non-animated PNG or the first frame of an animated PNG can't be
56 // decoded or parsed, set the decoder to the failed state, because there
57 // are no frames we can show to the client. Also set the state to failed if
58 // a parse error occurs before any frames were received.
59 // 2) When a decoding failure occurs for non-first frames, we still want to
60 // show earlier frames. This means the frame count needs to be adjusted.
61 // 3) When a parsing failure occurs, the frame count is adjusted to the number
62 // of successfully parsed frames, since we can still show those.
63 //
64 // In cases 2 and 3, we have to prevent parse() from adjusting the frame
65 // count to pre-failure values by setting |m_failedWithCorrectFrames| to true.
66 bool setFailed() override;
48 67
49 // Callbacks from libpng 68 // Callbacks from libpng
50 void headerAvailable(); 69 void headerAvailable();
51 void rowAvailable(unsigned char* row, unsigned rowIndex, int); 70 void rowAvailable(unsigned char* row, unsigned rowIndex, int);
52 void complete(); 71 void complete();
53 72
73 // Additional methods used for APNG
74 void setRepetitionCount(size_t);
75
54 private: 76 private:
55 // ImageDecoder: 77 // ImageDecoder:
56 void decodeSize() override { decode(true); } 78 void decodeSize() override {
57 void decode(size_t) override { decode(false); } 79 parse(PNGImageReader::PNGParseQuery::PNGSizeQuery);
80 }
81 void decode(size_t) override;
82 size_t decodeFrameCount() override;
83 void initializeNewFrame(size_t) override;
84 void clearFrameBuffer(size_t) override;
58 85
59 // Decodes the image. If |onlySize| is true, stops decoding after 86 // Create an interlacing buffer when the frame is encoded with interlacing.
60 // calculating the image size. If decoding fails but there is no more 87 void onInitFrameBuffer(size_t) override;
61 // data coming, sets the "decode failure" flag.
62 void decode(bool onlySize);
63 88
64 std::unique_ptr<PNGImageReader> m_reader; 89 // When the disposal method of the frame is DisposeOverwritePrevious, the
65 const unsigned m_offset; 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(PNGImageReader::PNGParseQuery);
96
97 PNGImageReader m_reader;
98 size_t m_frameCount;
99 size_t m_currentFrame;
100 // m_repetitionCount is set to cAnimationLoopOnce by default, so the
101 // DeferredImageDecoder takes into account that this may be an animated
102 // image, but we don't know for sure yet.
103 int m_repetitionCount;
104 bool m_hasAlphaChannel;
105 bool m_currentBufferSawAlpha;
106
107 // This flag is set to true while PNGImageReader is parsing. This is used by
108 // setFailed() to determine how to handle a failure.
109 bool m_isParsing;
66 }; 110 };
67 111
68 } // namespace blink 112 } // namespace blink
69 113
70 #endif 114 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698