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 Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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-2000. 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 "gdkinternals.h"
33 gdk_colormap_ref (GdkColormap *cmap)
35 return (GdkColormap *) g_object_ref (G_OBJECT (cmap));
39 gdk_colormap_unref (GdkColormap *cmap)
41 g_object_unref (G_OBJECT (cmap));
45 gdk_colormap_get_visual (GdkColormap *colormap)
47 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
49 return colormap->visual;
53 gdk_colors_store (GdkColormap *colormap,
59 for (i = 0; i < ncolors; i++)
61 colormap->colors[i].pixel = colors[i].pixel;
62 colormap->colors[i].red = colors[i].red;
63 colormap->colors[i].green = colors[i].green;
64 colormap->colors[i].blue = colors[i].blue;
67 gdk_colormap_change (colormap, ncolors);
71 *--------------------------------------------------------------
74 * Copy a color structure into new storage.
77 * "color" is the color struct to copy.
80 * A new color structure. Free it with gdk_color_free.
82 *--------------------------------------------------------------
85 static GMemChunk *color_chunk;
88 gdk_color_copy (const GdkColor *color)
92 g_return_val_if_fail (color != NULL, NULL);
94 if (color_chunk == NULL)
95 color_chunk = g_mem_chunk_new ("colors",
100 new_color = g_chunk_new (GdkColor, color_chunk);
106 *--------------------------------------------------------------
109 * Free a color structure obtained from gdk_color_copy. Do not use
110 * with other color structures.
113 * "color" is the color struct to free.
115 *-------------------------------------------------------------- */
118 gdk_color_free (GdkColor *color)
120 g_assert (color_chunk != NULL);
121 g_return_if_fail (color != NULL);
123 g_mem_chunk_free (color_chunk, color);
127 gdk_color_white (GdkColormap *colormap,
132 g_return_val_if_fail (colormap != NULL, FALSE);
137 color->green = 65535;
140 return_val = gdk_color_alloc (colormap, color);
149 gdk_color_black (GdkColormap *colormap,
154 g_return_val_if_fail (colormap != NULL, FALSE);
162 return_val = gdk_color_alloc (colormap, color);
170 /********************
172 ********************/
175 gdk_colormap_alloc_color (GdkColormap *colormap,
182 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
189 gdk_color_alloc (GdkColormap *colormap,
194 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
200 gdk_color_hash (const GdkColor *colora)
202 return ((colora->red) +
203 (colora->green << 11) +
204 (colora->blue << 22) +
205 (colora->blue >> 6));
209 gdk_color_equal (const GdkColor *colora,
210 const GdkColor *colorb)
212 g_return_val_if_fail (colora != NULL, FALSE);
213 g_return_val_if_fail (colorb != NULL, FALSE);
215 return ((colora->red == colorb->red) &&
216 (colora->green == colorb->green) &&
217 (colora->blue == colorb->blue));