| 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 |
| 8 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| 11 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
| 12 #include "SkMovie.h" | 12 #include "SkMovie.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkStreamHelpers.h" |
| 14 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
| 15 #include "SkUnPreMultiply.h" | 16 #include "SkUnPreMultiply.h" |
| 16 | 17 |
| 17 #ifdef SK_BUILD_FOR_MAC | 18 #ifdef SK_BUILD_FOR_MAC |
| 18 #include <ApplicationServices/ApplicationServices.h> | 19 #include <ApplicationServices/ApplicationServices.h> |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 #ifdef SK_BUILD_FOR_IOS | 22 #ifdef SK_BUILD_FOR_IOS |
| 22 #include <CoreGraphics/CoreGraphics.h> | 23 #include <CoreGraphics/CoreGraphics.h> |
| 23 #include <ImageIO/ImageIO.h> | 24 #include <ImageIO/ImageIO.h> |
| 24 #include <MobileCoreServices/MobileCoreServices.h> | 25 #include <MobileCoreServices/MobileCoreServices.h> |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 static void malloc_release_proc(void* info, const void* data, size_t size) { | 28 static void malloc_release_proc(void* info, const void* data, size_t size) { |
| 28 sk_free(info); | 29 sk_free(info); |
| 29 } | 30 } |
| 30 | 31 |
| 31 static CGDataProviderRef SkStreamToDataProvider(SkStream* stream) { | 32 static CGDataProviderRef SkStreamToDataProvider(SkStream* stream) { |
| 32 // TODO: use callbacks, so we don't have to load all the data into RAM | 33 // TODO: use callbacks, so we don't have to load all the data into RAM |
| 33 size_t len = stream->getLength(); | 34 SkAutoMalloc storage; |
| 34 void* data = sk_malloc_throw(len); | 35 const size_t len = CopyStreamToStorage(&storage, stream); |
| 35 stream->read(data, len); | 36 void* data = storage.detach(); |
| 36 | 37 |
| 37 return CGDataProviderCreateWithData(data, data, len, malloc_release_proc); | 38 return CGDataProviderCreateWithData(data, data, len, malloc_release_proc); |
| 38 } | 39 } |
| 39 | 40 |
| 40 static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { | 41 static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) { |
| 41 CGDataProviderRef data = SkStreamToDataProvider(stream); | 42 CGDataProviderRef data = SkStreamToDataProvider(stream); |
| 42 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); | 43 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); |
| 43 CGDataProviderRelease(data); | 44 CGDataProviderRelease(data); |
| 44 return imageSrc; | 45 return imageSrc; |
| 45 } | 46 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 296 |
| 296 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 297 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
| 297 const CFStringRef name = CGImageSourceGetType(imageSrc); | 298 const CFStringRef name = CGImageSourceGetType(imageSrc); |
| 298 if (NULL == name) { | 299 if (NULL == name) { |
| 299 return SkImageDecoder::kUnknown_Format; | 300 return SkImageDecoder::kUnknown_Format; |
| 300 } | 301 } |
| 301 return UTType_to_Format(name); | 302 return UTType_to_Format(name); |
| 302 } | 303 } |
| 303 | 304 |
| 304 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_cg); | 305 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_cg); |
| OLD | NEW |