1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gdkprivate.h"
33 gdk_colormap_ref (GdkColormap *cmap)
35 GdkColormapPrivate *private = (GdkColormapPrivate *)cmap;
37 g_return_val_if_fail (cmap != NULL, NULL);
39 private->ref_count += 1;
44 gdk_colormap_unref (GdkColormap *cmap)
46 GdkColormapPrivate *private = (GdkColormapPrivate *)cmap;
48 g_return_if_fail (cmap != NULL);
49 g_return_if_fail (private->ref_count > 0);
51 private->ref_count -= 1;
52 if (private->ref_count == 0)
53 _gdk_colormap_real_destroy (cmap);
57 gdk_colormap_get_visual (GdkColormap *colormap)
59 GdkColormapPrivate *private;
61 g_return_val_if_fail (colormap != NULL, NULL);
63 private = (GdkColormapPrivate *)colormap;
65 return private->visual;
69 gdk_colors_store (GdkColormap *colormap,
75 for (i = 0; i < ncolors; i++)
77 colormap->colors[i].pixel = colors[i].pixel;
78 colormap->colors[i].red = colors[i].red;
79 colormap->colors[i].green = colors[i].green;
80 colormap->colors[i].blue = colors[i].blue;
83 gdk_colormap_change (colormap, ncolors);
87 *--------------------------------------------------------------
90 * Copy a color structure into new storage.
93 * "color" is the color struct to copy.
96 * A new color structure. Free it with gdk_color_free.
98 *--------------------------------------------------------------
101 static GMemChunk *color_chunk;
104 gdk_color_copy (const GdkColor *color)
108 g_return_val_if_fail (color != NULL, NULL);
110 if (color_chunk == NULL)
111 color_chunk = g_mem_chunk_new ("colors",
116 new_color = g_chunk_new (GdkColor, color_chunk);
122 *--------------------------------------------------------------
125 * Free a color structure obtained from gdk_color_copy. Do not use
126 * with other color structures.
129 * "color" is the color struct to free.
131 *-------------------------------------------------------------- */
134 gdk_color_free (GdkColor *color)
136 g_assert (color_chunk != NULL);
137 g_return_if_fail (color != NULL);
139 g_mem_chunk_free (color_chunk, color);
143 gdk_color_white (GdkColormap *colormap,
148 g_return_val_if_fail (colormap != NULL, FALSE);
153 color->green = 65535;
156 return_val = gdk_color_alloc (colormap, color);
165 gdk_color_black (GdkColormap *colormap,
170 g_return_val_if_fail (colormap != NULL, FALSE);
178 return_val = gdk_color_alloc (colormap, color);
186 /********************
188 ********************/
191 gdk_colormap_alloc_color (GdkColormap *colormap,
198 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
205 gdk_color_alloc (GdkColormap *colormap,
210 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
216 gdk_color_hash (const GdkColor *colora)
218 return ((colora->red) +
219 (colora->green << 11) +
220 (colora->blue << 22) +
221 (colora->blue >> 6));
225 gdk_color_equal (const GdkColor *colora,
226 const GdkColor *colorb)
228 g_return_val_if_fail (colora != NULL, FALSE);
229 g_return_val_if_fail (colorb != NULL, FALSE);
231 return ((colora->red == colorb->red) &&
232 (colora->green == colorb->green) &&
233 (colora->blue == colorb->blue));