OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkCodec_wbmp_DEFINED | 8 #ifndef SkCodec_wbmp_DEFINED |
9 #define SkCodec_wbmp_DEFINED | 9 #define SkCodec_wbmp_DEFINED |
10 | 10 |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkSwizzler.h" | 12 #include "SkSwizzler.h" |
13 | 13 |
14 class SkWbmpCodec final : public SkCodec { | 14 class SkWbmpCodec final : public SkCodec { |
15 public: | 15 public: |
16 static bool IsWbmp(SkStream*); | 16 static bool IsWbmp(SkStream*); |
17 | 17 |
18 /* | 18 /* |
19 * Assumes IsWbmp was called and returned true | 19 * Assumes IsWbmp was called and returned true |
20 * Creates a wbmp codec | 20 * Creates a wbmp codec |
21 * Takes ownership of the stream | 21 * Takes ownership of the stream |
22 */ | 22 */ |
23 static SkCodec* NewFromStream(SkStream*); | 23 static SkCodec* NewFromStream(SkStream*); |
24 | 24 |
25 protected: | 25 protected: |
26 SkEncodedFormat onGetEncodedFormat() const override; | 26 SkEncodedFormat onGetEncodedFormat() const override; |
27 Result onGetPixels(const SkImageInfo&, void*, size_t, | 27 Result onGetPixels(const SkImageInfo&, void*, size_t, |
28 const Options&, SkPMColor[], int*) override; | 28 const Options&, SkPMColor[], int*, int*) override; |
29 bool onRewind() override; | 29 bool onRewind() override; |
30 private: | 30 private: |
31 /* | 31 /* |
32 * Returns a swizzler on success, nullptr on failure | 32 * Returns a swizzler on success, nullptr on failure |
33 */ | 33 */ |
34 SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* cta
ble, | 34 SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* cta
ble, |
35 const Options& opts); | 35 const Options& opts); |
36 SkSampler* getSampler() override { return fSwizzler; } | 36 SkSampler* getSampler(bool createIfNecessary) override { |
| 37 SkASSERT(fSwizzler || !createIfNecessary); |
| 38 return fSwizzler; |
| 39 } |
37 | 40 |
38 /* | 41 /* |
39 * Read a src row from the encoded stream | 42 * Read a src row from the encoded stream |
40 */ | 43 */ |
41 Result readRow(uint8_t* row); | 44 bool readRow(uint8_t* row); |
42 | 45 |
43 SkWbmpCodec(const SkImageInfo&, SkStream*); | 46 SkWbmpCodec(const SkImageInfo&, SkStream*); |
44 | 47 |
45 const size_t fSrcRowBytes; | 48 const size_t fSrcRowBytes; |
46 | 49 |
47 // Used for scanline decodes: | 50 // Used for scanline decodes: |
| 51 SkAutoTDelete<SkSwizzler> fSwizzler; |
48 SkAutoTUnref<SkColorTable> fColorTable; | 52 SkAutoTUnref<SkColorTable> fColorTable; |
49 SkAutoTDelete<SkSwizzler> fSwizzler; | |
50 SkAutoTMalloc<uint8_t> fSrcBuffer; | 53 SkAutoTMalloc<uint8_t> fSrcBuffer; |
51 | 54 |
52 // FIXME: Override onSkipScanlines to avoid swizzling. | 55 // FIXME: Override onSkipScanlines to avoid swizzling. |
53 Result onGetScanlines(void* dst, int count, size_t dstRowBytes) override; | 56 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override; |
54 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 57 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
55 SkPMColor inputColorTable[], int* inputColorCount) override; | 58 SkPMColor inputColorTable[], int* inputColorCount) override; |
56 | 59 |
57 typedef SkCodec INHERITED; | 60 typedef SkCodec INHERITED; |
58 }; | 61 }; |
59 | 62 |
60 #endif // SkCodec_wbmp_DEFINED | 63 #endif // SkCodec_wbmp_DEFINED |
OLD | NEW |