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 |
(...skipping 26 matching lines...) Expand all Loading... |
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 |
| 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); |
64 | 96 |
65 std::unique_ptr<PNGImageReader> m_reader; | 97 std::unique_ptr<PNGImageReader> m_reader; |
66 const unsigned m_offset; | 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; |
67 }; | 110 }; |
68 | 111 |
69 } // namespace blink | 112 } // namespace blink |
70 | 113 |
71 #endif | 114 #endif |
OLD | NEW |