summaryrefslogtreecommitdiff
path: root/gfbgraph
diff options
context:
space:
mode:
authorÁlvaro Peña <alvaropg@gmail.com>2013-08-26 19:24:39 +0200
committerÁlvaro Peña <alvaropg@gmail.com>2013-08-26 19:24:39 +0200
commit651bc2810057e69e4684cf61e0cd57325e7d5dde (patch)
tree6286f329ccd3274aaf7a904b0abbea20d4f57f6d /gfbgraph
parent42749a92806d1077ad6f025a476327626b74af76 (diff)
downloadlibgfbgraph-651bc2810057e69e4684cf61e0cd57325e7d5dde.tar.gz
photo: userful functions to get the image with a width/height closest to a given number
Diffstat (limited to 'gfbgraph')
-rw-r--r--gfbgraph/gfbgraph-photo.c57
-rw-r--r--gfbgraph/gfbgraph-photo.h2
2 files changed, 59 insertions, 0 deletions
diff --git a/gfbgraph/gfbgraph-photo.c b/gfbgraph/gfbgraph-photo.c
index 6b29841..b366d7b 100644
--- a/gfbgraph/gfbgraph-photo.c
+++ b/gfbgraph/gfbgraph-photo.c
@@ -546,3 +546,60 @@ gfbgraph_photo_get_image_hires (GFBGraphPhoto *photo)
return photo->priv->hires_image;
}
+GFBGraphPhotoImage*
+gfbgraph_photo_get_image_near_width (GFBGraphPhoto *photo, guint width)
+{
+ GList *images_list;
+ GFBGraphPhotoImage *tmp_photo_image;
+ GFBGraphPhotoImage *photo_image;
+ gint tmp_w_dif, w_dif;
+
+ g_return_val_if_fail (GFBGRAPH_IS_PHOTO (photo), NULL);
+
+ photo_image = NULL;
+ images_list = photo->priv->images;
+ while (images_list) {
+ tmp_photo_image = (GFBGraphPhotoImage *) images_list->data;
+ tmp_w_dif = tmp_photo_image->width - width;
+ tmp_w_dif = (tmp_w_dif > 0) ? tmp_w_dif : (tmp_w_dif * -1);
+
+ if (photo_image == NULL
+ || tmp_w_dif < w_dif) {
+ w_dif = tmp_w_dif;
+ photo_image = tmp_photo_image;
+ } else {
+ }
+
+ images_list = g_list_next (images_list);
+ }
+
+ return photo_image;
+}
+
+GFBGraphPhotoImage*
+gfbgraph_photo_get_image_near_height (GFBGraphPhoto *photo, guint height)
+{
+ GList *images_list;
+ GFBGraphPhotoImage *tmp_photo_image;
+ GFBGraphPhotoImage *photo_image;
+ gint tmp_h_dif, h_dif;
+
+ g_return_val_if_fail (GFBGRAPH_IS_PHOTO (photo), NULL);
+
+ photo_image = NULL;
+ images_list = photo->priv->images;
+ while (images_list) {
+ tmp_photo_image = (GFBGraphPhotoImage *) images_list->data;
+ tmp_h_dif = ABS(tmp_photo_image->height - height);
+
+ if (photo_image == NULL
+ || tmp_h_dif < h_dif) {
+ h_dif = tmp_h_dif;
+ photo_image = tmp_photo_image;
+ }
+
+ images_list = g_list_next (images_list);
+ }
+
+ return photo_image;
+}
diff --git a/gfbgraph/gfbgraph-photo.h b/gfbgraph/gfbgraph-photo.h
index 73e474e..993a18b 100644
--- a/gfbgraph/gfbgraph-photo.h
+++ b/gfbgraph/gfbgraph-photo.h
@@ -66,6 +66,8 @@ guint gfbgraph_photo_get_default_width (GFBGraphPhoto *photo)
guint gfbgraph_photo_get_default_height (GFBGraphPhoto *photo);
GList* gfbgraph_photo_get_images (GFBGraphPhoto *photo);
GFBGraphPhotoImage* gfbgraph_photo_get_image_hires (GFBGraphPhoto *photo);
+GFBGraphPhotoImage* gfbgraph_photo_get_image_near_width (GFBGraphPhoto *photo, guint width);
+GFBGraphPhotoImage* gfbgraph_photo_get_image_near_height (GFBGraphPhoto *photo, guint height);
G_END_DECLS