| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ | 5 #ifndef IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ |
| 6 #define IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ | 6 #define IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 DecodedImageFormat format) = 0; | 33 DecodedImageFormat format) = 0; |
| 34 virtual void OnDataDecoded(NSData* data) = 0; | 34 virtual void OnDataDecoded(NSData* data) = 0; |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>; | 37 friend class base::RefCountedThreadSafe<WebpDecoder::Delegate>; |
| 38 virtual ~Delegate() {} | 38 virtual ~Delegate() {} |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 explicit WebpDecoder(WebpDecoder::Delegate* delegate); | 41 explicit WebpDecoder(WebpDecoder::Delegate* delegate); |
| 42 | 42 |
| 43 // Returns an NSData object containing the decoded image data of the given |
| 44 // webp_image. Returns nil in case of failure. |
| 45 static NSData* DecodeWebpImage(NSData* webp_image); |
| 46 |
| 47 // Returns true if the given image_data is a WebP image. |
| 48 // |
| 49 // Every WebP file contains a 12 byte file header in the beginning of the |
| 50 // file. |
| 51 // A WebP file header starts with the four ASCII characters "RIFF". The next |
| 52 // four bytes contain the image size and the last four header bytes contain |
| 53 // the four ASCII characters "WEBP". |
| 54 // |
| 55 // WebP file header: |
| 56 // 1 1 |
| 57 // Byte Nr. 0 1 2 3 4 5 6 7 8 9 0 1 |
| 58 // Byte value [ R I F F ? ? ? ? W E B P ] |
| 59 // |
| 60 // For more information see: |
| 61 // https://developers.google.com/speed/webp/docs/riff_container#webp_file_head
er |
| 62 static bool IsWebpImage(const std::string& image_data); |
| 63 |
| 43 // For tests. | 64 // For tests. |
| 44 static size_t GetHeaderSize(); | 65 static size_t GetHeaderSize(); |
| 45 | 66 |
| 46 // Main entry point. | 67 // Main entry point. |
| 47 void OnDataReceived(NSData* data); | 68 void OnDataReceived(NSData* data); |
| 48 | 69 |
| 49 // Stops the decoding. | 70 // Stops the decoding. |
| 50 void Stop(); | 71 void Stop(); |
| 51 | 72 |
| 52 private: | 73 private: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 WebpDecoder::State state_; | 90 WebpDecoder::State state_; |
| 70 std::unique_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_; | 91 std::unique_ptr<WebPIDecoder, WebPIDecoderDeleter> incremental_decoder_; |
| 71 base::scoped_nsobject<NSData> output_buffer_; | 92 base::scoped_nsobject<NSData> output_buffer_; |
| 72 base::scoped_nsobject<NSMutableData> features_; | 93 base::scoped_nsobject<NSMutableData> features_; |
| 73 int has_alpha_; | 94 int has_alpha_; |
| 74 }; | 95 }; |
| 75 | 96 |
| 76 } // namespace webp_transcode | 97 } // namespace webp_transcode |
| 77 | 98 |
| 78 #endif // IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ | 99 #endif // IOS_WEB_PUBLIC_IMAGE_FETCHER_WEBP_DECODER_H_ |
| OLD | NEW |