icontheme: even pixel blocks for fractional upscaling
This commit is contained in:
parent
fa5c4defa2
commit
661814faf0
1 changed files with 50 additions and 34 deletions
|
|
@ -2979,29 +2979,49 @@ apply_emblems (GtkIconInfo *info)
|
|||
info->emblems_applied = TRUE;
|
||||
}
|
||||
|
||||
static GdkInterpType
|
||||
icon_info_get_scale_interp_type (gint image_width,
|
||||
gint image_height,
|
||||
gdouble scale)
|
||||
/* Scales an icon to @dest_width x @dest_height.
|
||||
*
|
||||
* Strongly upscaling small bitmap icons with bilinear filtering makes
|
||||
* them blurry. For tiny bitmap icons enlarged two times or more, each
|
||||
* source pixel becomes a block of whole pixels instead (nearest), as
|
||||
* many as fit, and only what is left of the factor is filtered
|
||||
* (bilinear): at 2x and 3x the blocks are all alike, and at 2.5x they
|
||||
* do not alternate between two and three pixels as with nearest alone.
|
||||
* Larger sources and moderate scaling keep bilinear filtering.
|
||||
*
|
||||
* This is done only when the icon pixbuf is created. Cached pixbufs
|
||||
* are reused while scrolling and drawing.
|
||||
*/
|
||||
static GdkPixbuf *
|
||||
icon_scale_pixbuf (GdkPixbuf *source,
|
||||
gint dest_width,
|
||||
gint dest_height,
|
||||
gdouble scale)
|
||||
{
|
||||
gint image_size;
|
||||
gint width = gdk_pixbuf_get_width (source);
|
||||
gint height = gdk_pixbuf_get_height (source);
|
||||
gint image_size = MAX (width, height);
|
||||
GdkPixbuf *blocks, *scaled;
|
||||
gint k;
|
||||
|
||||
image_size = MAX (image_width, image_height);
|
||||
if (image_size <= 0 || image_size > 64 || scale < 2.0)
|
||||
return gdk_pixbuf_scale_simple (source, dest_width, dest_height,
|
||||
GDK_INTERP_BILINEAR);
|
||||
|
||||
/*
|
||||
* Strongly upscaling small bitmap icons with bilinear filtering makes
|
||||
* them blurry and costs more CPU. Keep bilinear filtering for larger
|
||||
* sources and moderate scaling, but use nearest-neighbour scaling for
|
||||
* tiny bitmap icons that are enlarged substantially.
|
||||
*
|
||||
* This decision is made only when the icon pixbuf is created. Cached
|
||||
* pixbufs are reused while scrolling and drawing.
|
||||
*/
|
||||
/*if (image_size > 0 && image_size <= 64 && scale >= 3.0) */
|
||||
if (image_size > 0 && image_size <= 64 && scale >= 2.0)
|
||||
return GDK_INTERP_NEAREST;
|
||||
k = MIN (dest_width / width, dest_height / height);
|
||||
if (k < 2 || (width * k == dest_width && height * k == dest_height))
|
||||
return gdk_pixbuf_scale_simple (source, dest_width, dest_height,
|
||||
GDK_INTERP_NEAREST);
|
||||
|
||||
return GDK_INTERP_BILINEAR;
|
||||
blocks = gdk_pixbuf_scale_simple (source, width * k, height * k,
|
||||
GDK_INTERP_NEAREST);
|
||||
if (!blocks)
|
||||
return NULL;
|
||||
scaled = gdk_pixbuf_scale_simple (blocks, dest_width, dest_height,
|
||||
GDK_INTERP_BILINEAR);
|
||||
g_object_unref (blocks);
|
||||
|
||||
return scaled;
|
||||
}
|
||||
|
||||
/* This function contains the complicated logic for deciding
|
||||
|
|
@ -3191,12 +3211,10 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
|
|||
icon_info->pixbuf = source_pixbuf;
|
||||
else
|
||||
{
|
||||
icon_info->pixbuf = gdk_pixbuf_scale_simple (source_pixbuf,
|
||||
0.5 + image_width * icon_info->scale,
|
||||
0.5 + image_height * icon_info->scale,
|
||||
icon_info_get_scale_interp_type (image_width,
|
||||
image_height,
|
||||
icon_info->scale));
|
||||
icon_info->pixbuf = icon_scale_pixbuf (source_pixbuf,
|
||||
0.5 + image_width * icon_info->scale,
|
||||
0.5 + image_height * icon_info->scale,
|
||||
icon_info->scale);
|
||||
_gtk_icon_pixbuf_mark_shared (icon_info->pixbuf);
|
||||
g_object_unref (source_pixbuf);
|
||||
}
|
||||
|
|
@ -3698,12 +3716,10 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme,
|
|||
max = MAX (width, height);
|
||||
scale = (gdouble) size / (gdouble) max;
|
||||
|
||||
scaled = gdk_pixbuf_scale_simple (pixbuf,
|
||||
0.5 + width * scale,
|
||||
0.5 + height * scale,
|
||||
icon_info_get_scale_interp_type (width,
|
||||
height,
|
||||
scale));
|
||||
scaled = icon_scale_pixbuf (pixbuf,
|
||||
0.5 + width * scale,
|
||||
0.5 + height * scale,
|
||||
scale);
|
||||
|
||||
info = gtk_icon_info_new_for_pixbuf (icon_theme, scaled);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue