| 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 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkChunkReader.h" |
| 12 #include "SkImage.h" | 13 #include "SkImage.h" |
| 13 #include "SkRect.h" | 14 #include "SkRect.h" |
| 14 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
| 15 #include "SkTRegistry.h" | 16 #include "SkTRegistry.h" |
| 16 #include "SkTypes.h" | 17 #include "SkTypes.h" |
| 17 | 18 |
| 18 class SkStream; | 19 class SkStream; |
| 19 class SkStreamRewindable; | 20 class SkStreamRewindable; |
| 20 | 21 |
| 21 /** \class SkImageDecoder | 22 /** \class SkImageDecoder |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 */ | 120 */ |
| 120 void setRequireUnpremultipliedColors(bool request) { | 121 void setRequireUnpremultipliedColors(bool request) { |
| 121 fRequireUnpremultipliedColors = request; | 122 fRequireUnpremultipliedColors = request; |
| 122 } | 123 } |
| 123 | 124 |
| 124 /** Returns true if the decoder will only return bitmaps with unpremultiplie
d | 125 /** Returns true if the decoder will only return bitmaps with unpremultiplie
d |
| 125 colors. | 126 colors. |
| 126 */ | 127 */ |
| 127 bool getRequireUnpremultipliedColors() const { return fRequireUnpremultiplie
dColors; } | 128 bool getRequireUnpremultipliedColors() const { return fRequireUnpremultiplie
dColors; } |
| 128 | 129 |
| 129 /** \class Peeker | 130 SkChunkReader* getPeeker() const { return fPeeker; } |
| 130 | 131 SkChunkReader* setPeeker(SkChunkReader*); |
| 131 Base class for optional callbacks to retrieve meta/chunk data out of | |
| 132 an image as it is being decoded. | |
| 133 */ | |
| 134 class Peeker : public SkRefCnt { | |
| 135 public: | |
| 136 SK_DECLARE_INST_COUNT(Peeker) | |
| 137 | |
| 138 /** Return true to continue decoding, or false to indicate an error, whi
ch | |
| 139 will cause the decoder to not return the image. | |
| 140 */ | |
| 141 virtual bool peek(const char tag[], const void* data, size_t length) = 0
; | |
| 142 private: | |
| 143 typedef SkRefCnt INHERITED; | |
| 144 }; | |
| 145 | |
| 146 Peeker* getPeeker() const { return fPeeker; } | |
| 147 Peeker* setPeeker(Peeker*); | |
| 148 | 132 |
| 149 /** | 133 /** |
| 150 * By default, the codec will try to comply with the "pref" colortype | 134 * By default, the codec will try to comply with the "pref" colortype |
| 151 * that is passed to decode() or decodeSubset(). However, this can be calle
d | 135 * that is passed to decode() or decodeSubset(). However, this can be calle
d |
| 152 * to override that, causing the codec to try to match the src depth instea
d | 136 * to override that, causing the codec to try to match the src depth instea
d |
| 153 * (as shown below). | 137 * (as shown below). |
| 154 * | 138 * |
| 155 * src_8Index -> kIndex_8_SkColorType | 139 * src_8Index -> kIndex_8_SkColorType |
| 156 * src_8Gray -> kN32_SkColorType | 140 * src_8Gray -> kN32_SkColorType |
| 157 * src_8bpc -> kN32_SkColorType | 141 * src_8bpc -> kN32_SkColorType |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 * If the image cannot be decompressed, return kFailure. After the | 208 * If the image cannot be decompressed, return kFailure. After the |
| 225 * decoding, the function converts the decoded colortype in bitmap | 209 * decoding, the function converts the decoded colortype in bitmap |
| 226 * to pref if possible. Whether a conversion is feasible is | 210 * to pref if possible. Whether a conversion is feasible is |
| 227 * tested by Bitmap::canCopyTo(pref). | 211 * tested by Bitmap::canCopyTo(pref). |
| 228 | 212 |
| 229 If an SkBitmap::Allocator is installed via setAllocator, it will be | 213 If an SkBitmap::Allocator is installed via setAllocator, it will be |
| 230 used to allocate the pixel memory. A clever allocator can be used | 214 used to allocate the pixel memory. A clever allocator can be used |
| 231 to allocate the memory from a cache, volatile memory, or even from | 215 to allocate the memory from a cache, volatile memory, or even from |
| 232 an existing bitmap's memory. | 216 an existing bitmap's memory. |
| 233 | 217 |
| 234 If a Peeker is installed via setPeeker, it may be used to peek into | 218 If a SkChunkReader is installed via setPeeker, it may be used to peek in
to |
| 235 meta data during the decode. | 219 meta data during the decode. |
| 236 */ | 220 */ |
| 237 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); | 221 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); |
| 238 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { | 222 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { |
| 239 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); | 223 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); |
| 240 } | 224 } |
| 241 | 225 |
| 242 /** | 226 /** |
| 243 * Given a stream, build an index for doing tile-based decode. | 227 * Given a stream, build an index for doing tile-based decode. |
| 244 * The built index will be saved in the decoder, and the image size will | 228 * The built index will be saved in the decoder, and the image size will |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 k32Bit_SrcDepth, | 378 k32Bit_SrcDepth, |
| 395 }; | 379 }; |
| 396 /** The subclass, inside onDecode(), calls this to determine the colorType o
f | 380 /** The subclass, inside onDecode(), calls this to determine the colorType o
f |
| 397 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the | 381 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the |
| 398 src image. This routine returns the caller's preference given | 382 src image. This routine returns the caller's preference given |
| 399 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference
. | 383 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference
. |
| 400 */ | 384 */ |
| 401 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; | 385 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; |
| 402 | 386 |
| 403 private: | 387 private: |
| 404 Peeker* fPeeker; | 388 SkChunkReader* fPeeker; |
| 405 SkBitmap::Allocator* fAllocator; | 389 SkBitmap::Allocator* fAllocator; |
| 406 int fSampleSize; | 390 int fSampleSize; |
| 407 SkColorType fDefaultPref; // use if fUsePrefTable is false | 391 SkColorType fDefaultPref; // use if fUsePrefTable is false |
| 408 bool fPreserveSrcDepth; | 392 bool fPreserveSrcDepth; |
| 409 bool fDitherImage; | 393 bool fDitherImage; |
| 410 bool fSkipWritingZeroes; | 394 bool fSkipWritingZeroes; |
| 411 mutable bool fShouldCancelDecode; | 395 mutable bool fShouldCancelDecode; |
| 412 bool fPreferQualityOverSpeed; | 396 bool fPreferQualityOverSpeed; |
| 413 bool fRequireUnpremultipliedColors; | 397 bool fRequireUnpremultipliedColors; |
| 414 }; | 398 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 445 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
| 462 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 446 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
| 463 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 447 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
| 464 | 448 |
| 465 // Typedefs to make registering decoder and formatter callbacks easier. | 449 // Typedefs to make registering decoder and formatter callbacks easier. |
| 466 // These have to be defined outside SkImageDecoder. :( | 450 // These have to be defined outside SkImageDecoder. :( |
| 467 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; | 451 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; |
| 468 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; | 452 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; |
| 469 | 453 |
| 470 #endif | 454 #endif |
| OLD | NEW |