diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h index d2b23a1216..d293cec774 100644 --- a/include/images/SkImageDecoder.h +++ b/include/images/SkImageDecoder.h @@ -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. diff --git a/samplecode/SampleFilter2.cpp b/samplecode/SampleFilter2.cpp index 1800eb90be..e181870fc6 100644 --- a/samplecode/SampleFilter2.cpp +++ b/samplecode/SampleFilter2.cpp @@ -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; } diff --git a/samplecode/SampleImage.cpp b/samplecode/SampleImage.cpp index 7683e633d6..69cbd794d7 100644 --- a/samplecode/SampleImage.cpp +++ b/samplecode/SampleImage.cpp @@ -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()); diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index b910df60ab..4f9fa9bb1b 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -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;