static gint
gdk_rgb_cmap_fail (const char *msg, GdkColormap *cmap, gulong *pixels)
{
- gulong free_pixels[256];
+ GdkColor free_colors[256];
gint n_free;
gint i;
n_free = 0;
for (i = 0; i < 256; i++)
if (pixels[i] < 256)
- free_pixels[n_free++] = pixels[i];
+ free_colors[n_free++].pixel = pixels[i];
if (n_free)
- gdk_colors_free (cmap, free_pixels, n_free, 0);
+ gdk_colormap_free_colors (cmap, free_colors, n_free);
return 0;
}
{
image_info->colorcube[i] = pixels[rt[i >> 8] + gt[(i >> 4) & 0x0f] + bt[i & 0x0f]];
#ifdef VERBOSE
- g_print ("%03x %02x %x %x %x\n", i, image-info->colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
+ g_print ("%03x %02x %x %x %x\n", i, image_info->colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
#endif
}
}
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_colormap_alloc_color (cmap, &color, FALSE, FALSE))
- return gdk_rgb_cmap_fail ("error allocating system color\n",
- cmap, pixels);
- pixels[idx] = color.pixel; /* which is almost certainly i */
- best[idx] = d2;
- }
+ if (d2 < best[idx])
+ {
+ if (pixels[idx] < 256)
+ {
+ color.pixel = pixels[idx];
+ gdk_colormap_free_colors (cmap, &color, 1);
+ }
+ else
+ colors_needed--;
+ color = cmap->colors[i];
+ if (!gdk_colormap_alloc_color (cmap, &color, FALSE, FALSE))
+ 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 (colors_needed &&
+ image_info->visual->type != GDK_VISUAL_STATIC_COLOR)
{
if (!gdk_colors_alloc (cmap, 0, NULL, 0, junk, colors_needed))
{
gdk_rgb_cmap_free (image_info->gray_cmap);
if (image_info->own_gc)
- gdk_gc_unref (image_info->own_gc);
+ g_object_unref (image_info->own_gc);
if (image_info->colorcube)
g_free (image_info->colorcube);
image_info->visual->depth >= 3))
{
if (!image_info->cmap)
- image_info->cmap = gdk_colormap_ref (gdk_screen_get_system_colormap (screen));
+ image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
gdk_rgb_colorcube_222 (image_info);
}
- else if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR)
+ else if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR
+ || image_info->visual->type == GDK_VISUAL_STATIC_COLOR)
{
if (!image_info->cmap &&
(gdk_rgb_install_cmap || image_info->visual != gdk_screen_get_system_visual (screen)))
image_info->nblue_shades);
if (!image_info->cmap)
- image_info->cmap = gdk_colormap_ref (gdk_screen_get_system_colormap (screen));
+ image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
}
#ifdef ENABLE_GRAYSCALE
else if (image_info->visual->type == GDK_VISUAL_GRAYSCALE)
/* Always install colormap in direct color. */
if (image_info->visual->type != GDK_VISUAL_DIRECT_COLOR &&
image_info->visual == gdk_screen_get_system_visual (screen))
- image_info->cmap = gdk_colormap_ref (gdk_screen_get_system_colormap (screen));
+ image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
else
{
image_info->cmap = gdk_colormap_new (image_info->visual, FALSE);
guint32 g = rgb & 0xff00;
guint32 b = rgb & 0xff;
- return gdk_rgb_xpixel_from_rgb_internal (gdk_screen_get_rgb_colormap (gdk_get_default_screen ()),
+ return gdk_rgb_xpixel_from_rgb_internal (gdk_screen_get_rgb_colormap (gdk_screen_get_default ()),
(r >> 8) + (r >> 16), g + (g >> 8), b + (b << 8));
}
}
else if (bpp == 8 &&
depth <= 8 &&
+ depth > 4 &&
(vtype == GDK_VISUAL_PSEUDO_COLOR
+ || vtype == GDK_VISUAL_STATIC_COLOR
#ifdef ENABLE_GRAYSCALE
|| vtype == GDK_VISUAL_GRAYSCALE
#endif
if (image_info->bitmap)
{
if (image_info->own_gc == NULL)
- {
- GdkColor color;
-
- image_info->own_gc = gdk_gc_new (drawable);
- gdk_color_white (image_info->cmap, &color);
- gdk_gc_set_foreground (image_info->own_gc, &color);
- gdk_color_black (image_info->cmap, &color);
- gdk_gc_set_background (image_info->own_gc, &color);
- }
+ image_info->own_gc = gdk_gc_new (drawable);
gc = image_info->own_gc;
}
for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT)
if (image_info->bpp == 1 &&
image_info->gray_cmap == NULL &&
(image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
+ image_info->visual->type == GDK_VISUAL_STATIC_COLOR ||
image_info->visual->type == GDK_VISUAL_GRAYSCALE))
gdk_rgb_make_gray_cmap (image_info);
int i, j;
guint32 rgb;
- /* We only need a LUT for pseudo-color and grayscale cmaps */
+ /* We don't need a LUT for TrueColor or DirectColor visuals */
if (image_info->bpp != 1 ||
!(image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
+ image_info->visual->type == GDK_VISUAL_STATIC_COLOR ||
image_info->visual->type == GDK_VISUAL_GRAYSCALE))
return NULL;
((rgb & 0xf000) >> 8) |
((rgb & 0xf0) >> 4);
#ifdef VERBOSE
- g_print ("%d %x %x %d\n", i, j, image_info->colorcube[j]);
+ g_print ("%d %x %x\n", i, j, image_info->colorcube[j]);
#endif
cmap_info->lut[i] = image_info->colorcube[j];
}
GdkRgbCmapInfo *cmap_info = tmp_list->data;
cmap_info->image_info->cmap_info_list = g_slist_remove (cmap_info->image_info->cmap_info_list, cmap_info);
g_free (cmap_info);
+ tmp_list = tmp_list->next;
}
g_slist_free (cmap->info_list);
static GdkColormap *cmap = NULL;
if (!cmap)
{
- GdkRgbInfo *image_info = gdk_rgb_create_info (gdk_rgb_choose_visual (gdk_get_default_screen ()), NULL);
+ GdkRgbInfo *image_info = gdk_rgb_create_info (gdk_rgb_choose_visual (gdk_screen_get_default ()), NULL);
cmap = image_info->cmap;
}
GdkVisual *
gdk_rgb_get_visual (void)
{
- return gdk_screen_get_rgb_visual (gdk_get_default_screen ());
+ return gdk_screen_get_rgb_visual (gdk_screen_get_default ());
}