[gegl] Use explicit rects for box-max and box-min process
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] Use explicit rects for box-max and box-min process
- Date: Mon, 20 Dec 2010 22:01:54 +0000 (UTC)
commit 0b6bce93c3e2dc64ffd57ce241dc391e744aaf2a
Author: Danny Robson <danny blubinc net>
Date: Wed Feb 3 22:30:22 2010 +1100
Use explicit rects for box-max and box-min process
Instead of using the entire input and output pads, use the roi and
require_for_output rects for processing the box-min and box-max.
operations/workshop/box-max.c | 74 ++++++++++++++++++++--------------------
operations/workshop/box-min.c | 61 ++++++++++++++++-----------------
2 files changed, 67 insertions(+), 68 deletions(-)
---
diff --git a/operations/workshop/box-max.c b/operations/workshop/box-max.c
index 6c99aa0..6d3af64 100644
--- a/operations/workshop/box-max.c
+++ b/operations/workshop/box-max.c
@@ -31,8 +31,8 @@ gegl_chant_double (radius, _("Radius"), 0.0, 200.0, 4.0,
#define GEGL_CHANT_C_FILE "box-max.c"
#include "gegl-chant.h"
-#include <math.h>
#include <stdio.h>
+#include <math.h>
static inline gfloat
get_max_component (gfloat *buf,
@@ -44,9 +44,9 @@ get_max_component (gfloat *buf,
gint height,
gint component)
{
- gint x, y;
+ gint x, y;
gfloat max=-1000000000.0;
- gint count=0;
+ gint count=0;
gint offset = (y0 * buf_width + x0) * 4 + component;
@@ -69,38 +69,40 @@ get_max_component (gfloat *buf,
}
static void
-hor_max (GeglBuffer *src,
- GeglBuffer *dst,
- gint radius)
+hor_max (GeglBuffer *src,
+ const GeglRectangle *src_rect,
+ GeglBuffer *dst,
+ const GeglRectangle *dst_rect,
+ gint radius)
{
gint u,v;
gint offset;
gfloat *src_buf;
gfloat *dst_buf;
- src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
- dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
+ src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+ dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4);
- gegl_buffer_get (src, 1.0, NULL, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_get (src, 1.0, src_rect, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
offset = 0;
- for (v=0; v<gegl_buffer_get_height (dst); v++)
- for (u=0; u<gegl_buffer_get_width (dst); u++)
+ for (v=0; v<dst_rect->height; v++)
+ for (u=0; u<dst_rect->width; u++)
{
gint i;
for (i=0; i<4; i++)
dst_buf [offset++] = get_max_component (src_buf,
- gegl_buffer_get_width (src),
- gegl_buffer_get_height (src),
- u - radius,
- v,
+ src_rect->width,
+ src_rect->height,
+ u + radius - radius,
+ v + radius,
1 + radius*2,
1,
i);
}
- gegl_buffer_set (dst, NULL, babl_format ("RGBA float"), dst_buf,
+ gegl_buffer_set (dst, dst_rect, babl_format ("RGBA float"), dst_buf,
GEGL_AUTO_ROWSTRIDE);
g_free (src_buf);
g_free (dst_buf);
@@ -109,30 +111,32 @@ hor_max (GeglBuffer *src,
static void
ver_max (GeglBuffer *src,
- GeglBuffer *dst,
- gint radius)
+ const GeglRectangle *src_rect,
+ GeglBuffer *dst,
+ const GeglRectangle *dst_rect,
+ gint radius)
{
gint u,v;
gint offset;
gfloat *src_buf;
gfloat *dst_buf;
- src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
- dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
+ src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+ dst_buf = g_new0 (gfloat, dst_rect->width * src_rect->height * 4);
- gegl_buffer_get (src, 1.0, NULL, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_get (src, 1.0, src_rect, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
offset=0;
- for (v=0; v<gegl_buffer_get_height (dst); v++)
- for (u=0; u<gegl_buffer_get_width (dst); u++)
+ for (v=0; v<dst_rect->height; v++)
+ for (u=0; u<dst_rect->width; u++)
{
gint c;
for (c=0; c<4; c++)
dst_buf [offset++] =
get_max_component (src_buf,
- gegl_buffer_get_width (src),
- gegl_buffer_get_height (src),
+ src_rect->width,
+ src_rect->height,
u,
v - radius,
1,
@@ -140,7 +144,7 @@ ver_max (GeglBuffer *src,
c);
}
- gegl_buffer_set (dst, NULL, babl_format ("RGBA float"), dst_buf,
+ gegl_buffer_set (dst, dst_rect, babl_format ("RGBA float"), dst_buf,
GEGL_AUTO_ROWSTRIDE);
g_free (src_buf);
g_free (dst_buf);
@@ -149,9 +153,10 @@ ver_max (GeglBuffer *src,
static void prepare (GeglOperation *operation)
{
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
-
- area->left = area->right = area->top = area->bottom =
- ceil (GEGL_CHANT_PROPERTIES (operation)->radius);
+ area->left =
+ area->right =
+ area->top =
+ area->bottom = GEGL_CHANT_PROPERTIES (operation)->radius;
gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
}
@@ -162,15 +167,10 @@ process (GeglOperation *operation,
const GeglRectangle *result)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
- GeglBuffer *temp;
-
- temp = gegl_buffer_new (gegl_buffer_get_extent (input),
- babl_format ("RGBA float"));
-
- hor_max (input, temp, o->radius);
- ver_max (temp, output, o->radius);
+ GeglRectangle input_rect = gegl_operation_get_required_for_output (operation, "input", result);
- g_object_unref (temp);
+ hor_max ( input, &input_rect, output, result, o->radius);
+ ver_max (output, result, output, result, o->radius);
return TRUE;
}
diff --git a/operations/workshop/box-min.c b/operations/workshop/box-min.c
index 586f5e4..78f197c 100644
--- a/operations/workshop/box-min.c
+++ b/operations/workshop/box-min.c
@@ -69,38 +69,40 @@ get_min_component (gfloat *buf,
}
static void
-hor_min (GeglBuffer *src,
- GeglBuffer *dst,
- gint radius)
+hor_min (GeglBuffer *src,
+ const GeglRectangle *src_rect,
+ GeglBuffer *dst,
+ const GeglRectangle *dst_rect,
+ gint radius)
{
gint u,v;
gint offset;
gfloat *src_buf;
gfloat *dst_buf;
- src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
- dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
+ src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+ dst_buf = g_new0 (gfloat, dst_rect->width * dst_rect->height * 4);
- gegl_buffer_get (src, 1.0, NULL, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_get (src, 1.0, src_rect, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
offset = 0;
- for (v=0; v<gegl_buffer_get_height (dst); v++)
- for (u=0; u<gegl_buffer_get_width (dst); u++)
+ for (v=0; v<dst_rect->height; v++)
+ for (u=0; u<dst_rect->width; u++)
{
gint i;
for (i=0; i<4; i++)
dst_buf [offset++] = get_min_component (src_buf,
- gegl_buffer_get_width (src),
- gegl_buffer_get_height (src),
- u - radius,
- v,
+ src_rect->width,
+ src_rect->height,
+ u + radius - radius,
+ v + radius,
1 + radius*2,
1,
i);
}
- gegl_buffer_set (dst, NULL, babl_format ("RGBA float"), dst_buf,
+ gegl_buffer_set (dst, dst_rect, babl_format ("RGBA float"), dst_buf,
GEGL_AUTO_ROWSTRIDE);
g_free (src_buf);
g_free (dst_buf);
@@ -109,30 +111,32 @@ hor_min (GeglBuffer *src,
static void
ver_min (GeglBuffer *src,
- GeglBuffer *dst,
- gint radius)
+ const GeglRectangle *src_rect,
+ GeglBuffer *dst,
+ const GeglRectangle *dst_rect,
+ gint radius)
{
gint u,v;
gint offset;
gfloat *src_buf;
gfloat *dst_buf;
- src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (src) * 4);
- dst_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (dst) * 4);
+ src_buf = g_new0 (gfloat, src_rect->width * src_rect->height * 4);
+ dst_buf = g_new0 (gfloat, dst_rect->width * src_rect->height * 4);
- gegl_buffer_get (src, 1.0, NULL, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_get (src, 1.0, src_rect, babl_format ("RGBA float"), src_buf, GEGL_AUTO_ROWSTRIDE);
offset=0;
- for (v=0; v<gegl_buffer_get_height (dst); v++)
- for (u=0; u<gegl_buffer_get_width (dst); u++)
+ for (v=0; v<dst_rect->height; v++)
+ for (u=0; u<dst_rect->width; u++)
{
gint c;
for (c=0; c<4; c++)
dst_buf [offset++] =
get_min_component (src_buf,
- gegl_buffer_get_width (src),
- gegl_buffer_get_height (src),
+ src_rect->width,
+ src_rect->height,
u,
v - radius,
1,
@@ -140,7 +144,7 @@ ver_min (GeglBuffer *src,
c);
}
- gegl_buffer_set (dst, NULL, babl_format ("RGBA float"), dst_buf,
+ gegl_buffer_set (dst, dst_rect, babl_format ("RGBA float"), dst_buf,
GEGL_AUTO_ROWSTRIDE);
g_free (src_buf);
g_free (dst_buf);
@@ -163,15 +167,10 @@ process (GeglOperation *operation,
const GeglRectangle *result)
{
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
- GeglBuffer *temp;
+ GeglRectangle input_rect = gegl_operation_get_required_for_output (operation, "input", result);
- temp = gegl_buffer_new (gegl_buffer_get_extent (input),
- babl_format ("RGBA float"));
-
- hor_min (input, temp, o->radius);
- ver_min (temp, output, o->radius);
-
- g_object_unref (temp);
+ hor_min ( input, &input_rect, output, result, o->radius);
+ ver_min (output, result, output, result, o->radius);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]