[gthumb] rotate tool: locking the cropping region inside the rotated image
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] rotate tool: locking the cropping region inside the rotated image
- Date: Sun, 1 May 2011 18:15:58 +0000 (UTC)
commit ee29c42ee986cf9d604aab664186194dcde1fc9e
Author: Stefano Pettini <spettini users sourceforge net>
Date: Sat Apr 30 23:07:49 2011 +0100
rotate tool: locking the cropping region inside the rotated image
extensions/file_tools/gdk-pixbuf-rotate.c | 18 +++++++++++++++++-
extensions/file_tools/gdk-pixbuf-rotate.h | 3 ++-
extensions/file_tools/gth-file-tool-rotate.c | 18 +++++++++++++-----
3 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index 3f59b4c..c0ad497 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -47,7 +47,8 @@
void
_gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
double angle,
- double *p1_plus_p2)
+ double *p1_plus_p2,
+ double *p_min)
{
double angle_rad;
double cos_angle, sin_angle;
@@ -69,12 +70,16 @@ _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
t2 = sin_angle * src_width + cos_angle * src_height;
*p1_plus_p2 = 1.0 + (t1 * src_height) / (t2 * src_width);
+
+ *p_min = src_height / src_width * sin_angle * cos_angle + (*p1_plus_p2 - 1) * cos_angle * cos_angle;
}
else {
t1 = cos_angle * src_height - sin_angle * src_width;
t2 = sin_angle * src_height + cos_angle * src_width;
*p1_plus_p2 = 1.0 + (t1 * src_width) / (t2 * src_height);
+
+ *p_min = src_width / src_height * sin_angle * cos_angle + (*p1_plus_p2 - 1) * cos_angle * cos_angle;
}
}
@@ -105,6 +110,17 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
src_width = gdk_pixbuf_get_width (src_pixbuf) - 1;
src_height = gdk_pixbuf_get_height (src_pixbuf) - 1;
+ if (angle < 0) {
+
+ /* This is to make the p1/p2 sliders behavour more user friendly */
+
+ double t;
+
+ t = p1;
+ p1 = p2;
+ p2 = t;
+ }
+
if (src_width > src_height) {
xx1 = p1 * src_width * cos_angle + src_height * sin_angle;
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.h b/extensions/file_tools/gdk-pixbuf-rotate.h
index c037e80..01db0e8 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.h
+++ b/extensions/file_tools/gdk-pixbuf-rotate.h
@@ -30,7 +30,8 @@ G_BEGIN_DECLS
void _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
double angle,
- double *p1_plus_p2);
+ double *p1_plus_p2,
+ double *p_min);
void _gdk_pixbuf_rotate_get_cropping_region (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 259ff0d..07419ac 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -69,6 +69,7 @@ update_crop_parameters (GthFileToolRotate *self)
double rotation_angle;
gboolean keep_aspect_ratio;
double crop_p1;
+ double crop_p_min;
window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
@@ -94,14 +95,18 @@ update_crop_parameters (GthFileToolRotate *self)
_gdk_pixbuf_rotate_get_cropping_parameters (self->priv->src_pixbuf,
rotation_angle,
- &self->priv->crop_p1_plus_p2);
+ &self->priv->crop_p1_plus_p2,
+ &crop_p_min);
/* This centers the cropping region in the middle of the rotated image */
crop_p1 = self->priv->crop_p1_plus_p2 / 2.0;
- gtk_adjustment_set_lower (self->priv->crop_p1_adj, MAX (self->priv->crop_p1_plus_p2 - 1, 0));
- gtk_adjustment_set_lower (self->priv->crop_p2_adj, MAX (self->priv->crop_p1_plus_p2 - 1, 0));
+ gtk_adjustment_set_lower (self->priv->crop_p1_adj, MAX (crop_p_min, 0.0));
+ gtk_adjustment_set_lower (self->priv->crop_p2_adj, MAX (crop_p_min, 0.0));
+
+ gtk_adjustment_set_upper (self->priv->crop_p1_adj, MIN (self->priv->crop_p1_plus_p2 - crop_p_min, 1.0));
+ gtk_adjustment_set_upper (self->priv->crop_p2_adj, MIN (self->priv->crop_p1_plus_p2 - crop_p_min, 1.0));
gtk_adjustment_set_value (self->priv->crop_p1_adj, crop_p1);
}
@@ -111,8 +116,11 @@ update_crop_parameters (GthFileToolRotate *self)
gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_label"), TRUE);
gtk_widget_set_sensitive (GET_WIDGET ("crop_p2_hbox"), TRUE);
- gtk_adjustment_set_lower (self->priv->crop_p1_adj, 0);
- gtk_adjustment_set_lower (self->priv->crop_p2_adj, 0);
+ gtk_adjustment_set_lower (self->priv->crop_p1_adj, 0.0);
+ gtk_adjustment_set_lower (self->priv->crop_p2_adj, 0.0);
+
+ gtk_adjustment_set_upper (self->priv->crop_p1_adj, 1.0);
+ gtk_adjustment_set_upper (self->priv->crop_p2_adj, 1.0);
}
gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_crop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]