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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/webp_decoder.h
diff --git a/ios/web/public/webp_decoder.h b/ios/web/public/webp_decoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..8700718cfaa7f94e5c26eaa051101e2f91f358ef
--- /dev/null
+++ b/ios/web/public/webp_decoder.h
@@ -0,0 +1,83 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_WEB_PUBLIC_WEBP_DECODER_H_
+#define IOS_WEB_PUBLIC_WEBP_DECODER_H_
+
+#include "base/mac/scoped_nsobject.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "third_party/libwebp/webp/decode.h"
+
+@class NSData;
+
+namespace web {
+
+// Decodes a WebP image into either JPEG, PNG or uncompressed TIFF.
+class WebpDecoder : public base::RefCountedThreadSafe<WebpDecoder> {
+ public:
+ // Format of the decoded image.
+ // This enum is used for UMA reporting, keep it in sync with the histogram
+ // definition.
+ enum DecodedImageFormat {
+ JPEG = 1,
+ PNG,
+ TIFF,
+ DECODED_FORMAT_COUNT
+ };
+
+ class Delegate : public base::RefCountedThreadSafe<WebpDecoder::Delegate> {
+ public:
+ virtual void OnFinishedDecoding(bool success) = 0;
+ virtual void SetImageFeatures(size_t total_size, // In bytes.
+ DecodedImageFormat format) = 0;
+ virtual void OnDataDecoded(NSData* data) = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>;
+ virtual ~Delegate() {}
+ };
+
+ explicit WebpDecoder(WebpDecoder::Delegate* delegate);
+
+ // For tests.
+ static size_t GetHeaderSize();
+
+ // Main entry point.
+ void OnDataReceived(const base::scoped_nsobject<NSData>& data);
+
+ // Stops the decoding.
+ void Stop();
+
+ private:
+ struct WebPIDecoderDeleter {
+ inline void operator()(WebPIDecoder* ptr) const { WebPIDelete(ptr); }
+ };
+
+ enum State {
+ READING_FEATURES,
+ READING_DATA,
+ DONE
+ };
+
+ friend class base::RefCountedThreadSafe<WebpDecoder>;
+ virtual ~WebpDecoder();
+
+ // Implements WebP image decoding state machine steps.
+ void DoReadFeatures(NSData* data);
+ void DoReadData(NSData* data);
+ bool DoSendData();
+
+ scoped_refptr<WebpDecoder::Delegate> delegate_;
+ WebPDecoderConfig config_;
+ WebpDecoder::State state_;
+ scoped_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_;
+ base::scoped_nsobject<NSData> output_buffer_;
+ base::scoped_nsobject<NSMutableData> features_;
+ int has_alpha_;
+};
+
+} // namespace web
+
+#endif // IOS_WEB_PUBLIC_WEBP_DECODER_H_
« 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