Scaling icons



A surprisingly difficult part of the icon theme code is figuring
out at what size to actually load the icon at, once you've
located the right file.

There are three inputs:

 The size that the user asked for, desired_size

 The size of the image file; image_width x image_height

 Various sizes coming from where the icon was found
 in the icon theme. There are four branches here:

  A) The icon was in "Fixed" size directory; there is
  a single dir_size size for the directory.

  B) The icon was in a "Scalable" directory. There is a 
  dir_size for the directory, and a max_size/min_size
  giving the range of possible sizes for scaling this
  icon.
 
  C) The icon was in a "Threshold" directory. There is a
  dir_size for the directory, and "threshold" 
  describing the allowed difference between the 
  requested size and the nominal directory size.

  D) The icon was "unthemed" - found floating loose rather
  than in a theme directory.

The nautilus algorithm 
(nautilus/libnautilusprivate/nautilus-icon-factory.c:load_icon())
is as follows:

 - For unthemed icons: Define 

    image_size = MAX (image_width, image_height);

   if image_size is greater than NAUTILUS_ICON_SIZE_STANDARD(=48) + 5
   load the icon at at a scale factor of:
  
    scale = desired_size / image_size

   Otherwise use image_width/image_height

 - For all other icons, load them with a scale of:

    scale = desired_size / dir_size

   (Note that the directory size is used here rather than
   the image size; this is important for emblems which
   may be much smaller than the directory size)

The KDE algorithm
(kdelibs/kdecore/kiconloader.cpp:KIconLoader::loadIcon())
seems to be:

 - For "Fixed" size icons, don't scale

 - For "Scalable" icons, load them at desired_size x desired_size
   (don't preserve aspect ratio)

 - For "Threshold" icons, if desired_size - image_width > threshold,
   load at desired_size x desired_size (don't preserve aspect ratio),
   otherwise don't scale.

 - unthemed icons aren't handled by KIconLoader currently.

Both of the algorithms here have some issues - I think the KDE
code is more right in not scaling in some circumstances, but the
handling of the exact scale ratios in nautilus seems better.

What I'm thinking of doing 
(image_size = MAX(image_width,image_height):
 
 - For "fixed" size icons, don't scale

 - For "Scalable" icons, load them at a scale of 
   desired_size / dir_size. If dir_size isn't set (the icon
   theme spec requires dir_size, but I bet some KDE themes will
   omit it) load them at a scale of desired_size/image_size.

 - For "Threshold" icons, if desired_size - dir_size > threshold
   load at a scale of desired_size / dir_size, otherwise don't
   scale.

 - For unthemed icons, adopt the nautilus algorithm: scale
   by desired_size / image_size if image_size > MIN_SIZE,
   otherwise don't scale. Probably use the nautilus MIN_SIZE
   value of 53 for lack of anything better.

Does this make sense?

Thanks,
                                          Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]