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

Side by Side Diff: ios/web/public/webp_decoder.h

Issue 771723002: Add support for decoding WebP images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-browser-state
Patch Set: Rebase Created 6 years 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
« no previous file with comments | « ios/web/ios_web.gyp ('k') | ios/web/public/webp_decoder.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IOS_WEB_PUBLIC_WEBP_DECODER_H_
6 #define IOS_WEB_PUBLIC_WEBP_DECODER_H_
7
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "third_party/libwebp/webp/decode.h"
12
13 @class NSData;
14
15 namespace web {
16
17 // Decodes a WebP image into either JPEG, PNG or uncompressed TIFF.
18 class WebpDecoder : public base::RefCountedThreadSafe<WebpDecoder> {
19 public:
20 // Format of the decoded image.
21 // This enum is used for UMA reporting, keep it in sync with the histogram
22 // definition.
23 enum DecodedImageFormat {
24 JPEG = 1,
25 PNG,
26 TIFF,
27 DECODED_FORMAT_COUNT
28 };
29
30 class Delegate : public base::RefCountedThreadSafe<WebpDecoder::Delegate> {
31 public:
32 virtual void OnFinishedDecoding(bool success) = 0;
33 virtual void SetImageFeatures(size_t total_size, // In bytes.
34 DecodedImageFormat format) = 0;
35 virtual void OnDataDecoded(NSData* data) = 0;
36
37 protected:
38 friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>;
39 virtual ~Delegate() {}
40 };
41
42 explicit WebpDecoder(WebpDecoder::Delegate* delegate);
43
44 // For tests.
45 static size_t GetHeaderSize();
46
47 // Main entry point.
48 void OnDataReceived(const base::scoped_nsobject<NSData>& data);
49
50 // Stops the decoding.
51 void Stop();
52
53 private:
54 struct WebPIDecoderDeleter {
55 inline void operator()(WebPIDecoder* ptr) const { WebPIDelete(ptr); }
56 };
57
58 enum State {
59 READING_FEATURES,
60 READING_DATA,
61 DONE
62 };
63
64 friend class base::RefCountedThreadSafe<WebpDecoder>;
65 virtual ~WebpDecoder();
66
67 // Implements WebP image decoding state machine steps.
68 void DoReadFeatures(NSData* data);
69 void DoReadData(NSData* data);
70 bool DoSendData();
71
72 scoped_refptr<WebpDecoder::Delegate> delegate_;
73 WebPDecoderConfig config_;
74 WebpDecoder::State state_;
75 scoped_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_;
76 base::scoped_nsobject<NSData> output_buffer_;
77 base::scoped_nsobject<NSMutableData> features_;
78 int has_alpha_;
79 };
80
81 } // namespace web
82
83 #endif // IOS_WEB_PUBLIC_WEBP_DECODER_H_
OLDNEW
« no previous file with comments | « ios/web/ios_web.gyp ('k') | ios/web/public/webp_decoder.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698