OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 #include "SkImageDecoder_CG.h" |
8 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkImageDecoder.h" | |
11 #include "SkImageEncoder.h" | |
12 #include "SkMovie.h" | |
13 #include "SkStream.h" | 10 #include "SkStream.h" |
14 #include "SkStreamPriv.h" | 11 #include "SkStreamPriv.h" |
15 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
16 #include "SkUnPreMultiply.h" | 13 #include "SkUnPreMultiply.h" |
17 | 14 |
18 #ifdef SK_BUILD_FOR_MAC | 15 #ifdef SK_BUILD_FOR_MAC |
19 #include <ApplicationServices/ApplicationServices.h> | 16 #include <ApplicationServices/ApplicationServices.h> |
20 #endif | 17 #endif |
21 | 18 |
22 #ifdef SK_BUILD_FOR_IOS | 19 #ifdef SK_BUILD_FOR_IOS |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 *addr = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*addr)
; | 194 *addr = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*addr)
; |
198 } | 195 } |
199 } | 196 } |
200 bm->setAlphaType(kUnpremul_SkAlphaType); | 197 bm->setAlphaType(kUnpremul_SkAlphaType); |
201 } | 198 } |
202 return kSuccess; | 199 return kSuccess; |
203 } | 200 } |
204 | 201 |
205 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
206 | 203 |
207 extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*); | |
208 | |
209 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { | |
210 SkImageDecoder* decoder = image_decoder_from_stream(stream); | |
211 if (NULL == decoder) { | |
212 // If no image decoder specific to the stream exists, use SkImageDecoder
_CG. | |
213 return SkNEW(SkImageDecoder_CG); | |
214 } else { | |
215 return decoder; | |
216 } | |
217 } | |
218 | |
219 ///////////////////////////////////////////////////////////////////////// | |
220 | |
221 SkMovie* SkMovie::DecodeStream(SkStreamRewindable* stream) { | |
222 return NULL; | |
223 } | |
224 | |
225 ///////////////////////////////////////////////////////////////////////// | |
226 | 204 |
227 static size_t consumer_put(void* info, const void* buffer, size_t count) { | 205 static size_t consumer_put(void* info, const void* buffer, size_t count) { |
228 SkWStream* stream = reinterpret_cast<SkWStream*>(info); | 206 SkWStream* stream = reinterpret_cast<SkWStream*>(info); |
229 return stream->write(buffer, count) ? count : 0; | 207 return stream->write(buffer, count) ? count : 0; |
230 } | 208 } |
231 | 209 |
232 static void consumer_release(void* info) { | 210 static void consumer_release(void* info) { |
233 // we do nothing, since by design we don't "own" the stream (i.e. info) | 211 // we do nothing, since by design we don't "own" the stream (i.e. info) |
234 } | 212 } |
235 | 213 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 CGImageRef image = SkCreateCGImageRef(*bmPtr); | 291 CGImageRef image = SkCreateCGImageRef(*bmPtr); |
314 if (NULL == image) { | 292 if (NULL == image) { |
315 return false; | 293 return false; |
316 } | 294 } |
317 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image); | 295 SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image); |
318 | 296 |
319 CGImageDestinationAddImage(dst, image, NULL); | 297 CGImageDestinationAddImage(dst, image, NULL); |
320 return CGImageDestinationFinalize(dst); | 298 return CGImageDestinationFinalize(dst); |
321 } | 299 } |
322 | 300 |
323 /////////////////////////////////////////////////////////////////////////////// | 301 SkImageEncoder* SkCreateImageEncoder_CG(SkImageEncoder::Type t) { |
324 | |
325 static SkImageEncoder* sk_imageencoder_cg_factory(SkImageEncoder::Type t) { | |
326 switch (t) { | 302 switch (t) { |
| 303 #ifndef SK_BUILD_FOR_IOS |
327 case SkImageEncoder::kICO_Type: | 304 case SkImageEncoder::kICO_Type: |
328 case SkImageEncoder::kBMP_Type: | 305 case SkImageEncoder::kBMP_Type: |
329 case SkImageEncoder::kGIF_Type: | 306 case SkImageEncoder::kGIF_Type: |
330 case SkImageEncoder::kJPEG_Type: | 307 case SkImageEncoder::kJPEG_Type: |
| 308 #endif |
331 case SkImageEncoder::kPNG_Type: | 309 case SkImageEncoder::kPNG_Type: |
332 break; | 310 break; |
333 default: | 311 default: |
334 return NULL; | 312 return NULL; |
335 } | 313 } |
336 return SkNEW_ARGS(SkImageEncoder_CG, (t)); | 314 return SkNEW_ARGS(SkImageEncoder_CG, (t)); |
337 } | 315 } |
338 | 316 |
339 static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_cg_factory); | |
340 | |
341 #ifdef SK_BUILD_FOR_IOS | |
342 class SkPNGImageEncoder_IOS : public SkImageEncoder_CG { | |
343 public: | |
344 SkPNGImageEncoder_IOS() | |
345 : SkImageEncoder_CG(kPNG_Type) { | |
346 } | |
347 }; | |
348 | |
349 DEFINE_ENCODER_CREATOR(PNGImageEncoder_IOS); | |
350 #endif | |
351 | |
352 struct FormatConversion { | 317 struct FormatConversion { |
353 CFStringRef fUTType; | 318 CFStringRef fUTType; |
354 SkImageDecoder::Format fFormat; | 319 SkImageDecoder::Format fFormat; |
355 }; | 320 }; |
356 | 321 |
357 // Array of the types supported by the decoder. | 322 // Array of the types supported by the decoder. |
358 static const FormatConversion gFormatConversions[] = { | 323 static const FormatConversion gFormatConversions[] = { |
359 { kUTTypeBMP, SkImageDecoder::kBMP_Format }, | 324 { kUTTypeBMP, SkImageDecoder::kBMP_Format }, |
360 { kUTTypeGIF, SkImageDecoder::kGIF_Format }, | 325 { kUTTypeGIF, SkImageDecoder::kGIF_Format }, |
361 { kUTTypeICO, SkImageDecoder::kICO_Format }, | 326 { kUTTypeICO, SkImageDecoder::kICO_Format }, |
362 { kUTTypeJPEG, SkImageDecoder::kJPEG_Format }, | 327 { kUTTypeJPEG, SkImageDecoder::kJPEG_Format }, |
363 // Also include JPEG2000 | 328 // Also include JPEG2000 |
364 { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format }, | 329 { kUTTypeJPEG2000, SkImageDecoder::kJPEG_Format }, |
365 { kUTTypePNG, SkImageDecoder::kPNG_Format }, | 330 { kUTTypePNG, SkImageDecoder::kPNG_Format }, |
366 }; | 331 }; |
367 | 332 |
368 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { | 333 static SkImageDecoder::Format UTType_to_Format(const CFStringRef uttype) { |
369 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { | 334 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { |
370 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp
areEqualTo) { | 335 if (CFStringCompare(uttype, gFormatConversions[i].fUTType, 0) == kCFComp
areEqualTo) { |
371 return gFormatConversions[i].fFormat; | 336 return gFormatConversions[i].fFormat; |
372 } | 337 } |
373 } | 338 } |
374 return SkImageDecoder::kUnknown_Format; | 339 return SkImageDecoder::kUnknown_Format; |
375 } | 340 } |
376 | 341 |
377 static SkImageDecoder::Format get_format_cg(SkStreamRewindable* stream) { | 342 SkImageDecoder::Format SkDetectFormatImageDecoder_CG(SkStreamRewindable* stream)
{ |
378 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); | 343 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
379 | 344 |
380 if (NULL == imageSrc) { | 345 if (NULL == imageSrc) { |
381 return SkImageDecoder::kUnknown_Format; | 346 return SkImageDecoder::kUnknown_Format; |
382 } | 347 } |
383 | 348 |
384 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 349 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
385 const CFStringRef name = CGImageSourceGetType(imageSrc); | 350 const CFStringRef name = CGImageSourceGetType(imageSrc); |
386 if (NULL == name) { | 351 if (NULL == name) { |
387 return SkImageDecoder::kUnknown_Format; | 352 return SkImageDecoder::kUnknown_Format; |
388 } | 353 } |
389 return UTType_to_Format(name); | 354 return UTType_to_Format(name); |
390 } | 355 } |
391 | 356 |
392 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); | 357 SkImageDecoder* SkCreateImageDecoder_CG(SkImageDecoder::Format format) { |
| 358 SkASSERT(SkImageDecoder::kUnknown_Format != format); |
| 359 return SkNEW(SkImageDecoder_CG); |
| 360 } |
OLD | NEW |