Debian Codegraph @

gdk/quartz/gdkcolor-quartz.c

raw
1 /* gdkcolor-quartz.c
2 *
3 * Copyright (C) 2005 Imendio AB
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21 #include "config.h"
22
23 #include "gdkcolor.h"
24 #include "gdkprivate-quartz.h"
25
26 GType
27 gdk_colormap_get_type (void)
28 {
29 static GType object_type = 0;
30
31 if (!object_type)
32 {
33 const GTypeInfo object_info =
34 {
35 sizeof (GdkColormapClass),
36 (GBaseInitFunc) NULL,
37 (GBaseFinalizeFunc) NULL,
38 (GClassInitFunc) NULL,
39 NULL, /* class_finalize */
40 NULL, /* class_data */
41 sizeof (GdkColormap),
42 0, /* n_preallocs */
43 (GInstanceInitFunc) NULL,
44 };
45
46 object_type = g_type_register_static (G_TYPE_OBJECT,
47 "GdkColormap",
48 &object_info,
49 0);
50 }
51
52 return object_type;
53 }
54
55 GdkColormap *
56 gdk_colormap_new (GdkVisual *visual,
57 gint private_cmap)
58 {
59 g_return_val_if_fail (visual != NULL, NULL);
60
61 /* FIXME: Implement */
62 return NULL;
63 }
64
65 GdkColormap *
66 gdk_screen_get_system_colormap (GdkScreen *screen)
67 {
68 static GdkColormap *colormap = NULL;
69
70 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
71
72 if (!colormap)
73 {
74 colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
75
76 colormap->visual = gdk_visual_get_system ();
77 colormap->size = colormap->visual->colormap_size;
78 }
79
80 return colormap;
81 }
82
83
84 GdkColormap *
85 gdk_screen_get_rgba_colormap (GdkScreen *screen)
86 {
87 static GdkColormap *colormap = NULL;
88
89 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
90
91 if (!colormap)
92 {
93 colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
94
95 colormap->visual = gdk_screen_get_rgba_visual (screen);
96 colormap->size = colormap->visual->colormap_size;
97 }
98
99 return colormap;
100 }
101
102 gint
103 gdk_colormap_get_system_size (void)
104 {
105 /* FIXME: Implement */
106 return 0;
107 }
108
109 void
110 gdk_colormap_change (GdkColormap *colormap,
111 gint ncolors)
112 {
113 /* FIXME: Implement */
114 }
115
116 gboolean
117 gdk_colors_alloc (GdkColormap *colormap,
118 gboolean contiguous,
119 gulong *planes,
120 gint nplanes,
121 gulong *pixels,
122 gint npixels)
123 {
124 return TRUE;
125 }
126
127 void
128 gdk_colors_free (GdkColormap *colormap,
129 gulong *pixels,
130 gint npixels,
131 gulong planes)
132 {
133 }
134
135 void
136 gdk_colormap_free_colors (GdkColormap *colormap,
137 const GdkColor *colors,
138 gint n_colors)
139 {
140 /* This function shouldn't do anything since colors are never allocated. */
141 }
142
143 gint
144 gdk_colormap_alloc_colors (GdkColormap *colormap,
145 GdkColor *colors,
146 gint ncolors,
147 gboolean writeable,
148 gboolean best_match,
149 gboolean *success)
150 {
151 int i;
152 int alpha;
153
154 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), ncolors);
155 g_return_val_if_fail (colors != NULL, ncolors);
156 g_return_val_if_fail (success != NULL, ncolors);
157
158 if (gdk_colormap_get_visual (colormap)->depth == 32)
159 alpha = 0xff;
160 else
161 alpha = 0;
162
163 for (i = 0; i < ncolors; i++)
164 {
165 colors[i].pixel = alpha << 24 |
166 ((colors[i].red >> 8) & 0xff) << 16 |
167 ((colors[i].green >> 8) & 0xff) << 8 |
168 ((colors[i].blue >> 8) & 0xff);
169 }
170
171 *success = TRUE;
172
173 return 0;
174 }
175
176 void
177 gdk_colormap_query_color (GdkColormap *colormap,
178 gulong pixel,
179 GdkColor *result)
180 {
181 result->red = pixel >> 16 & 0xff;
182 result->red += result->red << 8;
183
184 result->green = pixel >> 8 & 0xff;
185 result->green += result->green << 8;
186
187 result->blue = pixel & 0xff;
188 result->blue += result->blue << 8;
189 }
190
191 GdkScreen*
192 gdk_colormap_get_screen (GdkColormap *cmap)
193 {
194 g_return_val_if_fail (cmap != NULL, NULL);
195
196 return gdk_screen_get_default ();
197 }
198
199 CGColorRef
200 _gdk_quartz_colormap_get_cgcolor_from_pixel (GdkDrawable *drawable,
201 guint32 pixel)
202 {
203 CGFloat components[4] = { 0.0f, };
204 CGColorRef color;
205 CGColorSpaceRef colorspace;
206 const GdkVisual *visual;
207 GdkColormap *colormap;
208
209 colormap = gdk_drawable_get_colormap (drawable);
210 if (colormap)
211 visual = gdk_colormap_get_visual (colormap);
212 else
213 visual = gdk_visual_get_best_with_depth (gdk_drawable_get_depth (drawable));
214
215 switch (visual->type)
216 {
217 case GDK_VISUAL_STATIC_GRAY:
218 case GDK_VISUAL_GRAYSCALE:
219 components[0] = (pixel & 0xff) / 255.0f;
220
221 if (visual->depth == 1)
222 components[0] = components[0] == 0.0f ? 0.0f : 1.0f;
223 components[1] = 1.0f;
224
225 colorspace = CGColorSpaceCreateWithName (kCGColorSpaceGenericGray);
226 color = CGColorCreate (colorspace, components);
227 CGColorSpaceRelease (colorspace);
228 break;
229
230 default:
231 components[0] = (pixel >> 16 & 0xff) / 255.0;
232 components[1] = (pixel >> 8 & 0xff) / 255.0;
233 components[2] = (pixel & 0xff) / 255.0;
234
235 if (visual->depth == 32)
236 components[3] = (pixel >> 24 & 0xff) / 255.0;
237 else
238 components[3] = 1.0;
239
240 colorspace = CGColorSpaceCreateDeviceRGB ();
241 color = CGColorCreate (colorspace, components);
242 CGColorSpaceRelease (colorspace);
243 break;
244 }
245
246 return color;
247 }
248
249 gboolean
250 gdk_color_change (GdkColormap *colormap,
251 GdkColor *color)
252 {
253 if (color->pixel < 0 || color->pixel >= colormap->size)
254 return FALSE;
255
256 return TRUE;
257 }
258