Chromium Code Reviews| Index: src/ports/SkImageDecoder_CG.cpp |
| diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp |
| index 9fc49a445f264ffab1f2431dbb9bc6ca43a6af37..7ad34d75014e621cadff5946b640f05d99e2ec2e 100644 |
| --- a/src/ports/SkImageDecoder_CG.cpp |
| +++ b/src/ports/SkImageDecoder_CG.cpp |
| @@ -25,6 +25,31 @@ |
| #include <MobileCoreServices/MobileCoreServices.h> |
| #endif |
| +struct FormatConversion { |
| + CFStringRef fUTType; |
| + SkImageDecoder::Format fFormat; |
| +}; |
| + |
| +// Array of the types supported by the decoder. |
| +static const FormatConversion gFormatConversions[] = { |
| + { kUTTypeBMP, SkImageDecoder::kBMP_Format }, |
| + { kUTTypeGIF, SkImageDecoder::kGIF_Format }, |
| + { kUTTypeICO, SkImageDecoder::kICO_Format }, |
| + { kUTTypeJPEG, SkImageDecoder::kJPEG_Format }, |
| + // Also include JPEG2000 |
| + { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format }, |
| + { kUTTypePNG, SkImageDecoder::kPNG_Format }, |
| +}; |
| + |
| +static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { |
| + if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFCompareEqualTo) { |
| + return gFormatConversions[i].fFormat; |
| + } |
| + } |
| + return SkImageDecoder::kUnknown_Format; |
| +} |
| + |
| static void malloc_release_proc(void* info, const void* data, size_t size) { |
| sk_free(info); |
| } |
| @@ -46,10 +71,26 @@ static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { |
| } |
| class SkImageDecoder_CG : public SkImageDecoder { |
| +public: |
| + virtual Format getFormat() const SK_OVERRIDE { return kMultiple_Formats; } |
| + Format onGetFormat(SkStream* stream) const SK_OVERRIDE; |
| + |
| protected: |
| virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); |
| }; |
| +SkImageDecoder::Format SkImageDecoder_CG::onGetFormat(SkStream *stream) const { |
| + CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
| + |
| + if (NULL == imageSrc) { |
| + return kUnknown_Format; |
| + } |
| + |
| + SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
| + const CFStringRef name = CGImageSourceGetType(imageSrc); |
| + return UTType_to_Format(name); |
|
epoger
2013/04/23 16:03:41
Oh. I guess this is why the SkImageDecoder subcla
scroggo
2013/04/23 20:55:18
In general, you are correct. The typical client wi
|
| +} |
| + |
| #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) |
| bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { |