| 1 |
/* |
| 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 |
|
| 10 |
#include "include/codec/SkCodec.h" |
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
#include "include/private/base/SkNoncopyable.h" |
| 13 |
#include "src/codec/SkCodecPriv.h" |
| 14 |
|
| 15 |
#include <cstddef> |
| 16 |
|
| 17 |
struct SkImageInfo; |
| 18 |
|
| 19 |
class SkSampler : public SkNoncopyable { |
| 20 |
public: |
| 21 |
/** |
| 22 |
* Update the sampler to sample every sampleX'th pixel. Returns the |
| 23 |
* width after sampling. |
| 24 |
*/ |
| 25 |
int setSampleX(int sampleX) { |
| 26 |
return this->onSetSampleX(sampleX); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Update the sampler to sample every sampleY'th row. |
| 31 |
*/ |
| 32 |
void setSampleY(int sampleY) { |
| 33 |
fSampleY = sampleY; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Retrieve the value set for sampleY. |
| 38 |
*/ |
| 39 |
int sampleY() const { |
| 40 |
return fSampleY; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Based on fSampleY, return whether this row belongs in the output. |
| 45 |
* |
| 46 |
* @param row Row of the image, starting with the first row in the subset. |
| 47 |
*/ |
| 48 |
bool rowNeeded(int row) const { |
| 49 |
return (row - SkCodecPriv::GetStartCoord(fSampleY)) % fSampleY == 0; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Fill the remainder of the destination with 0. |
| 54 |
* |
| 55 |
* 0 has a different meaning depending on the SkColorType. For color types |
| 56 |
* with transparency, this means transparent. For k565 and kGray, 0 is |
| 57 |
* black. |
| 58 |
* |
| 59 |
* @param info |
| 60 |
* Contains the color type of the rows to fill. |
| 61 |
* Contains the pixel width of the destination rows to fill |
| 62 |
* Contains the number of rows that we need to fill. |
| 63 |
* |
| 64 |
* @param dst |
| 65 |
* The destination row to fill. |
| 66 |
* |
| 67 |
* @param rowBytes |
| 68 |
* Stride in bytes of the destination. |
| 69 |
* |
| 70 |
* @param zeroInit |
| 71 |
* Indicates whether memory is already zero initialized. |
| 72 |
*/ |
| 73 |
static void Fill(const SkImageInfo& info, void* dst, size_t rowBytes, |
| 74 |
SkCodec::ZeroInitialized zeroInit); |
| 75 |
|
| 76 |
virtual int fillWidth() const = 0; |
| 77 |
|
| 78 |
SkSampler() |
| 79 |
: fSampleY(1) |
| 80 |
{} |
| 81 |
|
| 82 |
virtual ~SkSampler() {} |
| 83 |
private: |
| 84 |
int fSampleY; |
| 85 |
|
| 86 |
virtual int onSetSampleX(int) = 0; |
| 87 |
}; |
| 88 |
|
| 89 |
#endif // SkSampler_DEFINED |