blob: 73e11c986e2949981a4f215678582fdfce060e8c [file] [log] [blame]
scroggoe7fc14b2015-10-02 13:14:46 -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#ifndef SkSampler_DEFINED
8#define SkSampler_DEFINED
9
msaretta4970dc2016-01-11 07:23:23 -080010#include "SkCodec.h"
scroggoe7fc14b2015-10-02 13:14:46 -070011#include "SkTypes.h"
12
13class SkSampler : public SkNoncopyable {
14public:
15 /**
16 * Update the sampler to sample every sampleX'th pixel. Returns the
17 * width after sampling.
18 */
19 int setSampleX(int sampleX) {
20 return this->onSetSampleX(sampleX);
21 }
22
msarette6dd0042015-10-09 11:07:34 -070023 /**
24 * Fill the remainder of the destination with a single color
25 *
26 * @param info
27 * Contains the color type of the rows to fill.
28 * Contains the width of the destination rows to fill
29 * Contains the number of rows that we need to fill.
30 *
31 * @param dst
32 * The destination row to fill from.
33 *
34 * @param rowBytes
35 * Stride in bytes of the destination.
36 *
37 * @param colorOrIndex
38 * If colorType is kN32, colorOrIndex is treated as a 32-bit color.
39 * If colorType is k565, colorOrIndex is treated as a 16-bit color.
40 * If colorType is kGray, colorOrIndex is treated as an 8-bit color.
41 * If colorType is kIndex, colorOrIndex is treated as an 8-bit index.
42 * Other SkColorTypes are not supported.
43 *
44 * @param zeroInit
45 * Indicates whether memory is already zero initialized.
46 *
47 */
48 static void Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
49 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit);
50
51 /**
52 * Allow subclasses to implement unique versions of fill().
53 */
54 virtual void fill(const SkImageInfo& info, void* dst, size_t rowBytes,
55 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) {}
56
scroggoe7fc14b2015-10-02 13:14:46 -070057 virtual ~SkSampler() {}
58private:
msarette6dd0042015-10-09 11:07:34 -070059
scroggoe7fc14b2015-10-02 13:14:46 -070060 virtual int onSetSampleX(int) = 0;
61};
62
63#endif // SkSampler_DEFINED