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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h

Issue 2930513004: [WIP] Move ImageDecoders to SkCodec
Patch Set: Adding check for decoder creation Created 3 years, 6 months 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
(Empty)
1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24 */
25
26 #ifndef GIFImageDecoder_h
27 #define GIFImageDecoder_h
28
29 #include <memory>
30 #include "platform/image-decoders/ImageDecoder.h"
31 #include "platform/wtf/Noncopyable.h"
32
33 namespace blink {
34
35 class GIFImageReader;
36
37 using GIFRow = Vector<unsigned char>;
38
39 // This class decodes the GIF image format.
40 class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder {
41 WTF_MAKE_NONCOPYABLE(GIFImageDecoder);
42
43 public:
44 GIFImageDecoder(AlphaOption, const ColorBehavior&, size_t max_decoded_bytes);
45 ~GIFImageDecoder() override;
46
47 enum GIFParseQuery { kGIFSizeQuery, kGIFFrameCountQuery };
48
49 // ImageDecoder:
50 String FilenameExtension() const override { return "gif"; }
51 void OnSetData(SegmentReader* data) override;
52 int RepetitionCount() const override;
53 bool FrameIsCompleteAtIndex(size_t) const override;
54 float FrameDurationAtIndex(size_t) const override;
55 // CAUTION: SetFailed() deletes |reader_|. Be careful to avoid
56 // accessing deleted memory, especially when calling this from inside
57 // GIFImageReader!
58 bool SetFailed() override;
59
60 // Callbacks from the GIF reader.
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
72 private:
73 // ImageDecoder:
74 void ClearFrameBuffer(size_t frame_index) override;
75 virtual void DecodeSize() { Parse(kGIFSizeQuery); }
76 size_t DecodeFrameCount() override;
77 void InitializeNewFrame(size_t) override;
78 void Decode(size_t) 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
89 // next frame will use the 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
91 // caller must verify that the frame exists.
92 bool CanReusePreviousFrameBuffer(size_t) const override;
93
94 bool current_buffer_saw_alpha_;
95 mutable int repetition_count_;
96 std::unique_ptr<GIFImageReader> reader_;
97 };
98
99 } // namespace blink
100
101 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698