[gnome-photos/wip/rishi/buffer-decoder: 14/16] loader



commit ee58de49530da337190aac52a0dd10cc3b90caad
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Sep 7 07:58:37 2018 +0200

    loader

 src/photos-gegl-buffer-loader.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-gegl-buffer-loader.c b/src/photos-gegl-buffer-loader.c
index 0e88e2ea..6e549656 100644
--- a/src/photos-gegl-buffer-loader.c
+++ b/src/photos-gegl-buffer-loader.c
@@ -164,45 +164,48 @@ photos_gegl_buffer_loader_notify_buffer (PhotosGeglBufferLoader *self)
 static void
 photos_gegl_buffer_loader_size_prepared (PhotosGeglBufferLoader *self, guint width, guint height)
 {
+  gdouble target_height = -1.0;
+  gdouble target_width = -1.0;
+
   g_signal_emit (self, signals[SIZE_PREPARED], 0, width, height);
 
   if (self->preserve_aspect_ratio && (self->height > 0 || self->width > 0))
     {
       if (self->width < 0)
         {
-          width = (guint) ((gdouble) width * (gdouble) self->height / (gdouble) height);
-          height = (guint) self->height;
+          target_width = (gdouble) width * (gdouble) self->height / (gdouble) height;
+          target_height = (gdouble) self->height;
         }
       else if (self->height < 0)
         {
-          height = (guint) ((gdouble) height * (gdouble) self->width / (gdouble) width);
-          width = (guint) self->width;
+          target_height = (gdouble) height * (gdouble) self->width / (gdouble) width;
+          target_width = (gdouble) self->width;
         }
       else if ((gdouble) height / (gdouble) width > (gdouble) self->height / (gdouble) self->width)
         {
-          width = (guint) ((gdouble) width * (gdouble) self->height / (gdouble) height + 0.5);
-          height = (guint) self->height;
+          target_width = (gdouble) width * (gdouble) self->height / (gdouble) height;
+          target_height = (gdouble) self->height;
         }
       else
         {
-          height = (guint) ((gdouble) height * (gdouble) self->width / (gdouble) width + 0.5);
-          width = (guint) self->width;
+          target_height = (gdouble) height * (gdouble) self->width / (gdouble) width;
+          target_width = (gdouble) self->width;
         }
     }
   else
     {
       if (self->height > 0)
-        height = (guint) self->height;
+        target_height = (gdouble) self->height;
 
       if (self->width > 0)
-        width = (guint) self->width;
+        target_width = (gdouble) self->width;
     }
 
-  height = MAX (height, 1);
-  width = MAX (width, 1);
+  g_return_if_fail (target_height >= 0.0);
+  g_return_if_fail (target_width >= 0.0);
 
-  photos_gegl_buffer_codec_set_height (self->codec, height);
-  photos_gegl_buffer_codec_set_width (self->codec, width);
+  photos_gegl_buffer_codec_set_height (self->codec, target_height);
+  photos_gegl_buffer_codec_set_width (self->codec, target_width);
 }
 
 


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