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