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 10 matching lines...) Expand all Loading... | |
| 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 GIFImageDecoder_h | 26 #ifndef GIFImageDecoder_h |
| 27 #define GIFImageDecoder_h | 27 #define GIFImageDecoder_h |
| 28 | 28 |
| 29 #include <memory> | 29 #include <memory> |
| 30 #include "platform/image-decoders/ImageDecoder.h" | 30 #include "platform/image-decoders/ImageDecoder.h" |
| 31 #include "platform/image-decoders/SegmentStream.h" | |
| 31 #include "platform/wtf/Noncopyable.h" | 32 #include "platform/wtf/Noncopyable.h" |
| 33 #include "platform/wtf/RefPtr.h" | |
| 34 #include "third_party/skia/include/codec/SkCodec.h" | |
| 32 | 35 |
| 33 namespace blink { | 36 namespace blink { |
| 34 | 37 |
| 35 class GIFImageReader; | |
| 36 | |
| 37 using GIFRow = Vector<unsigned char>; | |
| 38 | |
| 39 // This class decodes the GIF image format. | 38 // This class decodes the GIF image format. |
| 40 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder { | 39 class PLATFORM_EXPORT GIFImageDecoder final : public blink::ImageDecoder { |
|
scroggo_chromium
2017/07/18 21:10:10
Why did you add "blink::"?
cblume
2017/07/19 23:27:05
Hrmmm I'm guessing I accidentally removed the name
| |
| 41 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); | 40 WTF_MAKE_NONCOPYABLE(GIFImageDecoder); |
| 42 | 41 |
| 43 public: | 42 public: |
| 44 GIFImageDecoder(AlphaOption, const ColorBehavior&, size_t max_decoded_bytes); | 43 GIFImageDecoder(AlphaOption, const ColorBehavior&, size_t max_decoded_bytes); |
| 45 ~GIFImageDecoder() override; | 44 ~GIFImageDecoder() override; |
| 46 | 45 |
| 47 enum GIFParseQuery { kGIFSizeQuery, kGIFFrameCountQuery }; | |
| 48 | |
| 49 // ImageDecoder: | 46 // ImageDecoder: |
| 50 String FilenameExtension() const override { return "gif"; } | 47 String FilenameExtension() const override { return "gif"; } |
| 51 void OnSetData(SegmentReader* data) override; | 48 void OnSetData(SegmentReader* data) override; |
| 52 int RepetitionCount() const override; | 49 int RepetitionCount() const override; |
| 53 bool FrameIsCompleteAtIndex(size_t) const override; | 50 bool FrameIsCompleteAtIndex(size_t) const override; |
| 54 float FrameDurationAtIndex(size_t) const override; | 51 float FrameDurationAtIndex(size_t) const override; |
| 55 // CAUTION: SetFailed() deletes |reader_|. Be careful to avoid | 52 // CAUTION: SetFailed() deletes |codec_|. Be careful to avoid |
| 56 // accessing deleted memory, especially when calling this from inside | 53 // accessing deleted memory. |
| 57 // GIFImageReader! | |
| 58 bool SetFailed() override; | 54 bool SetFailed() override; |
| 59 | 55 |
| 60 // Callbacks from the GIF reader. | 56 size_t ClearCacheExceptFrame(size_t) override; |
| 61 bool HaveDecodedRow(size_t frame_index, | |
| 62 GIFRow::const_iterator row_begin, | |
| 63 size_t width, | |
| 64 size_t row_number, | |
| 65 unsigned repeat_count, | |
| 66 bool write_transparent_pixels); | |
| 67 bool FrameComplete(size_t frame_index); | |
| 68 | |
| 69 // For testing. | |
| 70 bool ParseCompleted() const; | |
| 71 | 57 |
| 72 private: | 58 private: |
| 73 // ImageDecoder: | 59 // ImageDecoder: |
| 74 void ClearFrameBuffer(size_t frame_index) override; | 60 void DecodeSize() override {} |
| 75 virtual void DecodeSize() { Parse(kGIFSizeQuery); } | |
| 76 size_t DecodeFrameCount() override; | 61 size_t DecodeFrameCount() override; |
| 77 void InitializeNewFrame(size_t) override; | 62 void InitializeNewFrame(size_t index) override; |
|
scroggo_chromium
2017/07/18 21:10:10
nit: It's been recommended to me to leave "index"
cblume
2017/07/19 23:27:05
Yeah. For example, a few lines above I leave it ou
scroggo_chromium
2017/07/20 13:59:52
I don't have a strong preference.
cblume
2017/07/20 21:53:44
I'll leave variable name out for now.
I thought ab
| |
| 78 void Decode(size_t) override; | 63 void Decode(size_t index) override; |
| 79 | |
| 80 // Parses as much as is needed to answer the query, ignoring bitmap | |
| 81 // data. If parsing fails, sets the "decode failure" flag. | |
| 82 void Parse(GIFParseQuery); | |
| 83 | |
| 84 // Reset the alpha tracker for this frame. Before calling this method, the | |
| 85 // caller must verify that the frame exists. | |
| 86 void OnInitFrameBuffer(size_t) override; | |
| 87 | |
| 88 // When the disposal method of the frame is DisposeOverWritePrevious, the | 64 // When the disposal method of the frame is DisposeOverWritePrevious, the |
| 89 // next frame will use the previous frame's buffer as its starting state, so | 65 // next frame will use a previous frame's buffer as its starting state, so |
| 90 // we can't take over the data in that case. Before calling this method, the | 66 // we can't take over the data in that case. Before calling this method, the |
| 91 // caller must verify that the frame exists. | 67 // caller must verify that the frame exists. |
| 92 bool CanReusePreviousFrameBuffer(size_t) const override; | 68 bool CanReusePreviousFrameBuffer(size_t) const override; |
| 93 | 69 |
| 94 bool current_buffer_saw_alpha_; | 70 // When a frame depends on a previous frames's content, there is a list of |
| 95 mutable int repetition_count_; | 71 // candidate reference frames. This function will find a previous frame from |
| 96 std::unique_ptr<GIFImageReader> reader_; | 72 // that list which satisfies the requirements of being a reference frame |
| 73 // (kFrameComplete, not kDisposeOverwritePrevious). | |
| 74 // If no frame is found, it returns kNotFound. | |
| 75 size_t GetViableReferenceFrameIndex(size_t dependent_index) const; | |
| 76 | |
| 77 std::unique_ptr<SkCodec> codec_; | |
| 78 // |codec_| owns the SegmentStream, but we need a reference to it to append | |
| 79 // more data as it arrives. | |
| 80 SegmentStream* segment_stream_; | |
| 97 }; | 81 }; |
| 98 | 82 |
| 99 } // namespace blink | 83 } // namespace blink |
| 100 | 84 |
| 101 #endif | 85 #endif |
| OLD | NEW |