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 SkCodec_DEFINED | 8 #ifndef SkCodec_DEFINED |
9 #define SkCodec_DEFINED | 9 #define SkCodec_DEFINED |
10 | 10 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 * of the encoded data, but then never use any colors which have alpha | 218 * of the encoded data, but then never use any colors which have alpha |
219 * less than 100%. This function can be called *after* decoding to | 219 * less than 100%. This function can be called *after* decoding to |
220 * determine if such an image truly had alpha. Calling it before decoding | 220 * determine if such an image truly had alpha. Calling it before decoding |
221 * is undefined. | 221 * is undefined. |
222 * FIXME: see skbug.com/3582. | 222 * FIXME: see skbug.com/3582. |
223 */ | 223 */ |
224 bool reallyHasAlpha() const { | 224 bool reallyHasAlpha() const { |
225 return this->onReallyHasAlpha(); | 225 return this->onReallyHasAlpha(); |
226 } | 226 } |
227 | 227 |
228 /** | |
229 * Before returning kIncompleteInput, onGetPixels() indicates how many unini tialized | |
230 * scanlines need to be filled. In order to fill these scanlines, we use th is function | |
231 * to determine what value to fill with. | |
232 * | |
233 * @param dstInfo Contains the destination colorType and alphaType, which ma y be | |
234 * used to choose the fill value. | |
235 * @return The value with which to fill uninitialized pixels. | |
236 * | |
237 * Note that we can interpret the return value as an SkPMColor, a 16-bit 565 color, | |
238 * an 8-bit gray color, or an 8-bit index into a color table, depending on t he color | |
239 * type specified in dstInfo. | |
240 */ | |
241 uint32_t getFillValue(const SkImageInfo& dstInfo) const { | |
242 return this->onGetFillValue(dstInfo); | |
243 } | |
244 | |
245 /** | |
246 * Before returning kIncompleteInput, onGetPixels() indicates how many unini tialized | |
247 * scanlines need to be filled. In order to fill these scanlines, we use th is function | |
248 * to determine where these pixels are located in destination memory. | |
249 * | |
250 * When encoded scanlines are arranged top-down, we fill the bottom of desti nation | |
251 * memory. When encoded scanlines are arranged bottom-up, we fill the top o f | |
252 * destination memory. When encoded scanlines are arranged out of order, it is the | |
253 * responsibility of the subclass to fill uninitialized memory. | |
scroggo
2015/09/25 15:55:05
FWIW, it seems like getY could be used to make the
msarett
2015/10/01 12:44:52
We will be able to do this (and I intend to do thi
| |
254 * | |
255 * @param dstStart Pointer to the start of destination memory | |
256 * @param dstRowBytes Stride length in destination memory | |
257 * @param decodedScanlines Number of scanlines decoded successfully | |
258 * @return Pointer to the destination memory that we need to fill | |
259 */ | |
260 void* getFillDst(void* dstStart, size_t rowBytes, uint32_t decodedScanlines) const { | |
261 return this->onGetFillDst(dstStart, rowBytes, decodedScanlines); | |
262 } | |
263 | |
228 protected: | 264 protected: |
229 SkCodec(const SkImageInfo&, SkStream*); | 265 SkCodec(const SkImageInfo&, SkStream*); |
230 | 266 |
231 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 267 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { |
232 // By default, scaling is not supported. | 268 // By default, scaling is not supported. |
233 return this->getInfo().dimensions(); | 269 return this->getInfo().dimensions(); |
234 } | 270 } |
235 | 271 |
236 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 272 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
237 | 273 |
274 /** | |
275 * @param incompleteScanlines When the encoded image stream is incomplete, t his function | |
scroggo
2015/09/25 15:55:05
As I keep thinking about skbug.com/4284, I wonder
msarett
2015/10/01 12:44:52
That would be great if we could do that! For now,
| |
276 * will return kIncompleteInput and incompleteSca nlines will | |
277 * be set to the number of scanlines that remain uninitialized. | |
278 * This will allow getPixels() to fill the uninit ialized memory. | |
279 */ | |
238 virtual Result onGetPixels(const SkImageInfo& info, | 280 virtual Result onGetPixels(const SkImageInfo& info, |
239 void* pixels, size_t rowBytes, const Options&, | 281 void* pixels, size_t rowBytes, const Options&, |
240 SkPMColor ctable[], int* ctableCount) = 0; | 282 SkPMColor ctable[], int* ctableCount, |
283 int* incompleteScanlines) = 0; | |
241 | 284 |
242 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 285 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { |
243 // By default, subsets are not supported. | 286 // By default, subsets are not supported. |
244 return false; | 287 return false; |
245 } | 288 } |
246 | 289 |
247 virtual bool onReallyHasAlpha() const { return false; } | 290 virtual bool onReallyHasAlpha() const { return false; } |
248 | 291 |
249 /** | 292 /** |
250 * If the stream was previously read, attempt to rewind. | 293 * If the stream was previously read, attempt to rewind. |
(...skipping 11 matching lines...) Expand all Loading... | |
262 /** | 305 /** |
263 * Called by rewindIfNeeded, if the stream needed to be rewound. | 306 * Called by rewindIfNeeded, if the stream needed to be rewound. |
264 * | 307 * |
265 * Subclasses should do any set up needed after a rewind. | 308 * Subclasses should do any set up needed after a rewind. |
266 */ | 309 */ |
267 virtual bool onRewind() { | 310 virtual bool onRewind() { |
268 return true; | 311 return true; |
269 } | 312 } |
270 | 313 |
271 /** | 314 /** |
315 * Some subclasses will override this function, but this is a useful default for the color | |
316 * types that we support. Note that for color types that do not use the ful l 32-bits, | |
317 * we will simply take the low bits of the fill value. | |
318 * | |
319 * kN32_SkColorType: Transparent or Black | |
320 * kRGB_565_SkColorType: Black | |
321 * kGray_8_SkColorType: Black | |
322 * kIndex_8_SkColorType: First color in color table | |
323 */ | |
324 virtual uint32_t onGetFillValue(const SkImageInfo& dstInfo) const { | |
325 return kOpaque_SkAlphaType == dstInfo.alphaType() ? SK_ColorBLACK : SK_C olorTRANSPARENT; | |
326 } | |
327 | |
328 /** | |
329 * This will only need to be overridden for images where the rows are not | |
330 * decoded in top-down order. | |
331 */ | |
332 virtual void* onGetFillDst(void* dstStart, size_t rowBytes, uint32_t decoded Scanlines) const { | |
333 return SkTAddOffset<void>(dstStart, rowBytes * decodedScanlines); | |
334 } | |
335 | |
336 /** | |
272 * Get method for the input stream | 337 * Get method for the input stream |
273 */ | 338 */ |
274 SkStream* stream() { | 339 SkStream* stream() { |
275 return fStream.get(); | 340 return fStream.get(); |
276 } | 341 } |
277 | 342 |
278 private: | 343 private: |
279 const SkImageInfo fInfo; | 344 const SkImageInfo fInfo; |
280 SkAutoTDelete<SkStream> fStream; | 345 SkAutoTDelete<SkStream> fStream; |
281 bool fNeedsRewind; | 346 bool fNeedsRewind; |
347 uint32_t fIncompleteScanlines; | |
scroggo
2015/09/25 15:55:05
I think this no longer needs to be a member variab
msarett
2015/10/01 12:44:52
Done.
| |
282 }; | 348 }; |
283 #endif // SkCodec_DEFINED | 349 #endif // SkCodec_DEFINED |
OLD | NEW |