From 64f11c366aae4b0d38bcd632ed75a55027667c81 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Sun, 27 Jun 2010 10:22:36 +0200 Subject: [PATCH] Refactor to use API that's available in OS X 10.4 as well (cherry picked from commit 3770d914ec3ac30248f8d187ccc9f5369d3a5fcc) --- gdk/quartz/gdkcolor-quartz.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/gdk/quartz/gdkcolor-quartz.c b/gdk/quartz/gdkcolor-quartz.c index 7afcf2cce5..315dd28be5 100644 --- a/gdk/quartz/gdkcolor-quartz.c +++ b/gdk/quartz/gdkcolor-quartz.c @@ -167,8 +167,9 @@ CGColorRef _gdk_quartz_colormap_get_cgcolor_from_pixel (GdkDrawable *drawable, guint32 pixel) { - CGFloat r, g, b, a; + CGFloat components[4] = { 0.0f, }; CGColorRef color; + CGColorSpaceRef colorspace; const GdkVisual *visual; GdkColormap *colormap; @@ -182,25 +183,30 @@ _gdk_quartz_colormap_get_cgcolor_from_pixel (GdkDrawable *drawable, { case GDK_VISUAL_STATIC_GRAY: case GDK_VISUAL_GRAYSCALE: - g = (pixel & 0xff) / 255.0f; + components[0] = (pixel & 0xff) / 255.0f; if (visual->depth == 1) - g = g == 0.0f ? 0.0f : 1.0f; + components[0] = components[0] == 0.0f ? 0.0f : 1.0f; + components[1] = 1.0f; - color = CGColorCreateGenericGray (g, 1.0f); + colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericGray); + color = CGColorCreate (colorspace, components); + CGColorSpaceRelease (colorspace); break; default: - r = (pixel >> 16 & 0xff) / 255.0; - g = (pixel >> 8 & 0xff) / 255.0; - b = (pixel & 0xff) / 255.0; + components[0] = (pixel >> 16 & 0xff) / 255.0; + components[1] = (pixel >> 8 & 0xff) / 255.0; + components[2] = (pixel & 0xff) / 255.0; if (visual->depth == 32) - a = (pixel >> 24 & 0xff) / 255.0; + components[3] = (pixel >> 24 & 0xff) / 255.0; else - a = 1.0; + components[3] = 1.0; - color = CGColorCreateGenericRGB (r, g, b, a); + colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB); + color = CGColorCreate (colorspace, components); + CGColorSpaceRelease (colorspace); break; } -- 2.22.0