[Rawstudio-commit] r981 - trunk/src

Anders Brander anders at brander.dk
Sat Dec 30 16:55:20 CET 2006


Author: abrander
Date: 2006-12-30 16:55:20 +0100 (Sat, 30 Dec 2006)
New Revision: 981

Modified:
   trunk/src/rawstudio.c
   trunk/src/rawstudio.h
   trunk/src/toolbox.c
Log:
Added functions to transform photo and crop in one operation.

Modified: trunk/src/rawstudio.c
===================================================================
--- trunk/src/rawstudio.c	2006-12-30 12:46:29 UTC (rev 980)
+++ trunk/src/rawstudio.c	2006-12-30 15:55:20 UTC (rev 981)
@@ -70,6 +70,10 @@
 static guchar *mycms_pack_rgb_w(void *info, register WORD wOut[], register LPBYTE output);
 static guchar *mycms_unroll_rgb_w(void *info, register WORD wIn[], register LPBYTE accum);
 static guchar *mycms_unroll_rgb_w_loadtable(void *info, register WORD wIn[], register LPBYTE accum);
+static void rs_rect_normalize(RS_RECT *in, RS_RECT *out);
+static void rs_rect_flip(RS_RECT *in, RS_RECT *out, gint w, gint h);
+static void rs_rect_mirror(RS_RECT *in, RS_RECT *out, gint w, gint h);
+static void rs_rect_rotate(RS_RECT *in, RS_RECT *out, gint w, gint h, gint quarterturns);
 
 RS_FILETYPE *filetypes;
 
@@ -678,6 +682,50 @@
 	return(photo);
 }
 
+void
+rs_photo_flip(RS_PHOTO *photo)
+{
+	if (photo->crop)
+	{
+		gint w,h;
+		rs_image16_transform_getwh(photo->input, NULL, photo->angle, photo->orientation, &w, &h);
+		rs_rect_flip(photo->crop, photo->crop, w, h);
+	}
+	ORIENTATION_FLIP(photo->orientation);
+}
+
+void
+rs_photo_mirror(RS_PHOTO *photo)
+{
+	if (photo->crop)
+	{
+		gint w,h;
+		rs_image16_transform_getwh(photo->input, NULL, photo->angle, photo->orientation, &w, &h);
+		rs_rect_mirror(photo->crop, photo->crop, w, h);
+	}
+	ORIENTATION_MIRROR(photo->orientation);
+}
+
+void
+rs_photo_rotate(RS_PHOTO *photo, gint quarterturns, gdouble angle)
+{
+	gint n;
+	photo->angle += angle;
+
+	if (photo->crop)
+	{
+		gint w,h;
+		rs_image16_transform_getwh(photo->input, NULL, photo->angle, photo->orientation, &w, &h);
+		rs_rect_rotate(photo->crop, photo->crop, w, h, quarterturns);
+	}
+
+	for(n=0;n<quarterturns;n++)
+		ORIENTATION_90(photo->orientation);
+
+	return;
+
+}
+
 gboolean
 rs_photo_save(RS_PHOTO *photo, const gchar *filename, gint filetype, const gchar *profile_filename, gint width, gint height, gdouble scale)
 {
@@ -1292,6 +1340,119 @@
 	return;
 }
 
