⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdkcolor-x11.c

📁 linux下电话本所依赖的一些图形库
💻 C
📖 第 1 页 / 共 3 页
字号:
				       gboolean     writeable,				       gboolean     best_match,				       gboolean    *success){  GdkColormapPrivateX11 *private;  GdkColor *lookup_color;  gint i;  gint nremaining = 0;  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  /* Check for an exact match among previously allocated colors */  for (i = 0; i < ncolors; i++)    {      if (!success[i])	{	  lookup_color = g_hash_table_lookup (private->hash, &colors[i]);	  if (lookup_color)	    {	      private->info[lookup_color->pixel].ref_count++;	      colors[i].pixel = lookup_color->pixel;	      success[i] = TRUE;	    }	  else	    nremaining++;	}    }  /* If that failed, we try to allocate a new color, or approxmiate   * with what we can get if best_match is TRUE.   */  if (nremaining > 0)    {      if (private->private_val)	return gdk_colormap_alloc_colors_private (colormap, colors, ncolors, writeable, best_match, success);      else	return gdk_colormap_alloc_colors_shared (colormap, colors, ncolors, writeable, best_match, success);    }  else    return 0;}/** * gdk_colormap_alloc_colors: * @colormap: a #GdkColormap. * @colors: The color values to allocate. On return, the pixel *    values for allocated colors will be filled in. * @ncolors: The number of colors in @colors. * @writeable: If %TRUE, the colors are allocated writeable *    (their values can later be changed using gdk_color_change()). *    Writeable colors cannot be shared between applications. * @best_match: If %TRUE, GDK will attempt to do matching against *    existing colors if the colors cannot be allocated as requested. * @success: An array of length @ncolors. On return, this *   indicates whether the corresponding color in @colors was *   successfully allocated or not. *  * Allocates colors from a colormap. *  * Return value: The number of colors that were not successfully  * allocated. **/gintgdk_colormap_alloc_colors (GdkColormap *colormap,			   GdkColor    *colors,			   gint         ncolors,			   gboolean     writeable,			   gboolean     best_match,			   gboolean    *success){  GdkColormapPrivateX11 *private;  GdkVisual *visual;  gint i;  gint nremaining = 0;  XColor xcolor;  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);  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  if (private->screen->closed)    return ncolors;  for (i = 0; i < ncolors; i++)    success[i] = FALSE;  switch (colormap->visual->type)    {    case GDK_VISUAL_PSEUDO_COLOR:    case GDK_VISUAL_GRAYSCALE:      if (writeable)	return gdk_colormap_alloc_colors_writeable (colormap, colors, ncolors,						    writeable, best_match, success);      else	return gdk_colormap_alloc_colors_pseudocolor (colormap, colors, ncolors,						    writeable, best_match, success);      break;    case GDK_VISUAL_DIRECT_COLOR:    case GDK_VISUAL_TRUE_COLOR:      visual = colormap->visual;      for (i = 0; i < ncolors; i++)	{	  /* If bits not used for color are used for something other than padding,	   * it's likely alpha, so we set them to 1s.	   */	  guint32 unused = ~ (visual->red_mask | visual->green_mask | visual->blue_mask |			      (((~(guint32)0)) << visual->depth));	  colors[i].pixel = (unused +			     ((colors[i].red >> (16 - visual->red_prec)) << visual->red_shift) +			     ((colors[i].green >> (16 - visual->green_prec)) << visual->green_shift) +			     ((colors[i].blue >> (16 - visual->blue_prec)) << visual->blue_shift));	  success[i] = TRUE;	}      break;    case GDK_VISUAL_STATIC_GRAY:    case GDK_VISUAL_STATIC_COLOR:      for (i = 0; i < ncolors; i++)	{	  xcolor.red = colors[i].red;	  xcolor.green = colors[i].green;	  xcolor.blue = colors[i].blue;	  xcolor.pixel = colors[i].pixel;	  xcolor.flags = DoRed | DoGreen | DoBlue;	  if (XAllocColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor))	    {	      colors[i].pixel = xcolor.pixel;	      success[i] = TRUE;	    }	  else	    nremaining++;	}      break;    }  return nremaining;}/** * gdk_colormap_query_color: * @colormap: a #GdkColormap * @pixel: pixel value in hardware display format * @result: #GdkColor with red, green, blue fields initialized *  * Locates the RGB color in @colormap corresponding to the given * hardware pixel @pixel. @pixel must be a valid pixel in the * colormap; it's a programmer error to call this function with a * pixel which is not in the colormap. Hardware pixels are normally * obtained from gdk_colormap_alloc_colors(), or from a #GdkImage. (A * #GdkImage contains image data in hardware format, a #GdkPixbuf * contains image data in a canonical 24-bit RGB format.) * * This function is rarely useful; it's used for example to * implement the eyedropper feature in #GtkColorSelection. *  **/voidgdk_colormap_query_color (GdkColormap *colormap,			  gulong       pixel,			  GdkColor    *result){  XColor xcolor;  GdkVisual *visual;  GdkColormapPrivateX11 *private;    g_return_if_fail (GDK_IS_COLORMAP (colormap));    private = GDK_COLORMAP_PRIVATE_DATA (colormap);  visual = gdk_colormap_get_visual (colormap);  switch (visual->type) {  case GDK_VISUAL_DIRECT_COLOR:  case GDK_VISUAL_TRUE_COLOR:    result->red = 65535. * (double)((pixel & visual->red_mask) >> visual->red_shift) / ((1 << visual->red_prec) - 1);    result->green = 65535. * (double)((pixel & visual->green_mask) >> visual->green_shift) / ((1 << visual->green_prec) - 1);    result->blue = 65535. * (double)((pixel & visual->blue_mask) >> visual->blue_shift) / ((1 << visual->blue_prec) - 1);    break;  case GDK_VISUAL_STATIC_GRAY:  case GDK_VISUAL_GRAYSCALE:    result->red = result->green = result->blue = 65535. * (double)pixel/((1<<visual->depth) - 1);    break;  case GDK_VISUAL_STATIC_COLOR:    xcolor.pixel = pixel;    if (!private->screen->closed)      {	XQueryColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor);	result->red = xcolor.red;	result->green = xcolor.green;	result->blue =  xcolor.blue;      }    else      result->red = result->green = result->blue = 0;    break;  case GDK_VISUAL_PSEUDO_COLOR:    g_return_if_fail (pixel < colormap->size);    result->red = colormap->colors[pixel].red;    result->green = colormap->colors[pixel].green;    result->blue = colormap->colors[pixel].blue;    break;  default:    g_assert_not_reached ();    break;  }}/** * gdk_color_change: * @colormap: a #GdkColormap. * @color: a #GdkColor, with the color to change * in the <structfield>pixel</structfield> field, * and the new value in the remaining fields. *  * Changes the value of a color that has already * been allocated. If @colormap is not a private * colormap, then the color must have been allocated * using gdk_colormap_alloc_colors() with the  * @writeable set to %TRUE. *  * Return value: %TRUE if the color was successfully changed. **/gbooleangdk_color_change (GdkColormap *colormap,		  GdkColor    *color){  GdkColormapPrivateX11 *private;  XColor xcolor;  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), FALSE);  g_return_val_if_fail (color != NULL, FALSE);  xcolor.pixel = color->pixel;  xcolor.red = color->red;  xcolor.green = color->green;  xcolor.blue = color->blue;  xcolor.flags = DoRed | DoGreen | DoBlue;  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  if (!private->screen->closed)    XStoreColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor);  return TRUE;}/** * gdk_x11_colormap_foreign_new: * @visual: a #GdkVisual * @xcolormap: The XID of a colormap with visual @visual *  * If xcolormap refers to a colormap previously known to GTK+, * returns a new reference to the existing #GdkColormap object, * otherwise creates a new GdkColormap object and returns that * * Return value: the #GdkColormap object for @xcolormap. *   Free with g_object_unref(). Note that for colormap created *   with gdk_x11_colormap_foreign_new(), unref'ing the last *   reference to the object will only free the #GdkColoramp *   object and not call XFreeColormap() * * Since: 2.2 **/GdkColormap *gdk_x11_colormap_foreign_new (GdkVisual *visual,			      Colormap   xcolormap){  GdkColormap *colormap;  GdkScreen *screen;  GdkColormapPrivateX11 *private;    g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);  g_return_val_if_fail (xcolormap != None, NULL);  screen = gdk_visual_get_screen (visual);    if (xcolormap == DefaultColormap (GDK_SCREEN_XDISPLAY (screen),				    GDK_SCREEN_XNUMBER (screen)))    return g_object_ref (gdk_screen_get_system_colormap (screen));  colormap = gdk_colormap_lookup (screen, xcolormap);  if (colormap)    return g_object_ref (colormap);  colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  colormap->visual = visual;  private->screen = screen;  private->xcolormap = xcolormap;  private->private_val = FALSE;  colormap->size = visual->colormap_size;  switch (colormap->visual->type)    {    case GDK_VISUAL_GRAYSCALE:    case GDK_VISUAL_PSEUDO_COLOR:      private->info = g_new0 (GdkColorInfo, colormap->size);      private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash,					(GEqualFunc) gdk_color_equal);      /* Fall through */    case GDK_VISUAL_STATIC_GRAY:    case GDK_VISUAL_STATIC_COLOR:    case GDK_VISUAL_DIRECT_COLOR:      colormap->colors = g_new (GdkColor, colormap->size);      gdk_colormap_sync (colormap, TRUE);          case GDK_VISUAL_TRUE_COLOR:      break;    }  gdk_colormap_add (colormap);  return colormap;  }/** * gdkx_colormap_get: * @xcolormap: the XID of a colormap for the default screen. *  * Returns a #GdkColormap corresponding to a X colormap; * this function only works if the colormap is already * known to GTK+ (a colormap created by GTK+ or the default * colormap for the screen), since GTK+  * * Always use gdk_x11_colormap_foreign_new() instead. * * Return value: the existing #GdkColormap object if it was *  already known to GTK+, otherwise warns and return *  %NULL. **/GdkColormap*gdkx_colormap_get (Colormap xcolormap){  GdkScreen *screen = gdk_screen_get_default ();  GdkColormap *colormap;  if (xcolormap == DefaultColormap (GDK_SCREEN_XDISPLAY (screen),				    GDK_SCREEN_XNUMBER (screen)));    return g_object_ref (gdk_screen_get_system_colormap (screen));  colormap = gdk_colormap_lookup (screen, xcolormap);  if (colormap)    return g_object_ref (colormap);  g_warning ("Colormap passed to gdkx_colormap_get\n"	     "does not previously exist");  return NULL;}static gintgdk_colormap_match_color (GdkColormap *cmap,			  GdkColor    *color,			  const gchar *available){  GdkColor *colors;  guint sum, max;  gint rdiff, gdiff, bdiff;  gint i, index;  colors = cmap->colors;  max = 3 * (65536);  index = -1;  for (i = 0; i < cmap->size; i++)    {      if ((!available) || (available && available[i]))	{	  rdiff = (color->red - colors[i].red);	  gdiff = (color->green - colors[i].green);	  bdiff = (color->blue - colors[i].blue);	  sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);	  if (sum < max)	    {	      index = i;	      max = sum;	    }	}    }  return index;}static GdkColormap*gdk_colormap_lookup (GdkScreen *screen,		     Colormap   xcolormap){  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);  if (screen_x11->colormap_hash)    return g_hash_table_lookup (screen_x11->colormap_hash, &xcolormap);  else    return NULL;}static voidgdk_colormap_add (GdkColormap *cmap){  GdkScreenX11 *screen_x11;  GdkColormapPrivateX11 *private;  private = GDK_COLORMAP_PRIVATE_DATA (cmap);  screen_x11 = GDK_SCREEN_X11 (private->screen);  if (!screen_x11->colormap_hash)    screen_x11->colormap_hash = g_hash_table_new ((GHashFunc) gdk_colormap_hash,						  (GEqualFunc) gdk_colormap_equal);  g_hash_table_insert (screen_x11->colormap_hash, &private->xcolormap, cmap);}static voidgdk_colormap_remove (GdkColormap *cmap){  GdkScreenX11 *screen_x11;  GdkColormapPrivateX11 *private;  private = GDK_COLORMAP_PRIVATE_DATA (cmap);  screen_x11 = GDK_SCREEN_X11 (private->screen);  if (screen_x11->colormap_hash)    g_hash_table_remove (screen_x11->colormap_hash, &private->xcolormap);}static guintgdk_colormap_hash (Colormap *colormap){  return *colormap;}static gbooleangdk_colormap_equal (Colormap *a,		    Colormap *b){  return (*a == *b);}/** * gdk_x11_colormap_get_xdisplay: * @colormap: a #GdkColormap. *  * Returns the display of a #GdkColormap. *  * Return value: an Xlib <type>Display*</type>. **/Display *gdk_x11_colormap_get_xdisplay (GdkColormap *colormap){  GdkColormapPrivateX11 *private;  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  return GDK_SCREEN_XDISPLAY (private->screen);}/** * gdk_x11_colormap_get_xcolormap: * @colormap:  a #GdkColormap. *  * Returns the X colormap belonging to a #GdkColormap. *  * Return value: an Xlib <type>Colormap</type>. **/Colormapgdk_x11_colormap_get_xcolormap (GdkColormap *colormap){  GdkColormapPrivateX11 *private;  g_return_val_if_fail (GDK_IS_COLORMAP (colormap), None);  private = GDK_COLORMAP_PRIVATE_DATA (colormap);  if (private->screen->closed)    return None;  else    return private->xcolormap;}/** * gdk_colormap_get_screen: * @cmap: a #GdkColormap *  * Gets the screen for which this colormap was created. *  * Return value: the screen for which this colormap was created. * * Since: 2.2 **/GdkScreen *gdk_colormap_get_screen (GdkColormap *cmap){  g_return_val_if_fail (GDK_IS_COLORMAP (cmap), NULL);  return  GDK_COLORMAP_PRIVATE_DATA (cmap)->screen;}#define __GDK_COLOR_X11_C__#include "gdkaliasdef.c"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -