[gthumb: 114/129] rotate tool: crop completed, algorithm fixed and UI improved



commit 96e8bc23e4651464a2e596947c9f0ed090cb4115
Author: Stefano Pettini <spettini users sourceforge net>
Date:   Mon Apr 25 01:07:35 2011 +0100

    rotate tool: crop completed, algorithm fixed and UI improved

 extensions/file_tools/data/ui/rotate-options.ui |  179 ++++++++++++++---------
 extensions/file_tools/gdk-pixbuf-rotate.c       |   30 ++--
 extensions/file_tools/gdk-pixbuf-rotate.h       |    8 +-
 extensions/file_tools/gth-file-tool-rotate.c    |   70 ++++++++--
 4 files changed, 191 insertions(+), 96 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index a039772..98500fa 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -23,11 +23,33 @@
                     <property name="top_padding">6</property>
                     <property name="left_padding">12</property>
                     <child>
-                      <object class="GtkHBox" id="rotation_angle_hbox">
+                      <object class="GtkVBox" id="vbox6">
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <placeholder/>
+                          <object class="GtkHBox" id="rotation_angle_hbox">
+                            <property name="visible">True</property>
+                            <child>
+                              <placeholder/>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="high_quality">
+                            <property name="label" translatable="yes">High _quality</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
                         </child>
                       </object>
                     </child>
@@ -70,10 +92,18 @@
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkButton" id="get_1_button">
-                                <property name="label" translatable="yes">Get</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label1">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Get</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
                               </object>
                               <packing>
                                 <property name="position">0</property>
@@ -119,10 +149,18 @@
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkButton" id="get_2_button">
-                                <property name="label" translatable="yes">Get</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label5">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Get</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
                               </object>
                               <packing>
                                 <property name="position">0</property>
@@ -163,29 +201,55 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="align_h_button">
-                            <property name="label" translatable="yes">Align _horizontally</property>
+                          <object class="GtkVButtonBox" id="vbuttonbox1">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="use_underline">True</property>
+                            <property name="spacing">6</property>
+                            <property name="layout_style">spread</property>
+                            <child>
+                              <object class="GtkButton" id="align_h_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="use_underline">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label6">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Align the points horizontally</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="align_v_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="use_underline">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label7">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Align the points vertically</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">2</property>
                           </packing>
                         </child>
-                        <child>
-                          <object class="GtkButton" id="align_v_button">
-                            <property name="label" translatable="yes">Align _vertically</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
-                            <property name="use_underline">True</property>
-                          </object>
-                          <packing>
-                            <property name="position">3</property>
-                          </packing>
-                        </child>
                       </object>
                     </child>
                   </object>
@@ -270,53 +334,34 @@
                             <property name="position">3</property>
                           </packing>
                         </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child type="label">
-                  <object class="GtkLabel" id="guided_crop_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Guided crop</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkFrame" id="frame1">
-                <property name="visible">True</property>
-                <property name="label_xalign">0</property>
-                <property name="shadow_type">none</property>
-                <child>
-                  <object class="GtkAlignment" id="alignment1">
-                    <property name="visible">True</property>
-                    <property name="top_padding">6</property>
-                    <property name="left_padding">12</property>
-                    <child>
-                      <object class="GtkVBox" id="vbox3">
-                        <property name="visible">True</property>
-                        <property name="spacing">6</property>
                         <child>
-                          <object class="GtkCheckButton" id="high_quality">
-                            <property name="label" translatable="yes">High _quality</property>
+                          <object class="GtkHButtonBox" id="hbuttonbox2">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="tooltip_text" translatable="yes">Slower but produces better results</property>
-                            <property name="use_underline">True</property>
-                            <property name="active">True</property>
-                            <property name="draw_indicator">True</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkButton" id="crop_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label4">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Crop</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
-                            <property name="position">0</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                       </object>
@@ -324,9 +369,9 @@
                   </object>
                 </child>
                 <child type="label">
