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 SkBmpMaskCodec_DEFINED
9#define SkBmpMaskCodec_DEFINED
10
11#include "include/core/SkImageInfo.h"
12#include "include/core/SkTypes.h"
13#include "src/codec/SkBmpBaseCodec.h"
14#include "src/codec/SkMaskSwizzler.h"
15
16/*
17 * This class implements the decoding for bmp images using bit masks
18 */
19class SkBmpMaskCodec : public SkBmpBaseCodec {
20public:
21
22 /*
23 * Creates an instance of the decoder
24 *
25 * Called only by SkBmpCodec::MakeFromStream
26 * There should be no other callers despite this being public
27 *
28 * @param info contains properties of the encoded data
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 */
34 SkBmpMaskCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream>,
35 uint16_t bitsPerPixel, SkMasks* masks,
36 SkCodec::SkScanlineOrder rowOrder);
37
38protected:
39
40 Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
41 size_t dstRowBytes, const Options&,
42 int*) override;
43
44 SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo,
45 const SkCodec::Options& options) override;
46
47private:
48
49 SkSampler* getSampler(bool createIfNecessary) override {
50 SkASSERT(fMaskSwizzler);
51 return fMaskSwizzler.get();
52 }
53
54 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
55 const Options& opts) override;
56
57 std::unique_ptr<SkMasks> fMasks;
58 std::unique_ptr<SkMaskSwizzler> fMaskSwizzler;
59
60 typedef SkBmpBaseCodec INHERITED;
61};
62#endif // SkBmpMaskCodec_DEFINED
63