diff options
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 |
commit | 651bc2810057e69e4684cf61e0cd57325e7d5dde (patch) | |
tree | 6286f329ccd3274aaf7a904b0abbea20d4f57f6d | |
parent | 42749a92806d1077ad6f025a476327626b74af76 (diff) | |
download | libgfbgraph-651bc2810057e69e4684cf61e0cd57325e7d5dde.tar.gz |
photo: userful functions to get the image with a width/height closest to a given number
-rw-r--r-- | gfbgraph/gfbgraph-photo.c | 57 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-photo.h | 2 |
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 |