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 | */ |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 24 | static SkCodec* NewFromStream(SkStream*); |
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, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 29 | const Options&, SkPMColor[], int*, int*) override; |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 30 | bool onRewind() override; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 31 | private: |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 32 | /* |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 33 | * Returns a swizzler on success, nullptr on failure |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 34 | */ |
| 35 | SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable, |
| 36 | const Options& opts); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 37 | SkSampler* getSampler(bool createIfNecessary) override { |
| 38 | SkASSERT(fSwizzler || !createIfNecessary); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 39 | return fSwizzler.get(); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 40 | } |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Read a src row from the encoded stream |
| 44 | */ |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 45 | bool readRow(uint8_t* row); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 46 | |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 47 | SkWbmpCodec(int width, int height, const SkEncodedInfo&, SkStream*); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 48 | |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 49 | const size_t fSrcRowBytes; |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 50 | |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 51 | // Used for scanline decodes: |
Hal Canary | 67b39de | 2016-11-07 11:47:44 -0500 | [diff] [blame] | 52 | std::unique_ptr<SkSwizzler> fSwizzler; |
| 53 | sk_sp<SkColorTable> fColorTable; |
| 54 | SkAutoTMalloc<uint8_t> fSrcBuffer; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 55 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 56 | int onGetScanlines(void* dst, int count, size_t dstRowBytes) override; |
msarett | 9b9497e | 2016-02-11 13:29:36 -0800 | [diff] [blame] | 57 | bool onSkipScanlines(int count) override; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 58 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options, |
| 59 | SkPMColor inputColorTable[], int* inputColorCount) override; |
| 60 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 61 | typedef SkCodec INHERITED; |
| 62 | }; |
| 63 | |
| 64 | #endif // SkCodec_wbmp_DEFINED |