From 38669c12c5ab784d5ad94eb2b26b89becac2ba12 Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Mon, 3 Jan 2011 13:48:50 +0000 Subject: add colorspace option to SkBitmap -> CGImageRef utility (patch from nico) git-svn-id: http://skia.googlecode.com/svn/trunk@666 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/utils/mac/SkCreateCGImageRef.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/utils/mac') diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp index 2169bc09cb..dea443c13c 100644 --- a/src/utils/mac/SkCreateCGImageRef.cpp +++ b/src/utils/mac/SkCreateCGImageRef.cpp @@ -2,8 +2,6 @@ #include "SkBitmap.h" #include "SkColorPriv.h" -extern CGImageRef SkCreateCGImageRef(const SkBitmap&); - static void SkBitmap_ReleaseInfo(void* info, const void* pixelData, size_t size) { SkBitmap* bitmap = reinterpret_cast(info); delete bitmap; @@ -74,9 +72,10 @@ static SkBitmap* prepareForImageRef(const SkBitmap& bm, #undef HAS_ARGB_SHIFTS -CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { - size_t bitsPerComponent; - CGBitmapInfo info; +CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, + CGColorSpaceRef colorSpace) { + size_t bitsPerComponent SK_INIT_TO_AVOID_WARNING; + CGBitmapInfo info SK_INIT_TO_AVOID_WARNING; SkBitmap* bitmap = prepareForImageRef(bm, &bitsPerComponent, &info); if (NULL == bitmap) { @@ -94,12 +93,20 @@ CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { CGDataProviderRef dataRef = CGDataProviderCreateWithData(bitmap, bitmap->getPixels(), s, SkBitmap_ReleaseInfo); - CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); + bool releaseColorSpace = false; + if (NULL == colorSpace) { + colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + releaseColorSpace = true; + } + CGImageRef ref = CGImageCreate(w, h, bitsPerComponent, bitmap->bytesPerPixel() * 8, - bitmap->rowBytes(), space, info, dataRef, + bitmap->rowBytes(), colorSpace, info, dataRef, NULL, false, kCGRenderingIntentDefault); - CGColorSpaceRelease(space); + + if (releaseColorSpace) { + CGColorSpaceRelease(colorSpace); + } CGDataProviderRelease(dataRef); return ref; } -- cgit v1.2.3