After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 154142 - gtk_icon_theme_load_icon doesn't always scale
gtk_icon_theme_load_icon doesn't always scale
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.4.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-09-30 10:59 UTC by Ross Burton
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ross Burton 2004-09-30 10:59:59 UTC
It appears that when I call gtk_icon_theme_load_icon with an icon name which is
in /usr/share/pixmaps, the icon doesn't get scaled to the size I requested.

I'd say this is a bug, but if this is a feature, it really should be documented.
Comment 1 James Henstridge 2004-10-01 02:37:52 UTC
The following results might be useful.  The "gnome-fs-directory" icon exists in
the icon theme, but the "gnome-eyes" icon is in the pixmaps folder.

  >>> import gtk
  >>> icon_theme = gtk.icon_theme_get_default()
  >>> pixbuf = icon_theme.load_icon('gnome-fs-directory', 24, 0)
  >>> pixbuf.get_width(), pixbuf.get_height()
  (24, 24)
  >>> pixbuf = icon_theme.load_icon('gnome-fs-directory', 256, 0)
  >>> pixbuf.get_width(), pixbuf.get_height()
  (256, 256)
  >>> pixbuf = icon_theme.load_icon('gnome-eyes', 24, 0)
  >>> pixbuf.get_width(), pixbuf.get_height()
  (48, 48)
  >>> pixbuf = icon_theme.load_icon('gnome-eyes', 256, 0)
  >>> pixbuf.get_width(), pixbuf.get_height()
  (240, 240)
  >>>
Comment 2 Matthias Clasen 2004-10-01 20:02:49 UTC
The code responsible for this is in gtkicontheme.c:

  if (icon_info->scale < 0.0)
    {
      gint image_size = MAX (image_width, image_height);
      if (image_size > 0)
	icon_info->scale = icon_info->desired_size / image_size;
      else
	icon_info->scale = 1.0;
      
      if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
	icon_info->scale = MAX (icon_info->scale, 1.0);
    }

It would have to be changed to 

 if (icon_info->scale < 0.0)
    {
      gint image_size = MAX (image_width, image_height);
      if (image_size > 0)
	icon_info->scale = icon_info->desired_size / (gdouble)image_size;
      else
	icon_info->scale = 1.0;     
     }

but I don't know enough about this code to judge whether that would be
an improvement, or if the current code works as intended and is just
underdocumented... I'll ask Owen on Monday
Comment 3 James Henstridge 2004-10-04 06:58:35 UTC
The documentation for gtk_icon_theme_load_icon() says the following:
 * @size: the desired icon size. The resulting icon may not be
 *        exactly this size; see gtk_icon_info_load_icon().
 ...
 * Looks up an icon in an icon theme, scales it to the given size
 * and renders it into a pixbuf. This is a convenience function;
 * if more details about the icon are needed, use
 * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().

And for gtk_icon_info_load_icon(), it says the following:
 * Note that the resulting
 * pixbuf may not be exactly this size; an icon theme may have icons
 * that differ slightly from their nominal sizes, and in addition GTK+
 * will avoid scaling icons that it considers sufficiently close to the
 * requested size. (This maintains sharpness.)

So I'd say that the result for rendering "gnome-eyes" at size 256 matches the
documentation (240 pixels is close to 256), but returning a 48x48 pixbuf when
size 24 is requested sounds like a bug.
Comment 4 Owen Taylor 2004-10-04 15:47:33 UTC
There is discussion from:

http://mail.gnome.org/archives/gtk-devel-list/2003-May/msg00055.html

It looks like I might have simplified even a bit further from what
was discussed there, but it's along the same lines.

The gnome-eyes example above doesn't make a lot of sense to me;
as I read the code, GTK+ never scales a unthemed icon up but scales down
if requested

I'd consider this bug at most 'docs'.
Comment 5 Matthias Clasen 2004-10-04 16:19:10 UTC
Its the opposite, Owen. The code refuses to scale down. It does scale up, but
the scale factor is (mis-)calculated using int math instead of floating point, 
thus we don't exactly reach the desired size. Talking to alex earlier, he
doesn't remember any particular reason to refuse to scale unthemed icons down,
and considers the rounding issue to be an oversight.
Comment 6 Owen Taylor 2004-10-04 16:57:47 UTC
Likely I just got the MAX/MIN backwards. If you read the discussion above,
especially:

 http://mail.gnome.org/archives/gtk-devel-list/2003-May/msg00060.html

You'll see I was thinking "down but not up". I suspect the scale factor
was also a bug, while scaling up by integer factors looks a bit better,
it still looks crappy, and we do use filtered scaling.

Comment 7 Matthias Clasen 2004-10-05 03:26:15 UTC
2004-10-04  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkicontheme.c (icon_info_ensure_scale_and_pixbuf): 
	Make the code work as intended for unthemed icons; don't scale
	them up too much. Allow to scale them down, and do so 
	exactly.  (#154142, Ross Burton)
	(gtk_icon_info_load_icon): Amend docs.