| OLD | NEW |
| (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 COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_ | |
| 6 #define COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_ | |
| 7 | |
| 8 #import <Foundation/Foundation.h> | |
| 9 #include <stddef.h> | |
| 10 | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "base/mac/scoped_nsobject.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "third_party/libwebp/webp/decode.h" | |
| 16 | |
| 17 @class NSData; | |
| 18 | |
| 19 namespace webp_transcode { | |
| 20 | |
| 21 // Decodes a WebP image into either JPEG, PNG or uncompressed TIFF. | |
| 22 class WebpDecoder : public base::RefCountedThreadSafe<WebpDecoder> { | |
| 23 public: | |
| 24 // Format of the decoded image. | |
| 25 // This enum is used for UMA reporting, keep it in sync with the histogram | |
| 26 // definition. | |
| 27 enum DecodedImageFormat { JPEG = 1, PNG, TIFF, DECODED_FORMAT_COUNT }; | |
| 28 | |
| 29 class Delegate : public base::RefCountedThreadSafe<WebpDecoder::Delegate> { | |
| 30 public: | |
| 31 virtual void OnFinishedDecoding(bool success) = 0; | |
| 32 virtual void SetImageFeatures(size_t total_size, // In bytes. | |
| 33 DecodedImageFormat format) = 0; | |
| 34 virtual void OnDataDecoded(NSData* data) = 0; | |
| 35 | |
| 36 protected: | |
| 37 friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>; | |
| 38 virtual ~Delegate() {} | |
| 39 }; | |
| 40 | |
| 41 explicit WebpDecoder(WebpDecoder::Delegate* delegate); | |
| 42 | |
| 43 // For tests. | |
| 44 static size_t GetHeaderSize(); | |
| 45 | |
| 46 // Main entry point. | |
| 47 void OnDataReceived(const base::scoped_nsobject<NSData>& data); | |
| 48 | |
| 49 // Stops the decoding. | |
| 50 void Stop(); | |
| 51 | |
| 52 private: | |
| 53 struct WebPIDecoderDeleter { | |
| 54 inline void operator()(WebPIDecoder* ptr) const { WebPIDelete(ptr); } | |
| 55 }; | |
| 56 | |
| 57 enum State { READING_FEATURES, READING_DATA, DONE }; | |
| 58 | |
| 59 friend class base::RefCountedThreadSafe<WebpDecoder>; | |
| 60 virtual ~WebpDecoder(); | |
| 61 | |
| 62 // Implements WebP image decoding state machine steps. | |
| 63 void DoReadFeatures(NSData* data); | |
| 64 void DoReadData(NSData* data); | |
| 65 bool DoSendData(); | |
| 66 | |
| 67 scoped_refptr<WebpDecoder::Delegate> delegate_; | |
| 68 WebPDecoderConfig config_; | |
| 69 WebpDecoder::State state_; | |
| 70 std::unique_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_; | |
| 71 base::scoped_nsobject<NSData> output_buffer_; | |
| 72 base::scoped_nsobject<NSMutableData> features_; | |
| 73 int has_alpha_; | |
| 74 }; | |
| 75 | |
| 76 } // namespace webp_transcode | |
| 77 | |
| 78 #endif // COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_ | |
| OLD | NEW |