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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/webp/WEBPImageDecoder.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) 2010 Google 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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef WEBPImageDecoder_h
30 #define WEBPImageDecoder_h
31
32 #include "platform/image-decoders/ImageDecoder.h"
33 #include "third_party/skia/include/core/SkData.h"
34 #include "webp/decode.h"
35 #include "webp/demux.h"
36
37 namespace blink {
38
39 class PLATFORM_EXPORT WEBPImageDecoder final : public ImageDecoder {
40 WTF_MAKE_NONCOPYABLE(WEBPImageDecoder);
41
42 public:
43 WEBPImageDecoder(AlphaOption, const ColorBehavior&, size_t max_decoded_bytes);
44 ~WEBPImageDecoder() override;
45
46 // ImageDecoder:
47 String FilenameExtension() const override { return "webp"; }
48 void OnSetData(SegmentReader* data) override;
49 int RepetitionCount() const override;
50 bool FrameIsCompleteAtIndex(size_t) const override;
51 float FrameDurationAtIndex(size_t) const override;
52
53 private:
54 // ImageDecoder:
55 virtual void DecodeSize() { UpdateDemuxer(); }
56 size_t DecodeFrameCount() override;
57 void InitializeNewFrame(size_t) override;
58 void Decode(size_t) override;
59
60 bool DecodeSingleFrame(const uint8_t* data_bytes,
61 size_t data_size,
62 size_t frame_index);
63
64 // For WebP images, the frame status needs to be FrameComplete to decode
65 // subsequent frames that depend on frame |index|. The reason for this is that
66 // WebP uses the previous frame for alpha blending, in ApplyPostProcessing().
67 //
68 // Before calling this, verify that frame |index| exists by checking that
69 // |index| is smaller than |frame_buffer_cache_|.size().
70 bool FrameStatusSufficientForSuccessors(size_t index) override {
71 DCHECK(index < frame_buffer_cache_.size());
72 return frame_buffer_cache_[index].GetStatus() == ImageFrame::kFrameComplete;
73 }
74
75 WebPIDecoder* decoder_;
76 WebPDecBuffer decoder_buffer_;
77 int format_flags_;
78 bool frame_background_has_alpha_;
79
80 void ReadColorProfile();
81 bool UpdateDemuxer();
82
83 // Set |frame_background_has_alpha_| based on this frame's characteristics.
84 // Before calling this method, the caller must verify that the frame exists.
85 void OnInitFrameBuffer(size_t frame_index) override;
86
87 // When the blending method of this frame is BlendAtopPreviousFrame, the
88 // previous frame's buffer is necessary to decode this frame in
89 // ApplyPostProcessing, so we can't take over the data. Before calling this
90 // method, the caller must verify that the frame exists.
91 bool CanReusePreviousFrameBuffer(size_t frame_index) const override;
92
93 void ApplyPostProcessing(size_t frame_index);
94 void ClearFrameBuffer(size_t frame_index) override;
95
96 WebPDemuxer* demux_;
97 WebPDemuxState demux_state_;
98 bool have_already_parsed_this_data_;
99 int repetition_count_;
100 int decoded_height_;
101
102 typedef void (*AlphaBlendFunction)(ImageFrame&, ImageFrame&, int, int, int);
103 AlphaBlendFunction blend_function_;
104
105 void Clear();
106 void ClearDecoder();
107
108 // FIXME: Update libwebp's API so it does not require copying the data on each
109 // update.
110 sk_sp<SkData> consolidated_data_;
111 };
112
113 } // namespace blink
114
115 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698