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 | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 12 | #include "SkSwizzler.h" |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 13 | |
| 14 | class SkWbmpCodec final : public SkCodec { |
| 15 | public: |
scroggo | db30be2 | 2015-12-08 18:54:13 -0800 | [diff] [blame] | 16 | static bool IsWbmp(const void*, size_t); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * Assumes IsWbmp was called and returned true |
| 20 | * Creates a wbmp codec |
| 21 | * Takes ownership of the stream |
| 22 | */ |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 23 | static SkCodec* NewFromStream(SkStream*); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 24 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 25 | protected: |
| 26 | SkEncodedFormat onGetEncodedFormat() const override; |
| 27 | Result onGetPixels(const SkImageInfo&, void*, size_t, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 28 | const Options&, SkPMColor[], int*, int*) override; |
scroggo | b427db1 | 2015-08-12 07:24:13 -0700 | [diff] [blame] | 29 | bool onRewind() override; |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 30 | private: |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 31 | /* |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 32 | * Returns a swizzler on success, nullptr on failure |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 33 | */ |
| 34 | SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable, |
| 35 | const Options& opts); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 36 | SkSampler* getSampler(bool createIfNecessary) override { |
| 37 | SkASSERT(fSwizzler || !createIfNecessary); |
| 38 | return fSwizzler; |
| 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 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 46 | SkWbmpCodec(const SkImageInfo&, SkStream*); |
msarett | 99f567e | 2015-08-05 12:58:26 -0700 | [diff] [blame] | 47 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [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: |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 51 | SkAutoTDelete<SkSwizzler> fSwizzler; |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 52 | SkAutoTUnref<SkColorTable> fColorTable; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 53 | SkAutoTMalloc<uint8_t> fSrcBuffer; |
| 54 | |
| 55 | // FIXME: Override onSkipScanlines to avoid swizzling. |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 56 | int onGetScanlines(void* dst, int count, size_t dstRowBytes) override; |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 57 | Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options, |
| 58 | SkPMColor inputColorTable[], int* inputColorCount) override; |
| 59 | |
halcanary | a096d7a | 2015-03-27 12:16:53 -0700 | [diff] [blame] | 60 | typedef SkCodec INHERITED; |
| 61 | }; |
| 62 | |
| 63 | #endif // SkCodec_wbmp_DEFINED |