blob: b9c493f204682aaeea9ca077b6d84dcedaf9ce77 [file] [log] [blame]
scroggo6f5e6192015-06-18 12:53:43 -07001/*
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"
msarettad8bcfe2016-03-07 07:09:03 -080012#include "SkColorSpace.h"
scroggo6f5e6192015-06-18 12:53:43 -070013#include "SkEncodedFormat.h"
14#include "SkImageInfo.h"
15#include "SkTypes.h"
16
17class SkStream;
msarettff2a6c82016-09-07 11:23:28 -070018extern "C" {
19 struct WebPDemuxer;
20 void WebPDemuxDelete(WebPDemuxer* dmux);
21}
scroggo6f5e6192015-06-18 12:53:43 -070022
scroggodb30be22015-12-08 18:54:13 -080023static const size_t WEBP_VP8_HEADER_SIZE = 30;
24
scroggo6f5e6192015-06-18 12:53:43 -070025class SkWebpCodec final : public SkCodec {
26public:
27 // Assumes IsWebp was called and returned true.
28 static SkCodec* NewFromStream(SkStream*);
scroggodb30be22015-12-08 18:54:13 -080029 static bool IsWebp(const void*, size_t);
scroggo6f5e6192015-06-18 12:53:43 -070030protected:
msarette6dd0042015-10-09 11:07:34 -070031 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*, int*)
scroggo6f5e6192015-06-18 12:53:43 -070032 override;
33 SkEncodedFormat onGetEncodedFormat() const override { return kWEBP_SkEncodedFormat; }
34
scroggo6f5e6192015-06-18 12:53:43 -070035 SkISize onGetScaledDimensions(float desiredScale) const override;
scroggob636b452015-07-22 07:16:20 -070036
scroggoe7fc14b2015-10-02 13:14:46 -070037 bool onDimensionsSupported(const SkISize&) override;
38
scroggob636b452015-07-22 07:16:20 -070039 bool onGetValidSubset(SkIRect* /* desiredSubset */) const override;
scroggo6f5e6192015-06-18 12:53:43 -070040private:
msarettff2a6c82016-09-07 11:23:28 -070041 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;
scroggo6f5e6192015-06-18 12:53:43 -070049
50 typedef SkCodec INHERITED;
51};
52#endif // SkWebpCodec_DEFINED