blob: eff43ee025bcfc6705cea17f8bac94d2772404f4 [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 * @param masks Unowned pointer to helper class
msarett74114382015-03-16 11:55:18 -070026 */
msarett5406d6f2015-08-31 06:55:13 -070027 static SkMaskSwizzler* CreateMaskSwizzler(const SkImageInfo& dstInfo,
Leon Scroggins III712476e2018-10-03 15:47:00 -040028 bool srcIsOpaque,
msarett74114382015-03-16 11:55:18 -070029 SkMasks* masks,
msarettfdb47572015-10-13 12:50:14 -070030 uint32_t bitsPerPixel,
31 const SkCodec::Options& options);
msarett74114382015-03-16 11:55:18 -070032
33 /*
msarett614aa072015-07-27 15:13:17 -070034 * Swizzle a row
msarett74114382015-03-16 11:55:18 -070035 */
msaretta4970dc2016-01-11 07:23:23 -080036 void swizzle(void* dst, const uint8_t* SK_RESTRICT src);
msarett74114382015-03-16 11:55:18 -070037
Leon Scroggins IIIa6161b12018-10-18 14:45:26 -040038 int fillWidth() const override {
39 return fDstWidth;
msarette6dd0042015-10-09 11:07:34 -070040 }
41
Matt Sarett1b96c6f2016-11-03 16:15:20 -040042 /**
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
msarett74114382015-03-16 11:55:18 -070049private:
50
51 /*
msarett74114382015-03-16 11:55:18 -070052 * Row procedure used for swizzle
msarett74114382015-03-16 11:55:18 -070053 */
msaretta4970dc2016-01-11 07:23:23 -080054 typedef void (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
msarett5406d6f2015-08-31 06:55:13 -070055 SkMasks* masks, uint32_t startX, uint32_t sampleX);
msarett74114382015-03-16 11:55:18 -070056
msarett80803ff2015-10-16 10:54:12 -070057 SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
msarett74114382015-03-16 11:55:18 -070058
scroggoe7fc14b2015-10-02 13:14:46 -070059 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.
msarett80803ff2015-10-16 10:54:12 -070065 const int fSubsetWidth; // Width of the subset of source before any sampling.
scroggoe7fc14b2015-10-02 13:14:46 -070066 int fDstWidth; // Width of dst, which may differ with sampling.
67 int fSampleX;
msarettfdb47572015-10-13 12:50:14 -070068 int fSrcOffset;
scroggoe7fc14b2015-10-02 13:14:46 -070069 int fX0;
msarett74114382015-03-16 11:55:18 -070070};
msarett4ab9d5f2015-08-06 15:34:42 -070071
72#endif