add optional Format* parameter to decoder helper functions.
git-svn-id: http://skia.googlecode.com/svn/trunk@215 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
5119bdb952
commit
b3ade9d1b0
@ -160,12 +160,16 @@ public:
|
||||
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.
|
||||
|
||||
@param 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 DecodeFile(const char file[], SkBitmap* bitmap,
|
||||
SkBitmap::Config prefConfig, Mode);
|
||||
static bool DecodeFile(const char file[], SkBitmap* bitmap)
|
||||
{
|
||||
return DecodeFile(file, bitmap, SkBitmap::kNo_Config, kDecodePixels_Mode);
|
||||
SkBitmap::Config prefConfig, Mode,
|
||||
Format* format);
|
||||
static bool DecodeFile(const char file[], SkBitmap* bitmap) {
|
||||
return DecodeFile(file, bitmap, SkBitmap::kNo_Config,
|
||||
kDecodePixels_Mode, NULL);
|
||||
}
|
||||
/** Decode the image stored in the specified memory buffer, and store the
|
||||
result in bitmap. Return true for success or false on failure.
|
||||
@ -176,13 +180,16 @@ public:
|
||||
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.
|
||||
|
||||
@param format On success, if format is non-null, it is set to the format
|
||||
of the decoded buffer. On failure it is ignored.
|
||||
*/
|
||||
static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap,
|
||||
SkBitmap::Config prefConfig, Mode);
|
||||
static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap)
|
||||
{
|
||||
SkBitmap::Config prefConfig, Mode,
|
||||
Format* format);
|
||||
static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){
|
||||
return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config,
|
||||
kDecodePixels_Mode);
|
||||
kDecodePixels_Mode, NULL);
|
||||
}
|
||||
/** Decode the image stored in the specified SkStream, and store the result
|
||||
in bitmap. Return true for success or false on failure.
|
||||
@ -193,13 +200,16 @@ public:
|
||||
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.
|
||||
|
||||
@param format On success, if format is non-null, it is set to the format
|
||||
of the decoded stream. On failure it is ignored.
|
||||
*/
|
||||
static bool DecodeStream(SkStream* stream, SkBitmap* bitmap,
|
||||
SkBitmap::Config prefConfig, Mode);
|
||||
static bool DecodeStream(SkStream* stream, SkBitmap* bitmap)
|
||||
{
|
||||
SkBitmap::Config prefConfig, Mode,
|
||||
Format* format);
|
||||
static bool DecodeStream(SkStream* stream, SkBitmap* bitmap) {
|
||||
return DecodeStream(stream, bitmap, SkBitmap::kNo_Config,
|
||||
kDecodePixels_Mode);
|
||||
kDecodePixels_Mode, NULL);
|
||||
}
|
||||
|
||||
/** Return the default config for the running device.
|
||||
|
@ -31,12 +31,12 @@ public:
|
||||
for (int i = 0; i < fBitmapCount/2; i++) {
|
||||
SkImageDecoder::DecodeFile(gNames[i], &fBitmaps[i],
|
||||
SkBitmap::kARGB_8888_Config,
|
||||
SkImageDecoder::kDecodePixels_Mode);
|
||||
SkImageDecoder::kDecodePixels_Mode, NULL);
|
||||
}
|
||||
for (int i = fBitmapCount/2; i < fBitmapCount; i++) {
|
||||
SkImageDecoder::DecodeFile(gNames[i-fBitmapCount/2], &fBitmaps[i],
|
||||
SkBitmap::kRGB_565_Config,
|
||||
SkImageDecoder::kDecodePixels_Mode);
|
||||
SkImageDecoder::kDecodePixels_Mode, NULL);
|
||||
}
|
||||
fCurrIndex = 0;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ static bool SetImageRef(SkBitmap* bitmap, SkStream* stream,
|
||||
SkBitmap::Config pref, const char name[] = NULL)
|
||||
{
|
||||
if (SkImageDecoder::DecodeStream(stream, bitmap, pref,
|
||||
SkImageDecoder::kDecodeBounds_Mode)) {
|
||||
SkImageDecoder::kDecodeBounds_Mode, NULL)) {
|
||||
SkASSERT(bitmap->config() != SkBitmap::kNo_Config);
|
||||
|
||||
SkImageRef* ref = new SkImageRef_GlobalPool(stream, bitmap->config());
|
||||
|
@ -120,13 +120,13 @@ bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm,
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
|
||||
SkBitmap::Config pref, Mode mode) {
|
||||
SkBitmap::Config pref, Mode mode, Format* format) {
|
||||
SkASSERT(file);
|
||||
SkASSERT(bm);
|
||||
|
||||
SkFILEStream stream(file);
|
||||
if (stream.isValid()) {
|
||||
if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode)) {
|
||||
if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format)) {
|
||||
bm->pixelRef()->setURI(file);
|
||||
}
|
||||
return true;
|
||||
@ -135,18 +135,18 @@ bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
|
||||
}
|
||||
|
||||
bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm,
|
||||
SkBitmap::Config pref, Mode mode) {
|
||||
SkBitmap::Config pref, Mode mode, Format* format) {
|
||||
if (0 == size) {
|
||||
return false;
|
||||
}
|
||||
SkASSERT(buffer);
|
||||
|
||||
SkMemoryStream stream(buffer, size);
|
||||
return SkImageDecoder::DecodeStream(&stream, bm, pref, mode);
|
||||
return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format);
|
||||
}
|
||||
|
||||
bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm,
|
||||
SkBitmap::Config pref, Mode mode) {
|
||||
SkBitmap::Config pref, Mode mode, Format* format) {
|
||||
SkASSERT(stream);
|
||||
SkASSERT(bm);
|
||||
|
||||
@ -155,6 +155,9 @@ bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm,
|
||||
|
||||
if (NULL != codec) {
|
||||
success = codec->decode(stream, bm, pref, mode);
|
||||
if (success && format) {
|
||||
*format = codec->getFormat();
|
||||
}
|
||||
delete codec;
|
||||
}
|
||||
return success;
|
||||
|
Loading…
Reference in New Issue
Block a user