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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 will cause the decoder to not return the image. | 138 will cause the decoder to not return the image. |
139 */ | 139 */ |
140 virtual bool peek(const char tag[], const void* data, size_t length) = 0
; | 140 virtual bool peek(const char tag[], const void* data, size_t length) = 0
; |
141 private: | 141 private: |
142 typedef SkRefCnt INHERITED; | 142 typedef SkRefCnt INHERITED; |
143 }; | 143 }; |
144 | 144 |
145 Peeker* getPeeker() const { return fPeeker; } | 145 Peeker* getPeeker() const { return fPeeker; } |
146 Peeker* setPeeker(Peeker*); | 146 Peeker* setPeeker(Peeker*); |
147 | 147 |
148 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | |
149 /** \class Chooser | |
150 | |
151 Base class for optional callbacks to choose an image from a format that | |
152 contains multiple images. | |
153 */ | |
154 class Chooser : public SkRefCnt { | |
155 public: | |
156 SK_DECLARE_INST_COUNT(Chooser) | |
157 | |
158 virtual void begin(int count) {} | |
159 virtual void inspect(int index, SkBitmap::Config config, int width, int
height) {} | |
160 /** Return the index of the subimage you want, or -1 to choose none of t
hem. | |
161 */ | |
162 virtual int choose() = 0; | |
163 | |
164 private: | |
165 typedef SkRefCnt INHERITED; | |
166 }; | |
167 | |
168 Chooser* getChooser() const { return fChooser; } | |
169 Chooser* setChooser(Chooser*); | |
170 #endif | |
171 | |
172 /** | 148 /** |
173 * By default, the codec will try to comply with the "pref" colortype | 149 * By default, the codec will try to comply with the "pref" colortype |
174 * that is passed to decode() or decodeSubset(). However, this can be calle
d | 150 * that is passed to decode() or decodeSubset(). However, this can be calle
d |
175 * to override that, causing the codec to try to match the src depth instea
d | 151 * to override that, causing the codec to try to match the src depth instea
d |
176 * (as shown below). | 152 * (as shown below). |
177 * | 153 * |
178 * src_8Index -> kIndex_8_SkColorType | 154 * src_8Index -> kIndex_8_SkColorType |
179 * src_8Gray -> kN32_SkColorType | 155 * src_8Gray -> kN32_SkColorType |
180 * src_8bpc -> kN32_SkColorType | 156 * src_8bpc -> kN32_SkColorType |
181 */ | 157 */ |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 bool shouldCancelDecode() const { return fShouldCancelDecode; } | 369 bool shouldCancelDecode() const { return fShouldCancelDecode; } |
394 | 370 |
395 protected: | 371 protected: |
396 SkImageDecoder(); | 372 SkImageDecoder(); |
397 | 373 |
398 /** | 374 /** |
399 * Return the default preference being used by the current or latest call t
o decode. | 375 * Return the default preference being used by the current or latest call t
o decode. |
400 */ | 376 */ |
401 SkColorType getDefaultPref() { return fDefaultPref; } | 377 SkColorType getDefaultPref() { return fDefaultPref; } |
402 | 378 |
403 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | |
404 // helper function for decoders to handle the (common) case where there is o
nly | |
405 // once choice available in the image file. | |
406 bool chooseFromOneChoice(SkColorType, int width, int height) const; | |
407 #endif | |
408 | |
409 /* Helper for subclasses. Call this to allocate the pixel memory given the
bitmap's info. | 379 /* Helper for subclasses. Call this to allocate the pixel memory given the
bitmap's info. |
410 Returns true on success. This method handles checking for an optional Al
locator. | 380 Returns true on success. This method handles checking for an optional Al
locator. |
411 */ | 381 */ |
412 bool allocPixelRef(SkBitmap*, SkColorTable*) const; | 382 bool allocPixelRef(SkBitmap*, SkColorTable*) const; |
413 | 383 |
414 /** | 384 /** |
415 * The raw data of the src image. | 385 * The raw data of the src image. |
416 */ | 386 */ |
417 enum SrcDepth { | 387 enum SrcDepth { |
418 // Color-indexed. | 388 // Color-indexed. |
419 kIndex_SrcDepth, | 389 kIndex_SrcDepth, |
420 // Grayscale in 8 bits. | 390 // Grayscale in 8 bits. |
421 k8BitGray_SrcDepth, | 391 k8BitGray_SrcDepth, |
422 // 8 bits per component. Used for 24 bit if there is no alpha. | 392 // 8 bits per component. Used for 24 bit if there is no alpha. |
423 k32Bit_SrcDepth, | 393 k32Bit_SrcDepth, |
424 }; | 394 }; |
425 /** The subclass, inside onDecode(), calls this to determine the colorType o
f | 395 /** The subclass, inside onDecode(), calls this to determine the colorType o
f |
426 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the | 396 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the |
427 src image. This routine returns the caller's preference given | 397 src image. This routine returns the caller's preference given |
428 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference
. | 398 srcDepth and hasAlpha, or kUnknown_SkColorType if there is no preference
. |
429 */ | 399 */ |
430 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; | 400 SkColorType getPrefColorType(SrcDepth, bool hasAlpha) const; |
431 | 401 |
432 private: | 402 private: |
433 Peeker* fPeeker; | 403 Peeker* fPeeker; |
434 #ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER | |
435 Chooser* fChooser; | |
436 #endif | |
437 SkBitmap::Allocator* fAllocator; | 404 SkBitmap::Allocator* fAllocator; |
438 int fSampleSize; | 405 int fSampleSize; |
439 SkColorType fDefaultPref; // use if fUsePrefTable is false | 406 SkColorType fDefaultPref; // use if fUsePrefTable is false |
440 bool fPreserveSrcDepth; | 407 bool fPreserveSrcDepth; |
441 bool fDitherImage; | 408 bool fDitherImage; |
442 bool fSkipWritingZeroes; | 409 bool fSkipWritingZeroes; |
443 mutable bool fShouldCancelDecode; | 410 mutable bool fShouldCancelDecode; |
444 bool fPreferQualityOverSpeed; | 411 bool fPreferQualityOverSpeed; |
445 bool fRequireUnpremultipliedColors; | 412 bool fRequireUnpremultipliedColors; |
446 }; | 413 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 460 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
494 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 461 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
495 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 462 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
496 | 463 |
497 // Typedefs to make registering decoder and formatter callbacks easier. | 464 // Typedefs to make registering decoder and formatter callbacks easier. |
498 // These have to be defined outside SkImageDecoder. :( | 465 // These have to be defined outside SkImageDecoder. :( |
499 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; | 466 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; |
500 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; | 467 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; |
501 | 468 |
502 #endif | 469 #endif |
OLD | NEW |