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