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