[Xfce4-commits] r20329 - libxfcegui4/trunk/libxfcegui4

Brian J. Tarricone bjt23 at cornell.edu
Sat Mar 11 21:46:01 CET 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jasper Huijsmans wrote:

> Modified: libxfcegui4/trunk/libxfcegui4/icons.c
> ===================================================================
> --- libxfcegui4/trunk/libxfcegui4/icons.c	2006-03-11 10:14:27 UTC (rev 20328)
> +++ libxfcegui4/trunk/libxfcegui4/icons.c	2006-03-11 10:38:13 UTC (rev 20329)
> @@ -29,6 +29,7 @@
>  #ifdef HAVE_STRING_H
>  #include <string.h>
>  #endif
> +#include <math.h>
>  
>  #ifndef PATH_MAX
>  #define PATH_MAX 1024
> @@ -131,6 +132,7 @@
>  {
>      GdkPixbuf *pix = NULL;
>      gchar *name_fixed = NULL, *p;
> +    int w, h;
>      
>      g_return_val_if_fail(name, NULL);
>      
> @@ -154,6 +156,32 @@
>      
>      g_free(name_fixed);
>      
> +    if (pix)
> +    {
> +        w = gdk_pixbuf_get_width (pix);
> +        h = gdk_pixbuf_get_height (pix);
> +        
> +        if (h > size || w > size)
> +        {
> +            GdkPixbuf *scale;
> +
> +            if (h > w)
> +            {
> +                w = rint ((double)w * (double)size / (double)h);
> +                h = size;
> +            }
> +            else
> +            {
> +                h = rint ((double)h * (double)size / (double)w);
> +                w = size;
> +            }
> +
> +            scale = gdk_pixbuf_scale_simple (pix, w, h, GDK_INTERP_NEAREST);
> +            g_object_unref (pix);
> +            pix = scale;
> +        }
> +    }
> +    
>      return pix;
>  }

Er, I thought we talked about this, and I said this was icky and slow.
At the very least, please check for (w == h) before doing floating point
operations.

There's probably no reason to use rint() either.  A cast to gint should do.

	-brian

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEEzcI6XyW6VEeAnsRAor4AJ9xnCXOnMsh/UeLGWDFpI/o1BmzzgCgxLKe
gbAVxWXF6eEMGw5mmzo57ho=
=M3bx
-----END PGP SIGNATURE-----



More information about the Xfce4-dev mailing list