blob: af6f48598c36cdab720f792bb5dc7a7db3bd807e [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 /**
scroggoa4b09a12016-05-31 06:30:14 -070024 * Update the sampler to sample every sampleY'th row.
25 */
26 void setSampleY(int sampleY) {
27 fSampleY = sampleY;
28 }
29
30 /**
31 * Retrieve the value set for sampleY.
32 */
33 int sampleY() const {
34 return fSampleY;
35 }
36
37 /**
38 * Based on fSampleY, return whether this row belongs in the output.
39 *
40 * @param row Row of the image, starting with the first row used in the
41 * output.
42 */
43 bool rowNeeded(int row) const {
44 return row % fSampleY == 0;
45 }
46
47 /**
msarette6dd0042015-10-09 11:07:34 -070048 * Fill the remainder of the destination with a single color
49 *
50 * @param info
51 * Contains the color type of the rows to fill.
52 * Contains the width of the destination rows to fill
53 * Contains the number of rows that we need to fill.
54 *
55 * @param dst
56 * The destination row to fill from.
57 *
58 * @param rowBytes
59 * Stride in bytes of the destination.
60 *
61 * @param colorOrIndex
62 * If colorType is kN32, colorOrIndex is treated as a 32-bit color.
63 * If colorType is k565, colorOrIndex is treated as a 16-bit color.
64 * If colorType is kGray, colorOrIndex is treated as an 8-bit color.
65 * If colorType is kIndex, colorOrIndex is treated as an 8-bit index.
66 * Other SkColorTypes are not supported.
67 *
68 * @param zeroInit
69 * Indicates whether memory is already zero initialized.
70 *
71 */
72 static void Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
73 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit);
74
75 /**
76 * Allow subclasses to implement unique versions of fill().
77 */
78 virtual void fill(const SkImageInfo& info, void* dst, size_t rowBytes,
79 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) {}
80
scroggoa4b09a12016-05-31 06:30:14 -070081 SkSampler()
82 : fSampleY(1)
83 {}
84
scroggoe7fc14b2015-10-02 13:14:46 -070085 virtual ~SkSampler() {}
86private:
scroggoa4b09a12016-05-31 06:30:14 -070087 int fSampleY;
msarette6dd0042015-10-09 11:07:34 -070088
scroggoe7fc14b2015-10-02 13:14:46 -070089 virtual int onSetSampleX(int) = 0;
90};
91
92#endif // SkSampler_DEFINED