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#ifndef SkMaskSwizzler_DEFINED
8#define SkMaskSwizzler_DEFINED
9
10#include "include/core/SkTypes.h"
11#include "src/codec/SkMasks.h"
12#include "src/codec/SkSampler.h"
13#include "src/codec/SkSwizzler.h"
14
15/*
16 *
17 * Used to swizzle images whose pixel components are extracted by bit masks
18 * Currently only used by bmp
19 *
20 */
21class SkMaskSwizzler : public SkSampler {
22public:
23
24 /*
25 * @param masks Unowned pointer to helper class
26 */
27 static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
28 bool srcIsOpaque,
29 SkMasks* masks,
30 uint32_t bitsPerPixel,
31 const SkCodec::Options& options);
32
33 /*
34 * Swizzle a row
35 */
36 void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
37
38 int fillWidth() const override {
39 return fDstWidth;
40 }
41
42 /**
43 * Returns the byte offset at which we write to destination memory, taking
44 * scaling, subsetting, and partial frames into account.
45 * A similar function exists on SkSwizzler.
46 */
47 int swizzleWidth() const { return fDstWidth; }
48
49private:
50
51 /*
52 * Row procedure used for swizzle
53 */
54 typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
55 SkMasks* masks, uint32_t startX, uint32_t sampleX);
56
57 SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
58
59 int onSetSampleX(int) override;
60
61 SkMasks* fMasks; // unowned
62 const RowProc fRowProc;
63
64 // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
65 const int fSubsetWidth; // Width of the subset of source before any sampling.
66 int fDstWidth; // Width of dst, which may differ with sampling.
67 int fSampleX;
68 int fSrcOffset;
69 int fX0;
70};
71
72#endif
73