Add some explanatory comments to bits of the code Fix the ratio
2004-02-24 Rodney Dawes <dobey@ximian.com> * gnome-wp-item.c (gnome_wp_item_get_thumbnail): Add some explanatory comments to bits of the code Fix the ratio calculation to handle images of all sizes (#134541) Don't force tiling of square images Don't do _save_thumbnail () for the custom thumbnails If pixbuf is NULL, copy away bgpixbuf and return that instead * gnome-wp-utils.c (gnome_wp_tile_pixbuf): (gnome_wp_center_pixbuf): Return copied pixbufs Fixes #134541
This commit is contained in:
parent
cdfef1c131
commit
48c884fe25
3 changed files with 63 additions and 37 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2004-02-24 Rodney Dawes <dobey@ximian.com>
|
||||||
|
|
||||||
|
* gnome-wp-item.c (gnome_wp_item_get_thumbnail): Add some explanatory
|
||||||
|
comments to bits of the code
|
||||||
|
Fix the ratio calculation to handle images of all sizes (#134541)
|
||||||
|
Don't force tiling of square images
|
||||||
|
Don't do _save_thumbnail () for the custom thumbnails
|
||||||
|
If pixbuf is NULL, copy away bgpixbuf and return that instead
|
||||||
|
* gnome-wp-utils.c (gnome_wp_tile_pixbuf):
|
||||||
|
(gnome_wp_center_pixbuf): Return copied pixbufs
|
||||||
|
|
||||||
|
Fixes #134541
|
||||||
|
|
||||||
2004-02-17 Rodney Dawes <dobey@ximian.com>
|
2004-02-17 Rodney Dawes <dobey@ximian.com>
|
||||||
|
|
||||||
* gnome-background-properties.glade: Use untranslated strings for
|
* gnome-background-properties.glade: Use untranslated strings for
|
||||||
|
|
|
@ -53,11 +53,23 @@ GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
|
||||||
GdkPixbuf * pixbuf, * bgpixbuf;
|
GdkPixbuf * pixbuf, * bgpixbuf;
|
||||||
GdkPixbuf * scaled = NULL;
|
GdkPixbuf * scaled = NULL;
|
||||||
gint w, h, ratio;
|
gint w, h, ratio;
|
||||||
|
gint bw, bh;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Get the size of the screen and calculate our aspect ratio divisor
|
||||||
|
We do this, so that images are thumbnailed as they would look on
|
||||||
|
the screen in reality
|
||||||
|
*/
|
||||||
w = gdk_screen_get_width (gdk_screen_get_default ());
|
w = gdk_screen_get_width (gdk_screen_get_default ());
|
||||||
h = gdk_screen_get_height (gdk_screen_get_default ());
|
h = gdk_screen_get_height (gdk_screen_get_default ());
|
||||||
ratio = h / 96;
|
ratio = h / 48;
|
||||||
|
bw = w / ratio;
|
||||||
|
bh = h / ratio;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create the pixbuf for the background colors, which will show up for
|
||||||
|
oddly sized images, smaller images that are centered, or alpha images
|
||||||
|
*/
|
||||||
if (!strcmp (item->shade_type, "solid")) {
|
if (!strcmp (item->shade_type, "solid")) {
|
||||||
bgpixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, w / ratio, h / ratio);
|
bgpixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, w / ratio, h / ratio);
|
||||||
} else if (!strcmp (item->shade_type, "vertical-gradient")) {
|
} else if (!strcmp (item->shade_type, "vertical-gradient")) {
|
||||||
|
@ -70,6 +82,12 @@ GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
|
||||||
w / ratio, h / ratio);
|
w / ratio, h / ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Load up the thumbnail image using the thumbnail spec
|
||||||
|
If the image doesn't exist, we create it
|
||||||
|
If we are creating the thumbnail for "No Wallpaper", then we just copy
|
||||||
|
the background colors pixbuf we created above, here
|
||||||
|
*/
|
||||||
if (item->fileinfo->thumburi != NULL &&
|
if (item->fileinfo->thumburi != NULL &&
|
||||||
g_file_test (item->fileinfo->thumburi, G_FILE_TEST_EXISTS)) {
|
g_file_test (item->fileinfo->thumburi, G_FILE_TEST_EXISTS)) {
|
||||||
pixbuf = gdk_pixbuf_new_from_file (item->fileinfo->thumburi, NULL);
|
pixbuf = gdk_pixbuf_new_from_file (item->fileinfo->thumburi, NULL);
|
||||||
|
@ -87,49 +105,44 @@ GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
|
||||||
if (pixbuf != NULL) {
|
if (pixbuf != NULL) {
|
||||||
w = gdk_pixbuf_get_width (pixbuf);
|
w = gdk_pixbuf_get_width (pixbuf);
|
||||||
h = gdk_pixbuf_get_height (pixbuf);
|
h = gdk_pixbuf_get_height (pixbuf);
|
||||||
ratio = h / 48;
|
|
||||||
|
|
||||||
if (ratio == 0)
|
/*
|
||||||
|
Handle images large and small. We default to 1, since images smaller
|
||||||
|
than 64x48 don't need to be scaled down, and the tiled thumbnails
|
||||||
|
will look correct for really small pattern images
|
||||||
|
*/
|
||||||
|
if (h >= 48)
|
||||||
|
ratio = h / 48;
|
||||||
|
else if (w >= 64)
|
||||||
ratio = w / 64;
|
ratio = w / 64;
|
||||||
|
else
|
||||||
|
ratio = 1;
|
||||||
|
|
||||||
if (ratio == 1)
|
scaled = gnome_thumbnail_scale_down_pixbuf (pixbuf, w / ratio, h / ratio);
|
||||||
ratio = 2;
|
|
||||||
|
|
||||||
scaled = gnome_thumbnail_scale_down_pixbuf (pixbuf,
|
if (!strcmp (item->options, "wallpaper")) {
|
||||||
w / ratio, h / ratio);
|
w = gdk_pixbuf_get_width (scaled);
|
||||||
|
h = gdk_pixbuf_get_height (scaled);
|
||||||
|
|
||||||
if (w == h) {
|
|
||||||
item->options = g_strdup ("wallpaper");
|
|
||||||
scaled = gnome_wp_pixbuf_tile (scaled, bgpixbuf);
|
scaled = gnome_wp_pixbuf_tile (scaled, bgpixbuf);
|
||||||
|
} else if (!strcmp (item->options, "centered")) {
|
||||||
gnome_thumbnail_factory_save_thumbnail (thumbs, scaled,
|
|
||||||
item->filename,
|
|
||||||
item->fileinfo->mtime);
|
|
||||||
|
|
||||||
w = gdk_pixbuf_get_width (scaled);
|
w = gdk_pixbuf_get_width (scaled);
|
||||||
h = gdk_pixbuf_get_height (scaled);
|
h = gdk_pixbuf_get_height (scaled);
|
||||||
ratio = h / 48;
|
|
||||||
|
|
||||||
if (ratio == 1)
|
/*
|
||||||
ratio = 2;
|
This is for alpha centered images like gnome-logo-transparent.jpg
|
||||||
|
It's an ugly hack, that can potentially be removed when round() or
|
||||||
|
something like it decides to work
|
||||||
|
We scale it down again so that it looks proper, instead of the off-
|
||||||
|
center look that seems to appear without this hack
|
||||||
|
*/
|
||||||
|
if (gdk_pixbuf_get_has_alpha (pixbuf) && (w > bw || h > bh))
|
||||||
|
scaled = gnome_thumbnail_scale_down_pixbuf (scaled, w / 2, h / 2);
|
||||||
|
|
||||||
scaled = gnome_thumbnail_scale_down_pixbuf (scaled,
|
|
||||||
w / ratio, h / ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp (item->options, "centered")) {
|
|
||||||
scaled = gnome_wp_pixbuf_center (scaled, bgpixbuf);
|
scaled = gnome_wp_pixbuf_center (scaled, bgpixbuf);
|
||||||
|
|
||||||
w = gdk_pixbuf_get_width (scaled);
|
|
||||||
h = gdk_pixbuf_get_height (scaled);
|
|
||||||
ratio = h / 48;
|
|
||||||
|
|
||||||
if (ratio == 1)
|
|
||||||
ratio = 2;
|
|
||||||
|
|
||||||
scaled = gnome_thumbnail_scale_down_pixbuf (scaled,
|
|
||||||
w / ratio, h / ratio);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scaled = gdk_pixbuf_copy (bgpixbuf);
|
||||||
}
|
}
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
g_object_unref (bgpixbuf);
|
g_object_unref (bgpixbuf);
|
||||||
|
|
|
@ -112,7 +112,7 @@ GdkPixbuf * gnome_wp_pixbuf_tile (GdkPixbuf * src_pixbuf,
|
||||||
guint alpha = 255;
|
guint alpha = 255;
|
||||||
|
|
||||||
if (dest_pixbuf == NULL) {
|
if (dest_pixbuf == NULL) {
|
||||||
return src_pixbuf;
|
return gdk_pixbuf_copy (src_pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
swidth = gdk_pixbuf_get_width (src_pixbuf);
|
swidth = gdk_pixbuf_get_width (src_pixbuf);
|
||||||
|
@ -130,7 +130,7 @@ GdkPixbuf * gnome_wp_pixbuf_tile (GdkPixbuf * src_pixbuf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest_pixbuf;
|
return gdk_pixbuf_copy (dest_pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf,
|
GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf,
|
||||||
|
@ -141,7 +141,7 @@ GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf,
|
||||||
guint alpha = 255;
|
guint alpha = 255;
|
||||||
|
|
||||||
if (dest_pixbuf == NULL) {
|
if (dest_pixbuf == NULL) {
|
||||||
return src_pixbuf;
|
return gdk_pixbuf_copy (src_pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
swidth = gdk_pixbuf_get_width (src_pixbuf);
|
swidth = gdk_pixbuf_get_width (src_pixbuf);
|
||||||
|
@ -156,6 +156,6 @@ GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf,
|
||||||
gdk_pixbuf_composite (src_pixbuf, dest_pixbuf, cx, cy,
|
gdk_pixbuf_composite (src_pixbuf, dest_pixbuf, cx, cy,
|
||||||
swidth, sheight,
|
swidth, sheight,
|
||||||
cx, cy, 1.0, 1.0, GDK_INTERP_BILINEAR, alpha);
|
cx, cy, 1.0, 1.0, GDK_INTERP_BILINEAR, alpha);
|
||||||
return dest_pixbuf;
|
return gdk_pixbuf_copy (dest_pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue