aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-avatar-chooser.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-11-11 23:28:12 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-11-11 23:28:12 +0800
commitdcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7 (patch)
tree5fda1b3709182b2f9aaf7006c816cac4f347a381 /libempathy-gtk/empathy-avatar-chooser.c
parente7b23f0d2a0dc99944ace914078c256f2c867f64 (diff)
downloadgsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar.gz
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar.bz2
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar.lz
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar.xz
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.tar.zst
gsoc2013-empathy-dcdf66a81197fbd36f25ff095ef0e9d08d2fa1f7.zip
Cleanup code and add some comments
svn path=/trunk/; revision=1710
Diffstat (limited to 'libempathy-gtk/empathy-avatar-chooser.c')
-rw-r--r--libempathy-gtk/empathy-avatar-chooser.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/libempathy-gtk/empathy-avatar-chooser.c b/libempathy-gtk/empathy-avatar-chooser.c
index a004d2dd0..36f4c1453 100644
--- a/libempathy-gtk/empathy-avatar-chooser.c
+++ b/libempathy-gtk/empathy-avatar-chooser.c
@@ -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) {