[Mac] Apps should not prevent Chrome restart.
[chromium-blink-merge.git] / components / webp_transcode / webp_decoder.h
blob64126c26648cbae0b3cbe92c915d2d4e4eae53c0
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.
5 #ifndef COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_
6 #define COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_
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"
13 @class NSData;
15 namespace webp_transcode {
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 { JPEG = 1, PNG, TIFF, DECODED_FORMAT_COUNT };
25 class Delegate : public base::RefCountedThreadSafe<WebpDecoder::Delegate> {
26 public:
27 virtual void OnFinishedDecoding(bool success) = 0;
28 virtual void SetImageFeatures(size_t total_size, // In bytes.
29 DecodedImageFormat format) = 0;
30 virtual void OnDataDecoded(NSData* data) = 0;
32 protected:
33 friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>;
34 virtual ~Delegate() {}
37 explicit WebpDecoder(WebpDecoder::Delegate* delegate);
39 // For tests.
40 static size_t GetHeaderSize();
42 // Main entry point.
43 void OnDataReceived(const base::scoped_nsobject<NSData>& data);
45 // Stops the decoding.
46 void Stop();
48 private:
49 struct WebPIDecoderDeleter {
50 inline void operator()(WebPIDecoder* ptr) const { WebPIDelete(ptr); }
53 enum State { READING_FEATURES, READING_DATA, DONE };
55 friend class base::RefCountedThreadSafe<WebpDecoder>;
56 virtual ~WebpDecoder();
58 // Implements WebP image decoding state machine steps.
59 void DoReadFeatures(NSData* data);
60 void DoReadData(NSData* data);
61 bool DoSendData();
63 scoped_refptr<WebpDecoder::Delegate> delegate_;
64 WebPDecoderConfig config_;
65 WebpDecoder::State state_;
66 scoped_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_;
67 base::scoped_nsobject<NSData> output_buffer_;
68 base::scoped_nsobject<NSMutableData> features_;
69 int has_alpha_;
72 } // namespace webp_transcode
74 #endif // COMPONENTS_WEBP_TRANSCODE_WEBP_DECODER_H_