-                  <object class="GtkLabel" id="label1">
+                  <object class="GtkLabel" id="guided_crop_label">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">Settings</property>
+                    <property name="label" translatable="yes">Guided crop</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -336,7 +381,7 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">3</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index 4c1d5de..67e7125 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -53,7 +53,7 @@ _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
 	double angle_rad;
 	double cos_angle, sin_angle;
 	double src_width, src_height;
-	double px, py, pz;
+	double p1, p2, p3, p4;
 
 	angle = CLAMP (angle, -90.0, 90.0);
 
@@ -65,12 +65,14 @@ _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
 	src_width  = gdk_pixbuf_get_width  (src_pixbuf) - 1;
 	src_height = gdk_pixbuf_get_height (src_pixbuf) - 1;
 
-	px =   cos_angle * src_width - sin_angle * src_height;
-	py =   sin_angle * src_width + cos_angle * src_height;
-	pz = - sin_angle * src_width + cos_angle * src_height;
+	p1 =   cos_angle * src_width - sin_angle * src_height;
+	p2 =   sin_angle * src_width + cos_angle * src_height;
 
-	*alpha_plus_beta  = 1.0 + (px * src_height) / (py * src_width);
-	*gamma_plus_delta = *alpha_plus_beta; // 1.0 + (pz * src_width)  / (px * src_height);
+	p3 =   cos_angle * src_height - sin_angle * src_width;
+	p4 =   sin_angle * src_height + cos_angle * src_width;
+
+	*alpha_plus_beta  = 1.0 + (p1 * src_height) / (p2 * src_width);
+	*gamma_plus_delta = 1.0 + (p3 * src_width)  / (p4 * src_height);
 }
 
 
@@ -81,10 +83,10 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 					double     beta,
 					double     gamma,
 					double     delta,
-					int       *x1,
-					int       *y1,
-					int       *x2,
-					int       *y2)
+					int       *x,
+					int       *y,
+					int       *width,
+					int       *height)
 {
 	double angle_rad;
 	double cos_angle, sin_angle;
@@ -131,11 +133,11 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 		xx2 = new_width - xx2;
 	}
 
-	*x1 = ROUND (MIN (xx1, xx2));
-	*y1 = ROUND (MIN (yy1, yy2));
+	*x = ROUND (MIN (xx1, xx2));
+	*y = ROUND (MIN (yy1, yy2));
 	
-	*x2 = ROUND (MAX (xx1, xx2));
-	*y2 = ROUND (MAX (yy1, yy2));
+	*width  = ROUND (MAX (xx1, xx2)) - *x;
+	*height = ROUND (MAX (yy1, yy2)) - *y;
 }
 
 
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.h b/extensions/file_tools/gdk-pixbuf-rotate.h
index 9244a7d..74b76bd 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.h
+++ b/extensions/file_tools/gdk-pixbuf-rotate.h
@@ -39,10 +39,10 @@ void _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 					     double     beta,
 					     double     gamma,
 					     double     delta,
-					     int       *x1,
-					     int       *y1,
-					     int       *x2,
-					     int       *y2);
+					     int       *x,
+					     int       *y,
+					     int       *width,
+					     int       *height);
 
 GdkPixbuf* _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
 			       double     angle,
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 9c79b30..baf0a03 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -52,6 +52,10 @@ struct _GthFileToolRotatePrivate {
 	GthImageSelector *selector_align;
 	guint             selector_align_point;
 	guint             apply_event;
+	int               crop_x;
+	int               crop_y;
+	int               crop_width;
+	int               crop_height;
 };
 
 
