[gthumb: 105/129] rotate tool: removed skew algorithm, ready for affine transformation
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 105/129] rotate tool: removed skew algorithm, ready for affine transformation
- Date: Wed, 27 Apr 2011 20:59:12 +0000 (UTC)
commit 7a1b478f41e34632b3396cec1943a77ea4d06efc
Author: Stefano Pettini <spettini users sourceforge net>
Date: Thu Apr 21 12:19:01 2011 +0100
rotate tool: removed skew algorithm, ready for affine transformation
extensions/file_tools/gdk-pixbuf-rotate.c | 144 +++----------------------
extensions/file_tools/gdk-pixbuf-rotate.h | 4 +-
extensions/file_tools/gth-file-tool-rotate.c | 21 ++--
3 files changed, 29 insertions(+), 140 deletions(-)
---
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index 24a6f9e..9014dfd 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -19,143 +19,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <math.h>
#include <gthumb.h>
#include "gdk-pixbuf-rotate.h"
-#define interpolate_value(v1, f1, v2, f2) (CLAMP ((f1) * (v1) + (f2) * (v2), 0, 255))
-
-
-static GdkPixbuf*
-skew(GdkPixbuf *src_pixbuf,
- double angle,
- gint auto_crop)
-{
- GdkPixbuf *new_pixbuf;
- double skew;
- int src_rowstride, new_rowstride, n_channels;
- int width;
- int width_new;
- int height;
- int delta_max;
- int x;
- int y;
- guchar *p_src, *p_src2;
- guchar *p_new, *p_new_row;
- guchar r1, g1, b1;
- guchar r2, g2, b2;
- double delta;
- double f1, f2;
- int x1, x2;
-
- if (angle != 0.0 && angle >= -45 && angle <= 45.0) {
-
- skew = tan (angle / 180.0 * 3.1415926535);
-
- n_channels = gdk_pixbuf_get_n_channels (src_pixbuf);
-
- width = gdk_pixbuf_get_width (src_pixbuf);
- height = gdk_pixbuf_get_height (src_pixbuf);
- delta_max = (int) floor (fabs (skew * height));
-
- if (auto_crop)
- width_new = width - delta_max;
- else
- width_new = width + delta_max;
-
- new_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src_pixbuf),
- gdk_pixbuf_get_has_alpha (src_pixbuf),
- gdk_pixbuf_get_bits_per_sample (src_pixbuf),
- width_new,
- height);
-
- p_src = gdk_pixbuf_get_pixels (src_pixbuf);
- p_new = gdk_pixbuf_get_pixels (new_pixbuf);
-
- src_rowstride = gdk_pixbuf_get_rowstride (src_pixbuf);
- new_rowstride = gdk_pixbuf_get_rowstride (new_pixbuf);
-
- for (y = 0; y < height; y++) {
-
- if (skew > 0)
- delta = skew * y;
- else
- delta = skew * -(height - y - 1);
-
- f1 = delta - floor (delta);
- f2 = 1.0 - f1;
-
- p_new_row = p_new;
-
- for (x = 0; x < width_new; x++) {
-
- x1 = (int) floor (x - delta);
- x2 = (int) ceil (x - delta);
-
- if (auto_crop) {
- x1 += delta_max;
- x2 += delta_max;
- }
-
- if (x1 < 0 || x1 >= width) {
- r1 = 0;
- g1 = 0;
- b1 = 0;
- }
- else {
- p_src2 = p_src + x1 * n_channels;
-
- r1 = p_src2[RED_PIX];
- g1 = p_src2[GREEN_PIX];
- b1 = p_src2[BLUE_PIX];
- }
-
- if (x2 < 0 || x2 >= width) {
- r2 = 0;
- g2 = 0;
- b2 = 0;
- }
- else {
- p_src2 = p_src + x2 * n_channels;
-
- r2 = p_src2[RED_PIX];
- g2 = p_src2[GREEN_PIX];
- b2 = p_src2[BLUE_PIX];
- }
-
- p_new_row[RED_PIX] = interpolate_value(r1, f1, r2, f2);
- p_new_row[GREEN_PIX] = interpolate_value(g1, f1, g2, f2);
- p_new_row[BLUE_PIX] = interpolate_value(b1, f1, b2, f2);
-
- p_new_row += n_channels;
- }
-
- p_src += src_rowstride;
- p_new += new_rowstride;
- }
- }
- else {
- g_object_ref (src_pixbuf);
- new_pixbuf = src_pixbuf;
- }
-
- return new_pixbuf;
-}
-
-
GdkPixbuf*
_gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
- int center_x,
- int center_y,
+ double center_x,
+ double center_y,
double angle,
gint auto_crop)
{
GdkPixbuf *new_pixbuf;
-
- // TODO: implement the correct rotate algorithm
+
+ if (angle == 0.0) {
+ new_pixbuf = src_pixbuf;
+ g_object_ref (new_pixbuf);
+ }
+ else if (angle >= 90.0) {
+ new_pixbuf = gdk_pixbuf_rotate_simple (src_pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
+ }
+ else if (angle <= -90.0) {
+ new_pixbuf = gdk_pixbuf_rotate_simple (src_pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
+ }
+ else {
+ // TODO: implement the rotation here
- new_pixbuf = skew (src_pixbuf, angle, auto_crop);
+ new_pixbuf = src_pixbuf;
+ g_object_ref (new_pixbuf);
+ }
return new_pixbuf;
}
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.h b/extensions/file_tools/gdk-pixbuf-rotate.h
index 8749bc4..b73a4b6 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.h
+++ b/extensions/file_tools/gdk-pixbuf-rotate.h
@@ -29,8 +29,8 @@
G_BEGIN_DECLS
GdkPixbuf* _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
- int center_x,
- int center_y,
+ double center_x,
+ double center_y,
double angle,
gint auto_crop);
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 1c16bb1..fc95060 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -107,8 +107,8 @@ apply_cb (gpointer user_data)
GtkWidget *window;
GtkWidget *viewer_page;
double rotation_angle;
- int center_x;
- int center_y;
+ double center_x;
+ double center_y;
gint auto_crop;
if (self->priv->apply_event != 0) {
@@ -120,17 +120,14 @@ apply_cb (gpointer user_data)
viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
rotation_angle = gtk_range_get_value (GTK_RANGE (self->priv->rotation_angle));
+ center_x = (self->priv->pixbuf_width - 1) / 2.0;
+ center_y = (self->priv->pixbuf_height - 1) / 2.0;
+ auto_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->auto_crop));
- if (rotation_angle != 0.0) {
- center_x = self->priv->pixbuf_width / 2;
- center_y = self->priv->pixbuf_height / 2;
- auto_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->auto_crop));
-
- _g_object_unref (self->priv->dest_pixbuf);
- self->priv->dest_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, center_x, center_y, rotation_angle, auto_crop);
-
- gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
- }
+ _g_object_unref (self->priv->dest_pixbuf);
+ self->priv->dest_pixbuf = _gdk_pixbuf_rotate (self->priv->src_pixbuf, center_x, center_y, rotation_angle, auto_crop);
+
+ gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]