/** * gwy_data_view_get_pixbuf: * @data_view: A #GwyDataView. * @max_width: Pixbuf width that should not be exceeeded. Value smaller than * 1 means unlimited size. * @max_height: Pixbuf height that should not be exceeeded. Value smaller than * 1 means unlimited size. * * Creates and returns a pixbuf from the data view. * * If the data is not square, the resulting pixbuf is also nonsquare, this is * different from gwy_data_view_get_thumbnail(). The returned pixbuf also * never has alpha channel. * * Returns: The pixbuf as a newly created #GdkPixbuf, it should be freed * when no longer needed. It is never larger than the actual data * size, as @max_width and @max_height are only upper limits. * * Since: 1.5 **/ GdkPixbuf* gwy_data_view_get_pixbuf(GwyDataView *data_view, gint max_width, gint max_height) { GdkPixbuf *pixbuf; gint width, height, width_scaled, height_scaled; gdouble xscale, yscale, scale; g_return_val_if_fail(GWY_IS_DATA_VIEW(data_view), NULL); g_return_val_if_fail(data_view->pixbuf, NULL); width = gdk_pixbuf_get_width(data_view->pixbuf); height = gdk_pixbuf_get_height(data_view->pixbuf); xscale = (max_width > 0) ? (gdouble)max_width/width : 1.0; yscale = (max_height > 0) ? (gdouble)max_height/height : 1.0; scale = MIN(MIN(xscale, yscale), 1.0); width_scaled = (gint)(scale*width); height_scaled = (gint)(scale*height); if (max_width) width_scaled = CLAMP(width_scaled, 1, max_width); if (max_height) height_scaled = CLAMP(height_scaled, 1, max_height); pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, BITS_PER_SAMPLE, width_scaled, height_scaled); gwy_debug_objects_creation(G_OBJECT(pixbuf)); gdk_pixbuf_scale(data_view->pixbuf, pixbuf, 0, 0, width_scaled, height_scaled, 0.0, 0.0, scale, scale, GDK_INTERP_TILES); return pixbuf; }
static GdkPixbuf * scale_and_crop_pixbuf (const GdkPixbuf *source, HDImageSize *destination_size) { HDImageSize image_size; double scale; GdkPixbuf *pixbuf; image_size.width = gdk_pixbuf_get_width (source); image_size.height = gdk_pixbuf_get_height (source); scale = get_scale_for_aspect_ratio (&image_size, destination_size); pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (source), gdk_pixbuf_get_has_alpha (source), gdk_pixbuf_get_bits_per_sample (source), destination_size->width, destination_size->height); gdk_pixbuf_scale (source, pixbuf, 0, 0, destination_size->width, destination_size->height, - (image_size.width * scale - destination_size->width) / 2, - (image_size.height * scale - destination_size->height) / 2, scale, scale, GDK_INTERP_BILINEAR); return pixbuf; }
void stickynotes_applet_update_icon(StickyNotesApplet *applet) { GdkPixbuf *pixbuf1, *pixbuf2; gint size = applet->panel_size; if (size > 3) size = size -3; /* Choose appropriate icon and size it */ if (applet->prelighted) pixbuf1 = gdk_pixbuf_scale_simple(stickynotes->icon_prelight, size, size, GDK_INTERP_BILINEAR); else pixbuf1 = gdk_pixbuf_scale_simple(stickynotes->icon_normal, size, size, GDK_INTERP_BILINEAR); /* Shift the icon if pressed */ pixbuf2 = gdk_pixbuf_copy(pixbuf1); if (applet->pressed) gdk_pixbuf_scale(pixbuf1, pixbuf2, 0, 0, size, size, 1, 1, 1, 1, GDK_INTERP_BILINEAR); /* Apply the finished pixbuf to the applet image */ gtk_image_set_from_pixbuf(GTK_IMAGE(applet->w_image), pixbuf2); g_object_unref(pixbuf1); g_object_unref(pixbuf2); }
static GdkPixbuf * avatar_create_pixbuf (TwituxAvatar *avatar, gint size) { GdkPixbuf *tmp_pixbuf; GdkPixbuf *ret_pixbuf; GdkPixbufLoader *loader; GError *error = NULL; int orig_width; int orig_height; int scale_width; int scale_height; if (!avatar) { return NULL; } loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) { g_warning ("Couldn't write avatar image: %p with " "length: %" G_GSIZE_FORMAT " to pixbuf loader: %s", avatar->data, avatar->len, error->message); g_error_free (error); return NULL; } gdk_pixbuf_loader_close (loader, NULL); tmp_pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); scale_width = orig_width = gdk_pixbuf_get_width (tmp_pixbuf); scale_height = orig_height = gdk_pixbuf_get_height (tmp_pixbuf); if (scale_height > scale_width) { scale_width = (gdouble) size * (gdouble) scale_width / (double) scale_height; scale_height = size; } else { scale_height = (gdouble) size * (gdouble) scale_height / (gdouble) scale_width; scale_width = size; } ret_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 32, 32); gdk_pixbuf_fill (ret_pixbuf, 0x00000000); gdk_pixbuf_scale (tmp_pixbuf, ret_pixbuf, (size - scale_width)/2, (size - scale_height)/2, scale_width, scale_height, (size - scale_width)/2, (size - scale_height)/2, (double)scale_width/(double)orig_width, (double)scale_height/(double)orig_height, GDK_INTERP_BILINEAR); if (avatar_pixbuf_is_opaque (ret_pixbuf)) { avatar_pixbuf_roundify (ret_pixbuf); } g_object_unref (loader); return ret_pixbuf; }
/** * gdk_pixbuf_copy_area: * @src_pixbuf: Source pixbuf. * @src_x: Source X coordinate within @src_pixbuf. * @src_y: Source Y coordinate within @src_pixbuf. * @width: Width of the area to copy. * @height: Height of the area to copy. * @dest_pixbuf: Destination pixbuf. * @dest_x: X coordinate within @dest_pixbuf. * @dest_y: Y coordinate within @dest_pixbuf. * * Copies a rectangular area from @src_pixbuf to @dest_pixbuf. Conversion of * pixbuf formats is done automatically. * * If the source rectangle overlaps the destination rectangle on the * same pixbuf, it will be overwritten during the copy operation. * Therefore, you can not use this function to scroll a pixbuf. **/ void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf, int src_x, int src_y, int width, int height, GdkPixbuf *dest_pixbuf, int dest_x, int dest_y) { g_return_if_fail (src_pixbuf != NULL); g_return_if_fail (dest_pixbuf != NULL); g_return_if_fail (src_x >= 0 && src_x + width <= src_pixbuf->width); g_return_if_fail (src_y >= 0 && src_y + height <= src_pixbuf->height); g_return_if_fail (dest_x >= 0 && dest_x + width <= dest_pixbuf->width); g_return_if_fail (dest_y >= 0 && dest_y + height <= dest_pixbuf->height); g_return_if_fail (!(gdk_pixbuf_get_has_alpha (src_pixbuf) && !gdk_pixbuf_get_has_alpha (dest_pixbuf))); /* This will perform format conversions automatically */ gdk_pixbuf_scale (src_pixbuf, dest_pixbuf, dest_x, dest_y, width, height, (double) (dest_x - src_x), (double) (dest_y - src_y), 1.0, 1.0, GDK_INTERP_NEAREST); }
/** * gwy_data_view_get_thumbnail: * @data_view: A #GwyDataView. * @size: Requested thumbnail size. * * Creates and returns a thumbnail of the data view. * * If the data is not square, it is centered onto the pixbuf, with transparent * borders. The returned pixbuf always has an alpha channel, even if it fits * exactly. * * Returns: The thumbnail as a newly created #GdkPixbuf, which should be freed * when no longer needed. **/ GdkPixbuf* gwy_data_view_get_thumbnail(GwyDataView *data_view, gint size) { GdkPixbuf *pixbuf; gint width, height, width_scaled, height_scaled; gdouble scale; g_return_val_if_fail(GWY_IS_DATA_VIEW(data_view), NULL); g_return_val_if_fail(data_view->pixbuf, NULL); g_return_val_if_fail(size > 0, NULL); pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, BITS_PER_SAMPLE, size, size); gwy_debug_objects_creation(G_OBJECT(pixbuf)); gdk_pixbuf_fill(pixbuf, 0x00000000); width = gdk_pixbuf_get_width(data_view->pixbuf); height = gdk_pixbuf_get_height(data_view->pixbuf); scale = MIN((gdouble)size/width, (gdouble)size/height); width_scaled = CLAMP((gint)(scale*width), 1, size); height_scaled = CLAMP((gint)(scale*height), 1, size); gdk_pixbuf_scale(data_view->pixbuf, pixbuf, (size - width_scaled)/2, (size - height_scaled)/2, width_scaled, height_scaled, (size - width_scaled)/2, (size - height_scaled)/2, scale, scale, GDK_INTERP_TILES); return pixbuf; }
/** * gdk_pixbuf_scale_simple: * @src: a #GdkPixbuf * @dest_width: the width of destination image * @dest_height: the height of destination image * @interp_type: the interpolation type for the transformation. * * Create a new #GdkPixbuf containing a copy of @src scaled to * @dest_width x @dest_height. Leaves @src unaffected. @interp_type * should be #GDK_INTERP_NEAREST if you want maximum speed (but when * scaling down #GDK_INTERP_NEAREST is usually unusably ugly). The * default @interp_type should be #GDK_INTERP_BILINEAR which offers * reasonable quality and speed. * * You can scale a sub-portion of @src by creating a sub-pixbuf * pointing into @src; see gdk_pixbuf_new_subpixbuf(). * * If @dest_width and @dest_height are equal to the @src width and height, a * copy of @src is returned, avoiding any scaling. * * For more complicated scaling/alpha blending see gdk_pixbuf_scale() * and gdk_pixbuf_composite(). * * Return value: (nullable) (transfer full): the new #GdkPixbuf, or %NULL if not enough memory could be * allocated for it. **/ GdkPixbuf * gdk_pixbuf_scale_simple (const GdkPixbuf *src, int dest_width, int dest_height, GdkInterpType interp_type) { GdkPixbuf *dest; g_return_val_if_fail (GDK_IS_PIXBUF (src), NULL); g_return_val_if_fail (dest_width > 0, NULL); g_return_val_if_fail (dest_height > 0, NULL); /* Fast path. */ if (dest_width == src->width && dest_height == src->height) return gdk_pixbuf_copy (src); dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height); if (!dest) return NULL; gdk_pixbuf_scale (src, dest, 0, 0, dest_width, dest_height, 0, 0, (double) dest_width / src->width, (double) dest_height / src->height, interp_type); return dest; }
static GstFlowReturn gst_pixbufscale_transform_frame (GstVideoFilter * filter, GstVideoFrame * in, GstVideoFrame * out) { GstPixbufScale *scale; GdkPixbuf *src_pixbuf, *dest_pixbuf; scale = GST_PIXBUFSCALE (filter); src_pixbuf = gdk_pixbuf_new_from_data (GST_VIDEO_FRAME_COMP_DATA (in, 0), GDK_COLORSPACE_RGB, FALSE, 8, GST_VIDEO_FRAME_WIDTH (in), GST_VIDEO_FRAME_HEIGHT (in), GST_VIDEO_FRAME_COMP_STRIDE (in, 0), NULL, NULL); dest_pixbuf = gdk_pixbuf_new_from_data (GST_VIDEO_FRAME_COMP_DATA (out, 0), GDK_COLORSPACE_RGB, FALSE, 8, GST_VIDEO_FRAME_WIDTH (out), GST_VIDEO_FRAME_HEIGHT (out), GST_VIDEO_FRAME_COMP_STRIDE (out, 0), NULL, NULL); gdk_pixbuf_scale (src_pixbuf, dest_pixbuf, 0, 0, GST_VIDEO_FRAME_WIDTH (out), GST_VIDEO_FRAME_HEIGHT (out), 0, 0, (double) GST_VIDEO_FRAME_WIDTH (out) / GST_VIDEO_FRAME_WIDTH (in), (double) GST_VIDEO_FRAME_HEIGHT (out) / GST_VIDEO_FRAME_HEIGHT (in), scale->gdk_method); g_object_unref (src_pixbuf); g_object_unref (dest_pixbuf); return GST_FLOW_OK; }
static void _mt_draw_image(MT_WINDOW *win, MT_GC *gc, MT_IMAGE *img, int xsrc, int ysrc, int wsrc, int hsrc, int xdest, int ydest, int width, int height) { GdkPixbuf *pixbuf = (GdkPixbuf *)img; GdkPixbuf *pixbuf2 = NULL; /* scale if needed: */ if (wsrc != width || hsrc != height) { double scale_x = (double)width / (double)wsrc; double scale_y = (double)height / (double)hsrc; pixbuf2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); gdk_pixbuf_scale(pixbuf, pixbuf2, 0, 0, width, height, -xsrc * scale_x, -ysrc * scale_y, scale_x, scale_y, GDK_INTERP_NEAREST); pixbuf = pixbuf2; xsrc = 0; ysrc = 0; } _set_clipping(gc); gdk_draw_pixbuf((GdkWindow *)win, ((MT_GTK_GC *)gc)->gc, pixbuf, xsrc, ysrc, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0); _unset_clipping(gc); if (pixbuf2) { gdk_pixbuf_unref(pixbuf2); } }
static void config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data) { GdkPixbuf *pixbuf; pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf"); #if 0 if (((event->width) != gdk_pixbuf_get_width (pixbuf)) || ((event->height) != gdk_pixbuf_get_height (pixbuf))) gdk_pixbuf_scale(pixbuf, event->width, event->height); #endif }
static void simple_gdk_pixbuf_scale_or_copy(GdkPixbuf *source, GdkPixbuf *dest) { gint height, width, src_height, src_width; src_height = gdk_pixbuf_get_height(source); src_width = gdk_pixbuf_get_width(source); height = gdk_pixbuf_get_height(dest); width = gdk_pixbuf_get_width(dest); if (src_width == width && src_height == height) gdk_pixbuf_copy_area(source, 0, 0, src_width, src_height, dest, 0, 0); else gdk_pixbuf_scale(source, dest, 0, 0, width, height, 0.0, 0.0, (gdouble)width/src_width, (gdouble)height/src_height, GDK_INTERP_TILES); }
/** * gdk_pixbuf_scale_simple: * @src: a #GdkPixbuf * @dest_width: the width of destination image * @dest_height: the height of destination image * @interp_type: the interpolation type for the transformation. * * Create a new #GdkPixbuf containing a copy of @src scaled to * @dest_width x @dest_height. Leaves @src unaffected. @interp_type * should be #GDK_INTERP_NEAREST if you want maximum speed (but when * scaling down #GDK_INTERP_NEAREST is usually unusably ugly). The * default @interp_type should be #GDK_INTERP_BILINEAR which offers * reasonable quality and speed. * * You can scale a sub-portion of @src by creating a sub-pixbuf * pointing into @src; see gdk_pixbuf_new_subpixbuf(). * * For more complicated scaling/compositing see gdk_pixbuf_scale() * and gdk_pixbuf_composite(). * * Return value: the new #GdkPixbuf, or %NULL if not enough memory could be * allocated for it. **/ GdkPixbuf * gdk_pixbuf_scale_simple (const GdkPixbuf *src, int dest_width, int dest_height, GdkInterpType interp_type) { GdkPixbuf *dest; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (dest_width > 0, NULL); g_return_val_if_fail (dest_height > 0, NULL); dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height); if (!dest) return NULL; gdk_pixbuf_scale (src, dest, 0, 0, dest_width, dest_height, 0, 0, (double) dest_width / src->width, (double) dest_height / src->height, interp_type); return dest; }
/* utility to make an attractive pattern image by compositing with a frame */ GdkPixbuf* nautilus_customization_make_pattern_chit (GdkPixbuf *pattern_tile, GdkPixbuf *frame, gboolean dragging, gboolean is_reset) { GdkPixbuf *pixbuf, *temp_pixbuf; int frame_width, frame_height; int pattern_width, pattern_height; g_assert (pattern_tile != NULL); g_assert (frame != NULL); frame_width = gdk_pixbuf_get_width (frame); frame_height = gdk_pixbuf_get_height (frame); pattern_width = gdk_pixbuf_get_width (pattern_tile); pattern_height = gdk_pixbuf_get_height (pattern_tile); pixbuf = gdk_pixbuf_copy (frame); /* scale the pattern tile to the proper size */ gdk_pixbuf_scale (pattern_tile, pixbuf, 2, 2, frame_width - 8, frame_height - 8, 0, 0, (double)(frame_width - 8 + 1)/pattern_width, (double)(frame_height - 8 + 1)/pattern_height, GDK_INTERP_BILINEAR); /* if we're dragging, get rid of the light-colored halo */ if (dragging) { temp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, frame_width - 8, frame_height - 8); gdk_pixbuf_copy_area (pixbuf, 2, 2, frame_width - 8, frame_height - 8, temp_pixbuf, 0, 0); g_object_unref (pixbuf); pixbuf = temp_pixbuf; } return pixbuf; }
GdkPixbuf* hybrid_create_round_pixbuf(const guchar *pixbuf_data, gint pixbuf_len, gint scale_size) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; GdkPixbuf *newpixbuf; gint orig_width; gint orig_height; guchar *default_pixbuf_data; gsize default_pixbuf_size; loader = gdk_pixbuf_loader_new(); if (!pixbuf_data || pixbuf_len == 0) { /**< Load the default. */ g_file_get_contents(PIXMAPS_DIR"icons/icon.png", (gchar**)&default_pixbuf_data, &default_pixbuf_size, NULL); gdk_pixbuf_loader_write(loader, default_pixbuf_data, default_pixbuf_size, NULL); g_free(default_pixbuf_data); } else { gdk_pixbuf_loader_write(loader, pixbuf_data, pixbuf_len, NULL); } gdk_pixbuf_loader_close(loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); if (pixbuf) { g_object_ref(loader); } g_object_unref(loader); if (!pixbuf) { hybrid_debug_error("blist", "get pixbuf from loader"); return NULL; } orig_width = gdk_pixbuf_get_width(pixbuf); orig_height = gdk_pixbuf_get_height(pixbuf); newpixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, scale_size, scale_size); gdk_pixbuf_fill(newpixbuf, 0x00000000); gdk_pixbuf_scale(pixbuf, newpixbuf, 0, 0, scale_size, scale_size, 0, 0, (double)scale_size/(double)orig_width, (double)scale_size/(double)orig_height, GDK_INTERP_BILINEAR); g_object_unref(pixbuf); if (pixbuf_is_opaque(newpixbuf)) { pixbuf_make_round(newpixbuf); } pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, scale_size, scale_size); gdk_pixbuf_fill(pixbuf, 0x00000000); gdk_pixbuf_copy_area(newpixbuf, 0, 0, scale_size, scale_size, pixbuf, 0, 0); g_object_unref(newpixbuf); return pixbuf; }
/** * Creates the "Fonts & logo" tab. This function creates some buttons * that are borrowed from applications like gedit. * * \returns A newly allocated vbox */ GtkWidget * onglet_display_fonts ( void ) { GtkWidget *hbox, *vbox_pref, *label, *paddingbox, *font_button; GtkWidget *check_button, *vbox; GdkPixbuf * pixbuf = NULL; GtkWidget *button; GtkWidget *color_combobox; GtkWidget *color_button; vbox_pref = new_vbox_with_title_and_icon ( _("Fonts & logo"), "fonts.png" ); /* Change Grisbi Logo */ paddingbox = new_paddingbox_with_title ( vbox_pref, FALSE, _("Grisbi logo") ); hbox = gtk_hbox_new ( FALSE, 5 ); gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, FALSE, 0 ); check_button = gtk_check_button_new_with_label ( _("Display a logo")); gtk_box_pack_start ( GTK_BOX ( hbox ), check_button, FALSE, FALSE, 0 ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ), etat.utilise_logo ); hbox = gtk_hbox_new ( FALSE, 5 ); gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, FALSE, 0 ); /* le logo est grisé ou non suivant qu'on l'utilise ou pas */ gtk_widget_set_sensitive ( hbox, etat.utilise_logo ); g_signal_connect ( G_OBJECT ( check_button ), "toggled", G_CALLBACK ( change_choix_utilise_logo ), hbox ); logo_button = gtk_button_new (); gtk_button_set_relief ( GTK_BUTTON ( logo_button ), GTK_RELIEF_NONE ); pixbuf = gsb_select_icon_get_logo_pixbuf ( ); if (!pixbuf) { preview = gtk_image_new_from_pixbuf ( gsb_select_icon_get_default_logo_pixbuf ( ) ); } else { if ( gdk_pixbuf_get_width(pixbuf) > 64 || gdk_pixbuf_get_height(pixbuf) > 64 ) { GdkPixbuf * tmp; tmp = gdk_pixbuf_new ( GDK_COLORSPACE_RGB, TRUE, 8, gdk_pixbuf_get_width(pixbuf)/2, gdk_pixbuf_get_height(pixbuf)/2 ); gdk_pixbuf_scale ( pixbuf, tmp, 0, 0, gdk_pixbuf_get_width(pixbuf)/2, gdk_pixbuf_get_height(pixbuf)/2, 0, 0, 0.5, 0.5, GDK_INTERP_HYPER ); pixbuf = tmp; } preview = gtk_image_new_from_pixbuf (pixbuf); } gtk_container_add (GTK_CONTAINER(logo_button), preview); g_signal_connect_swapped ( G_OBJECT ( logo_button ), "clicked", G_CALLBACK ( modification_logo_accueil ), NULL ); gtk_box_pack_start ( GTK_BOX ( hbox ), logo_button, FALSE, FALSE, 0 ); label = gtk_label_new ( _("Click on preview to change logo") ); gtk_box_pack_start ( GTK_BOX ( hbox ), label, FALSE, FALSE, 0 ); /* Change fonts */ paddingbox = new_paddingbox_with_title ( vbox_pref, FALSE, _("Fonts") ); hbox = gtk_hbox_new ( FALSE, 10 ); gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, FALSE, 0 ); check_button = gtk_check_button_new_with_label ( _("Use a custom font for the transactions: ")); gtk_box_pack_start ( GTK_BOX ( hbox ), check_button, FALSE, FALSE, 0 ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check_button ), conf.utilise_fonte_listes ); /* on crée la vbox qui contiendra la font button et le raz */ vbox = gtk_vbox_new ( FALSE, 10 ); gtk_box_pack_start ( GTK_BOX ( hbox ), vbox, FALSE, FALSE, 0 ); gtk_widget_set_sensitive ( vbox, conf.utilise_fonte_listes ); g_signal_connect ( G_OBJECT ( check_button ), "toggled", G_CALLBACK ( change_choix_utilise_fonte_liste ), vbox ); /* Create font button */ font_button = utils_font_create_button ( &conf.font_string, G_CALLBACK (update_fonte_listes), NULL); gtk_box_pack_start ( GTK_BOX (vbox), font_button, FALSE, FALSE, 0 ); if ( !gsb_data_account_get_accounts_amount () ) { gtk_widget_set_sensitive ( vbox_pref, FALSE ); } /* change colors */ paddingbox = new_paddingbox_with_title ( vbox_pref, FALSE, _("Colors") ); vbox = gtk_vbox_new ( FALSE, 10 ); gtk_box_pack_start ( GTK_BOX ( paddingbox ), vbox, FALSE, FALSE, 10 ); hbox = gtk_hbox_new ( FALSE, 10 ); gtk_box_pack_start ( GTK_BOX ( vbox ), hbox, FALSE, FALSE, 10 ); color_combobox = gsb_color_create_color_combobox ( ); gtk_box_pack_start ( GTK_BOX (hbox), color_combobox, FALSE, FALSE, 0); color_button = gtk_color_button_new (); gtk_color_button_set_title ( GTK_COLOR_BUTTON(color_button), _("Choosing color") ); g_signal_connect ( G_OBJECT (color_button), "color-set", G_CALLBACK (preferences_view_color_changed), G_OBJECT (color_combobox)); gtk_box_pack_start ( GTK_BOX (hbox), color_button, FALSE, FALSE, 0); /* connect the color button to the combobox if changed */ g_signal_connect ( G_OBJECT (color_combobox), "changed", G_CALLBACK (preferences_view_color_combobox_changed), G_OBJECT (color_button)); button = gtk_button_new_with_label (_("Back to default")); g_signal_connect ( G_OBJECT (button), "clicked", G_CALLBACK (preferences_view_color_default), G_OBJECT (color_combobox)); gtk_box_pack_start ( GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_combo_box_set_active ( GTK_COMBO_BOX (color_combobox), 0); return vbox_pref; }
static GdkPixbuf * add_holes_to_pixbuf_large (GdkPixbuf *pixbuf, int size) { char *filename; int lh, lw, rh, rw, i; GdkPixbuf *left, *right, *small; int canvas_w, canvas_h; int d_height, d_width; double ratio; filename = g_build_filename (DATADIR, "xplayer", "filmholes-big-left.png", NULL); left = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); if (left == NULL) { g_object_ref (pixbuf); return pixbuf; } filename = g_build_filename (DATADIR, "xplayer", "filmholes-big-right.png", NULL); right = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); if (right == NULL) { g_object_unref (left); g_object_ref (pixbuf); return pixbuf; } lh = gdk_pixbuf_get_height (left); lw = gdk_pixbuf_get_width (left); rh = gdk_pixbuf_get_height (right); rw = gdk_pixbuf_get_width (right); g_assert (lh == rh); g_assert (lw == rw); { int height, width; height = gdk_pixbuf_get_height (pixbuf); width = gdk_pixbuf_get_width (pixbuf); if (width > height) { d_width = size - lw - lw; d_height = d_width * height / width; } else { d_height = size - lw -lw; d_width = d_height * width / height; } canvas_h = d_height; canvas_w = d_width + 2 * lw; } small = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, canvas_w, canvas_h); gdk_pixbuf_fill (small, 0x000000ff); ratio = ((double)d_width / (double) gdk_pixbuf_get_width (pixbuf)); gdk_pixbuf_scale (pixbuf, small, lw, 0, d_width, d_height, lw, 0, ratio, ratio, GDK_INTERP_BILINEAR); /* Left side holes */ for (i = 0; i < canvas_h; i += lh) { gdk_pixbuf_composite (left, small, 0, i, MIN (canvas_w, lw), MIN (canvas_h - i, lh), 0, i, 1, 1, GDK_INTERP_NEAREST, 255); } /* Right side holes */ for (i = 0; i < canvas_h; i += rh) { gdk_pixbuf_composite (right, small, canvas_w - rw, i, MIN (canvas_w, rw), MIN (canvas_h - i, rh), canvas_w - rw, i, 1, 1, GDK_INTERP_NEAREST, 255); } /* TODO Add a one pixel border of 0x33333300 all around */ return small; }
void load_tile( gchar *dir, int zoom, int x, int y, int offset_x, int offset_y) { int detail_zoom = global_detail_zoom; /* round (dpi/96.0) */ int detail_scale = (int) pow (2.0, (float) detail_zoom); int overzoom = 0; int upscale = 1; gboolean hash_not_found = TRUE; static gchar filename[256]; static gchar wanted_filename[256]; GdkPixbuf *pixbuf = NULL; repo_t *repo; tile_hash_t *tile_hash; if(gc_map) g_object_unref(gc_map); if(pixmap) { gc_map = gdk_gc_new(pixmap); } else printf("no drawable -> NULL\n"); upscale = detail_scale; zoom -= detail_zoom; g_snprintf(wanted_filename, 255, "%s/%u/%u/%u.png", dir, zoom, x, y); tile_hash = g_hash_table_lookup(hash_table, wanted_filename); if(tile_hash) { pixbuf = tile_hash->pixbuf; tile_hash->reused = TRUE; hash_not_found = FALSE; } else { for(overzoom=0; overzoom<=3; overzoom++) { g_snprintf(filename, 255, "%s/%u/%u/%u.png", dir, zoom-overzoom, x/upscale, y/upscale); pixbuf = gdk_pixbuf_new_from_file (filename, NULL); if(pixbuf) break; upscale *= 2; } if(pixbuf && upscale > 1) { GdkPixbuf *pixbuf_scaled = NULL; pixbuf_scaled = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 256, 256); gdk_pixbuf_scale ( pixbuf, pixbuf_scaled, 0, 0, TILESIZE, TILESIZE, -TILESIZE*(x%upscale), -TILESIZE*(y%upscale), upscale, upscale, GDK_INTERP_BILINEAR ); if (pixbuf) { g_object_unref (pixbuf); } pixbuf = pixbuf_scaled; } } if(!pixbuf) { GtkWidget *widget; widget = lookup_widget(window1, "drawingarea1"); gdk_draw_rectangle ( pixmap, widget->style->white_gc, TRUE, offset_x, offset_y, 256, 256); gtk_widget_queue_draw_area ( widget, offset_x,offset_y,256,256); } else { gdk_draw_pixbuf ( pixmap, gc_map, pixbuf, 0,0, offset_x,offset_y, TILESIZE,TILESIZE, GDK_RGB_DITHER_NONE, 0, 0); if(hash_not_found) { tile_hash = g_new0(tile_hash_t,1); tile_hash->pixbuf = pixbuf; tile_hash->reused = TRUE; g_hash_table_insert(hash_table, g_strdup(wanted_filename), tile_hash); } } drawingarea11 = lookup_widget(window1, "drawingarea1"); gtk_widget_queue_draw_area ( drawingarea11, offset_x,offset_y, TILESIZE,TILESIZE); if(overzoom && global_auto_download) { repo = global_curr_repo->data; download_tile(repo,zoom,x/detail_scale,y/detail_scale); } }
static void mouse_settings_themes_preview_image (const gchar *path, GtkImage *image) { GdkPixbuf *pixbuf; GdkPixbuf *preview; guint i, position; gchar *filename; gint dest_x, dest_y; /* create an empty preview image */ preview = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (PREVIEW_SIZE + PREVIEW_SPACING) * PREVIEW_COLUMNS - PREVIEW_SPACING, (PREVIEW_SIZE + PREVIEW_SPACING) * PREVIEW_ROWS - PREVIEW_SPACING); if (G_LIKELY (preview)) { /* make the pixbuf transparent */ gdk_pixbuf_fill (preview, 0x00000000); for (i = 0, position = 0; i < G_N_ELEMENTS (preview_names); i++) { /* create cursor filename and try to load the pixbuf */ filename = g_build_filename (path, preview_names[i], NULL); pixbuf = mouse_settings_themes_pixbuf_from_filename (filename, PREVIEW_SIZE); g_free (filename); if (G_LIKELY (pixbuf)) { /* calculate the icon position */ dest_x = (position % PREVIEW_COLUMNS) * (PREVIEW_SIZE + PREVIEW_SPACING); dest_y = (position / PREVIEW_COLUMNS) * (PREVIEW_SIZE + PREVIEW_SPACING); /* render it in the preview */ gdk_pixbuf_scale (pixbuf, preview, dest_x, dest_y, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), dest_x, dest_y, 1.00, 1.00, GDK_INTERP_BILINEAR); /* release the pixbuf */ g_object_unref (G_OBJECT (pixbuf)); /* break if we've added enough icons */ if (++position >= PREVIEW_ROWS * PREVIEW_COLUMNS) break; } } /* set the image */ gtk_image_set_from_pixbuf (GTK_IMAGE (image), preview); /* release the pixbuf */ g_object_unref (G_OBJECT (preview)); } else { /* clear the image */ gtk_image_clear (GTK_IMAGE (image)); } }
wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy ) { wxCHECK_MSG( Ok(), wxNullBitmap, wxT("invalid bitmap") ); if (newy==M_BMPDATA->m_width && newy==M_BMPDATA->m_height) return *this; int width = wxMax(newx, 1); int height = wxMax(newy, 1); width = wxMin(width, clipwidth); height = wxMin(height, clipheight); wxBitmap bmp; #ifdef __WXGTK20__ if (HasPixbuf()) { bmp.SetWidth(width); bmp.SetHeight(height); bmp.SetDepth(GetDepth()); bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha(GetPixbuf()), 8, width, height)); gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(), 0, 0, width, height, clipx, clipy, (double)newx/GetWidth(), (double)newy/GetHeight(), GDK_INTERP_BILINEAR); } else #endif // __WXGTK20__ { GdkImage *img = (GdkImage*) NULL; if (GetPixmap()) img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() ); else if (GetBitmap()) img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() ); else wxFAIL_MSG( wxT("Ill-formed bitmap") ); wxCHECK_MSG( img, wxNullBitmap, wxT("couldn't create image") ); int bpp = -1; GdkGC *gc = NULL; GdkPixmap *dstpix = NULL; if (GetPixmap()) { GdkVisual *visual = gdk_window_get_visual( GetPixmap() ); if (visual == NULL) visual = wxTheApp->GetGdkVisual(); bpp = visual->depth; bmp = wxBitmap(width,height,bpp); dstpix = bmp.GetPixmap(); gc = gdk_gc_new( dstpix ); } char *dst = NULL; long dstbyteperline = 0; if (GetBitmap()) { bpp = 1; dstbyteperline = width/8*M_BMPDATA->m_bpp; if (width*M_BMPDATA->m_bpp % 8 != 0) dstbyteperline++; dst = (char*) malloc(dstbyteperline*height); } // be careful to use the right scaling factor float scx = (float)M_BMPDATA->m_width/(float)newx; float scy = (float)M_BMPDATA->m_height/(float)newy; // prepare accel-tables int *tablex = (int *)calloc(width,sizeof(int)); int *tabley = (int *)calloc(height,sizeof(int)); // accel table filled with clipped values for (int x = 0; x < width; x++) tablex[x] = (int) (scx * (x+clipx)); for (int y = 0; y < height; y++) tabley[y] = (int) (scy * (y+clipy)); // Main rescaling routine starts here for (int h = 0; h < height; h++) { char outbyte = 0; int old_x = -1; guint32 old_pixval = 0; for (int w = 0; w < width; w++) { guint32 pixval; int x = tablex[w]; if (x == old_x) pixval = old_pixval; else { pixval = gdk_image_get_pixel( img, x, tabley[h] ); old_pixval = pixval; old_x = x; } if (bpp == 1) { if (!pixval) { char bit=1; char shift = bit << w % 8; outbyte |= shift; } if ((w+1)%8==0) { dst[h*dstbyteperline+w/8] = outbyte; outbyte = 0; } } else { GdkColor col; col.pixel = pixval; gdk_gc_set_foreground( gc, &col ); gdk_draw_point( dstpix, gc, w, h); } } // do not forget the last byte if ((bpp == 1) && (width % 8 != 0)) dst[h*dstbyteperline+width/8] = outbyte; } gdk_image_destroy( img ); if (gc) gdk_gc_unref( gc ); if (bpp == 1) { bmp = wxBitmap( (const char *)dst, width, height, 1 ); free( dst ); } if (GetMask()) { dstbyteperline = width/8; if (width % 8 != 0) dstbyteperline++; dst = (char*) malloc(dstbyteperline*height); img = gdk_image_get( GetMask()->GetBitmap(), 0, 0, GetWidth(), GetHeight() ); for (int h = 0; h < height; h++) { char outbyte = 0; int old_x = -1; guint32 old_pixval = 0; for (int w = 0; w < width; w++) { guint32 pixval; int x = tablex[w]; if (x == old_x) pixval = old_pixval; else { pixval = gdk_image_get_pixel( img, x, tabley[h] ); old_pixval = pixval; old_x = x; } if (pixval) { char bit=1; char shift = bit << w % 8; outbyte |= shift; } if ((w+1)%8 == 0) { dst[h*dstbyteperline+w/8] = outbyte; outbyte = 0; } } // do not forget the last byte if (width % 8 != 0) dst[h*dstbyteperline+width/8] = outbyte; } wxMask* mask = new wxMask; mask->m_bitmap = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) dst, width, height ); bmp.SetMask(mask); free( dst ); gdk_image_destroy( img ); } free( tablex ); free( tabley ); } return bmp; }
/* * update_pixbufs: * @area: a #UmCropArea * * Update the #GdkPixbuf objects inside @area, by darkening the regions outside * the current crop area. */ static void update_pixbufs (UmCropArea *area) { UmCropAreaPrivate *priv = um_crop_area_get_instance_private (area); gint width; gint height; GtkAllocation allocation; gdouble scale; gint dest_width, dest_height; GtkWidget *widget; widget = GTK_WIDGET (area); gtk_widget_get_allocation (widget, &allocation); width = gdk_pixbuf_get_width (priv->browse_pixbuf); height = gdk_pixbuf_get_height (priv->browse_pixbuf); scale = allocation.height / (gdouble)height; if (scale * width > allocation.width) scale = allocation.width / (gdouble)width; dest_width = width * scale; dest_height = height * scale; if (priv->pixbuf == NULL || gdk_pixbuf_get_width (priv->pixbuf) != allocation.width || gdk_pixbuf_get_height (priv->pixbuf) != allocation.height) { if (priv->pixbuf != NULL) g_object_unref (priv->pixbuf); priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha (priv->browse_pixbuf), 8, dest_width, dest_height); gdk_pixbuf_fill (priv->pixbuf, 0x0); gdk_pixbuf_scale (priv->browse_pixbuf, priv->pixbuf, 0, 0, dest_width, dest_height, 0, 0, scale, scale, GDK_INTERP_BILINEAR); if (priv->color_shifted) g_object_unref (priv->color_shifted); priv->color_shifted = gdk_pixbuf_copy (priv->pixbuf); shift_colors (priv->color_shifted, -32, -32, -32, 0); if (priv->scale == 0.0) { gdouble scale_to_80, scale_to_image, crop_scale; /* Scale the crop rectangle to 80% of the area, or less to fit the image */ scale_to_80 = MIN ((gdouble)gdk_pixbuf_get_width (priv->pixbuf) * 0.8 / priv->base_width, (gdouble)gdk_pixbuf_get_height (priv->pixbuf) * 0.8 / priv->base_height); scale_to_image = MIN ((gdouble)dest_width / priv->base_width, (gdouble)dest_height / priv->base_height); crop_scale = MIN (scale_to_80, scale_to_image); priv->crop.width = crop_scale * priv->base_width / scale; priv->crop.height = crop_scale * priv->base_height / scale; priv->crop.x = (gdk_pixbuf_get_width (priv->browse_pixbuf) - priv->crop.width) / 2; priv->crop.y = (gdk_pixbuf_get_height (priv->browse_pixbuf) - priv->crop.height) / 2; } priv->scale = scale; priv->image.x = (allocation.width - dest_width) / 2; priv->image.y = (allocation.height - dest_height) / 2; priv->image.width = dest_width; priv->image.height = dest_height; } }
static void update_pixbufs (UmCropArea *area) { gint width; gint height; GtkAllocation allocation; gdouble scale; GdkRGBA color; guint32 pixel; gint dest_x, dest_y, dest_width, dest_height; GtkWidget *widget; GtkStyleContext *context; widget = GTK_WIDGET (area); gtk_widget_get_allocation (widget, &allocation); context = gtk_widget_get_style_context (widget); if (area->priv->pixbuf == NULL || gdk_pixbuf_get_width (area->priv->pixbuf) != allocation.width || gdk_pixbuf_get_height (area->priv->pixbuf) != allocation.height) { if (area->priv->pixbuf != NULL) g_object_unref (area->priv->pixbuf); area->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha (area->priv->browse_pixbuf), 8, allocation.width, allocation.height); gtk_style_context_get_background_color (context, gtk_style_context_get_state (context), &color); pixel = (((gint)(color.red * 1.0)) << 16) | (((gint)(color.green * 1.0)) << 8) | ((gint)(color.blue * 1.0)); gdk_pixbuf_fill (area->priv->pixbuf, pixel); width = gdk_pixbuf_get_width (area->priv->browse_pixbuf); height = gdk_pixbuf_get_height (area->priv->browse_pixbuf); scale = allocation.height / (gdouble)height; if (scale * width > allocation.width) scale = allocation.width / (gdouble)width; dest_width = width * scale; dest_height = height * scale; dest_x = (allocation.width - dest_width) / 2; dest_y = (allocation.height - dest_height) / 2, gdk_pixbuf_scale (area->priv->browse_pixbuf, area->priv->pixbuf, dest_x, dest_y, dest_width, dest_height, dest_x, dest_y, scale, scale, GDK_INTERP_BILINEAR); if (area->priv->color_shifted) g_object_unref (area->priv->color_shifted); area->priv->color_shifted = gdk_pixbuf_copy (area->priv->pixbuf); shift_colors (area->priv->color_shifted, -32, -32, -32, 0); if (area->priv->scale == 0.0) { area->priv->crop.width = 2 * area->priv->base_width / scale; area->priv->crop.height = 2 * area->priv->base_height / scale; area->priv->crop.x = (gdk_pixbuf_get_width (area->priv->browse_pixbuf) - area->priv->crop.width) / 2; area->priv->crop.y = (gdk_pixbuf_get_height (area->priv->browse_pixbuf) - area->priv->crop.height) / 2; } area->priv->scale = scale; area->priv->image.x = dest_x; area->priv->image.y = dest_y; area->priv->image.width = dest_width; area->priv->image.height = dest_height; } }