@@ -123,13 +127,47 @@ align_v_button_clicked_cb (GtkButton         *button,
 
 
 static void
+crop_button_clicked_cb (GtkButton         *button,
+			GthFileToolRotate *self)
+{
+	GtkWidget *window;
+	GtkWidget *viewer_page;
+	GtkWidget *viewer;
+	GdkPixbuf *temp_pixbuf;
+	
+	temp_pixbuf = gdk_pixbuf_new_subpixbuf (self->priv->dest_pixbuf,
+						self->priv->crop_x,
+						self->priv->crop_y,
+						self->priv->crop_width,
+						self->priv->crop_height);
+	
+	_g_object_unref (self->priv->dest_pixbuf);
+	self->priv->dest_pixbuf = temp_pixbuf;
+	
+	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+
+	gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
+
+	gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
+	
+	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->enable_guided_crop), FALSE);
+	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), FALSE);
+	gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
+	gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
+	gtk_widget_set_sensitive (GET_WIDGET ("crop_button"), FALSE);
+}
+
+
+static void
 apply_button_clicked_cb (GtkButton         *button,
 			 GthFileToolRotate *self)
 {
 	if (self->priv->dest_pixbuf != NULL) {
 		GtkWidget *window;
 		GtkWidget *viewer_page;
-
+		
 		window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
 		viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
 		gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, TRUE);
@@ -171,18 +209,19 @@ update_crop_region (gpointer user_data)
 	gboolean           keep_aspect_ratio;
 	double             crop_alpha, crop_beta, crop_alpha_plus_beta;
 	double             crop_gamma, crop_delta, crop_gamma_plus_delta;
-	int                crop_x1, crop_y1;
-	int                crop_x2, crop_y2;
 
 	window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
 	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
 	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
 
+	gtk_widget_set_sensitive (GTK_WIDGET (self->priv->enable_guided_crop), TRUE);
+
 	enable_guided_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->enable_guided_crop));
-	
+
 	if (enable_guided_crop) {
 
 		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), TRUE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"), TRUE);
 		
 		rotation_angle = gtk_adjustment_get_value (self->priv->rotation_angle_adj);
 		keep_aspect_ratio = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->keep_aspect_ratio));
@@ -199,8 +238,6 @@ update_crop_region (gpointer user_data)
 			crop_beta  = crop_alpha_plus_beta  / 2.0;
 			crop_gamma = crop_gamma_plus_delta / 2.0;
 			crop_delta = crop_gamma_plus_delta / 2.0;
-		
-			printf("%f, %f\n", crop_alpha_plus_beta, crop_gamma_plus_delta);
 		}
 		else {
 			gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), TRUE);
@@ -214,20 +251,27 @@ update_crop_region (gpointer user_data)
 		
 		_gdk_pixbuf_rotate_get_cropping_region (self->priv->src_pixbuf, rotation_angle,
 							crop_alpha, crop_beta, crop_gamma, crop_delta,
-							&crop_x1, &crop_y1, &crop_x2, &crop_y2);
+							&self->priv->crop_x,
+							&self->priv->crop_y,
+							&self->priv->crop_width,
+							&self->priv->crop_height);
 
 		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_crop);
 
-		gth_image_selector_set_selection_pos (self->priv->selector_crop, crop_x1, crop_y1);
-		gth_image_selector_set_selection_width (self->priv->selector_crop, crop_x2 - crop_x1);
-		gth_image_selector_set_selection_height (self->priv->selector_crop, crop_y2 - crop_y1);
+		gth_image_selector_set_selection_pos (self->priv->selector_crop,
+						      self->priv->crop_x,
+						      self->priv->crop_y);
+						      
+		gth_image_selector_set_selection_width  (self->priv->selector_crop, self->priv->crop_width);
+		gth_image_selector_set_selection_height (self->priv->selector_crop, self->priv->crop_height);
 	}
 	else {
 		gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
-
+		
 		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), FALSE);
 		gtk_widget_set_sensitive (GET_WIDGET ("crop_p1_hbox"), FALSE);
 		gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), FALSE);
+		gtk_widget_set_sensitive (GET_WIDGET ("crop_button"),  FALSE);
 	}
 }
 
@@ -403,6 +447,10 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "clicked",
 			  G_CALLBACK (align_v_button_clicked_cb),
 			  self);
+	g_signal_connect (GET_WIDGET ("crop_button"),
+			  "clicked",
+			  G_CALLBACK (crop_button_clicked_cb),
+			  self);
 	g_signal_connect (G_OBJECT (self->priv->rotation_angle_adj),
 			  "value-changed",
 			  G_CALLBACK (value_changed_cb),



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