static GdkPixmap * scale_pixmap (GdkWindow *window, GdkPixmap *pixmap, gdouble scale_x, gdouble scale_y) { GdkGC *gc; GdkColormap *colormap; GdkColorContext *cc; GdkVisual *visual; GdkImage *image; GdkPixmap *new_pixmap; gint x, y, width, height, new_width, new_height; if(!pixmap) return NULL; if(!window) return NULL; gc = gdk_gc_new(pixmap); colormap = gdk_colormap_get_system (); visual = gdk_visual_get_system (); cc = gdk_color_context_new(visual, colormap); gdk_window_get_size(pixmap, &width, &height); if(scale_x == 1.0 && scale_y == 1.0){ new_pixmap = gdk_pixmap_new(window, width, height, -1); gdk_draw_pixmap(new_pixmap, gc, pixmap, 0, 0, 0, 0, width, height); return new_pixmap; } new_width = roundint(width * scale_x); new_height = roundint(height * scale_y); new_pixmap = gdk_pixmap_new(window, new_width, new_height, -1); image = gdk_image_get(pixmap, 0, 0, width, height); for(x = 0; x < new_width; x++){ for(y = 0; y < new_height; y++){ GdkColor color; gint px, py; px = MIN(roundint(x / scale_x), width - 1); py = MIN(roundint(y / scale_y), height - 1); color.pixel = gdk_image_get_pixel(image, px, py); gdk_color_context_query_color(cc, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_point(new_pixmap, gc, x, y); } } gdk_image_destroy(image); gdk_color_context_free(cc); return new_pixmap; }
void color_init(void) { GdkVisual *visual = gtk_widget_get_default_visual(); GdkColormap *colormap = gtk_widget_get_default_colormap(); color_context = gdk_color_context_new(visual, colormap); color_convert(&color_black, &color_gdk_black); color_convert(&color_white, &color_gdk_white); }