[gegl] replace many uses of double precision float with single
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] replace many uses of double precision float with single
- Date: Wed, 9 Jul 2014 06:53:50 +0000 (UTC)
commit 125ff4bc8f5f6e3b1168037004bb6e25226f4beb
Author: Øyvind Kolås <pippin gimp org>
Date: Sat Jul 5 22:21:58 2014 +0200
replace many uses of double precision float with single
For computing cubic / linear weights, we do not need the double binary
floating point precision to our "native" output format which is 32bit float.
gegl/buffer/gegl-buffer-access.c | 8 +++---
gegl/buffer/gegl-sampler-cubic.c | 4 +-
gegl/buffer/gegl-sampler-linear.c | 8 +++---
gegl/gegl-algorithms-boxfilter.inc | 51 ++++++++++++++++++++++++++---------
gegl/gegl-algorithms.c | 8 +++---
5 files changed, 52 insertions(+), 27 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index bd11d66..a9c71d7 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1337,9 +1337,9 @@ _gegl_get_required_for_scale (const Babl *format,
return *roi;
else
{
- gint x1 = floor (roi->x / scale + GEGL_SCALE_EPSILON);
+ gint x1 = floorf (roi->x / scale + GEGL_SCALE_EPSILON);
gint x2 = ceil ((roi->x + roi->width) / scale - GEGL_SCALE_EPSILON);
- gint y1 = floor (roi->y / scale + GEGL_SCALE_EPSILON);
+ gint y1 = floorf (roi->y / scale + GEGL_SCALE_EPSILON);
gint y2 = ceil ((roi->y + roi->height) / scale - GEGL_SCALE_EPSILON);
gint pad = (1.0 / scale > 1.0) ? ceil (1.0 / scale) : 1;
@@ -1416,9 +1416,9 @@ _gegl_buffer_get_unlocked (GeglBuffer *buffer,
gint bpp = babl_format_get_bytes_per_pixel (format);
GeglRectangle sample_rect;
void *sample_buf;
- gint x1 = floor (rect->x / scale + GEGL_SCALE_EPSILON);
+ gint x1 = floorf (rect->x / scale + GEGL_SCALE_EPSILON);
gint x2 = ceil ((rect->x + rect->width) / scale - GEGL_SCALE_EPSILON);
- gint y1 = floor (rect->y / scale + GEGL_SCALE_EPSILON);
+ gint y1 = floorf (rect->y / scale + GEGL_SCALE_EPSILON);
gint y2 = ceil ((rect->y + rect->height) / scale - GEGL_SCALE_EPSILON);
gint factor = 1;
gint stride;
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index 156a327..ad4f4a7 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -188,8 +188,8 @@ gegl_sampler_cubic_get ( GeglSampler *self,
const double iabsolute_x = (double) absolute_x - 0.5;
const double iabsolute_y = (double) absolute_y - 0.5;
- const gint ix = floor (iabsolute_x);
- const gint iy = floor (iabsolute_y);
+ const gint ix = floorf (iabsolute_x);
+ const gint iy = floorf (iabsolute_y);
/*
* x is the x-coordinate of the sampling point relative to the
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index 92a881f..add9f04 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -93,11 +93,11 @@ gegl_sampler_linear_get ( GeglSampler* restrict self,
* index (0,0), to a coordinate system in which the origin is at the
* center of the same pixel.
*/
- const double iabsolute_x = (double) absolute_x - 0.5;
- const double iabsolute_y = (double) absolute_y - 0.5;
+ const float iabsolute_x = (float) absolute_x - 0.5;
+ const float iabsolute_y = (float) absolute_y - 0.5;
- const gint ix = floor (iabsolute_x);
- const gint iy = floor (iabsolute_y);
+ const gint ix = floorf (iabsolute_x);
+ const gint iy = floorf (iabsolute_y);
/*
* Point the data tile pointer to the first channel of the top_left
diff --git a/gegl/gegl-algorithms-boxfilter.inc b/gegl/gegl-algorithms-boxfilter.inc
index 3db883b..262578d 100644
--- a/gegl/gegl-algorithms-boxfilter.inc
+++ b/gegl/gegl-algorithms-boxfilter.inc
@@ -8,16 +8,16 @@ BOXFILTER_FUNCNAME (guchar *dest_buf,
const gint bpp,
const gint d_rowstride)
{
- gdouble left_weight, center_weight, right_weight;
- gdouble top_weight, middle_weight, bottom_weight;
+ gfloat left_weight, center_weight, right_weight;
+ gfloat top_weight, middle_weight, bottom_weight;
const BOXFILTER_TYPE *src[9];
gint x, y;
gint components = bpp / sizeof(BOXFILTER_TYPE);
for (y = 0; y < dst_rect->height; y++)
{
- const gdouble sy = (dst_rect->y + y + .5) / scale - src_rect->y;
- const gint ii = floor (sy);
+ const gfloat sy = (dst_rect->y + y + .5) / scale - src_rect->y;
+ const gint ii = floorf (sy);
BOXFILTER_TYPE *dst = (BOXFILTER_TYPE*)(dest_buf + y * d_rowstride);
const guchar *src_base = source_buf + ii * s_rowstride;
@@ -27,8 +27,8 @@ BOXFILTER_FUNCNAME (guchar *dest_buf,
for (x = 0; x < dst_rect->width; x++)
{
- const gdouble sx = (dst_rect->x + x + .5) / scale - src_rect->x;
- const gint jj = floor (sx);
+ const gfloat sx = (dst_rect->x + x + .5) / scale - src_rect->x;
+ const gint jj = floorf (sx);
left_weight = MAX (0., .5 - scale * (sx - jj));
right_weight = MAX (0., .5 - scale * ((jj + 1) - sx));
@@ -57,13 +57,38 @@ BOXFILTER_FUNCNAME (guchar *dest_buf,
const gdouble rm = right_weight * middle_weight;
const gdouble rb = right_weight * bottom_weight;
- for (gint i = 0; i < components; ++i)
- {
- dst[i] = BOXFILTER_ROUND(
- src[0][i] * lt + src[3][i] * lm + src[6][i] * lb +
- src[1][i] * ct + src[4][i] * cm + src[7][i] * cb +
- src[2][i] * rt + src[5][i] * rm + src[8][i] * rb);
- }
+ switch (components)
+ {
+ case 4:
+ dst[3] = BOXFILTER_ROUND(
+ src[0][3] * lt + src[3][3] * lm + src[6][3] * lb +
+ src[1][3] * ct + src[4][3] * cm + src[7][3] * cb +
+ src[2][3] * rt + src[5][3] * rm + src[8][3] * rb);
+ case 3:
+ dst[2] = BOXFILTER_ROUND(
+ src[0][2] * lt + src[3][2] * lm + src[6][2] * lb +
+ src[1][2] * ct + src[4][2] * cm + src[7][2] * cb +
+ src[2][2] * rt + src[5][2] * rm + src[8][2] * rb);
+ case 2:
+ dst[1] = BOXFILTER_ROUND(
+ src[0][1] * lt + src[3][1] * lm + src[6][1] * lb +
+ src[1][1] * ct + src[4][1] * cm + src[7][1] * cb +
+ src[2][1] * rt + src[5][1] * rm + src[8][1] * rb);
+ case 1:
+ dst[0] = BOXFILTER_ROUND(
+ src[0][0] * lt + src[3][0] * lm + src[6][0] * lb +
+ src[1][0] * ct + src[4][0] * cm + src[7][0] * cb +
+ src[2][0] * rt + src[5][0] * rm + src[8][0] * rb);
+ break;
+ default:
+ for (gint i = 0; i < components; ++i)
+ {
+ dst[i] = BOXFILTER_ROUND(
+ src[0][i] * lt + src[3][i] * lm + src[6][i] * lb +
+ src[1][i] * ct + src[4][i] * cm + src[7][i] * cb +
+ src[2][i] * rt + src[5][i] * rm + src[8][i] * rb);
+ }
+ }
}
dst += components;
diff --git a/gegl/gegl-algorithms.c b/gegl/gegl-algorithms.c
index d5a5959..ebe9663 100644
--- a/gegl/gegl-algorithms.c
+++ b/gegl/gegl-algorithms.c
@@ -130,13 +130,13 @@ gegl_resample_nearest (guchar *dst,
for (i = 0; i < dst_rect->height; i++)
{
- const gdouble sy = (dst_rect->y + .5 + i) / scale - src_rect->y;
- const gint ii = floor (sy + GEGL_SCALE_EPSILON);
+ const gfloat sy = (dst_rect->y + .5 + i) / scale - src_rect->y;
+ const gint ii = floorf (sy + GEGL_SCALE_EPSILON);
for (j = 0; j < dst_rect->width; j++)
{
- const gdouble sx = (dst_rect->x + .5 + j) / scale - src_rect->x;
- const gint jj = floor (sx + GEGL_SCALE_EPSILON);
+ const gfloat sx = (dst_rect->x + .5 + j) / scale - src_rect->x;
+ const gint jj = floorf (sx + GEGL_SCALE_EPSILON);
memcpy (&dst[i * dst_stride + j * bpp],
&src[ii * src_stride + jj * bpp],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]