[gegl/npd-squashed: 8/11] npd: access input and output buffers directly



commit d9d45dfcc7184ad4d7e3739aeedfea9d084eb46b
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Mon Dec 2 04:10:42 2013 +0100

    npd: access input and output buffers directly

 libs/npd/Makefile.am      |    1 +
 libs/npd/npd_gegl.c       |   30 ++++++++++++++------------
 libs/npd/npd_gegl.h       |   16 +++++++++-----
 libs/npd/npd_math.h       |    9 --------
 operations/external/npd.c |   49 ++++++++++++++++++++------------------------
 5 files changed, 49 insertions(+), 56 deletions(-)
---
diff --git a/libs/npd/Makefile.am b/libs/npd/Makefile.am
index be99db0..080bb9d 100644
--- a/libs/npd/Makefile.am
+++ b/libs/npd/Makefile.am
@@ -12,6 +12,7 @@ GEGL_NPD_public_HEADERS = \
        npd_math.h       \
        graphics.h       \
        lattice_cut.h    \
+       npd_gegl.h       \
        npd.h
 
 GEGL_NPD_SOURCES = \
diff --git a/libs/npd/npd_gegl.c b/libs/npd/npd_gegl.c
index 509a123..baf3dbe 100644
--- a/libs/npd/npd_gegl.c
+++ b/libs/npd/npd_gegl.c
@@ -65,7 +65,7 @@ npd_gegl_set_pixel_color (NPDImage *image,
   if (x > -1 && x < image->width &&
       y > -1 && y < image->height)
     {
-      gint position = 4 * (y * image->width + x);
+      gint position = y * image->rowstride + 4 * x;
 
       image->buffer[position + 0] = color->r;
       image->buffer[position + 1] = color->g;
@@ -83,7 +83,7 @@ npd_gegl_get_pixel_color (NPDImage *image,
   if (x > -1 && x < image->width &&
       y > -1 && y < image->height)
     {
-      gint position = 4 * (y * image->width + x);
+      gint position = y * image->rowstride + 4 * x;
 
       color->r = image->buffer[position + 0];
       color->g = image->buffer[position + 1];
@@ -97,22 +97,24 @@ npd_gegl_get_pixel_color (NPDImage *image,
 }
 
 void
-npd_gegl_create_image (NPDImage   *image,
-                       GeglBuffer *gegl_buffer,
-                       const Babl *format)
+npd_gegl_open_buffer (NPDImage *image)
 {
-  guchar *buffer;
-  buffer = g_new0 (guchar, gegl_buffer_get_pixel_count (gegl_buffer) * 4);
-  gegl_buffer_get (gegl_buffer, NULL, 1.0, format,
-                   buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+  image->buffer = (guchar*) gegl_buffer_linear_open (image->gegl_buffer, NULL, &image->rowstride, 
image->format);
+}
 
-  image->buffer = buffer;
-  image->width = gegl_buffer_get_width (gegl_buffer);
-  image->height = gegl_buffer_get_height (gegl_buffer);
+void
+npd_gegl_close_buffer (NPDImage *image)
+{
+  gegl_buffer_linear_close (image->gegl_buffer, image->buffer);
 }
 
 void
-npd_gegl_destroy_image (NPDImage *image)
+npd_gegl_init_image (NPDImage   *image,
+                     GeglBuffer *gegl_buffer,
+                     const Babl *format)
 {
-  g_free(image->buffer);
+  image->gegl_buffer = gegl_buffer;
+  image->width = gegl_buffer_get_width (gegl_buffer);
+  image->height = gegl_buffer_get_height (gegl_buffer);
+  image->format = format;
 }
diff --git a/libs/npd/npd_gegl.h b/libs/npd/npd_gegl.h
index f255061..855473e 100644
--- a/libs/npd/npd_gegl.h
+++ b/libs/npd/npd_gegl.h
@@ -28,10 +28,13 @@
 
 struct _NPDImage
 {
-  gint     width;
-  gint     height;
-  NPDPoint position;
-  guchar  *buffer;
+  gint        width;
+  gint        height;
+  NPDPoint    position;
+  gint        rowstride;
+  GeglBuffer *gegl_buffer;
+  guchar     *buffer;
+  const Babl *format;
 };
 
 void npd_gegl_set_pixel_color (NPDImage *image,
@@ -43,9 +46,10 @@ void npd_gegl_get_pixel_color (NPDImage *image,
                                gint      x,
                                gint      y,
                                NPDColor *color);
-void npd_gegl_create_image    (NPDImage   *image,
+void npd_gegl_open_buffer     (NPDImage *image);
+void npd_gegl_close_buffer    (NPDImage *image);
+void npd_gegl_init_image      (NPDImage   *image,
                                GeglBuffer *gegl_buffer,
                                const Babl *format);
-void npd_gegl_destroy_image   (NPDImage *image);
 
 #endif /* __NPD_GEGL_H__ */
diff --git a/libs/npd/npd_math.h b/libs/npd/npd_math.h
index 3220d31..1b3e624 100644
--- a/libs/npd/npd_math.h
+++ b/libs/npd/npd_math.h
@@ -29,15 +29,6 @@ typedef GeglMatrix3 NPDMatrix;
 
 #define NPD_EPSILON 0.00001
 
-void        npd_compute_homography   (NPDPoint  *p11,
-                                      NPDPoint  *p21,
-                                      NPDPoint  *p31,
-                                      NPDPoint  *p41,
-                                      NPDPoint  *p12,
-                                      NPDPoint  *p22,
-                                      NPDPoint  *p32,
-                                      NPDPoint  *p42,
-                                      NPDMatrix *T);
 void        npd_compute_affinity     (NPDPoint  *p11,
                                       NPDPoint  *p21,
                                       NPDPoint  *p31,
diff --git a/operations/external/npd.c b/operations/external/npd.c
index be3e1bf..7660def 100644
--- a/operations/external/npd.c
+++ b/operations/external/npd.c
@@ -95,7 +95,7 @@ npd_draw_model (NPDModel   *model,
                                                      CAIRO_FORMAT_ARGB32,
                                                      display->image.width,
                                                      display->image.height,
-                                                     display->image.width);
+                                                     display->image.rowstride);
       display->cr = cairo_create (surface);
       cairo_set_line_width (display->cr, 1);
       cairo_set_source_rgba (display->cr, 0, 0, 0, 1);
@@ -127,43 +127,36 @@ static gboolean
 process (GeglOperation       *operation,
          GeglBuffer          *input,
          GeglBuffer          *output,
-         const GeglRectangle *result,
+         const GeglRectangle *roi,
          gint                 level)
 {
-  GeglChantO *o      = GEGL_CHANT_PROPERTIES (operation);
-  const Babl *format = babl_format ("RGBA u8");
-  NPDProperties *props = o->chant_data;
-  NPDModel *model = &props->model;
-  NPDHiddenModel *hm;
-  guchar *output_buffer;
-  gint length = gegl_buffer_get_pixel_count (input) * 4;
+  GeglChantO    *o       = GEGL_CHANT_PROPERTIES (operation);
+  const Babl    *format  = babl_format ("RGBA u8");
+  NPDProperties *props   = o->chant_data;
+  NPDModel      *model   = &props->model;
+  gint           length  = gegl_buffer_get_pixel_count (input) * 4;
+  NPDDisplay    *display = model->display;
 
   if (props->first_run)
     {
-      gint width, height;
       NPDImage *input_image = g_new (NPDImage, 1);
-      NPDDisplay *display = g_new (NPDDisplay, 1);
+      display = g_new (NPDDisplay, 1);
 
       npd_init (npd_gegl_set_pixel_color,
                 npd_gegl_get_pixel_color,
                 npd_draw_line_impl);
 
-      npd_gegl_create_image (input_image, input, format);
-      width = input_image->width;
-      height = input_image->height;
+      npd_gegl_init_image (input_image, input, format);
+      npd_gegl_open_buffer (input_image);
+      npd_gegl_init_image (&display->image, output, format);
+      npd_gegl_open_buffer (&display->image);
 
-      output_buffer = g_new0 (guchar, length);
-      display->image.width = width;
-      display->image.height = height;
-      display->image.buffer = output_buffer;
       model->display = display;
-
-      npd_create_model_from_image (model, input_image, width, height, 0, 0, o->square_size);
-      hm = model->hidden_model;
-
+      npd_create_model_from_image (model,input_image,
+                                   input_image->width, input_image->height,
+                                   0, 0, o->square_size);
       o->model = model;
-
-      memcpy (output_buffer, input_image->buffer, length);
+      memcpy (display->image.buffer, input_image->buffer, length);
 
       props->first_run = FALSE;
     }
@@ -180,13 +173,15 @@ process (GeglOperation       *operation,
 
       model->mesh_visible = o->mesh_visible;
 
-      output_buffer = model->display->image.buffer;
-      memset (output_buffer, 0, length);
+      npd_gegl_open_buffer (model->reference_image);
+      npd_gegl_open_buffer (&display->image);
+      memset (display->image.buffer, 0, length);
       npd_deform_model (model, o->rigidity);
       npd_draw_model (model, model->display);
     }
 
-  gegl_buffer_set (output, NULL, 0, format, output_buffer, GEGL_AUTO_ROWSTRIDE);
+  npd_gegl_close_buffer (model->reference_image);
+  npd_gegl_close_buffer (&display->image);
 
   return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]