OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkSwizzler_DEFINED | 8 #ifndef SkSwizzler_DEFINED |
9 #define SkSwizzler_DEFINED | 9 #define SkSwizzler_DEFINED |
10 | 10 |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
| 14 #include "SkSampler.h" |
14 | 15 |
15 class SkSwizzler : public SkNoncopyable { | 16 class SkSwizzler : public SkSampler { |
16 public: | 17 public: |
17 /** | 18 /** |
18 * Enum describing the config of the source data. | 19 * Enum describing the config of the source data. |
19 */ | 20 */ |
20 enum SrcConfig { | 21 enum SrcConfig { |
21 kUnknown, // Invalid type. | 22 kUnknown, // Invalid type. |
22 kBit, // A single bit to distinguish between white and black | 23 kBit, // A single bit to distinguish between white and black |
23 kGray, | 24 kGray, |
24 kIndex1, | 25 kIndex1, |
25 kIndex2, | 26 kIndex2, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 * | 111 * |
111 */ | 112 */ |
112 static int BytesPerPixel(SrcConfig sc) { | 113 static int BytesPerPixel(SrcConfig sc) { |
113 SkASSERT(SkIsAlign8(BitsPerPixel(sc))); | 114 SkASSERT(SkIsAlign8(BitsPerPixel(sc))); |
114 return BitsPerPixel(sc) >> 3; | 115 return BitsPerPixel(sc) >> 3; |
115 } | 116 } |
116 | 117 |
117 /** | 118 /** |
118 * Create a new SkSwizzler. | 119 * Create a new SkSwizzler. |
119 * @param SrcConfig Description of the format of the source. | 120 * @param SrcConfig Description of the format of the source. |
120 * @param dstInfo describes the destination. | 121 * @param ctable Unowned pointer to an array of up to 256 colors for an |
| 122 * index source. |
| 123 * @param dstInfo Describes the destination. |
121 * @param ZeroInitialized Whether dst is zero-initialized. The | 124 * @param ZeroInitialized Whether dst is zero-initialized. The |
122 implementation may choose to skip writing zeroes | 125 * implementation may choose to skip writing zeroes |
123 * if set to kYes_ZeroInitialized. | 126 * if set to kYes_ZeroInitialized. |
124 * @param srcInfo is the info of the source. Used to calculate the width sa
mplesize. | |
125 * Width sampling is supported by the swizzler, by skipping
pixels when | |
126 swizzling the row. Height sampling is not supported by t
he swizzler, | |
127 but is implemented in SkScaledCodec. | |
128 Sampling in Y can be done by a client with a scanline de
coder, | |
129 but sampling in X allows the swizzler to skip swizzling
pixels and | |
130 reading from and writing to memory. | |
131 * @return A new SkSwizzler or nullptr on failure. | 127 * @return A new SkSwizzler or nullptr on failure. |
132 */ | 128 */ |
133 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable, | 129 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable, |
134 const SkImageInfo& dstInfo, SkCodec::ZeroI
nitialized, | 130 const SkImageInfo& dstInfo, SkCodec::ZeroI
nitialized); |
135 const SkImageInfo& srcInfo); | 131 |
136 /** | 132 /** |
137 * Fill the remainder of the destination with a single color | 133 * Fill the remainder of the destination with a single color |
138 * | 134 * |
139 * @param dstStartRow | 135 * @param dstStartRow |
140 * The destination row to fill from. | 136 * The destination row to fill from. |
141 * | 137 * |
142 * @param numRows | 138 * @param numRows |
143 * The number of rows to fill. | 139 * The number of rows to fill. |
144 * | 140 * |
145 * @param colorOrIndex | 141 * @param colorOrIndex |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const uint8_t* SK_RESTRICT src, | 199 const uint8_t* SK_RESTRICT src, |
204 int dstWidth, int bpp, int deltaSrc, int offs
et, | 200 int dstWidth, int bpp, int deltaSrc, int offs
et, |
205 const SkPMColor ctable[]); | 201 const SkPMColor ctable[]); |
206 | 202 |
207 const RowProc fRowProc; | 203 const RowProc fRowProc; |
208 const SkPMColor* fColorTable; // Unowned pointer | 204 const SkPMColor* fColorTable; // Unowned pointer |
209 const int fDeltaSrc; // if bitsPerPixel % 8 == 0 | 205 const int fDeltaSrc; // if bitsPerPixel % 8 == 0 |
210 // deltaSrc is bytesPerPixel | 206 // deltaSrc is bytesPerPixel |
211 // else | 207 // else |
212 // deltaSrc is bitsPerPixel | 208 // deltaSrc is bitsPerPixel |
213 const SkImageInfo fDstInfo; | 209 const int fSrcWidth; // Width of the source - i.e. before a
ny sampling. |
214 int fCurrY; | 210 int fDstWidth; // Width of dst, which may differ with
sampling. |
215 const int fX0; // first X coord to sample | 211 int fX0; // first X coord to sample |
216 const int fSampleX; // step between X samples | 212 int fSampleX; // step between X samples |
217 | 213 |
218 SkSwizzler(RowProc proc, const SkPMColor* ctable, int deltaSrc, const SkImag
eInfo& info, | 214 SkSwizzler(RowProc proc, const SkPMColor* ctable, int deltaSrc, int srcWidth
); |
219 int sampleX); | 215 |
| 216 int onSetSampleX(int) override; |
220 }; | 217 }; |
221 #endif // SkSwizzler_DEFINED | 218 #endif // SkSwizzler_DEFINED |
OLD | NEW |