halcanary | a096d7a | 2015-03-27 12:16:53 -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 SkCodec_wbmp_DEFINED |
| 9 | #define SkCodec_wbmp_DEFINED |
| 10 | |
| 11 | #include "SkCodec.h" |
msarett | ad8bcfe | 2016-03-07 07:09:03 -0800 | [diff] [blame] | 12 | #include "SkColorSpace.h" |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 13 | #include "SkSwizzler.h" |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 14 | |
| 15 | class SkWbmpCodec final : public SkCodec { |
| 16 | public: |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 17 | static bool IsWbmp(const void*, size_t); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Assumes IsWbmp was called and returned true |
| 21 | * Creates a wbmp codec |
| 22 | * Takes ownership of the stream |
| 23 | */ |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 24 | static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 25 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 26 | protected: |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 27 | SkEncodedImageFormat onGetEncodedFormat() const override; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 28 | Result onGetPixels(const SkImageInfo&, void*, size_t, |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 29 | const Options&, int*) override; |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 30 | bool onRewind() override; |
Leon Scroggins III | 712476e | 2018-10-03 15:47:00 -0400 | [diff] [blame] | 31 | bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque, |
| 32 | bool needsXform) override; |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 33 | // No need to Xform; all pixels are either black or white. |
| 34 | bool usesColorXform() const override { return false; } |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 35 | private: |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 36 | SkSampler* getSampler(bool createIfNecessary) override { |
| 37 | SkASSERT(fSwizzler || !createIfNecessary); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 38 | return fSwizzler.get(); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 39 | } |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Read a src row from the encoded stream |
| 43 | */ |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 44 | bool readRow(uint8_t* row); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 45 | |
Leon Scroggins III | 36f7e32 | 2018-08-27 11:55:46 -0400 | [diff] [blame] | 46 | SkWbmpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 47 | |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 48 | const size_t fSrcRowBytes; |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 49 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 50 | // Used for scanline decodes: |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 51 | std::unique_ptr<SkSwizzler> fSwizzler; |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 52 | SkAutoTMalloc<uint8_t> fSrcBuffer; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 53 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 54 | int onGetScanlines(void* dst, int count, size_t dstRowBytes) override; |
msarett | 9b9497e | 2016-02-11 13:29:36 -0800 | [diff] [blame] | 55 | bool onSkipScanlines(int count) override; |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 56 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 57 | const Options& options) override; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 58 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 59 | typedef SkCodec INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif // SkCodec_wbmp_DEFINED |