Author: post
Date: 2009-07-08 18:43:46 +0200 (Wed, 08 Jul 2009)
New Revision: 2579

Modified:
   trunk/plugins/rotate/rotate.c
Log:
Added fast mode to rotate. Approx 4x speedup.

Modified: trunk/plugins/rotate/rotate.c
===================================================================
--- trunk/plugins/rotate/rotate.c       2009-07-07 23:26:46 UTC (rev 2578)
+++ trunk/plugins/rotate/rotate.c       2009-07-08 16:43:46 UTC (rev 2579)
@@ -65,6 +65,7 @@
        GThread *threadid;
        gboolean use_straight;
        RSRotate* rotate;
+       gboolean use_fast;              /* Use nearest neighbour resampler */
 } ThreadInfo;
 
 
@@ -76,6 +77,7 @@
 static gint get_width(RSFilter *filter);
 static gint get_height(RSFilter *filter);
 static void inline bilinear(RS_IMAGE16 *in, gushort *out, gint x, gint y);
+static void inline nearest(RS_IMAGE16 *in, gushort *out, gint x, gint y);
 static void recalculate(RSRotate *rotate);
 gpointer start_rotate_thread(gpointer _thread_info);
 
@@ -195,6 +197,7 @@
        RSFilterResponse *response;
        RS_IMAGE16 *input;
        RS_IMAGE16 *output = NULL;
+       gboolean use_fast = FALSE;
 
        previous_response = rs_filter_get_image(filter->previous, param);
 
@@ -223,6 +226,12 @@
                recalculate(rotate);
        }
 
+       if (rs_filter_param_get_quick(param))
+       {
+               use_fast = TRUE;
+               rs_filter_response_set_quick(response);
+       }
+
        /* Prepare threads */
        guint i, y_offset, y_per_thread, threaded_h;
        const guint threads = rs_get_number_of_processor_cores();
@@ -243,6 +252,7 @@
                y_offset = MIN(threaded_h, y_offset);
                t[i].end_y = y_offset;
                t[i].rotate = rotate;
+               t[i].use_fast = use_fast;
 
                t[i].threadid = g_thread_create(start_rotate_thread, &t[i], 
TRUE, NULL);
        }
@@ -290,7 +300,10 @@
                {
                        x = col * crapx + foox + 32768;
                        y = col * crapy + fooy + 32768;
-                       bilinear(input, &output->pixels[destoffset], x>>8, 
y>>8);
+                       if (t->use_fast)
+                               nearest(input, &output->pixels[destoffset], 
x>>16, y>>16);
+                       else
+                               bilinear(input, &output->pixels[destoffset], 
x>>8, y>>8);
                }
        }
 
@@ -323,6 +336,25 @@
 }
 
 static void inline
+nearest(RS_IMAGE16 *in, gushort *out, gint x, gint y)
+{
+
+       /* Try to interpolate borders against black */
+       if ((x < 0) || (y < 0) || (x >= (in->w-1)) || (y >= (in->h-1)))
+       {
+               out[R] = out[G] = out[B] = 0;
+               return;
+       }
+
+       gushort* p = GET_PIXEL(in, x, y);
+
+       out[R] = p[R];
+       out[G] = p[G];
+       out[B] = p[B];
+}
+
+
+static void inline
 bilinear(RS_IMAGE16 *in, gushort *out, gint x, gint y)
 {
        const static gushort black[4] = {0, 0, 0, 0};


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to