[gegl/soc-2013-n-point-deformation: 6/28] make shared NPD library



commit c4c8cf4e1fe89910357d9d9b7df007d8b93d1a3a
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Wed Jul 31 19:53:00 2013 +0200

    make shared NPD library

 configure.ac                    |    5 +--
 gegl.pc.in                      |    2 +-
 libs/npd/Makefile.am            |   57 +++++++++++++++++++++---------
 libs/npd/graphics.h             |    4 +-
 libs/npd/npd.h                  |    1 +
 libs/npd/npd_common.c           |    6 ++--
 libs/npd/npd_common.h           |    4 ++
 operations/external/Makefile.am |    4 +-
 operations/external/npd.c       |   73 +++++++++++++++++++++++----------------
 9 files changed, 98 insertions(+), 58 deletions(-)
---
diff --git a/configure.ac b/configure.ac
old mode 100644
new mode 100755
index d75d11d..6c2c72f
--- a/configure.ac
+++ b/configure.ac
@@ -1083,8 +1083,8 @@ fi
 ##################
 have_libnpd="yes (internal)"
 
-AC_SUBST(NPD_CFLAGS, "-I\$(top_srcdir)/libs/npd")
-AC_SUBST(NPD_LIBS, "-L\$(top_builddir)/libs/npd -lnpd")
+AC_SUBST(NPD_CFLAGS, "-I\$(top_srcdir)/libs")
+AC_SUBST(NPD_LIBS, "-L\$(top_builddir)/libs/npd -lgegl-npd-\$(GEGL_API_VERSION)")
 
 #######################
 # Check for other items
@@ -1238,5 +1238,4 @@ Optional dependencies:
   umfpack:         $have_umfpack
   webp:            $have_webp
   poly2tri-c:      $have_p2tc
-  libnpd:          $have_libnpd
 ]);
diff --git a/gegl.pc.in b/gegl.pc.in
index 614bb78..f4b70fc 100644
--- a/gegl.pc.in
+++ b/gegl.pc.in
@@ -8,5 +8,5 @@ Name: GEGL
 Description: Generic Graphics Library 
 Version: @GEGL_REAL_VERSION@
 Requires: @GLIB_PACKAGES@ babl
-Libs: -L${libdir} -l PACKAGE_NAME@- GEGL_API_VERSION@
+Libs: -L${libdir} -l PACKAGE_NAME@- GEGL_API_VERSION@ -l PACKAGE_NAME@-npd- GEGL_API_VERSION@
 Cflags: -I${includedir}/@PACKAGE_NAME -@GEGL_API_VERSION@
diff --git a/libs/npd/Makefile.am b/libs/npd/Makefile.am
index 16ad543..a5ca9fc 100644
--- a/libs/npd/Makefile.am
+++ b/libs/npd/Makefile.am
@@ -1,17 +1,40 @@
-noinst_LTLIBRARIES = libnpd.la
-
-AM_CFLAGS = $(GLIB_CFLAGS) $(NPD_CFLAGS) -I$(top_builddir)/gegl -I$(top_srcdir)/gegl
-AM_LDFLAGS = $(GLIB_LIBS) $(NPD_LIBS)
-
-libnpd_la_SOURCES = \
-    npd_common.h    \
-    npd_common.c    \
-    deformation.h   \
-    deformation.c   \
-    npd_math.h      \
-    npd_math.c      \
-    graphics.h      \
-    graphics.c      \
-    npd_gegl.h      \
-    npd_gegl.c      \
-    npd.h
+include $(top_srcdir)/operations/Makefile-common.am
+
+######################################################
+# A shared library for n-point image deformation API #
+######################################################
+
+GEGL_NPD_publicdir = $(includedir)/gegl-$(GEGL_API_VERSION)/npd
+
+GEGL_NPD_public_HEADERS = \
+       npd_common.h     \
+       deformation.h    \
+       npd_math.h       \
+       graphics.h       \
+       refine.h         \
+       npd_gegl.h       \
+       npd.h
+
+GEGL_NPD_SOURCES = \
+       $(GEGL_NPD_public_HEADERS)      \
+       npd_common.c                    \
+       deformation.c                   \
+       npd_math.c                      \
+       graphics.c                      \
+       refine.c                        \
+       npd_gegl.c
+
+libgegl_npd_ GEGL_API_VERSION@_la_SOURCES = \
+       $(GEGL_NPD_public_HEADERS)      \
+       $(GEGL_NPD_SOURCES)
+
+libgegl_npd_ GEGL_API_VERSION@_la_LDFLAGS = \
+       -avoid-version -export-dynamic $(no_undefined)
+
+libgegl_npd_ GEGL_API_VERSION@_la_CFLAGS = \
+  $(AM_CFLAGS)
+
+lib_LTLIBRARIES = libgegl-npd- GEGL_API_VERSION@.la
+
+libgegl_npd_ GEGL_API_VERSION@_la_LIBADD = \
+       $(libgegl)
diff --git a/libs/npd/graphics.h b/libs/npd/graphics.h
index d27cd5f..691ec4f 100644
--- a/libs/npd/graphics.h
+++ b/libs/npd/graphics.h
@@ -76,11 +76,11 @@ void        npd_bilinear_color_interpolation  (NPDColor *I0,
                                                gfloat    dx,
                                                gfloat    dy,
                                                NPDColor *out);
-void        npd_get_pixel_color               (NPDImage *image,
+void      (*npd_get_pixel_color)              (NPDImage *image,
                                                gint      x,
                                                gint      y,
                                                NPDColor *color);
-void        npd_set_pixel_color               (NPDImage *image,
+void      (*npd_set_pixel_color)              (NPDImage *image,
                                                gint      x,
                                                gint      y,
                                                NPDColor *color);
diff --git a/libs/npd/npd.h b/libs/npd/npd.h
index ae70e59..e01fc4b 100644
--- a/libs/npd/npd.h
+++ b/libs/npd/npd.h
@@ -24,6 +24,7 @@
 #include "graphics.h"
 #include "deformation.h"
 #include "npd_math.h"
+/*#include "refine.h"*/
 
 #endif /* __NPD_H__ */
 
diff --git a/libs/npd/npd_common.c b/libs/npd/npd_common.c
index 1991491..0f1ad97 100644
--- a/libs/npd/npd_common.c
+++ b/libs/npd/npd_common.c
@@ -128,11 +128,11 @@ npd_remove_control_point (NPDModel        *model,
   
   for (i = 0; i < model->control_points->len; i++)
     {
-      cp = &g_array_index(model->control_points, NPDControlPoint, i);
+      cp = &g_array_index (model->control_points, NPDControlPoint, i);
       
       if (cp == control_point)
         {
-          npd_set_control_point_weight(cp, 1.0);
+          npd_set_control_point_weight (cp, 1.0);
           g_array_remove_index (model->control_points, i);
           return;
         }
@@ -193,7 +193,7 @@ npd_get_control_point_at (NPDModel *model,
         }
     }
 
-  g_printf ("no control points\n");
+//  g_printf ("no control points\n");
   return NULL;
 }
 
diff --git a/libs/npd/npd_common.h b/libs/npd/npd_common.h
index 5ccadad..4414cc5 100644
--- a/libs/npd/npd_common.h
+++ b/libs/npd/npd_common.h
@@ -92,6 +92,10 @@ typedef struct
   NPDDisplay           *display;
 } NPDModel;
 
+#define npd_init(set_pixel, get_pixel)\
+npd_set_pixel_color = set_pixel;\
+npd_get_pixel_color = get_pixel
+
 void             npd_init_model             (NPDModel        *model);
 void             npd_destroy_hidden_model   (NPDHiddenModel  *model);
 void             npd_destroy_model          (NPDModel        *model);
diff --git a/operations/external/Makefile.am b/operations/external/Makefile.am
index 1de5fec..1d86ee0 100644
--- a/operations/external/Makefile.am
+++ b/operations/external/Makefile.am
@@ -161,8 +161,8 @@ rgbe_save_la_LIBADD = $(op_libs) $(top_builddir)/libs/rgbe/librgbe.la
 # Dependencies are in our source tree
 ops += npd.la
 npd_la_SOURCES = npd.c
-npd_la_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/libs
-npd_la_LIBADD = $(op_libs) $(top_builddir)/libs/npd/libnpd.la
+npd_la_CFLAGS = $(AM_CFLAGS) $(NPD_CFLAGS)
+npd_la_LIBADD = $(op_libs) $(NPD_LIBS)
 
 opdir = $(libdir)/gegl- GEGL_API_VERSION@
 op_LTLIBRARIES = $(ops)
diff --git a/operations/external/npd.c b/operations/external/npd.c
index a8d5707..c589280 100644
--- a/operations/external/npd.c
+++ b/operations/external/npd.c
@@ -20,6 +20,8 @@
 #include <glib/gi18n-lib.h>
 
 #ifdef GEGL_CHANT_PROPERTIES
+gegl_chant_pointer (model, _("model"), _(""))
+gegl_chant_int (rigidity, _("rigidity"), 100, 20000, 0, _(""))
 #else
 
 #define GEGL_CHANT_TYPE_FILTER
@@ -53,12 +55,23 @@ typedef struct
 void npd_create_image (NPDImage   *image,
                        GeglBuffer *gegl_buffer,
                        const Babl *format);
+void
+npd_set_pixel_color_impl (NPDImage *image,
+                          gint      x,
+                          gint      y,
+                          NPDColor *color);
+void
+npd_get_pixel_color_impl (NPDImage *image,
+                          gint      x,
+                          gint      y,
+                          NPDColor *color);
+
 
 void
-npd_set_pixel_color (NPDImage *image,
-                     gint      x,
-                     gint      y,
-                     NPDColor *color)
+npd_set_pixel_color_impl (NPDImage *image,
+                          gint      x,
+                          gint      y,
+                          NPDColor *color)
 {
   gint position = 4 * (y * image->width + x);
   gint max = 4 * image->width * image->height;
@@ -73,10 +86,10 @@ npd_set_pixel_color (NPDImage *image,
 }
 
 void
-npd_get_pixel_color (NPDImage *image,
-                     gint      x,
-                     gint      y,
-                     NPDColor *color)
+npd_get_pixel_color_impl (NPDImage *image,
+                          gint      x,
+                          gint      y,
+                          NPDColor *color)
 {
   gint position = 4 * (y * image->width + x);
   gint max = 4 * image->width * image->height;
@@ -177,47 +190,47 @@ process (GeglOperation       *operation,
   const Babl *format = babl_format ("RGBA u8");
   NPDProperties *props = o->chant_data;
   NPDModel *model = &props->model;
-  NPDControlPoint *cp;
-  NPDPoint coord, new_coord;
   guchar *output_buffer;
   
   if (props->first_run)
     {
       gint width, height;
-      NPDImage input_image;
-      NPDDisplay display;
+      NPDImage *input_image = g_new (NPDImage, 1);
+      NPDDisplay *display = g_new (NPDDisplay, 1);
+      
+      npd_init (npd_set_pixel_color_impl, npd_get_pixel_color_impl);
 
-      npd_create_image (&input_image, input, format);
-      width = input_image.width;
-      height = input_image.height;
+      npd_create_image (input_image, input, format);
+      width = input_image->width;
+      height = input_image->height;
 
       output_buffer = g_new0 (guchar, gegl_buffer_get_pixel_count (input) * 4);
-      display.image.width = width;
-      display.image.height = height;
-      display.image.buffer = output_buffer;
+      display->image.width = width;
+      display->image.height = height;
+      display->image.buffer = output_buffer;
 
-      npd_create_model_from_image(model, &input_image, 20);
+      npd_create_model_from_image (model, input_image, 20);
       npd_create_list_of_overlapping_points (model->hidden_model);
 
-      model->display = &display;
+      model->display = display;
+      
+      o->model = model;
+      NPDModel *m = o->model;
+      
+      props->first_run = FALSE;
     }
   else
     {
       output_buffer = model->display->image.buffer;
     }
 
-  coord.x = 20; coord.y = 200;
-  new_coord.x = 100; new_coord.y = 250;
-
-  cp = npd_add_control_point (model, &coord);
-  npd_set_point_coordinates (&cp->point, &new_coord);
-  
-  npd_deform_model (model, 1000);
+//  npd_deform_model (model, o->rigidity);
+  npd_deform_model (model, 2000);
   npd_draw_model (model, model->display);
-  
-  gegl_buffer_set (output, NULL, 0, format, output_buffer, GEGL_AUTO_ROWSTRIDE);
 
-  return  TRUE;
+  gegl_buffer_set (output, NULL, 0, format, output_buffer, GEGL_AUTO_ROWSTRIDE);
+  
+  return TRUE;
 }
 
 static void


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