Author: post
Date: 2010-03-23 22:21:54 +0100 (Tue, 23 Mar 2010)
New Revision: 3266
Modified:
trunk/plugins/resample/resample-sse2.c
trunk/plugins/resample/resample.c
Log:
Resampler: Use float instead of double for coefficient calculation. Faster and
good enough precision.
Modified: trunk/plugins/resample/resample-sse2.c
===================================================================
--- trunk/plugins/resample/resample-sse2.c 2010-03-23 21:20:25 UTC (rev
3265)
+++ trunk/plugins/resample/resample-sse2.c 2010-03-23 21:21:54 UTC (rev
3266)
@@ -36,7 +36,7 @@
guint dest_offset_other; /* Where in the unchanged direction
should we begin writing? */
guint dest_end_other; /* Where in the unchanged direction
should we stop writing? */
guint (*resample_support)();
- gdouble (*resample_func)(gdouble);
+ gfloat (*resample_func)(gfloat);
GThread *threadid;
gboolean use_compatible; /* Use compatible resampler if
pixelsize != 4 */
gboolean use_fast; /* Use nearest neighbour resampler,
also compatible*/
@@ -52,28 +52,28 @@
return 3;
}
-static gdouble
-sinc(gdouble value)
+static gfloat
+sinc(gfloat value)
{
- if (value != 0.0)
+ if (value != 0.0f)
{
value *= M_PI;
- return sin(value) / value;
+ return sinf(value) / value;
}
else
- return 1.0;
+ return 1.0f;
}
-static gdouble
-lanczos_weight(gdouble value)
+static gfloat
+lanczos_weight(gfloat value)
{
- value = fabs(value);
+ value = fabsf(value);
if (value < lanczos_taps())
{
return (sinc(value) * sinc(value / lanczos_taps()));
}
else
- return 0.0;
+ return 0.0f;
}
const static gint FPScale = 16384; /* fixed point scaler */
@@ -93,9 +93,9 @@
const guint start_x = info->dest_offset_other * input->pixelsize;
const guint end_x = info->dest_end_other * input->pixelsize;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0f / pos_step, 1.0f);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -104,7 +104,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0;
gint i,j,k;
@@ -122,10 +122,10 @@
offsets[i] = start_pos;
/* The following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -135,11 +135,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = ((gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5)) & 0xffff;
total2 = total3;
@@ -284,9 +284,9 @@
const guint start_x = info->dest_offset_other * input->pixelsize;
const guint end_x = info->dest_end_other * input->pixelsize;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0f / pos_step, 1.0f);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -295,7 +295,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0;
gint i,j,k;
@@ -313,10 +313,10 @@
offsets[i] = start_pos;
/* The following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0f,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -326,11 +326,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = ((gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5)) & 0xffff;
total2 = total3;
Modified: trunk/plugins/resample/resample.c
===================================================================
--- trunk/plugins/resample/resample.c 2010-03-23 21:20:25 UTC (rev 3265)
+++ trunk/plugins/resample/resample.c 2010-03-23 21:21:54 UTC (rev 3266)
@@ -54,7 +54,7 @@
guint dest_offset_other; /* Where in the unchanged direction
should we begin writing? */
guint dest_end_other; /* Where in the unchanged direction
should we stop writing? */
guint (*resample_support)();
- gdouble (*resample_func)(gdouble);
+ gfloat (*resample_func)(gfloat);
GThread *threadid;
gboolean use_compatible; /* Use compatible resampler if
pixelsize != 4 */
gboolean use_fast; /* Use nearest neighbour resampler,
also compatible*/
@@ -446,28 +446,28 @@
return 3;
}
-static gdouble
-sinc(gdouble value)
+static gfloat
+sinc(gfloat value)
{
- if (value != 0.0)
+ if (value != 0.0f)
{
value *= M_PI;
- return sin(value) / value;
+ return sinf(value) / value;
}
else
- return 1.0;
+ return 1.0f;
}
-static gdouble
-lanczos_weight(gdouble value)
+static gfloat
+lanczos_weight(gfloat value)
{
- value = fabs(value);
+ value = fabsf(value);
if (value < lanczos_taps())
{
return (sinc(value) * sinc(value / lanczos_taps()));
}
else
- return 0.0;
+ return 0.0f;
}
const static gint FPScale = 16384; /* fixed point scaler */
@@ -481,9 +481,9 @@
const guint old_size = info->old_size;
const guint new_size = info->new_size;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0 / pos_step, 1.0);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -492,7 +492,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0f;
gint i,j,k;
for (i=0; i<new_size; ++i)
@@ -510,10 +510,10 @@
offsets[i] = start_pos * 4;
/* the following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -523,11 +523,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = (gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5);
total2 = total3;
}
@@ -580,9 +580,9 @@
const guint start_x = info->dest_offset_other;
const guint end_x = info->dest_end_other;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0 / pos_step, 1.0);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -591,7 +591,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0;
gint i,j,k;
@@ -609,10 +609,10 @@
offsets[i] = start_pos;
/* The following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -622,11 +622,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = (gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5);
total2 = total3;
}
@@ -678,9 +678,9 @@
gint pixelsize = input->pixelsize;
gint ch = input->channels;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0 / pos_step, 1.0);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -689,7 +689,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0;
gint i,j,k;
for (i=0; i<new_size; ++i)
@@ -707,10 +707,10 @@
offsets[i] = start_pos * pixelsize;
/* the following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -720,11 +720,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = (gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5);
total2 = total3;
}
@@ -775,9 +775,9 @@
gint pixelsize = input->pixelsize;
gint ch = input->channels;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
- gdouble filter_step = MIN(1.0 / pos_step, 1.0);
- gdouble filter_support = (gdouble) lanczos_taps() / filter_step;
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
+ gfloat filter_step = MIN(1.0 / pos_step, 1.0);
+ gfloat filter_support = (gfloat) lanczos_taps() / filter_step;
gint fir_filter_size = (gint) (ceil(filter_support*2));
if (old_size <= fir_filter_size)
@@ -786,7 +786,7 @@
gint *weights = g_new(gint, new_size * fir_filter_size);
gint *offsets = g_new(gint, new_size);
- gdouble pos = 0.0;
+ gfloat pos = 0.0;
gint i,j,k;
@@ -804,10 +804,10 @@
offsets[i] = start_pos;
/* The following code ensures that the coefficients add to
exactly FPScale */
- gdouble total = 0.0;
+ gfloat total = 0.0;
/* Ensure that we have a valid position */
- gdouble ok_pos = MAX(0.0,MIN(old_size-1,pos));
+ gfloat ok_pos = MAX(0.0,MIN(old_size-1,pos));
for (j=0; j<fir_filter_size; ++j)
{
@@ -817,11 +817,11 @@
g_assert(total > 0.0f);
- gdouble total2 = 0.0;
+ gfloat total2 = 0.0;
for (k=0; k<fir_filter_size; ++k)
{
- gdouble total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
+ gfloat total3 = total2 + lanczos_weight((start_pos+k -
ok_pos) * filter_step) / total;
weights[i*fir_filter_size+k] = (gint)
(total3*FPScale+0.5) - (gint) (total2*FPScale+0.5);
total2 = total3;
}
@@ -868,7 +868,7 @@
gint pixelsize = input->pixelsize;
gint ch = input->channels;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
gint pos = 0;
gint delta = (gint)(pos_step * 65536.0);
@@ -903,7 +903,7 @@
gint pixelsize = input->pixelsize;
gint ch = input->channels;
- gdouble pos_step = ((gdouble) old_size) / ((gdouble)new_size);
+ gfloat pos_step = ((gfloat) old_size) / ((gfloat)new_size);
gint pos;
gint delta = (gint)(pos_step * 65536.0);
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit