blob: 5d2955caabded8066e1afa62ff4edab1f670f354 [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 */
msarettf7eb6fc2016-09-13 09:04:11 -070042 void fill(const SkImageInfo& info, void* dst, size_t rowBytes, uint64_t colorOrIndex,
msarette6dd0042015-10-09 11:07:34 -070043 SkCodec::ZeroInitialized zeroInit) override {
44 const SkImageInfo fillInfo = info.makeWH(fDstWidth, info.height());
45 SkSampler::Fill(fillInfo, dst, rowBytes, colorOrIndex, zeroInit);
46 }
47
Matt Sarett1b96c6f2016-11-03 16:15:20 -040048 /**
49 * Returns the byte offset at which we write to destination memory, taking
50 * scaling, subsetting, and partial frames into account.
51 * A similar function exists on SkSwizzler.
52 */
53 int swizzleWidth() const { return fDstWidth; }
54
msarett74114382015-03-16 11:55:18 -070055private:
56
57 /*
msarett74114382015-03-16 11:55:18 -070058 * Row procedure used for swizzle
msarett74114382015-03-16 11:55:18 -070059 */
msaretta4970dc2016-01-11 07:23:23 -080060 typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
msarett5406d6f2015-08-31 06:55:13 -070061 SkMasks* masks, uint32_t startX, uint32_t sampleX);
msarett74114382015-03-16 11:55:18 -070062
msarett80803ff2015-10-16 10:54:12 -070063 SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
msarett74114382015-03-16 11:55:18 -070064
scroggoe7fc14b2015-10-02 13:14:46 -070065 int onSetSampleX(int) override;
66
67 SkMasks* fMasks; // unowned
68 const RowProc fRowProc;
69
70 // FIXME: Can this class share more with SkSwizzler? These variables are all the same.
msarett80803ff2015-10-16 10:54:12 -070071 const int fSubsetWidth; // Width of the subset of source before any sampling.
scroggoe7fc14b2015-10-02 13:14:46 -070072 int fDstWidth; // Width of dst, which may differ with sampling.
73 int fSampleX;
msarettfdb47572015-10-13 12:50:14 -070074 int fSrcOffset;
scroggoe7fc14b2015-10-02 13:14:46 -070075 int fX0;
msarett74114382015-03-16 11:55:18 -070076};
msarett4ab9d5f2015-08-06 15:34:42 -070077
78#endif