blob: 50e285dff393e348566e7f5545ad4bdeed5cbf3a [file] [log] [blame]
msarett4ab9d5f2015-08-06 15:34:42 -07001/*
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 Canary03a7f5f2017-02-10 09:06:38 -05008#ifndef SkBmpMaskCodec_DEFINED
9#define SkBmpMaskCodec_DEFINED
10
msarett4ab9d5f2015-08-06 15:34:42 -070011#include "SkBmpCodec.h"
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 */
19class SkBmpMaskCodec : public SkBmpCodec {
20public:
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 *
msarettc30c4182016-04-20 11:53:35 -070028 * @param info contains properties of the encoded data
msarett4ab9d5f2015-08-06 15:34:42 -070029 * @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 */
msarettc30c4182016-04-20 11:53:35 -070034 SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
msarett5406d6f2015-08-31 06:55:13 -070035 uint16_t bitsPerPixel, SkMasks* masks,
scroggo46c57472015-09-30 08:57:13 -070036 SkCodec::SkScanlineOrder rowOrder);
msarett4ab9d5f2015-08-06 15:34:42 -070037
38protected:
39
40 Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
41 size_t dstRowBytes, const Options&, SkPMColor*,
msarette6dd0042015-10-09 11:07:34 -070042 int*, int*) override;
msarett4ab9d5f2015-08-06 15:34:42 -070043
Matt Sarett1b96c6f2016-11-03 16:15:20 -040044 SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo,
msarett5406d6f2015-08-31 06:55:13 -070045 const SkCodec::Options& options, SkPMColor inputColorPtr[],
46 int* inputColorCount) override;
47
msarett4ab9d5f2015-08-06 15:34:42 -070048private:
49
msarette6dd0042015-10-09 11:07:34 -070050 SkSampler* getSampler(bool createIfNecessary) override {
51 SkASSERT(fMaskSwizzler);
Ben Wagner145dbcd2016-11-03 14:40:50 -040052 return fMaskSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070053 }
msarett4ab9d5f2015-08-06 15:34:42 -070054
msarette6dd0042015-10-09 11:07:34 -070055 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
56 const Options& opts) override;
msarett4ab9d5f2015-08-06 15:34:42 -070057
Ben Wagner145dbcd2016-11-03 14:40:50 -040058 std::unique_ptr<SkMasks> fMasks;
59 std::unique_ptr<SkMaskSwizzler> fMaskSwizzler;
60 std::unique_ptr<uint8_t[]> fSrcBuffer;
msarett4ab9d5f2015-08-06 15:34:42 -070061
62 typedef SkBmpCodec INHERITED;
63};
Hal Canary03a7f5f2017-02-10 09:06:38 -050064#endif // SkBmpMaskCodec_DEFINED