OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkImageDecoder_DEFINED | 10 #ifndef SkImageDecoder_DEFINED |
11 #define SkImageDecoder_DEFINED | 11 #define SkImageDecoder_DEFINED |
12 | 12 |
13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
14 #include "SkBitmapFactory.h" | 14 #include "SkBitmapFactory.h" |
15 #include "SkImage.h" | 15 #include "SkImage.h" |
16 #include "SkRect.h" | 16 #include "SkRect.h" |
17 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
18 | 18 |
19 class SkStream; | 19 class SkStream; |
20 | 20 |
21 /** \class SkImageDecoder | 21 /** \class SkImageDecoder |
22 | 22 |
23 Base class for decoding compressed images into a SkBitmap | 23 Base class for decoding compressed images into a SkBitmap |
24 */ | 24 */ |
25 class SkImageDecoder { | 25 class SkImageDecoder { |
26 public: | 26 public: |
27 virtual ~SkImageDecoder(); | 27 virtual ~SkImageDecoder(); |
28 | 28 |
29 // Should be consistent with sFormatName | |
30 enum Format { | 29 enum Format { |
31 kUnknown_Format, | 30 kUnknown_Format, |
32 kBMP_Format, | 31 kBMP_Format, |
33 kGIF_Format, | 32 kGIF_Format, |
34 kICO_Format, | 33 kICO_Format, |
35 kJPEG_Format, | 34 kJPEG_Format, |
36 kPNG_Format, | 35 kPNG_Format, |
37 kWBMP_Format, | 36 kWBMP_Format, |
38 kWEBP_Format, | 37 kWEBP_Format, |
39 | 38 |
40 kLastKnownFormat = kWEBP_Format | 39 kLastKnownFormat = kWEBP_Format, |
40 kMultiple_Formats, | |
scroggo
2013/04/22 22:10:16
Does this seem like the right place for kMultiple_
epoger
2013/04/23 16:03:41
This seems problematic to me. Maybe, instead, the
scroggo
2013/04/24 18:00:05
That seems reasonable to me. For now though, I'll
| |
41 }; | 41 }; |
42 | 42 |
43 /** Return the format of image this decoder can decode. If this decoder can decode multiple | 43 /** Return the format of image this decoder can decode. If this decoder can decode multiple |
44 formats, kUnknown_Format will be returned. | 44 formats, returns kMultiple_Formats. |
45 */ | 45 */ |
46 virtual Format getFormat() const; | 46 virtual Format getFormat() const; |
47 | 47 |
48 /** If this decoder can determine the format of stream, return its format. O therwise return | |
49 kUnknown_Format. | |
epoger
2013/04/23 16:03:41
Please indicate what state the SkStream will be le
scroggo
2013/04/24 18:00:05
Done.
| |
50 */ | |
51 Format getFormat(SkStream*) const; | |
52 | |
48 /** Return a readable string of the value returned by getFormat(). | 53 /** Return a readable string of the value returned by getFormat(). |
49 */ | 54 */ |
50 const char* getFormatName() const; | 55 const char* getFormatName() const; |
scroggo
2013/04/22 22:10:16
Derek, does Android call this? (I assume I have ac
djsollen
2013/04/23 16:40:46
It is only used in a debug statement in the Bitmap
| |
51 | 56 |
52 /** Returns true if the decoder should try to dither the resulting image. | 57 /** Returns true if the decoder should try to dither the resulting image. |
53 The default setting is true. | 58 The default setting is true. |
54 */ | 59 */ |
55 bool getDitherImage() const { return fDitherImage; } | 60 bool getDitherImage() const { return fDitherImage; } |
56 | 61 |
57 /** Set to true if the the decoder should try to dither the resulting image. | 62 /** Set to true if the the decoder should try to dither the resulting image. |
58 The default setting is true. | 63 The default setting is true. |
59 */ | 64 */ |
60 void setDitherImage(bool dither) { fDitherImage = dither; } | 65 void setDitherImage(bool dither) { fDitherImage = dither; } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 static SkBitmap::Config GetDeviceConfig(); | 327 static SkBitmap::Config GetDeviceConfig(); |
323 /** Set the default config for the running device. | 328 /** Set the default config for the running device. |
324 Currently this used as a suggestion to image decoders that need to guess | 329 Currently this used as a suggestion to image decoders that need to guess |
325 what config they should decode into. | 330 what config they should decode into. |
326 Default is kNo_Config. | 331 Default is kNo_Config. |
327 This can be queried with GetDeviceConfig() | 332 This can be queried with GetDeviceConfig() |
328 */ | 333 */ |
329 static void SetDeviceConfig(SkBitmap::Config); | 334 static void SetDeviceConfig(SkBitmap::Config); |
330 | 335 |
331 protected: | 336 protected: |
337 // Override this in subclass to read a stream and determine its format. | |
338 // No need to rewind the stream, which will be handled in getFormat. | |
339 virtual Format onGetFormat(SkStream*) const; | |
340 | |
332 // must be overridden in subclasses. This guy is called by decode(...) | 341 // must be overridden in subclasses. This guy is called by decode(...) |
333 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 342 virtual bool onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; |
334 | 343 |
335 // If the decoder wants to support tiled based decoding, | 344 // If the decoder wants to support tiled based decoding, |
336 // this method must be overridden. This guy is called by buildTileIndex(...) | 345 // this method must be overridden. This guy is called by buildTileIndex(...) |
337 virtual bool onBuildTileIndex(SkStream*, int *width, int *height) { | 346 virtual bool onBuildTileIndex(SkStream*, int *width, int *height) { |
338 return false; | 347 return false; |
339 } | 348 } |
340 | 349 |
341 // If the decoder wants to support tiled based decoding, | 350 // If the decoder wants to support tiled based decoding, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 Chooser* fChooser; | 418 Chooser* fChooser; |
410 SkBitmap::Allocator* fAllocator; | 419 SkBitmap::Allocator* fAllocator; |
411 int fSampleSize; | 420 int fSampleSize; |
412 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false | 421 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false |
413 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true | 422 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true |
414 bool fDitherImage; | 423 bool fDitherImage; |
415 bool fUsePrefTable; | 424 bool fUsePrefTable; |
416 mutable bool fShouldCancelDecode; | 425 mutable bool fShouldCancelDecode; |
417 bool fPreferQualityOverSpeed; | 426 bool fPreferQualityOverSpeed; |
418 | 427 |
419 /** Contains the image format name. | |
420 * This should be consistent with Format. | |
421 * | |
422 * The format name gives a more meaningful error message than enum. | |
423 */ | |
424 static const char* sFormatName[]; | |
425 | |
426 // illegal | 428 // illegal |
427 SkImageDecoder(const SkImageDecoder&); | 429 SkImageDecoder(const SkImageDecoder&); |
428 SkImageDecoder& operator=(const SkImageDecoder&); | 430 SkImageDecoder& operator=(const SkImageDecoder&); |
429 }; | 431 }; |
430 | 432 |
431 /** Calling newDecoder with a stream returns a new matching imagedecoder | 433 /** Calling newDecoder with a stream returns a new matching imagedecoder |
432 instance, or NULL if none can be found. The caller must manage its ownership | 434 instance, or NULL if none can be found. The caller must manage its ownership |
433 of the stream as usual, calling unref() when it is done, as the returned | 435 of the stream as usual, calling unref() when it is done, as the returned |
434 decoder may have called ref() (and if so, the decoder is responsible for | 436 decoder may have called ref() (and if so, the decoder is responsible for |
435 balancing its ownership when it is destroyed). | 437 balancing its ownership when it is destroyed). |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 // not all of these will be available | 470 // not all of these will be available |
469 DECLARE_DECODER_CREATOR(BMPImageDecoder); | 471 DECLARE_DECODER_CREATOR(BMPImageDecoder); |
470 DECLARE_DECODER_CREATOR(GIFImageDecoder); | 472 DECLARE_DECODER_CREATOR(GIFImageDecoder); |
471 DECLARE_DECODER_CREATOR(ICOImageDecoder); | 473 DECLARE_DECODER_CREATOR(ICOImageDecoder); |
472 DECLARE_DECODER_CREATOR(JPEGImageDecoder); | 474 DECLARE_DECODER_CREATOR(JPEGImageDecoder); |
473 DECLARE_DECODER_CREATOR(PNGImageDecoder); | 475 DECLARE_DECODER_CREATOR(PNGImageDecoder); |
474 DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 476 DECLARE_DECODER_CREATOR(WBMPImageDecoder); |
475 DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 477 DECLARE_DECODER_CREATOR(WEBPImageDecoder); |
476 | 478 |
477 #endif | 479 #endif |
OLD | NEW |