blob: 1dc1918f494846ab63448a78f20434bc6d41d3c8 [file] [log] [blame]
msarett74114382015-03-16 11:55:18 -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 */
msarett4ab9d5f2015-08-06 15:34:42 -07007#ifndef SkMaskSwizzler_DEFINED
8#define SkMaskSwizzler_DEFINED
msarett74114382015-03-16 11:55:18 -07009
10#include "SkMasks.h"
scroggoe7fc14b2015-10-02 13:14:46 -070011#include "SkSampler.h"
msarett74114382015-03-16 11:55:18 -070012#include "SkSwizzler.h"
13#include "SkTypes.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 */
scroggoe7fc14b2015-10-02 13:14:46 -070021class SkMaskSwizzler : public SkSampler {
msarett74114382015-03-16 11:55:18 -070022public:
23
24 /*
msarett74114382015-03-16 11:55:18 -070025 * Create a new swizzler
26 * @param masks Unowned pointer to helper class
msarett74114382015-03-16 11:55:18 -070027 */
msarett5406d6f2015-08-31 06:55:13 -070028 static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
29 const SkImageInfo& srcInfo,
msarett74114382015-03-16 11:55:18 -070030 SkMasks* masks,
msarettfdb47572015-10-13 12:50:14 -070031 uint32_t bitsPerPixel,
32 const SkCodec::Options& options);
msarett74114382015-03-16 11:55:18 -070033
34 /*
msarett614aa072015-07-27 15:13:17 -070035 * Swizzle a row
msarett74114382015-03-16 11:55:18 -070036 */
msaretta4970dc2016-01-11 07:23:23 -080037 void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
msarett74114382015-03-16 11:55:18 -070038
msarette6dd0042015-10-09 11:07:34 -070039 /**
40 * Implement fill using a custom width.
41 */
42 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint32_t colorOrIndex,
43 SkCodec::ZeroInitialized zeroInit) override {
44 const SkImageInfo fillInfo = info.makeWH(fDstWidth, info.height());
45 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit);
46 }
47
msarett74114382015-03-16 11:55:18 -070048private:
49
50 /*
msarett74114382015-03-16 11:55:18 -070051 * Row procedure used for swizzle
msarett74114382015-03-16 11:55:18 -070052 */
msaretta4970dc2016-01-11 07:23:23 -080053 typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
msarett5406d6f2015-08-31 06:55:13 -070054 SkMasks* masks, uint32_t startX, uint32_t sampleX);
msarett74114382015-03-16 11:55:18 -070055
msarett80803ff2015-10-16 10:54:12 -070056 SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
msarett74114382015-03-16 11:55:18 -070057
scroggoe7fc14b2015-10-02 13:14:46 -070058 int onSetSampleX(int) override;
59
60 SkMasks* fMasks; // unowned
61 const RowProc fRowProc;
62
63 // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
msarett80803ff2015-10-16 10:54:12 -070064 const int fSubsetWidth; // Width of the subset of source before any sampling.
scroggoe7fc14b2015-10-02 13:14:46 -070065 int fDstWidth; // Width of dst, which may differ with sampling.
66 int fSampleX;
msarettfdb47572015-10-13 12:50:14 -070067 int fSrcOffset;
scroggoe7fc14b2015-10-02 13:14:46 -070068 int fX0;
msarett74114382015-03-16 11:55:18 -070069};
msarett4ab9d5f2015-08-06 15:34:42 -070070
71#endif