2005-11-22 10:03:32 +00:00
|
|
|
/* gdkcolor-quartz.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Imendio AB
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
#include "gdkcolor.h"
|
|
|
|
#include "gdkprivate-quartz.h"
|
|
|
|
|
|
|
|
GType
|
|
|
|
gdk_colormap_get_type (void)
|
|
|
|
{
|
|
|
|
static GType object_type = 0;
|
|
|
|
|
|
|
|
if (!object_type)
|
|
|
|
{
|
2009-11-06 00:21:09 +00:00
|
|
|
const GTypeInfo object_info =
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
sizeof (GdkColormapClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) NULL,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GdkColormap),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
object_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GdkColormap",
|
|
|
|
&object_info,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return object_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkColormap *
|
|
|
|
gdk_colormap_new (GdkVisual *visual,
|
|
|
|
gint private_cmap)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (visual != NULL, NULL);
|
|
|
|
|
|
|
|
/* FIXME: Implement */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkColormap *
|
|
|
|
gdk_screen_get_system_colormap (GdkScreen *screen)
|
|
|
|
{
|
|
|
|
static GdkColormap *colormap = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
|
|
|
|
|
|
|
if (!colormap)
|
|
|
|
{
|
|
|
|
colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
|
|
|
|
|
|
|
|
colormap->visual = gdk_visual_get_system ();
|
|
|
|
colormap->size = colormap->visual->colormap_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return colormap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GdkColormap *
|
|
|
|
gdk_screen_get_rgba_colormap (GdkScreen *screen)
|
|
|
|
{
|
|
|
|
static GdkColormap *colormap = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
|
|
|
|
|
|
|
if (!colormap)
|
|
|
|
{
|
|
|
|
colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
|
|
|
|
|
|
|
|
colormap->visual = gdk_screen_get_rgba_visual (screen);
|
|
|
|
colormap->size = colormap->visual->colormap_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return colormap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-14 14:02:12 +00:00
|
|
|
gdk_colormap_free_colors (GdkColormap *colormap,
|
|
|
|
const GdkColor *colors,
|
|
|
|
gint n_colors)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2008-02-13 14:20:51 +00:00
|
|
|
/* This function shouldn't do anything since colors are never allocated. */
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gdk_colormap_alloc_colors (GdkColormap *colormap,
|
|
|
|
GdkColor *colors,
|
|
|
|
gint ncolors,
|
|
|
|
gboolean writeable,
|
|
|
|
gboolean best_match,
|
|
|
|
gboolean *success)
|
|
|
|
{
|
|
|
|
int i;
|
2008-02-13 14:20:51 +00:00
|
|
|
int alpha;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_COLORMAP (colormap), ncolors);
|
|
|
|
g_return_val_if_fail (colors != NULL, ncolors);
|
|
|
|
g_return_val_if_fail (success != NULL, ncolors);
|
|
|
|
|
|
|
|
if (gdk_colormap_get_visual (colormap)->depth == 32)
|
|
|
|
alpha = 0xff;
|
|
|
|
else
|
|
|
|
alpha = 0;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ncolors; i++)
|
|
|
|
{
|
2008-02-13 14:20:51 +00:00
|
|
|
colors[i].pixel = alpha << 24 |
|
|
|
|
((colors[i].red >> 8) & 0xff) << 16 |
|
|
|
|
((colors[i].green >> 8) & 0xff) << 8 |
|
|
|
|
((colors[i].blue >> 8) & 0xff);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 14:20:51 +00:00
|
|
|
*success = TRUE;
|
2006-07-29 11:05:15 +00:00
|
|
|
|
2008-02-13 14:20:51 +00:00
|
|
|
return 0;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkScreen*
|
|
|
|
gdk_colormap_get_screen (GdkColormap *cmap)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (cmap != NULL, NULL);
|
|
|
|
|
|
|
|
return gdk_screen_get_default ();
|
|
|
|
}
|
|
|
|
|
2010-06-26 15:08:15 +00:00
|
|
|
CGColorRef
|
|
|
|
_gdk_quartz_colormap_get_cgcolor_from_pixel (GdkDrawable *drawable,
|
|
|
|
guint32 pixel)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2010-06-27 08:22:36 +00:00
|
|
|
CGFloat components[4] = { 0.0f, };
|
2010-06-26 15:08:15 +00:00
|
|
|
CGColorRef color;
|
2010-06-27 08:22:36 +00:00
|
|
|
CGColorSpaceRef colorspace;
|
2010-06-26 15:08:15 +00:00
|
|
|
const GdkVisual *visual;
|
|
|
|
GdkColormap *colormap;
|
|
|
|
|
|
|
|
colormap = gdk_drawable_get_colormap (drawable);
|
|
|
|
if (colormap)
|
|
|
|
visual = gdk_colormap_get_visual (colormap);
|
2005-11-22 10:03:32 +00:00
|
|
|
else
|
2010-06-26 15:08:15 +00:00
|
|
|
visual = gdk_visual_get_best_with_depth (gdk_drawable_get_depth (drawable));
|
|
|
|
|
|
|
|
switch (visual->type)
|
|
|
|
{
|
|
|
|
case GDK_VISUAL_STATIC_GRAY:
|
|
|
|
case GDK_VISUAL_GRAYSCALE:
|
2010-06-27 08:22:36 +00:00
|
|
|
components[0] = (pixel & 0xff) / 255.0f;
|
2010-06-26 15:08:15 +00:00
|
|
|
|
|
|
|
if (visual->depth == 1)
|
2010-06-27 08:22:36 +00:00
|
|
|
components[0] = components[0] == 0.0f ? 0.0f : 1.0f;
|
|
|
|
components[1] = 1.0f;
|
2010-06-26 15:08:15 +00:00
|
|
|
|
2010-06-27 08:22:36 +00:00
|
|
|
colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericGray);
|
|
|
|
color = CGColorCreate (colorspace, components);
|
|
|
|
CGColorSpaceRelease (colorspace);
|
2010-06-26 15:08:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-06-27 08:22:36 +00:00
|
|
|
components[0] = (pixel >> 16 & 0xff) / 255.0;
|
|
|
|
components[1] = (pixel >> 8 & 0xff) / 255.0;
|
|
|
|
components[2] = (pixel & 0xff) / 255.0;
|
2010-06-26 15:08:15 +00:00
|
|
|
|
|
|
|
if (visual->depth == 32)
|
2010-06-27 08:22:36 +00:00
|
|
|
components[3] = (pixel >> 24 & 0xff) / 255.0;
|
2010-06-26 15:08:15 +00:00
|
|
|
else
|
2010-06-27 08:22:36 +00:00
|
|
|
components[3] = 1.0;
|
2010-06-26 15:08:15 +00:00
|
|
|
|
2010-06-27 08:22:36 +00:00
|
|
|
colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericRGB);
|
|
|
|
color = CGColorCreate (colorspace, components);
|
|
|
|
CGColorSpaceRelease (colorspace);
|
2010-06-26 15:08:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|