msarett | 4ab9d5f | 2015-08-06 15:34:42 -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 | |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 8 | #ifndef SkBmpMaskCodec_DEFINED |
| 9 | #define SkBmpMaskCodec_DEFINED |
| 10 | |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame^] | 11 | #include "SkBmpBaseCodec.h" |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 12 | #include "SkImageInfo.h" |
| 13 | #include "SkMaskSwizzler.h" |
| 14 | #include "SkTypes.h" |
| 15 | |
| 16 | /* |
| 17 | * This class implements the decoding for bmp images using bit masks |
| 18 | */ |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame^] | 19 | class SkBmpMaskCodec : public SkBmpBaseCodec { |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 20 | public: |
| 21 | |
| 22 | /* |
| 23 | * Creates an instance of the decoder |
| 24 | * |
| 25 | * Called only by SkBmpCodec::NewFromStream |
| 26 | * There should be no other callers despite this being public |
| 27 | * |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 28 | * @param info contains properties of the encoded data |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 29 | * @param stream the stream of encoded image data |
| 30 | * @param bitsPerPixel the number of bits used to store each pixel |
| 31 | * @param masks color masks for certain bmp formats |
| 32 | * @param rowOrder indicates whether rows are ordered top-down or bottom-up |
| 33 | */ |
msarett | c30c418 | 2016-04-20 11:53:35 -0700 | [diff] [blame] | 34 | SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 35 | uint16_t bitsPerPixel, SkMasks* masks, |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 36 | SkCodec::SkScanlineOrder rowOrder); |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 37 | |
| 38 | protected: |
| 39 | |
| 40 | Result onGetPixels(const SkImageInfo& dstInfo, void* dst, |
| 41 | size_t dstRowBytes, const Options&, SkPMColor*, |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 42 | int*, int*) override; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 43 | |
Matt Sarett | 1b96c6f | 2016-11-03 16:15:20 -0400 | [diff] [blame] | 44 | SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo, |
msarett | 5406d6f | 2015-08-31 06:55:13 -0700 | [diff] [blame] | 45 | const SkCodec::Options& options, SkPMColor inputColorPtr[], |
| 46 | int* inputColorCount) override; |
| 47 | |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 48 | private: |
| 49 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 50 | SkSampler* getSampler(bool createIfNecessary) override { |
| 51 | SkASSERT(fMaskSwizzler); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 52 | return fMaskSwizzler.get(); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 53 | } |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 54 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 55 | int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, |
| 56 | const Options& opts) override; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 57 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 58 | std::unique_ptr<SkMasks> fMasks; |
| 59 | std::unique_ptr<SkMaskSwizzler> fMaskSwizzler; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 60 | |
Leon Scroggins III | d81fed9 | 2017-06-01 13:42:28 -0400 | [diff] [blame^] | 61 | typedef SkBmpBaseCodec INHERITED; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 62 | }; |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 63 | #endif // SkBmpMaskCodec_DEFINED |