[f-spot: 32/40] Fix loupe and sharpener



commit f06a4007bfe3537d176404862afd4e4b08e3c34b
Author: Stephane Delcroix <stephane delcroix org>
Date:   Mon Jun 22 17:31:26 2009 +0200

    Fix loupe and sharpener
    
    Transform the pixbuf in the Loupe according to ImageView.PixbufOrientation

 src/Loupe.cs             |   16 +++++++++-------
 src/Utils/PixbufUtils.cs |   38 ++++++++++++++++++++++++++++++++++++++
 src/Widgets/ImageView.cs |   13 +++++++++----
 3 files changed, 56 insertions(+), 11 deletions(-)
---
diff --git a/src/Loupe.cs b/src/Loupe.cs
index 257b6a0..a85d993 100644
--- a/src/Loupe.cs
+++ b/src/Loupe.cs
@@ -15,6 +15,7 @@ using Gdk;
 using System;
 using System.Runtime.InteropServices;
 using Mono.Unix;
+using FSpot.Utils;
 
 namespace FSpot.Widgets {
 	public class Loupe : Gtk.Window {
@@ -127,7 +128,7 @@ namespace FSpot.Widgets {
 			ShapeWindow ();
 		}
 
-		public void SetSamplePoint (Gdk.Point p)
+		void SetSamplePoint (Gdk.Point p)
 		{
 			region.X = p.X;
 			region.Y = p.Y;
@@ -135,12 +136,10 @@ namespace FSpot.Widgets {
 			region.Height = 2 * radius;
 			
 			if (view.Pixbuf != null) {
-				Gdk.Pixbuf pixbuf = view.Pixbuf;
-				
-				region.Offset (- Math.Min (region.X, Math.Max (region.Right - pixbuf.Width, radius)), 
-					       - Math.Min (region.Y, Math.Max (region.Bottom - pixbuf.Height, radius)));
+				region.Offset (- Math.Min (region.X, Math.Max (region.Right - view.Pixbuf.Width, radius)), 
+					       - Math.Min (region.Y, Math.Max (region.Bottom - view.Pixbuf.Height, radius)));
 
-				region.Intersect (new Gdk.Rectangle (0, 0, pixbuf.Width, pixbuf.Height));
+				region.Intersect (new Gdk.Rectangle (0, 0, view.Pixbuf.Width, view.Pixbuf.Height));
 			}
 			UpdateSample ();
 		}
@@ -161,9 +160,12 @@ namespace FSpot.Widgets {
 				QueueResize ();
 			}
 
-			source = new Gdk.Pixbuf (view.Pixbuf,
+			Pixbuf tmp = new Gdk.Pixbuf (view.Pixbuf,
 						 region.X, region.Y,
 						 region.Width, region.Height);
+			source = FSpot.Utils.PixbufUtils.TransformOrientation (tmp, view.PixbufOrientation);
+			if (source != tmp)
+				tmp.Dispose ();
 			
 			//FIXME sometimes that ctor returns results with a null
 			//handle this case ourselves
diff --git a/src/Utils/PixbufUtils.cs b/src/Utils/PixbufUtils.cs
index 8fef3ed..c391fe1 100644
--- a/src/Utils/PixbufUtils.cs
+++ b/src/Utils/PixbufUtils.cs
@@ -91,6 +91,44 @@ namespace FSpot.Utils
 			return area;
 		}
 
+		public static Point TransformOrientation (int total_width, int total_height, Point args, PixbufOrientation orientation)
+		{
+			Point p = args;
+
+			switch (orientation) {
+			default:
+			case PixbufOrientation.TopLeft:
+				break;
+			case PixbufOrientation.TopRight:
+				p.X = total_width - p.X;
+				break;
+			case PixbufOrientation.BottomRight:
+				p.X = total_width - p.X;
+				p.Y = total_height - p.Y;
+				break;
+			case PixbufOrientation.BottomLeft:
+				p.Y = total_height - p.Y;
+				break;
+			case PixbufOrientation.LeftTop:
+				p.X = args.Y;
+				p.Y = args.X;
+				break;
+			case PixbufOrientation.RightTop:
+				p.X = total_height - args.Y;
+				p.Y = args.X;
+				break;
+			case PixbufOrientation.RightBottom:
+				p.X = total_height - args.Y;
+				p.Y = total_width - args.X;
+				break;
+			case PixbufOrientation.LeftBottom:
+				p.X = args.Y;
+				p.Y = total_width - args.X;
+				break;
+			}
+			return p;
+		}
+
 		public static PixbufOrientation ReverseTransformation (PixbufOrientation orientation)
 		{
 			switch (orientation) {
diff --git a/src/Widgets/ImageView.cs b/src/Widgets/ImageView.cs
index 87b70ff..802851d 100644
--- a/src/Widgets/ImageView.cs
+++ b/src/Widgets/ImageView.cs
@@ -224,13 +224,16 @@ namespace FSpot.Widgets
 			int x_offset = scaled_width < Allocation.Width ? (int)(Allocation.Width - scaled_width) / 2 : -XOffset;
 			int y_offset = scaled_height < Allocation.Height ? (int)(Allocation.Height - scaled_height) / 2 : -YOffset;
 
-			win.X = Clamp (win.X, x_offset, x_offset + (int)scaled_width - 1);
-			win.Y = Clamp (win.Y, y_offset, y_offset + (int)scaled_height - 1);
+			win.X = Clamp (win.X - x_offset, 0, (int)scaled_width - 1);
+			win.Y = Clamp (win.Y - y_offset, 0, (int)scaled_height - 1);
 
-			return new Point ((int) Math.Floor ((win.X - x_offset) * (double)(Pixbuf.Width - 1) / (double)(scaled_width - 1) + .5),
-					  (int) Math.Floor ((win.Y - y_offset) * (double)(Pixbuf.Height - 1) / (double)(scaled_height - 1) + .5));
+			win = PixbufUtils.TransformOrientation ((int)scaled_width, (int)scaled_height, win, PixbufUtils.ReverseTransformation (pixbuf_orientation));
+
+			return  new Point ((int) Math.Floor (win.X * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Width : Pixbuf.Height) - 1) / (double)(scaled_width - 1) + .5),
+					   (int) Math.Floor (win.Y * (double)(((int)PixbufOrientation <= 4 ? Pixbuf.Height : Pixbuf.Width) - 1) / (double)(scaled_height - 1) + .5));
 		}
 
+//FIXME
 		public Rectangle WindowCoordsToImage (Rectangle win)
 		{
 			if (Pixbuf == null)
@@ -250,6 +253,7 @@ namespace FSpot.Widgets
 			return img;
 		}
 
+//FIXME
 		public Point ImageCoordsToWindow (Point image)
 		{
 			if (this.Pixbuf == null)
@@ -262,6 +266,7 @@ namespace FSpot.Widgets
 					  (int) Math.Floor (image.Y * (double) (scaled_height - 1) / (this.Pixbuf.Height - 1) + 0.5) + y_offset);
 		}
 
+//FIXME
 		public Rectangle ImageCoordsToWindow (Rectangle image)
 		{
 			if (this.Pixbuf == null)



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