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