Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { | 36 class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { |
| 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 size_t maxDecodedBytes, | 42 size_t maxDecodedBytes, |
| 43 size_t offset = 0); | 43 size_t offset = 0); |
| 44 ~PNGImageDecoder() override; | 44 ~PNGImageDecoder() override; |
| 45 | 45 |
| 46 enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery }; | |
| 47 | |
| 46 // ImageDecoder: | 48 // ImageDecoder: |
| 47 String filenameExtension() const override { return "png"; } | 49 String filenameExtension() const override { return "png"; } |
| 50 int repetitionCount() const override; | |
| 51 bool frameIsCompleteAtIndex(size_t) const override; | |
| 52 float frameDurationAtIndex(size_t) const override; | |
| 53 size_t clearCacheExceptFrame(size_t) override; | |
| 48 | 54 |
| 49 // Callbacks from libpng | 55 // Callbacks from libpng |
| 50 void headerAvailable(); | 56 void headerAvailable(); |
| 51 void rowAvailable(unsigned char* row, unsigned rowIndex, int); | 57 void rowAvailable(unsigned char* row, unsigned rowIndex, int); |
| 52 void complete(); | 58 void complete(); |
| 53 | 59 |
| 60 // Additional methods used for APNG | |
| 61 void setRepetitionCount(size_t); | |
| 62 | |
| 54 private: | 63 private: |
| 55 // ImageDecoder: | 64 // ImageDecoder: |
| 56 void decodeSize() override { decode(true); } | 65 void decodeSize() override { parse(PNGParseQuery::PNGSizeQuery); } |
| 57 void decode(size_t) override { decode(false); } | 66 void decode(size_t) override; |
| 67 size_t decodeFrameCount() override; | |
| 68 void initializeNewFrame(size_t) override; | |
| 69 void clearFrameBuffer(size_t) override; | |
| 58 | 70 |
| 59 // Decodes the image. If |onlySize| is true, stops decoding after | 71 bool initFrameBuffer(size_t); |
| 60 // calculating the image size. If decoding fails but there is no more | 72 void parse(PNGParseQuery); |
| 61 // data coming, sets the "decode failure" flag. | 73 // Used by clearCacheExceptFrame if two frames need to be kept in cache. |
| 62 void decode(bool onlySize); | 74 size_t clearCacheExceptTwoFrames(size_t, size_t); |
| 75 // Non-first frames that depend on previous frames should not be decoded row | |
|
scroggo_chromium
2016/11/09 13:42:50
I don't think "Non-first" is necessary here. The f
joostouwerling
2016/11/11 20:22:19
Acknowledged.
| |
| 76 // by row, to prevent partially overwriting the content of the previous frame. | |
| 77 // The frame at |index| must exist before calling this method. | |
| 78 bool frameShouldBeDecodedIncrementally(size_t index) { | |
| 79 ASSERT(index < m_frameBufferCache.size()); | |
| 80 return (index == 0 || | |
| 81 m_frameBufferCache[index].requiredPreviousFrameIndex() == kNotFound); | |
| 82 } | |
| 63 | 83 |
| 64 std::unique_ptr<PNGImageReader> m_reader; | 84 std::unique_ptr<PNGImageReader> m_reader; |
| 65 const unsigned m_offset; | 85 const unsigned m_offset; |
| 86 size_t m_frameCount; | |
| 87 size_t m_currentFrame; | |
| 88 // m_repetitionCount is set to cAnimationLoopOnce by default, so the | |
| 89 // DeferredImageDecoder takes into account that this may be an animated | |
| 90 // image, but we don't know for sure yet. | |
| 91 int m_repetitionCount; | |
| 66 }; | 92 }; |
| 67 | 93 |
| 68 } // namespace blink | 94 } // namespace blink |
| 69 | 95 |
| 70 #endif | 96 #endif |
| OLD | NEW |