blob: a1927f8c6236f0cfd989d9aced425df985f0c951 [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
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 */
16class SkBmpMaskCodec : public SkBmpCodec {
17public:
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 *
msarettc30c4182016-04-20 11:53:35 -070025 * @param info contains properties of the encoded data
msarett4ab9d5f2015-08-06 15:34:42 -070026 * @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 */
msarettc30c4182016-04-20 11:53:35 -070031 SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
msarett5406d6f2015-08-31 06:55:13 -070032 uint16_t bitsPerPixel, SkMasks* masks,
scroggo46c57472015-09-30 08:57:13 -070033 SkCodec::SkScanlineOrder rowOrder);
msarett4ab9d5f2015-08-06 15:34:42 -070034
35protected:
36
37 Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
38 size_t dstRowBytes, const Options&, SkPMColor*,
msarette6dd0042015-10-09 11:07:34 -070039 int*, int*) override;
msarett4ab9d5f2015-08-06 15:34:42 -070040
Matt Sarett61935682016-11-03 17:27:12 +000041 SkCodec::Result prepareToDecode(const SkImageInfo& dstInfo,
msarett5406d6f2015-08-31 06:55:13 -070042 const SkCodec::Options& options, SkPMColor inputColorPtr[],
43 int* inputColorCount) override;
44
msarett4ab9d5f2015-08-06 15:34:42 -070045private:
46
msarette6dd0042015-10-09 11:07:34 -070047 SkSampler* getSampler(bool createIfNecessary) override {
48 SkASSERT(fMaskSwizzler);
Ben Wagner145dbcd2016-11-03 14:40:50 -040049 return fMaskSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070050 }
msarett4ab9d5f2015-08-06 15:34:42 -070051
msarette6dd0042015-10-09 11:07:34 -070052 int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
53 const Options& opts) override;
msarett4ab9d5f2015-08-06 15:34:42 -070054
Ben Wagner145dbcd2016-11-03 14:40:50 -040055 std::unique_ptr<SkMasks> fMasks;
56 std::unique_ptr<SkMaskSwizzler> fMaskSwizzler;
57 std::unique_ptr<uint8_t[]> fSrcBuffer;
msarett4ab9d5f2015-08-06 15:34:42 -070058
59 typedef SkBmpCodec INHERITED;
60};