[gegl/npd-squashed] libs: npd: move some structures and functions from NPD operation to NPD library
- From: Marek Dvoroznak <dvoromar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/npd-squashed] libs: npd: move some structures and functions from NPD operation to NPD library
- Date: Tue, 3 Dec 2013 02:01:23 +0000 (UTC)
commit f8f3f7cd11067b58dce98b07268b999092c90b11
Author: Marek Dvoroznak <dvoromar gmail com>
Date: Mon Dec 2 03:41:33 2013 +0100
libs: npd: move some structures and functions from NPD operation to NPD library
Move some structures and functions from NPD operation
to NPD library in order to offer their functionality
to other potentional GEGL based applications.
libs/npd/npd_common.h | 3 -
libs/npd/npd_gegl.c | 70 ++++++++++++++++++++-
libs/npd/npd_gegl.h | 51 ++++++++++++++++
libs/npd/npd_math.h | 3 +
operations/external/npd.c | 145 +++++----------------------------------------
5 files changed, 135 insertions(+), 137 deletions(-)
---
diff --git a/libs/npd/npd_common.h b/libs/npd/npd_common.h
index e890e38..7ffb537 100644
--- a/libs/npd/npd_common.h
+++ b/libs/npd/npd_common.h
@@ -24,9 +24,6 @@
#include <glib.h>
-#include <gegl-matrix.h>
-typedef GeglMatrix3 NPDMatrix;
-
/* opaque types for independency on used display library */
typedef struct _NPDImage NPDImage;
typedef struct _NPDColor NPDColor;
diff --git a/libs/npd/npd_gegl.c b/libs/npd/npd_gegl.c
index af5237d..509a123 100644
--- a/libs/npd/npd_gegl.c
+++ b/libs/npd/npd_gegl.c
@@ -19,8 +19,9 @@
* Copyright (C) 2013 Marek Dvoroznak <dvoromar gmail com>
*/
-#include "npd_math.h"
+#include "npd_gegl.h"
#include <glib.h>
+#include <gegl.h>
void
npd_compute_affinity (NPDPoint *p11,
@@ -32,15 +33,15 @@ npd_compute_affinity (NPDPoint *p11,
NPDMatrix *T)
{
GeglMatrix3 Y, X;
-
+
Y.coeff[0][0] = p12->x; Y.coeff[1][0] = p12->y; Y.coeff[2][0] = 1;
Y.coeff[0][1] = p22->x; Y.coeff[1][1] = p22->y; Y.coeff[2][1] = 1;
Y.coeff[0][2] = p32->x; Y.coeff[1][2] = p32->y; Y.coeff[2][2] = 1;
-
+
X.coeff[0][0] = p11->x; X.coeff[1][0] = p11->y; X.coeff[2][0] = 1;
X.coeff[0][1] = p21->x; X.coeff[1][1] = p21->y; X.coeff[2][1] = 1;
X.coeff[0][2] = p31->x; X.coeff[1][2] = p31->y; X.coeff[2][2] = 1;
-
+
gegl_matrix3_invert (&X);
gegl_matrix3_multiply (&Y, &X, T);
}
@@ -54,3 +55,64 @@ npd_apply_transformation (NPDMatrix *T,
gegl_matrix3_transform_point (T, &x, &y);
dest->x = x; dest->y = y;
}
+
+void
+npd_gegl_set_pixel_color (NPDImage *image,
+ gint x,
+ gint y,
+ NPDColor *color)
+{
+ if (x > -1 && x < image->width &&
+ y > -1 && y < image->height)
+ {
+ gint position = 4 * (y * image->width + x);
+
+ image->buffer[position + 0] = color->r;
+ image->buffer[position + 1] = color->g;
+ image->buffer[position + 2] = color->b;
+ image->buffer[position + 3] = color->a;
+ }
+}
+
+void
+npd_gegl_get_pixel_color (NPDImage *image,
+ gint x,
+ gint y,
+ NPDColor *color)
+{
+ if (x > -1 && x < image->width &&
+ y > -1 && y < image->height)
+ {
+ gint position = 4 * (y * image->width + x);
+
+ color->r = image->buffer[position + 0];
+ color->g = image->buffer[position + 1];
+ color->b = image->buffer[position + 2];
+ color->a = image->buffer[position + 3];
+ }
+ else
+ {
+ color->r = color->g = color->b = color->a = 0;
+ }
+}
+
+void
+npd_gegl_create_image (NPDImage *image,
+ GeglBuffer *gegl_buffer,
+ const Babl *format)
+{
+ 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 = buffer;
+ image->width = gegl_buffer_get_width (gegl_buffer);
+ image->height = gegl_buffer_get_height (gegl_buffer);
+}
+
+void
+npd_gegl_destroy_image (NPDImage *image)
+{
+ g_free(image->buffer);
+}
diff --git a/libs/npd/npd_gegl.h b/libs/npd/npd_gegl.h
new file mode 100644
index 0000000..f255061
--- /dev/null
+++ b/libs/npd/npd_gegl.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of N-point image deformation library.
+ *
+ * N-point image deformation library is free software: you can
+ * redistribute it and/or modify it under the terms of the
+ * GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * N-point image deformation library is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with N-point image deformation library.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2013 Marek Dvoroznak <dvoromar gmail com>
+ */
+
+#ifndef __NPD_GEGL_H__
+#define __NPD_GEGL_H__
+
+#include "npd_math.h"
+#include "graphics.h"
+#include <gegl.h>
+
+struct _NPDImage
+{
+ gint width;
+ gint height;
+ NPDPoint position;
+ guchar *buffer;
+};
+
+void npd_gegl_set_pixel_color (NPDImage *image,
+ gint x,
+ gint y,
+ NPDColor *color);
+
+void npd_gegl_get_pixel_color (NPDImage *image,
+ gint x,
+ gint y,
+ NPDColor *color);
+void npd_gegl_create_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 39d4de0..3220d31 100644
--- a/libs/npd/npd_math.h
+++ b/libs/npd/npd_math.h
@@ -23,6 +23,9 @@
#define __NPD_MATH_H__
#include "npd_common.h"
+#include <gegl-matrix.h>
+
+typedef GeglMatrix3 NPDMatrix;
#define NPD_EPSILON 0.00001
diff --git a/operations/external/npd.c b/operations/external/npd.c
index c68ddcc..be3e1bf 100644
--- a/operations/external/npd.c
+++ b/operations/external/npd.c
@@ -55,16 +55,9 @@ gegl_chant_boolean (mesh_visible, _("mesh visible"),
#include <stdio.h>
#include <math.h>
#include <npd/npd.h>
+#include <npd/npd_gegl.h>
#include <cairo.h>
-struct _NPDImage
-{
- gint width;
- gint height;
- NPDPoint position;
- guchar *buffer;
-};
-
struct _NPDDisplay
{
NPDImage image;
@@ -77,96 +70,22 @@ typedef struct
NPDModel model;
} NPDProperties;
-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_draw_line_impl (NPDDisplay *display,
- gfloat x0,
- gfloat y0,
- gfloat x1,
- gfloat y1);
-
-void npd_set_pixel_color_impl (NPDImage *image,
- gint x,
- gint y,
- NPDColor *color)
-{
- if (x > -1 && x < image->width &&
- y > -1 && y < image->height)
- {
- gint position = 4 * (y * image->width + x);
-
- image->buffer[position + 0] = color->r;
- image->buffer[position + 1] = color->g;
- image->buffer[position + 2] = color->b;
- image->buffer[position + 3] = color->a;
- }
-}
-
-void
-npd_get_pixel_color_impl (NPDImage *image,
- gint x,
- gint y,
- NPDColor *color)
-{
- if (x > -1 && x < image->width &&
- y > -1 && y < image->height)
- {
- gint position = 4 * (y * image->width + x);
-
- color->r = image->buffer[position + 0];
- color->g = image->buffer[position + 1];
- color->b = image->buffer[position + 2];
- color->a = image->buffer[position + 3];
- }
- else
- {
- color->r = color->g = color->b = color->a = 0;
- }
-}
-
-void npd_draw_line_impl (NPDDisplay *display,
- gfloat x0,
- gfloat y0,
- gfloat x1,
- gfloat y1)
+static void npd_draw_line_impl (NPDDisplay *display,
+ gfloat x0,
+ gfloat y0,
+ gfloat x1,
+ gfloat y1)
{
cairo_move_to (display->cr, x0, y0);
cairo_line_to (display->cr, x1, y1);
}
-void
+static void
npd_draw_model (NPDModel *model,
NPDDisplay *display)
{
- NPDHiddenModel *hm = model->hidden_model;
- NPDImage *image = model->reference_image;
- gint i;
+ npd_draw_model_into_image (model, &display->image);
- /* draw texture */
- if (model->texture_visible)
- {
- for (i = 0; i < hm->num_of_bones; i++)
- {
- npd_texture_quadrilateral(&hm->reference_bones[i],
- &hm->current_bones[i],
- image,
- &display->image,
- NPD_BILINEAR_INTERPOLATION | NPD_ALPHA_BLENDING);
- }
- }
-
/* draw mesh */
if (model->mesh_visible)
{
@@ -176,7 +95,7 @@ npd_draw_model (NPDModel *model,
CAIRO_FORMAT_ARGB32,
display->image.width,
display->image.height,
- display->image.width * 4);
+ display->image.width);
display->cr = cairo_create (surface);
cairo_set_line_width (display->cr, 1);
cairo_set_source_rgba (display->cr, 0, 0, 0, 1);
@@ -185,39 +104,6 @@ npd_draw_model (NPDModel *model,
}
}
-void
-npd_create_model_from_image (NPDModel *model,
- NPDImage *image,
- gint square_size)
-{
- npd_init_model(model);
- model->reference_image = image;
- model->mesh_square_size = square_size;
-
- npd_create_mesh_from_image (model, image->width, image->height, 0, 0);
-}
-
-void
-npd_create_image (NPDImage *image,
- GeglBuffer *gegl_buffer,
- const Babl *format)
-{
- 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 = buffer;
- image->width = gegl_buffer_get_width (gegl_buffer);
- image->height = gegl_buffer_get_height (gegl_buffer);
-}
-
-void
-npd_destroy_image (NPDImage *image)
-{
- g_free(image->buffer);
-}
-
static void
prepare (GeglOperation *operation)
{
@@ -230,7 +116,7 @@ prepare (GeglOperation *operation)
props->first_run = TRUE;
o->chant_data = props;
}
-
+
gegl_operation_set_format (operation, "input",
babl_format ("RGBA float"));
gegl_operation_set_format (operation, "output",
@@ -258,11 +144,11 @@ process (GeglOperation *operation,
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_init (npd_gegl_set_pixel_color,
+ npd_gegl_get_pixel_color,
npd_draw_line_impl);
- npd_create_image (input_image, input, format);
+ npd_gegl_create_image (input_image, input, format);
width = input_image->width;
height = input_image->height;
@@ -272,9 +158,8 @@ process (GeglOperation *operation,
display->image.buffer = output_buffer;
model->display = display;
- npd_create_model_from_image (model, input_image, o->square_size);
+ npd_create_model_from_image (model, input_image, width, height, 0, 0, o->square_size);
hm = model->hidden_model;
-/* npd_create_list_of_overlapping_points (hm);*/
o->model = model;
@@ -302,7 +187,7 @@ process (GeglOperation *operation,
}
gegl_buffer_set (output, NULL, 0, format, output_buffer, GEGL_AUTO_ROWSTRIDE);
-
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]