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

📄 gdkrgb.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
    {      r = MIN (nr - 1, i >> 6);      g = MIN (ng - 1, (i >> 3) & 7);      b = MIN (nb - 1, i & 7);      colorcube_d[i] = pixels[(r * ng + g) * nb + b];    }}/* Try installing a color cube of the specified size.   Make the colorcube and return TRUE on success */static gintgdk_rgb_try_colormap (gint nr, gint ng, gint nb){  gint r, g, b;  gint ri, gi, bi;  gint r0, g0, b0;  GdkColormap *cmap;  GdkColor color;  gulong pixels[256];  gulong junk[256];  gint i;  gint d2;  gint colors_needed;  gint idx;  gint best[256];  if (nr * ng * nb < gdk_rgb_min_colors)    return FALSE;  if (image_info->cmap_alloced)    cmap = image_info->cmap;  else    cmap = gdk_colormap_get_system ();  colors_needed = nr * ng * nb;  for (i = 0; i < 256; i++)    {      best[i] = 192;      pixels[i] = 256;    }#ifndef GAMMA  if (!gdk_rgb_install_cmap)  /* find color cube colors that are already present */  for (i = 0; i < MIN (256, cmap->size); i++)    {      r = cmap->colors[i].red >> 8;      g = cmap->colors[i].green >> 8;      b = cmap->colors[i].blue >> 8;      ri = (r * (nr - 1) + 128) >> 8;      gi = (g * (ng - 1) + 128) >> 8;      bi = (b * (nb - 1) + 128) >> 8;      r0 = ri * 255 / (nr - 1);      g0 = gi * 255 / (ng - 1);      b0 = bi * 255 / (nb - 1);      idx = ((ri * nr) + gi) * nb + bi;      d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0);      if (d2 < best[idx]) {	if (pixels[idx] < 256)	  gdk_colors_free (cmap, pixels + idx, 1, 0);	else	  colors_needed--;	color = cmap->colors[i];	if (!gdk_color_alloc (cmap, &color))	  return gdk_rgb_cmap_fail ("error allocating system color\n",				    cmap, pixels);	pixels[idx] = color.pixel; /* which is almost certainly i */	best[idx] = d2;      }    }#endif  if (colors_needed)    {      if (!gdk_colors_alloc (cmap, 0, NULL, 0, junk, colors_needed))	{	  char tmp_str[80];	  	  sprintf (tmp_str,		   "%d %d %d colormap failed (in gdk_colors_alloc)\n",		   nr, ng, nb);	  return gdk_rgb_cmap_fail (tmp_str, cmap, pixels);	}      gdk_colors_free (cmap, junk, colors_needed, 0);    }  for (r = 0, i = 0; r < nr; r++)    for (g = 0; g < ng; g++)      for (b = 0; b < nb; b++, i++)	{	  if (pixels[i] == 256)	    {	      color.red = r * 65535 / (nr - 1);	      color.green = g * 65535 / (ng - 1);	      color.blue = b * 65535 / (nb - 1);#ifdef GAMMA	      color.red = 65535 * pow (color.red / 65535.0, 0.5);	      color.green = 65535 * pow (color.green / 65535.0, 0.5);	      color.blue = 65535 * pow (color.blue / 65535.0, 0.5);#endif	      /* This should be a raw XAllocColor call */	      if (!gdk_color_alloc (cmap, &color))		{		  char tmp_str[80];		  sprintf (tmp_str, "%d %d %d colormap failed\n",			   nr, ng, nb);		  return gdk_rgb_cmap_fail (tmp_str,					    cmap, pixels);		}	      pixels[i] = color.pixel;	    }#ifdef VERBOSE	  g_print ("%d: %lx\n", i, pixels[i]);#endif	}  image_info->nred_shades = nr;  image_info->ngreen_shades = ng;  image_info->nblue_shades = nb;  gdk_rgb_make_colorcube (pixels, nr, ng, nb);  gdk_rgb_make_colorcube_d (pixels, nr, ng, nb);  return TRUE;}/* Return TRUE on success. */static gbooleangdk_rgb_do_colormaps (void){  static const gint sizes[][3] = {    /*    { 6, 7, 6 }, */    { 6, 6, 6 },     { 6, 6, 5 },     { 6, 6, 4 },     { 5, 5, 5 },     { 5, 5, 4 },     { 4, 4, 4 },     { 4, 4, 3 },     { 3, 3, 3 },     { 2, 2, 2 }  };  static const gint n_sizes = sizeof(sizes) / (3 * sizeof(gint));  gint i;  for (i = 0; i < n_sizes; i++)    if (gdk_rgb_try_colormap (sizes[i][0], sizes[i][1], sizes[i][2]))      return TRUE;  return FALSE;}/* Make a 2 x 2 x 2 colorcube */static voidgdk_rgb_colorcube_222 (void){  int i;  GdkColor color;  GdkColormap *cmap;  if (image_info->cmap_alloced)    cmap = image_info->cmap;  else    cmap = gdk_colormap_get_system ();  colorcube_d = g_new (guchar, 512);  for (i = 0; i < 8; i++)    {      color.red = ((i & 4) >> 2) * 65535;      color.green = ((i & 2) >> 1) * 65535;      color.blue = (i & 1) * 65535;      gdk_color_alloc (cmap, &color);      colorcube_d[((i & 4) << 4) | ((i & 2) << 2) | (i & 1)] = color.pixel;    }}voidgdk_rgb_set_verbose (gboolean verbose){  gdk_rgb_verbose = verbose;}voidgdk_rgb_set_install (gboolean install){  gdk_rgb_install_cmap = install;}voidgdk_rgb_set_min_colors (gint min_colors)

⌨️ 快捷键说明

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