]> git.0d.be Git - empathy.git/commitdiff
Cleanup code and add some comments
authorXavier Claessens <xclaesse@src.gnome.org>
Tue, 11 Nov 2008 15:28:12 +0000 (15:28 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 11 Nov 2008 15:28:12 +0000 (15:28 +0000)
svn path=/trunk/; revision=1710

libempathy-gtk/empathy-avatar-chooser.c
libempathy-gtk/empathy-avatar-chooser.h

index a004d2dd0c269a183a871717dc26e4562c07b2a9..36f4c1453321612eddec6e7cc5b3a2342e469181 100644 (file)
@@ -30,6 +30,8 @@
 #include <gio/gio.h>
 
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-contact-factory.h>
+
 #include "empathy-avatar-chooser.h"
 #include "empathy-conf.h"
 #include "empathy-ui-utils.h"
@@ -498,15 +500,23 @@ avatar_chooser_maybe_convert_and_scale (EmpathyAvatarChooser *chooser,
                if (max_size == 0)
                        break;
 
-               /* Make a dichotomic search for the optimal factor that produce
-                * an image data size close to max_size */
+               /* Make a binary search for the bigest factor that produce
+                * an image data size less than max_size */
                if (converted_image_size > max_size)
                        max_factor = factor;
                if (converted_image_size < max_size)
                        min_factor = factor;
                factor = min_factor + (max_factor - min_factor)/2;
+
+               /* We are done if either:
+                * - min_factor == max_factor. That happens if we resized to
+                *   the max required dimension and the produced data size is
+                *   less than max_size.
+                * - The data size is close enough to max_size. Here we accept
+                *   a difference of 1k.
+                */
        } while (min_factor != max_factor &&
-                ABS (max_size - converted_image_size) > 1000);
+                ABS (max_size - converted_image_size) > 1024);
        g_free (new_format_name);
 
        /* Takes ownership of new_mime_type and converted_image_data */
@@ -546,7 +556,6 @@ avatar_chooser_set_image_from_data (EmpathyAvatarChooser *chooser,
 
        if (data == NULL) {
                avatar_chooser_clear_image (chooser);
-               g_free (data);
                return;
        }
 
@@ -609,8 +618,10 @@ avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
        g_assert (pixbuf != NULL);
 
        if (set_locally) {
-               EmpathyAvatar *conv = avatar_chooser_maybe_convert_and_scale (
-                       chooser, pixbuf, avatar);
+               EmpathyAvatar *conv;
+
+               conv = avatar_chooser_maybe_convert_and_scale (chooser,
+                       pixbuf, avatar);
                empathy_avatar_unref (avatar);
 
                if (conv == NULL) {
index 754e19447bdfff203def1b491b0505d848f11591..bdc5b40ae1a159905dfd9a8c7f3c1092f6c67f88 100644 (file)
@@ -27,7 +27,6 @@
 #include <gtk/gtkbutton.h>
 
 #include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-contact-factory.h>
 
 G_BEGIN_DECLS