[gimp] app: don't round results of gimp_display_shell_transform_bounds()



commit e384d533e702f00459e366541544835591d1e22b
Author: Ell <ell_se yahoo com>
Date:   Tue Aug 9 20:17:51 2016 +0000

    app: don't round results of gimp_display_shell_transform_bounds()
    
    The rounding causes some one-pixel-off errors in the canvas scaling
    code; the rest of its callers shouldn't be affected.

 app/display/gimpdisplayshell-transform.c |   42 +++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-transform.c b/app/display/gimpdisplayshell-transform.c
index 704bdd1..fe91255 100644
--- a/app/display/gimpdisplayshell-transform.c
+++ b/app/display/gimpdisplayshell-transform.c
@@ -37,6 +37,16 @@
 #include "gimpdisplayshell-transform.h"
 
 
+/*  local function prototypes  */
+
+static void gimp_display_shell_transform_xy_f_noround (GimpDisplayShell *shell,
+                                                       gdouble           x,
+                                                       gdouble           y,
+                                                       gdouble          *nx,
+                                                       gdouble          *ny);
+
+/*  public functions  */
+
 /**
  * gimp_display_shell_zoom_coords:
  * @shell:          a #GimpDisplayShell
@@ -795,10 +805,10 @@ gimp_display_shell_transform_bounds (GimpDisplayShell *shell,
       gdouble tx3, ty3;
       gdouble tx4, ty4;
 
-      gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1);
-      gimp_display_shell_transform_xy_f (shell, x1, y2, &tx2, &ty2);
-      gimp_display_shell_transform_xy_f (shell, x2, y1, &tx3, &ty3);
-      gimp_display_shell_transform_xy_f (shell, x2, y2, &tx4, &ty4);
+      gimp_display_shell_transform_xy_f_noround (shell, x1, y1, &tx1, &ty1);
+      gimp_display_shell_transform_xy_f_noround (shell, x1, y2, &tx2, &ty2);
+      gimp_display_shell_transform_xy_f_noround (shell, x2, y1, &tx3, &ty3);
+      gimp_display_shell_transform_xy_f_noround (shell, x2, y2, &tx4, &ty4);
 
       *nx1 = MIN4 (tx1, tx2, tx3, tx4);
       *ny1 = MIN4 (ty1, ty2, ty3, ty4);
@@ -807,8 +817,8 @@ gimp_display_shell_transform_bounds (GimpDisplayShell *shell,
     }
   else
     {
-      gimp_display_shell_transform_xy_f (shell, x1, y1, nx1, ny1);
-      gimp_display_shell_transform_xy_f (shell, x2, y2, nx2, ny2);
+      gimp_display_shell_transform_xy_f_noround (shell, x1, y1, nx1, ny1);
+      gimp_display_shell_transform_xy_f_noround (shell, x2, y2, nx2, ny2);
     }
 }
 
@@ -906,3 +916,23 @@ gimp_display_shell_untransform_viewport (GimpDisplayShell *shell,
   if (width)  *width  = x2 - x1;
   if (height) *height = y2 - y1;
 }
+
+
+/*  private functions  */
+
+/* Same as gimp_display_shell_transform_xy_f(), but doesn't do any rounding
+ * for the transformed coordiantes.
+ */
+static void
+gimp_display_shell_transform_xy_f_noround (GimpDisplayShell *shell,
+                                           gdouble           x,
+                                           gdouble           y,
+                                           gdouble          *nx,
+                                           gdouble          *ny)
+{
+  *nx = shell->scale_x * x - shell->offset_x;
+  *ny = shell->scale_y * y - shell->offset_y;
+
+  if (shell->rotate_transform)
+    cairo_matrix_transform_point (shell->rotate_transform, nx, ny);
+}


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