scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkWebpCodec_DEFINED |
| 9 | #define SkWebpCodec_DEFINED |
| 10 | |
| 11 | #include "SkCodec.h" |
msarett | ad8bcfe | 2016-03-07 07:09:03 -0800 | [diff] [blame] | 12 | #include "SkColorSpace.h" |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 13 | #include "SkEncodedFormat.h" |
| 14 | #include "SkImageInfo.h" |
| 15 | #include "SkTypes.h" |
| 16 | |
| 17 | class SkStream; |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 18 | extern "C" { |
| 19 | struct WebPDemuxer; |
| 20 | void WebPDemuxDelete(WebPDemuxer* dmux); |
| 21 | } |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 22 | |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 23 | static const size_t WEBP_VP8_HEADER_SIZE = 30; |
| 24 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 25 | class SkWebpCodec final : public SkCodec { |
| 26 | public: |
| 27 | // Assumes IsWebp was called and returned true. |
| 28 | static SkCodec* NewFromStream(SkStream*); |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 29 | static bool IsWebp(const void*, size_t); |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 30 | protected: |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 31 | Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*) |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 32 | override; |
| 33 | SkEncodedFormat onGetEncodedFormat() const override { return kWEBP_SkEncodedFormat; } |
| 34 | |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 35 | SkISize onGetScaledDimensions(float desiredScale) const override; |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 36 | |
scroggo | e7fc14b | 2015-10-02 13:14:46 -0700 | [diff] [blame] | 37 | bool onDimensionsSupported(const SkISize&) override; |
| 38 | |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 39 | bool onGetValidSubset(SkIRect* /* desiredSubset */) const override; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 40 | private: |
msarett | ff2a6c8 | 2016-09-07 11:23:28 -0700 | [diff] [blame] | 41 | SkWebpCodec(int width, int height, const SkEncodedInfo&, sk_sp<SkColorSpace>, SkStream*, |
| 42 | WebPDemuxer*, sk_sp<SkData>); |
| 43 | |
| 44 | SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> fDemux; |
| 45 | |
| 46 | // fDemux has a pointer into this data. |
| 47 | // This should not be freed until the decode is completed. |
| 48 | sk_sp<SkData> fData; |
scroggo | 6f5e619 | 2015-06-18 12:53:43 -0700 | [diff] [blame] | 49 | |
| 50 | typedef SkCodec INHERITED; |
| 51 | }; |
| 52 | #endif // SkWebpCodec_DEFINED |