[libgfbgraph] photo: userful functions to get the image with a width/height closest to a given number



commit 651bc2810057e69e4684cf61e0cd57325e7d5dde
Author: Álvaro Peña <alvaropg gmail com>
Date:   Mon Aug 26 19:24:39 2013 +0200

    photo: userful functions to get the image with a width/height closest to a given number

 gfbgraph/gfbgraph-photo.c |   57 +++++++++++++++++++++++++++++++++++++++++++++
 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
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]