colorsel: Use gdk_pixbuf_get_from_drawable()

Instead of fiddling with GdkImage directly.
This commit is contained in:
Benjamin Otte 2010-07-13 22:12:50 +02:00
parent df120b78b3
commit 99c851c72d

View File

@ -1636,33 +1636,39 @@ grab_color_at_mouse (GdkScreen *screen,
gint y_root, gint y_root,
gpointer data) gpointer data)
{ {
GdkImage *image; GdkPixbuf *pixbuf;
guint32 pixel; guchar *pixels;
GtkColorSelection *colorsel = data; GtkColorSelection *colorsel = data;
ColorSelectionPrivate *priv; ColorSelectionPrivate *priv;
GdkColor color; GdkColor color;
GdkColormap *colormap = gdk_screen_get_system_colormap (screen);
GdkWindow *root_window = gdk_screen_get_root_window (screen); GdkWindow *root_window = gdk_screen_get_root_window (screen);
priv = colorsel->private_data; priv = colorsel->private_data;
image = gdk_drawable_get_image (root_window, x_root, y_root, 1, 1); pixbuf = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
if (!image) x_root, y_root,
0, 0,
1, 1);
if (!pixbuf)
{ {
gint x, y; gint x, y;
GdkDisplay *display = gdk_screen_get_display (screen); GdkDisplay *display = gdk_screen_get_display (screen);
GdkWindow *window = gdk_display_get_window_at_pointer (display, &x, &y); GdkWindow *window = gdk_display_get_window_at_pointer (display, &x, &y);
if (!window) if (!window)
return; return;
image = gdk_drawable_get_image (window, x, y, 1, 1); pixbuf = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
if (!image) x, y,
0, 0,
1, 1);
if (!pixbuf)
return; return;
} }
pixel = gdk_image_get_pixel (image, 0, 0); pixels = gdk_pixbuf_get_pixels (pixbuf);
g_object_unref (image); color.red = pixels[0] * 0x101;
color.green = pixels[1] * 0x101;
color.blue = pixels[2] * 0x101;
g_object_unref (pixbuf);
gdk_colormap_query_color (colormap, pixel, &color);
priv->color[COLORSEL_RED] = SCALE (color.red); priv->color[COLORSEL_RED] = SCALE (color.red);
priv->color[COLORSEL_GREEN] = SCALE (color.green); priv->color[COLORSEL_GREEN] = SCALE (color.green);
priv->color[COLORSEL_BLUE] = SCALE (color.blue); priv->color[COLORSEL_BLUE] = SCALE (color.blue);