Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 SkImageDecoder_DEFINED | 8 #ifndef SkImageDecoder_DEFINED |
| 9 #define SkImageDecoder_DEFINED | 9 #define SkImageDecoder_DEFINED |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 218 |
| 219 /** Passed to the decode method. If kDecodeBounds_Mode is passed, then | 219 /** Passed to the decode method. If kDecodeBounds_Mode is passed, then |
| 220 only the bitmap's info need be set. If kDecodePixels_Mode | 220 only the bitmap's info need be set. If kDecodePixels_Mode |
| 221 is passed, then the bitmap must have pixels or a pixelRef. | 221 is passed, then the bitmap must have pixels or a pixelRef. |
| 222 */ | 222 */ |
| 223 enum Mode { | 223 enum Mode { |
| 224 kDecodeBounds_Mode, //!< only return info in bitmap | 224 kDecodeBounds_Mode, //!< only return info in bitmap |
| 225 kDecodePixels_Mode //!< return entire bitmap (including pixels) | 225 kDecodePixels_Mode //!< return entire bitmap (including pixels) |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 /** Result of a decode. If read as a boolean, a partial success is | |
| 229 considered a success (true). | |
| 230 */ | |
| 231 enum Result { | |
| 232 kFailure = 0, //!< Image failed to decode. bitmap will be | |
|
reed1
2014/10/17 21:07:26
nit: why specify the actual numeric values? we rar
scroggo
2014/10/17 21:11:44
I suppose I could be more explicit, but that is ho
| |
| 233 // unchanged. | |
| 234 kPartialSuccess = 1, //!< Part of the image decoded. The rest is | |
| 235 // filled in automatically | |
| 236 kSuccess = 2 //!< The entire image decoded. | |
| 237 }; | |
| 238 | |
| 228 /** Given a stream, decode it into the specified bitmap. | 239 /** Given a stream, decode it into the specified bitmap. |
| 229 If the decoder can decompress the image, it calls bitmap.setInfo(), | 240 If the decoder can decompress the image, it calls bitmap.setInfo(), |
| 230 and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), | 241 and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), |
| 231 which will allocated a pixelRef. To access the pixel memory, the codec | 242 which will allocated a pixelRef. To access the pixel memory, the codec |
| 232 needs to call lockPixels/unlockPixels on the | 243 needs to call lockPixels/unlockPixels on the |
| 233 bitmap. It can then set the pixels with the decompressed image. | 244 bitmap. It can then set the pixels with the decompressed image. |
| 234 * If the image cannot be decompressed, return false. After the | 245 * If the image cannot be decompressed, return false. After the |
| 235 * decoding, the function converts the decoded colortype in bitmap | 246 * decoding, the function converts the decoded colortype in bitmap |
| 236 * to pref if possible. Whether a conversion is feasible is | 247 * to pref if possible. Whether a conversion is feasible is |
| 237 * tested by Bitmap::canCopyTo(pref). | 248 * tested by Bitmap::canCopyTo(pref). |
| 238 | 249 |
| 239 If an SkBitmap::Allocator is installed via setAllocator, it will be | 250 If an SkBitmap::Allocator is installed via setAllocator, it will be |
| 240 used to allocate the pixel memory. A clever allocator can be used | 251 used to allocate the pixel memory. A clever allocator can be used |
| 241 to allocate the memory from a cache, volatile memory, or even from | 252 to allocate the memory from a cache, volatile memory, or even from |
| 242 an existing bitmap's memory. | 253 an existing bitmap's memory. |
| 243 | 254 |
| 244 If a Peeker is installed via setPeeker, it may be used to peek into | 255 If a Peeker is installed via setPeeker, it may be used to peek into |
| 245 meta data during the decode. | 256 meta data during the decode. |
| 246 */ | 257 */ |
| 247 bool decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); | 258 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); |
| 248 bool decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { | 259 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { |
| 249 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); | 260 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); |
| 250 } | 261 } |
| 251 | 262 |
| 252 /** | 263 /** |
| 253 * Given a stream, build an index for doing tile-based decode. | 264 * Given a stream, build an index for doing tile-based decode. |
| 254 * The built index will be saved in the decoder, and the image size will | 265 * The built index will be saved in the decoder, and the image size will |
| 255 * be returned in width and height. | 266 * be returned in width and height. |
| 256 * | 267 * |
| 257 * Return true for success or false on failure. | 268 * Return true for success or false on failure. |
| 258 */ | 269 */ |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 of the decoded stream. On failure it is ignored. | 338 of the decoded stream. On failure it is ignored. |
| 328 */ | 339 */ |
| 329 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol orType pref, Mode, | 340 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol orType pref, Mode, |
| 330 Format* format = NULL); | 341 Format* format = NULL); |
| 331 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { | 342 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { |
| 332 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_ Mode, NULL); | 343 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_ Mode, NULL); |
| 333 } | 344 } |
| 334 | 345 |
| 335 protected: | 346 protected: |
| 336 // must be overridden in subclasses. This guy is called by decode(...) | 347 // must be overridden in subclasses. This guy is called by decode(...) |
| 337 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 348 virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; |
| 338 | 349 |
| 339 // If the decoder wants to support tiled based decoding, | 350 // If the decoder wants to support tiled based decoding, |
| 340 // this method must be overridden. This guy is called by buildTileIndex(...) | 351 // this method must be overridden. This guy is called by buildTileIndex(...) |
| 341 virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) { | 352 virtual bool onBuildTileIndex(SkStreamRewindable*, int *width, int *height) { |
| 342 return false; | 353 return false; |
| 343 } | 354 } |
| 344 | 355 |
| 345 // If the decoder wants to support tiled based decoding, | 356 // If the decoder wants to support tiled based decoding, |
| 346 // this method must be overridden. This guy is called by decodeRegion(...) | 357 // this method must be overridden. This guy is called by decodeRegion(...) |
| 347 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { | 358 virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 508 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
| 498 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 509 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
| 499 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 510 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
| 500 | 511 |
| 501 // Typedefs to make registering decoder and formatter callbacks easier. | 512 // Typedefs to make registering decoder and formatter callbacks easier. |
| 502 // These have to be defined outside SkImageDecoder. :( | 513 // These have to be defined outside SkImageDecoder. :( |
| 503 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; | 514 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; |
| 504 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; | 515 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; |
| 505 | 516 |
| 506 #endif | 517 #endif |
| OLD | NEW |