aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/mac
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-03 13:48:50 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-03 13:48:50 +0000
commit38669c12c5ab784d5ad94eb2b26b89becac2ba12 (patch)
tree2a071ed819cf73e24dc5044d1c46e1e3e811744a /src/utils/mac
parent832806cf8ee1d623be343e55f26d59894f4bae6c (diff)
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
Diffstat (limited to 'src/utils/mac')
-rw-r--r--src/utils/mac/SkCreateCGImageRef.cpp23
1 files changed, 15 insertions, 8 deletions
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<SkBitmap*>(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;
}