#include <SkImageDecoder.h>
Classes | |
class | Chooser |
class | Peeker |
Public Types | |
enum | Format { kUnknown_Format, kBMP_Format, kGIF_Format, kICO_Format, kJPEG_Format, kPNG_Format, kWBMP_Format, kLastKnownFormat = kWBMP_Format } |
enum | Mode { kDecodeBounds_Mode, kDecodePixels_Mode } |
Public Member Functions | |
virtual | ~SkImageDecoder () |
virtual Format | getFormat () const |
bool | getDitherImage () const |
void | setDitherImage (bool dither) |
Peeker * | getPeeker () const |
Peeker * | setPeeker (Peeker *) |
Chooser * | getChooser () const |
Chooser * | setChooser (Chooser *) |
SkBitmap::Allocator * | getAllocator () const |
SkBitmap::Allocator * | setAllocator (SkBitmap::Allocator *) |
int | getSampleSize () const |
void | setSampleSize (int size) |
void | resetSampleSize () |
void | cancelDecode () |
bool | decode (SkStream *, SkBitmap *bitmap, SkBitmap::Config pref, Mode) |
bool | shouldCancelDecode () const |
Static Public Member Functions | |
static SkImageDecoder * | Factory (SkStream *) |
static bool | DecodeFile (const char file[], SkBitmap *bitmap, SkBitmap::Config prefConfig, Mode, Format *format=NULL) |
static bool | DecodeFile (const char file[], SkBitmap *bitmap) |
static bool | DecodeMemory (const void *buffer, size_t size, SkBitmap *bitmap, SkBitmap::Config prefConfig, Mode, Format *format=NULL) |
static bool | DecodeMemory (const void *buffer, size_t size, SkBitmap *bitmap) |
static bool | DecodeStream (SkStream *stream, SkBitmap *bitmap, SkBitmap::Config prefConfig, Mode, Format *format=NULL) |
static bool | DecodeStream (SkStream *stream, SkBitmap *bitmap) |
static SkBitmap::Config | GetDeviceConfig () |
static void | SetDeviceConfig (SkBitmap::Config) |
Protected Member Functions | |
virtual bool | onDecode (SkStream *, SkBitmap *bitmap, SkBitmap::Config pref, Mode)=0 |
SkImageDecoder () | |
bool | chooseFromOneChoice (SkBitmap::Config config, int width, int height) const |
bool | allocPixelRef (SkBitmap *, SkColorTable *) const |
Base class for decoding compressed images into a SkBitmap
Definition at line 29 of file SkImageDecoder.h.
kUnknown_Format | |
kBMP_Format | |
kGIF_Format | |
kICO_Format | |
kJPEG_Format | |
kPNG_Format | |
kWBMP_Format | |
kLastKnownFormat |
Definition at line 33 of file SkImageDecoder.h.
enum SkImageDecoder::Mode |
Passed to the decode method. If kDecodeBounds_Mode is passed, then only the bitmap's width/height/config need be set. If kDecodePixels_Mode is passed, then the bitmap must have pixels or a pixelRef.
kDecodeBounds_Mode |
only return width/height/config in bitmap |
kDecodePixels_Mode |
return entire bitmap (including pixels) |
Definition at line 129 of file SkImageDecoder.h.
virtual SkImageDecoder::~SkImageDecoder | ( | ) | [virtual] |
SkImageDecoder::SkImageDecoder | ( | ) | [protected] |
bool SkImageDecoder::allocPixelRef | ( | SkBitmap * | , | |
SkColorTable * | ||||
) | const [protected] |
void SkImageDecoder::cancelDecode | ( | ) | [inline] |
Decoding is synchronous, but for long decodes, a different thread can call this method safely. This sets a state that the decoders will periodically check, and if they see it changed to cancel, they will cancel. This will result in decode() returning false. However, there is no guarantee that the decoder will see the state change in time, so it is possible that cancelDecode() will be called, but will be ignored and decode() will return true (assuming no other problems were encountered).
This state is automatically reset at the beginning of decode().
Definition at line 119 of file SkImageDecoder.h.
bool SkImageDecoder::chooseFromOneChoice | ( | SkBitmap::Config | config, | |
int | width, | |||
int | height | |||
) | const [protected] |
bool SkImageDecoder::decode | ( | SkStream * | , | |
SkBitmap * | bitmap, | |||
SkBitmap::Config | pref, | |||
Mode | ||||
) |
Given a stream, decode it into the specified bitmap. If the decoder can decompress the image, it calls bitmap.setConfig(), and then if the Mode is kDecodePixels_Mode, call allocPixelRef(), which will allocated a pixelRef. To access the pixel memory, the codec needs to call lockPixels/unlockPixels on the bitmap. It can then set the pixels with the decompressed image. If the image cannot be decompressed, return false. After the decoding, the function converts the decoded config in bitmap to pref if possible. Whether a conversion is feasible is tested by Bitmap::canCopyTo(pref).
static bool SkImageDecoder::DecodeFile | ( | const char | file[], | |
SkBitmap * | bitmap | |||
) | [inline, static] |
Definition at line 170 of file SkImageDecoder.h.
static bool SkImageDecoder::DecodeFile | ( | const char | file[], | |
SkBitmap * | bitmap, | |||
SkBitmap::Config | prefConfig, | |||
Mode | , | |||
Format * | format = NULL | |||
) | [static] |
Decode the image stored in the specified file, and store the result in bitmap. Return true for success or false on failure.
If pref is kNo_Config, then the decoder is free to choose the most natural config given the image data. If pref something other than kNo_Config, the decoder will attempt to decode the image into that format, unless there is a conflict (e.g. the image has per-pixel alpha and the bitmap's config does not support that), in which case the decoder will choose a closest match configuration.
format | On success, if format is non-null, it is set to the format of the decoded file. On failure it is ignored. |
static bool SkImageDecoder::DecodeMemory | ( | const void * | buffer, | |
size_t | size, | |||
SkBitmap * | bitmap | |||
) | [inline, static] |
Definition at line 190 of file SkImageDecoder.h.
static bool SkImageDecoder::DecodeMemory | ( | const void * | buffer, | |
size_t | size, | |||
SkBitmap * | bitmap, | |||
SkBitmap::Config | prefConfig, | |||
Mode | , | |||
Format * | format = NULL | |||
) | [static] |
Decode the image stored in the specified memory buffer, and store the result in bitmap. Return true for success or false on failure.
If pref is kNo_Config, then the decoder is free to choose the most natural config given the image data. If pref something other than kNo_Config, the decoder will attempt to decode the image into that format, unless there is a conflict (e.g. the image has per-pixel alpha and the bitmap's config does not support that), in which case the decoder will choose a closest match configuration.
format | On success, if format is non-null, it is set to the format of the decoded buffer. On failure it is ignored. |
Definition at line 210 of file SkImageDecoder.h.
static bool SkImageDecoder::DecodeStream | ( | SkStream * | stream, | |
SkBitmap * | bitmap, | |||
SkBitmap::Config | prefConfig, | |||
Mode | , | |||
Format * | format = NULL | |||
) | [static] |
Decode the image stored in the specified SkStream, and store the result in bitmap. Return true for success or false on failure.
If pref is kNo_Config, then the decoder is free to choose the most natural config given the image data. If pref something other than kNo_Config, the decoder will attempt to decode the image into that format, unless there is a conflict (e.g. the image has per-pixel alpha and the bitmap's config does not support that), in which case the decoder will choose a closest match configuration.
format | On success, if format is non-null, it is set to the format of the decoded stream. On failure it is ignored. |
static SkImageDecoder* SkImageDecoder::Factory | ( | SkStream * | ) | [static] |
Given a stream, this will try to find an appropriate decoder object. If none is found, the method returns NULL.
SkBitmap::Allocator* SkImageDecoder::getAllocator | ( | ) | const [inline] |
Definition at line 92 of file SkImageDecoder.h.
Chooser* SkImageDecoder::getChooser | ( | ) | const [inline] |
Definition at line 89 of file SkImageDecoder.h.
static SkBitmap::Config SkImageDecoder::GetDeviceConfig | ( | ) | [static] |
Return the default config for the running device. Currently this used as a suggestion to image decoders that need to guess what config they should decode into. Default is kNo_Config, but this can be changed with SetDeviceConfig()
bool SkImageDecoder::getDitherImage | ( | ) | const [inline] |
Returns true if the decoder should try to dither the resulting image. The default setting is true.
Definition at line 52 of file SkImageDecoder.h.
virtual Format SkImageDecoder::getFormat | ( | ) | const [virtual] |
Return the compressed data's format (see Format enum)
Peeker* SkImageDecoder::getPeeker | ( | ) | const [inline] |
Definition at line 72 of file SkImageDecoder.h.
int SkImageDecoder::getSampleSize | ( | ) | const [inline] |
Definition at line 101 of file SkImageDecoder.h.
virtual bool SkImageDecoder::onDecode | ( | SkStream * | , | |
SkBitmap * | bitmap, | |||
SkBitmap::Config | pref, | |||
Mode | ||||
) | [protected, pure virtual] |
void SkImageDecoder::resetSampleSize | ( | ) | [inline] |
Reset the sampleSize to its default of 1
Definition at line 106 of file SkImageDecoder.h.
SkBitmap::Allocator* SkImageDecoder::setAllocator | ( | SkBitmap::Allocator * | ) |
static void SkImageDecoder::SetDeviceConfig | ( | SkBitmap::Config | ) | [static] |
Set the default config for the running device. Currently this used as a suggestion to image decoders that need to guess what config they should decode into. Default is kNo_Config. This can be queried with GetDeviceConfig()
void SkImageDecoder::setDitherImage | ( | bool | dither | ) | [inline] |
Set to true if the the decoder should try to dither the resulting image. The default setting is true.
Definition at line 57 of file SkImageDecoder.h.
void SkImageDecoder::setSampleSize | ( | int | size | ) |
bool SkImageDecoder::shouldCancelDecode | ( | ) | const [inline] |
Can be queried from within onDecode, to see if the user (possibly in a different thread) has requested the decode to cancel. If this returns true, your onDecode() should stop and return false. Each subclass needs to decide how often it can query this, to balance responsiveness with performance.
Calling this outside of onDecode() may return undefined values.
Definition at line 248 of file SkImageDecoder.h.