OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 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 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 | 10 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 case SkImageEncoder::kJPEG_Type: | 238 case SkImageEncoder::kJPEG_Type: |
239 case SkImageEncoder::kPNG_Type: | 239 case SkImageEncoder::kPNG_Type: |
240 break; | 240 break; |
241 default: | 241 default: |
242 return NULL; | 242 return NULL; |
243 } | 243 } |
244 return SkNEW_ARGS(SkImageEncoder_CG, (t)); | 244 return SkNEW_ARGS(SkImageEncoder_CG, (t)); |
245 } | 245 } |
246 | 246 |
247 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_
cg_factory); | 247 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_
cg_factory); |
| 248 |
| 249 struct FormatConversion { |
| 250 CFStringRef fUTType; |
| 251 SkImageDecoder::Format fFormat; |
| 252 }; |
| 253 |
| 254 // Array of the types supported by the decoder. |
| 255 static const FormatConversion gFormatConversions[] = { |
| 256 { kUTTypeBMP, SkImageDecoder::kBMP_Format }, |
| 257 { kUTTypeGIF, SkImageDecoder::kGIF_Format }, |
| 258 { kUTTypeICO, SkImageDecoder::kICO_Format }, |
| 259 { kUTTypeJPEG, SkImageDecoder::kJPEG_Format }, |
| 260 // Also include JPEG2000 |
| 261 { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format }, |
| 262 { kUTTypePNG, SkImageDecoder::kPNG_Format }, |
| 263 }; |
| 264 |
| 265 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { |
| 266 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { |
| 267 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp
areEqualTo) { |
| 268 return gFormatConversions[i].fFormat; |
| 269 } |
| 270 } |
| 271 return SkImageDecoder::kUnknown_Format; |
| 272 } |
| 273 |
| 274 static SkImageDecoder::Format get_format_cg(SkStream *stream) { |
| 275 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
| 276 |
| 277 if (NULL == imageSrc) { |
| 278 return SkImageDecoder::kUnknown_Format; |
| 279 } |
| 280 |
| 281 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
| 282 const CFStringRef name = CGImageSourceGetType(imageSrc); |
| 283 if (NULL == name) { |
| 284 return SkImageDecoder::kUnknown_Format; |
| 285 } |
| 286 return UTType_to_Format(name); |
| 287 } |
| 288 |
| 289 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_cg); |
OLD | NEW |