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 SkCodec_wbmp_DEFINED |
9 | #define SkCodec_wbmp_DEFINED |
10 | |
11 | #include "include/codec/SkCodec.h" |
12 | #include "include/core/SkColorSpace.h" |
13 | #include "src/codec/SkSwizzler.h" |
14 | |
15 | class SkWbmpCodec final : public SkCodec { |
16 | public: |
17 | static bool IsWbmp(const void*, size_t); |
18 | |
19 | /* |
20 | * Assumes IsWbmp was called and returned true |
21 | * Creates a wbmp codec |
22 | * Takes ownership of the stream |
23 | */ |
24 | static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*); |
25 | |
26 | protected: |
27 | SkEncodedImageFormat onGetEncodedFormat() const override; |
28 | Result onGetPixels(const SkImageInfo&, void*, size_t, |
29 | const Options&, int*) override; |
30 | bool onRewind() override; |
31 | bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque, |
32 | bool needsXform) override; |
33 | // No need to Xform; all pixels are either black or white. |
34 | bool usesColorXform() const override { return false; } |
35 | private: |
36 | SkSampler* getSampler(bool createIfNecessary) override { |
37 | SkASSERT(fSwizzler || !createIfNecessary); |
38 | return fSwizzler.get(); |
39 | } |
40 | |
41 | /* |
42 | * Read a src row from the encoded stream |
43 | */ |
44 | bool readRow(uint8_t* row); |
45 | |
46 | SkWbmpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>); |
47 | |
48 | const size_t fSrcRowBytes; |
49 | |
50 | // Used for scanline decodes: |
51 | std::unique_ptr<SkSwizzler> fSwizzler; |
52 | SkAutoTMalloc<uint8_t> fSrcBuffer; |
53 | |
54 | int onGetScanlines(void* dst, int count, size_t dstRowBytes) override; |
55 | bool onSkipScanlines(int count) override; |
56 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, |
57 | const Options& options) override; |
58 | |
59 | typedef SkCodec INHERITED; |
60 | }; |
61 | |
62 | #endif // SkCodec_wbmp_DEFINED |
63 | |