+static void
+rs_rect_normalize(RS_RECT *in, RS_RECT *out)
+{
+	gint n;
+	gint x1,y1;
+	gint x2,y2;
+
+	x1 = in->x2;
+	x2 = in->x1;
+	y1 = in->y1;
+	y2 = in->y2;
+
+	if (x1>x2)
+	{
+		n = x1;
+		x1 = x2;
+		x2 = n;
+	}
+	if (y1>y2)
+	{
+		n = y1;
+		y1 = y2;
+		y2 = n;
+	}
+
+	out->x1 = x1;
+	out->x2 = x2;
+	out->y1 = y1;
+	out->y2 = y2;
+}
+
+static void
+rs_rect_flip(RS_RECT *in, RS_RECT *out, gint w, gint h)
+{
+	gint x1,y1;
+	gint x2,y2;
+
+	x1 = in->x1;
+	x2 = in->x2;
+	y1 = h - in->y2 - 1;
+	y2 = h - in->y1 - 1;
+
+	out->x1 = x1;
+	out->x2 = x2;
+	out->y1 = y1;
+	out->y2 = y2;
+	rs_rect_normalize(out, out);
+
+	return;
+}
+
+static void
+rs_rect_mirror(RS_RECT *in, RS_RECT *out, gint w, gint h)
+{
+	gint x1,y1;
+	gint x2,y2;
+
+	x1 = w - in->x2 - 1;
+	x2 = w - in->x1 - 1;
+	y1 = in->y1;
+	y2 = in->y2;
+
+	out->x1 = x1;
+	out->x2 = x2;
+	out->y1 = y1;
+	out->y2 = y2;
+	rs_rect_normalize(out, out);
+
+	return;
+}
+
+static void
+rs_rect_rotate(RS_RECT *in, RS_RECT *out, gint w, gint h, gint quarterturns)
+{
+	gint x1,y1;
+	gint x2,y2;
+
+	x1 = in->x2;
+	x2 = in->x1;
+	y1 = in->y1;
+	y2 = in->y2;
+
+	switch(quarterturns)
+	{
+		case 1:
+			x1 = h - in->y1-1;
+			x2 = h - in->y2-1;
+			y1 = in->x1;
+			y2 = in->x2;
+			break;
+		case 2:
+			x1 = w - in->x1 - 1;
+			x2 = w - in->x2 - 1;
+			y1 = h - in->y1 - 1;
+			y2 = h - in->y2 - 1;
+			break;
+		case 3:
+			x1 = in->y1;
+			x2 = in->y2;
+			y1 = w - in->x1 - 1;
+			y2 = w - in->x2 - 1;
+			break;
+	}
+
+	out->x1 = x1;
+	out->x2 = x2;
+	out->y1 = y1;
+	out->y2 = y2;
+	rs_rect_normalize(out, out);
+
+	return;
+}
+
 void
 rs_roi_orientation(RS_BLOB *rs)
 {

Modified: trunk/src/rawstudio.h
===================================================================
--- trunk/src/rawstudio.h	2006-12-30 12:46:29 UTC (rev 980)
+++ trunk/src/rawstudio.h	2006-12-30 15:55:20 UTC (rev 981)
@@ -261,6 +261,9 @@
 RS_METADATA *rs_metadata_new();
 void rs_metadata_free(RS_METADATA *metadata);
 void rs_metadata_normalize_wb(RS_METADATA *meta);
+void rs_photo_flip(RS_PHOTO *photo);
+void rs_photo_mirror(RS_PHOTO *photo);
+void rs_photo_rotate(RS_PHOTO *photo, gint quarterturns, gdouble angle);
 RS_BLOB *rs_new();
 void rs_free(RS_BLOB *rs);
 void rs_zoom_to_fit(RS_BLOB *rs);

Modified: trunk/src/toolbox.c
===================================================================
--- trunk/src/toolbox.c	2006-12-30 12:46:29 UTC (rev 980)
+++ trunk/src/toolbox.c	2006-12-30 15:55:20 UTC (rev 981)
@@ -98,7 +98,7 @@
 gui_transform_rot90_clicked(GtkWidget *w, RS_BLOB *rs)
 {
 	if (!rs->photo) return;
-	ORIENTATION_90(rs->photo->orientation);
+	rs_photo_rotate(rs->photo, 1, 0.0);
 	update_preview(rs, FALSE, TRUE);
 }
 
@@ -106,7 +106,7 @@
 gui_transform_rot180_clicked(GtkWidget *w, RS_BLOB *rs)
 {
 	if (!rs->photo) return;
-	ORIENTATION_180(rs->photo->orientation);
+	rs_photo_rotate(rs->photo, 2, 0.0);
 	update_preview(rs, FALSE, TRUE);
 }
 
@@ -114,7 +114,7 @@
 gui_transform_rot270_clicked(GtkWidget *w, RS_BLOB *rs)
 {
 	if (!rs->photo) return;
-	ORIENTATION_270(rs->photo->orientation);
+	rs_photo_rotate(rs->photo, 3, 0.0);
 	update_preview(rs, FALSE, TRUE);
 }
 
@@ -122,7 +122,7 @@
 gui_transform_mirror_clicked(GtkWidget *w, RS_BLOB *rs)
 {
 	if (!rs->photo) return;
-	ORIENTATION_MIRROR(rs->photo->orientation);
+	rs_photo_mirror(rs->photo);
 	update_preview(rs, FALSE, TRUE);
 }
 
@@ -130,7 +130,7 @@
 gui_transform_flip_clicked(GtkWidget *w, RS_BLOB *rs)
 {
 	if (!rs->photo) return;
-	ORIENTATION_FLIP(rs->photo->orientation);
+	rs_photo_flip(rs->photo);
 	update_preview(rs, FALSE, TRUE);
 }
 




More information about the Rawstudio-commit mailing list