OLD | NEW |
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 <memory> |
29 #include "platform/image-decoders/ImageDecoder.h" | 30 #include "platform/image-decoders/ImageDecoder.h" |
30 #include <memory> | 31 #include "platform/image-decoders/png/PNGImageReader.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 class PNGImageReader; | |
35 | |
36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { | 35 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { |
37 WTF_MAKE_NONCOPYABLE(PNGImageDecoder); | 36 WTF_MAKE_NONCOPYABLE(PNGImageDecoder); |
38 | 37 |
39 public: | 38 public: |
40 PNGImageDecoder(AlphaOption, | 39 PNGImageDecoder(AlphaOption, |
41 const ColorBehavior&, | 40 const ColorBehavior&, |
42 size_t maxDecodedBytes, | 41 size_t maxDecodedBytes, |
43 size_t offset = 0); | 42 size_t offset = 0); |
44 ~PNGImageDecoder() override; | 43 ~PNGImageDecoder() override; |
45 | 44 |
46 // ImageDecoder: | 45 // ImageDecoder: |
47 String filenameExtension() const override { return "png"; } | 46 String filenameExtension() const override { return "png"; } |
| 47 int repetitionCount() const override; |
| 48 bool frameIsCompleteAtIndex(size_t) const override; |
| 49 float frameDurationAtIndex(size_t) const override; |
| 50 bool setFailed() override; |
48 | 51 |
49 // Callbacks from libpng | 52 // Callbacks from libpng |
50 void headerAvailable(); | 53 void headerAvailable(); |
51 void rowAvailable(unsigned char* row, unsigned rowIndex, int); | 54 void rowAvailable(unsigned char* row, unsigned rowIndex, int); |
52 void complete(); | 55 void frameComplete(); |
| 56 |
| 57 void setRepetitionCount(int); |
53 | 58 |
54 private: | 59 private: |
| 60 using ParseQuery = PNGImageReader::ParseQuery; |
| 61 |
55 // ImageDecoder: | 62 // ImageDecoder: |
56 void decodeSize() override { decode(true); } | 63 void decodeSize() override { parse(ParseQuery::Size); } |
57 void decode(size_t) override { decode(false); } | 64 void decode(size_t) override; |
58 | 65 void parse(ParseQuery); |
59 // Decodes the image. If |onlySize| is true, stops decoding after | 66 size_t decodeFrameCount() override; |
60 // calculating the image size. If decoding fails but there is no more | 67 void initializeNewFrame(size_t) override; |
61 // data coming, sets the "decode failure" flag. | 68 void clearFrameBuffer(size_t) override; |
62 void decode(bool onlySize); | 69 bool canReusePreviousFrameBuffer(size_t) const override; |
63 | 70 |
64 std::unique_ptr<PNGImageReader> m_reader; | 71 std::unique_ptr<PNGImageReader> m_reader; |
65 const unsigned m_offset; | 72 const unsigned m_offset; |
| 73 size_t m_currentFrame; |
| 74 int m_repetitionCount; |
| 75 bool m_hasAlphaChannel; |
| 76 bool m_currentBufferSawAlpha; |
66 }; | 77 }; |
67 | 78 |
68 } // namespace blink | 79 } // namespace blink |
69 | 80 |
70 #endif | 81 #endif |
OLD | NEW |