blob: 05043b981c7077d3ee92155ce2f3bef4521b72da [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"
scroggo4f2a88c2016-10-17 14:32:41 -070011#include "SkCodecPriv.h"
scroggoe7fc14b2015-10-02 13:14:46 -070012#include "SkTypes.h"
13
14class SkSampler : public SkNoncopyable {
15public:
16 /**
17 * Update the sampler to sample every sampleX'th pixel. Returns the
18 * width after sampling.
19 */
20 int setSampleX(int sampleX) {
21 return this->onSetSampleX(sampleX);
22 }
23
msarette6dd0042015-10-09 11:07:34 -070024 /**
scroggo8e6c7ad2016-09-16 08:20:38 -070025 * Update the sampler to sample every sampleY'th row.
26 */
27 void setSampleY(int sampleY) {
28 fSampleY = sampleY;
29 }
30
31 /**
32 * Retrieve the value set for sampleY.
33 */
34 int sampleY() const {
35 return fSampleY;
36 }
37
38 /**
39 * Based on fSampleY, return whether this row belongs in the output.
40 *
scroggo4f2a88c2016-10-17 14:32:41 -070041 * @param row Row of the image, starting with the first row in the subset.
scroggo8e6c7ad2016-09-16 08:20:38 -070042 */
43 bool rowNeeded(int row) const {
scroggoaef247a2016-10-19 12:56:46 -070044 return (row - get_start_coord(fSampleY)) % fSampleY == 0;
scroggo8e6c7ad2016-09-16 08:20:38 -070045 }
46
47 /**
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040048 * Fill the remainder of the destination with 0.
49 *
50 * 0 has a different meaning depending on the SkColorType. For color types
51 * with transparency, this means transparent. For k565 and kGray, 0 is
52 * black.
msarette6dd0042015-10-09 11:07:34 -070053 *
54 * @param info
55 * Contains the color type of the rows to fill.
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040056 * Contains the pixel width of the destination rows to fill
msarette6dd0042015-10-09 11:07:34 -070057 * Contains the number of rows that we need to fill.
58 *
59 * @param dst
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040060 * The destination row to fill.
msarette6dd0042015-10-09 11:07:34 -070061 *
62 * @param rowBytes
63 * Stride in bytes of the destination.
64 *
msarette6dd0042015-10-09 11:07:34 -070065 * @param zeroInit
66 * Indicates whether memory is already zero initialized.
msarette6dd0042015-10-09 11:07:34 -070067 */
68 static void Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040069 SkCodec::ZeroInitialized zeroInit);
msarette6dd0042015-10-09 11:07:34 -070070
Leon Scroggins IIIa6161b12018-10-18 14:45:26 -040071 virtual int fillWidth() const = 0;
msarette6dd0042015-10-09 11:07:34 -070072
scroggo8e6c7ad2016-09-16 08:20:38 -070073 SkSampler()
74 : fSampleY(1)
75 {}
76
scroggoe7fc14b2015-10-02 13:14:46 -070077 virtual ~SkSampler() {}
78private:
scroggo8e6c7ad2016-09-16 08:20:38 -070079 int fSampleY;
msarette6dd0042015-10-09 11:07:34 -070080
scroggoe7fc14b2015-10-02 13:14:46 -070081 virtual int onSetSampleX(int) = 0;
82};
83
84#endif // SkSampler_DEFINED