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 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 static int BytesPerPixel(SrcConfig sc) { | 110 static int BytesPerPixel(SrcConfig sc) { |
111 SkASSERT(SkIsAlign8(BitsPerPixel(sc))); | 111 SkASSERT(SkIsAlign8(BitsPerPixel(sc))); |
112 return BitsPerPixel(sc) >> 3; | 112 return BitsPerPixel(sc) >> 3; |
113 } | 113 } |
114 | 114 |
115 /** | 115 /** |
116 * Create a new SkSwizzler. | 116 * Create a new SkSwizzler. |
117 * @param SrcConfig Description of the format of the source. | 117 * @param SrcConfig Description of the format of the source. |
118 * @param SkImageInfo dimensions() describe both the src and the dst. | 118 * @param SkImageInfo dimensions() describe both the src and the dst. |
119 * Other fields describe the dst. | 119 * Other fields describe the dst. |
120 * @param dst Destination to write pixels. Must match info and dstRowBytes | |
121 * @param dstRowBytes rowBytes for dst. | |
122 * @param ZeroInitialized Whether dst is zero-initialized. The | 120 * @param ZeroInitialized Whether dst is zero-initialized. The |
123 implementation may choose to skip writing zeroes | 121 implementation may choose to skip writing zeroes |
124 * if set to kYes_ZeroInitialized. | 122 * if set to kYes_ZeroInitialized. |
125 * @return A new SkSwizzler or NULL on failure. | 123 * @return A new SkSwizzler or NULL on failure. |
126 */ | 124 */ |
127 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable, | 125 static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable, |
128 const SkImageInfo&, void* dst, | 126 const SkImageInfo&, SkCodec::ZeroInitializ
ed); |
129 size_t dstRowBytes, | |
130 SkCodec::ZeroInitialized); | |
131 | 127 |
132 /** | 128 /** |
133 * Fill the remainder of the destination with a single color | 129 * Fill the remainder of the destination with a single color |
134 * | 130 * |
135 * @param dstStartRow | 131 * @param dstStartRow |
136 * The destination row to fill from. | 132 * The destination row to fill from. |
137 * | 133 * |
138 * @param numRows | 134 * @param numRows |
139 * The number of rows to fill. | 135 * The number of rows to fill. |
140 * | 136 * |
(...skipping 16 matching lines...) Expand all Loading... |
157 * | 153 * |
158 * If dstInfo.colorType() is kGray, colorOrIndex is always treated as an 8-b
it color. | 154 * If dstInfo.colorType() is kGray, colorOrIndex is always treated as an 8-b
it color. |
159 * | 155 * |
160 * Other SkColorTypes are not supported. | 156 * Other SkColorTypes are not supported. |
161 * | 157 * |
162 */ | 158 */ |
163 static void Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRo
wBytes, | 159 static void Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRo
wBytes, |
164 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable
); | 160 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable
); |
165 | 161 |
166 /** | 162 /** |
167 * Swizzle the next line. Call height times, once for each row of source. | 163 * Swizzle a line. Generally this will be called height times, once |
| 164 * for each row of source. |
| 165 * By allowing the caller to pass in the dst pointer, we give the caller |
| 166 * flexibility to use the swizzler even when the encoded data does not |
| 167 * store the rows in order. This also improves usability for scaled and |
| 168 * subset decodes. |
| 169 * @param dst Where we write the output. |
168 * @param src The next row of the source data. | 170 * @param src The next row of the source data. |
169 * @return A result code describing if the row was fully opaque, fully | 171 * @return A result code describing if the row was fully opaque, fully |
170 * transparent, or neither | 172 * transparent, or neither |
171 */ | 173 */ |
172 ResultAlpha next(const uint8_t* SK_RESTRICT src); | 174 ResultAlpha swizzle(void* dst, const uint8_t* SK_RESTRICT src); |
173 | |
174 /** | |
175 * | |
176 * Alternate version of next that allows the caller to specify the row. | |
177 * It is very important to only use one version of next. Since the other | |
178 * version modifies the dst pointer, it will change the behavior of this | |
179 * function. We will check this in Debug mode. | |
180 * | |
181 */ | |
182 ResultAlpha next(const uint8_t* SK_RESTRICT src, int y); | |
183 | |
184 /** | |
185 * Update the destination row. | |
186 * | |
187 * Typically this is done by next, but for a client that wants to manually | |
188 * modify the destination row (for example, for decoding scanline one at a | |
189 * time) they can call this before each call to next. | |
190 * TODO: Maybe replace this with a version of next which allows supplying t
he | |
191 * destination? | |
192 */ | |
193 void setDstRow(void* dst) { fDstRow = dst; } | |
194 | |
195 /** | |
196 * Get the next destination row to decode to | |
197 */ | |
198 void* getDstRow() { | |
199 // kDesignateRow_NextMode does not update the fDstRow ptr. This functio
n is | |
200 // unnecessary in that case since fDstRow will always be equal to the po
inter | |
201 // passed to CreateSwizzler(). | |
202 SkASSERT(kDesignateRow_NextMode != fNextMode); | |
203 return fDstRow; | |
204 } | |
205 | 175 |
206 private: | 176 private: |
207 | 177 |
208 #ifdef SK_DEBUG | |
209 /* | |
210 * | |
211 * Keep track of which version of next the caller is using | |
212 * | |
213 */ | |
214 enum NextMode { | |
215 kUninitialized_NextMode, | |
216 kConsecutive_NextMode, | |
217 kDesignateRow_NextMode, | |
218 }; | |
219 | |
220 NextMode fNextMode; | |
221 #endif | |
222 | |
223 /** | 178 /** |
224 * Method for converting raw data to Skia pixels. | 179 * Method for converting raw data to Skia pixels. |
225 * @param dstRow Row in which to write the resulting pixels. | 180 * @param dstRow Row in which to write the resulting pixels. |
226 * @param src Row of src data, in format specified by SrcConfig | 181 * @param src Row of src data, in format specified by SrcConfig |
227 * @param width Width in pixels | 182 * @param width Width in pixels |
228 * @param deltaSrc if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel | 183 * @param deltaSrc if bitsPerPixel % 8 == 0, deltaSrc is bytesPerPixel |
229 * else, deltaSrc is bitsPerPixel | 184 * else, deltaSrc is bitsPerPixel |
230 * @param y Line of source. | |
231 * @param ctable Colors (used for kIndex source). | 185 * @param ctable Colors (used for kIndex source). |
232 */ | 186 */ |
233 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, | 187 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, |
234 const uint8_t* SK_RESTRICT src, | 188 const uint8_t* SK_RESTRICT src, |
235 int width, int deltaSrc, int y, | 189 int width, int deltaSrc, |
236 const SkPMColor ctable[]); | 190 const SkPMColor ctable[]); |
237 | 191 |
238 const RowProc fRowProc; | 192 const RowProc fRowProc; |
239 const SkPMColor* fColorTable; // Unowned pointer | 193 const SkPMColor* fColorTable; // Unowned pointer |
240 const int fDeltaSrc; // if bitsPerPixel % 8 == 0 | 194 const int fDeltaSrc; // if bitsPerPixel % 8 == 0 |
241 // deltaSrc is bytesPerPixel | 195 // deltaSrc is bytesPerPixel |
242 // else | 196 // else |
243 // deltaSrc is bitsPerPixel | 197 // deltaSrc is bitsPerPixel |
244 const SkImageInfo fDstInfo; | 198 const SkImageInfo fDstInfo; |
245 void* fDstRow; | |
246 const size_t fDstRowBytes; | |
247 int fCurrY; | 199 int fCurrY; |
248 | 200 |
249 SkSwizzler(RowProc proc, const SkPMColor* ctable, int deltaSrc, | 201 SkSwizzler(RowProc proc, const SkPMColor* ctable, int deltaSrc, |
250 const SkImageInfo& info, void* dst, size_t rowBytes); | 202 const SkImageInfo& info); |
251 | 203 |
252 }; | 204 }; |
253 #endif // SkSwizzler_DEFINED | 205 #endif // SkSwizzler_DEFINED |
OLD | NEW |