[gegl/soc-2011-seamless-clone] Make it compile and fix a critical error with the ScColor type



commit a49792bdf31e903fbf41a68666d86c1119457693
Author: Barak Itkin <lightningismyname gmail com>
Date:   Tue Sep 18 22:31:22 2012 +0300

    Make it compile and fix a critical error with the ScColor type

 libs/seamless-clone/sc-common.h                    |   57 ------------
 libs/seamless-clone/seamless-clone.h               |    4 -
 operations/common/seamless-clone/Makefile.am       |   17 +++--
 operations/common/seamless-clone/sc-common.h       |   80 +++++++++++++++++
 .../common}/seamless-clone/sc-context-private.h    |    9 ++-
 .../common}/seamless-clone/sc-context.c            |   93 +++++++++++++-------
 .../common}/seamless-clone/sc-context.h            |    2 +-
 .../common}/seamless-clone/sc-outline.c            |    0
 .../common}/seamless-clone/sc-outline.h            |    0
 .../common}/seamless-clone/sc-sample.c             |    0
 .../common}/seamless-clone/sc-sample.h             |    2 +-
 11 files changed, 161 insertions(+), 103 deletions(-)
---
diff --git a/operations/common/seamless-clone/Makefile.am b/operations/common/seamless-clone/Makefile.am
index 951e75b..96779e8 100644
--- a/operations/common/seamless-clone/Makefile.am
+++ b/operations/common/seamless-clone/Makefile.am
@@ -4,12 +4,17 @@ AM_LDFLAGS += $(op_libs) $(P2TC_LIBS)
 AM_CFLAGS  += $(op_cflags) $(P2TC_CFLAGS)
 
 sc_common_files =		\
- 	make-mesh.c		\
-	make-mesh.h		\
-	find-outline.c		\
-	find-outline.h		\
-	seamless-clone-common.c	\
-	seamless-clone-common.h
+	sc-common.h		\
+	sc-context.c		\
+	sc-context.h		\
+	sc-context-private.h	\
+	sc-outline.c		\
+	sc-outline.h		\
+	sc-sample.c		\
+	sc-sample.h
+
+noinst_LTLIBRARIES = libsc.la
+libsc_la_SOURCES = $(sc_common_files)
 
 seamless_clone_la_SOURCES = seamless-clone.c $(sc_common_files)
 seamless_clone_render_la_SOURCES = seamless-clone-render.c $(sc_common_files)
diff --git a/operations/common/seamless-clone/sc-common.h b/operations/common/seamless-clone/sc-common.h
new file mode 100644
index 0000000..604f213
--- /dev/null
+++ b/operations/common/seamless-clone/sc-common.h
@@ -0,0 +1,80 @@
+/*
+ * This file is an image processing operation for GEGL
+ * sc-common.h
+ * Copyright (C) 2012 Barak Itkin <lightningismyname gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEGL_SC_COMMON_H__
+#define __GEGL_SC_COMMON_H__
+
+#include <poly2tri-c/refine/refine.h>
+#include <gegl.h>
+
+/**
+ * The name of the Babl type used for working on colors.
+ * WARNING: THE CODE ASSUMES THAT NO MATTER WHAT THE FORMAT IS, THE
+ * ALPHA CHANNEL IS ALWAYS LAST. DO NOT CHANGE THIS WITHOUT UPDATING
+ * THE REST OF THE CODE!
+ */
+#define SC_COLOR_BABL_NAME     "R'G'B'A float"
+
+/**
+ * The type used for individual color channels. Note that this should
+ * never be used directly - you must get a pointer to this type using
+ * the allocation macros below!
+ */
+typedef gfloat ScColor;
+
+/**
+ * The amount of channels per color
+ */
+#define SC_COLORA_CHANNEL_COUNT 4
+#define SC_COLOR_CHANNEL_COUNT  ((SC_COLORA_CHANNEL_COUNT) - 1)
+
+#define sc_color_new()     (g_new (ScColor, SC_COLORA_CHANNEL_COUNT))
+#define sc_color_free(mem) (g_free (mem))
+/**
+ * The index of the alpha channel in the color
+ */
+#define SC_COLOR_ALPHA_INDEX   SC_COLOR_CHANNEL_COUNT
+
+/**
+ * Apply a macro once for each non-alpha color channel, with the
+ * channel index as an input
+ */
+#define sc_color_process()  \
+G_STMT_START                \
+  {                         \
+    sc_color_expr(0);       \
+    sc_color_expr(1);       \
+    sc_color_expr(2);       \
+  }                         \
+G_STMT_END
+
+typedef struct {
+  GeglBuffer    *bg;
+  GeglRectangle  bg_rect;
+
+  GeglBuffer    *fg;
+  GeglRectangle  fg_rect;
+
+  gint           xoff;
+  gint           yoff;
+
+  gboolean       render_bg;
+} ScRenderInfo;
+
+#endif
diff --git a/libs/seamless-clone/sc-context-private.h b/operations/common/seamless-clone/sc-context-private.h
similarity index 90%
rename from libs/seamless-clone/sc-context-private.h
rename to operations/common/seamless-clone/sc-context-private.h
index d364581..41ee52c 100644
--- a/libs/seamless-clone/sc-context-private.h
+++ b/operations/common/seamless-clone/sc-context-private.h
@@ -20,6 +20,13 @@
 #ifndef __GEGL_SC_CONTEXT_PRIVATE_H__
 #define __GEGL_SC_CONTEXT_PRIVATE_H__
 
+#include <gegl.h>
+#include <poly2tri-c/refine/refine.h>
+
+#include "sc-outline.h"
+#include "sc-context.h"
+#include "sc-sample.h"
+
 typedef struct
 {
   GHashTable     *pt2col;
@@ -27,7 +34,7 @@ typedef struct
   gboolean        is_valid;
 } ScRenderCache;
 
-struct ScContext_
+struct _ScContext
 {
   ScOutline      *outline;
   GeglRectangle   mesh_bounds;
diff --git a/libs/seamless-clone/sc-context.c b/operations/common/seamless-clone/sc-context.c
similarity index 85%
rename from libs/seamless-clone/sc-context.c
rename to operations/common/seamless-clone/sc-context.c
index 0f0f864..32f9b22 100644
--- a/libs/seamless-clone/sc-context.c
+++ b/operations/common/seamless-clone/sc-context.c
@@ -17,26 +17,42 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "seamless-clone-common.h"
-#include "make-mesh.h"
+#include <gegl.h>
 #include <gegl-utils.h>
+#include <poly2tri-c/refine/refine.h>
+#include <poly2tri-c/render/mesh-render.h>
 
-static ScOutline*  sc_context_create_outline (GeglBuffer          *input,
-                                              const GeglRectangle *roi,
-                                              gdouble              threshold,
-                                              ScCreationError     *error)
+#include "sc-context.h"
+#include "sc-context-private.h"
+#include "sc-common.h"
+#include "sc-sample.h"
 
-static P2trMesh*   sc_make_fine_mesh         (ScOutline           *outline,
-                                              GeglRectangle       *mesh_bounds,
-                                              int                  max_refine_steps);
+static ScOutline*  sc_context_create_outline             (GeglBuffer          *input,
+                                                          const GeglRectangle *roi,
+                                                          gdouble              threshold,
+                                                          ScCreationError     *error);
 
-static GeglBuffer* sc_compute_uvt_cache      (P2trMesh            *mesh,
-                                              const GeglRectangle *area);
+static P2trMesh*   sc_make_fine_mesh                     (ScOutline           *outline,
+                                                          GeglRectangle       *mesh_bounds,
+                                                          int                  max_refine_steps);
 
+static gboolean    sc_context_render_cache_pt2col_update (ScContext           *context);
 
-static gboolean sc_context_render_cache_pt2col_update (ScContext *context);
+static gboolean    sc_context_sample_point               (ScRenderInfo        *info,
+                                                          ScSampleList        *sl,
+                                                          P2trPoint           *point,
+                                                          ScColor             *dest);
 
-static void     sc_context_render_cache_pt2col_free   (ScContext *context);
+static void        sc_context_render_cache_pt2col_free   (ScContext           *context);
+
+static GeglBuffer* sc_compute_uvt_cache                  (P2trMesh            *mesh,
+                                                          const GeglRectangle *area);
+
+static void        sc_point_to_color_func                (P2trPoint           *point,
+                                                          gfloat              *dest,
+                                                          gpointer             pt2col_p);
+
+static void        sc_context_render_cache_free          (ScContext           *context);
 
 ScContext*
 sc_context_new (GeglBuffer          *input,
@@ -60,7 +76,7 @@ sc_context_new (GeglBuffer          *input,
   self->mesh         = sc_make_fine_mesh (self->outline,
                                           &self->mesh_bounds,
                                           5 * outline_length);
-  self->samplig      = sc_mesh_sampling_compute (self->outline,
+  self->sampling     = sc_mesh_sampling_compute (self->outline,
                                                  self->mesh);
   self->cache_uvt    = FALSE;
   self->uvt          = NULL;
@@ -69,7 +85,7 @@ sc_context_new (GeglBuffer          *input,
   return self;
 }
 
-static ScContext*
+static ScOutline*
 sc_context_create_outline (GeglBuffer          *input,
                            const GeglRectangle *roi,
                            gdouble              threshold,
@@ -95,7 +111,7 @@ sc_context_create_outline (GeglBuffer          *input,
       *error = SC_CREATION_ERROR_TOO_SMALL;
     }
   else if (ignored_islands ||
-           ! sc_outline_check_if_single (extents, fg, result->outline))
+           ! sc_outline_check_if_single (roi, input, outline))
     {
       *error = SC_CREATION_ERROR_HOLED_OR_SPLIT;
     }
@@ -192,7 +208,7 @@ sc_context_prepare_render (ScContext    *context,
     return FALSE;
 
   if (context->cache_uvt && context->uvt == NULL)
-    context->uvt = sc_compute_uvt_cache (context->mesh, info->fg_rect);
+    context->uvt = sc_compute_uvt_cache (context->mesh, &info->fg_rect);
 
   context->render_cache->is_valid = TRUE;
 
@@ -247,9 +263,9 @@ sc_context_render_cache_pt2col_update (ScContext *context)
     {
       /* See if we have a pt2col entry for this point? */
       if (! g_hash_table_lookup_extended (pt2col, pt, NULL,
-                                          &color_current))
+                                          (gpointer*) &color_current))
         {
-          color_current = g_slice_new (ScColor);
+          color_current = sc_color_new ();
           g_hash_table_insert (pt2col,
                                p2tr_point_ref (pt),
                                color_current);
@@ -264,8 +280,11 @@ sc_context_render_cache_pt2col_update (ScContext *context)
        * after allocating/reffing but before inserting, we would have a
        * memory leak!
        */
-      if (! sc_context_sample_point (sl, info, pt, color_current))
-        return FALSE;
+      if (! sc_context_sample_point (context->render_cache->info, sl,
+                                     pt, color_current))
+        {
+          return FALSE;
+        }
     }
 
   /* Now, lets see if there were any additional points in the mapping, that
@@ -281,7 +300,7 @@ sc_context_render_cache_pt2col_update (ScContext *context)
           /* See if we have a sampling entry for this point? */
           if (! g_hash_table_lookup_extended (context->sampling, pt, NULL, NULL))
             {
-              g_slice_free (ScColor, color_current);
+              sc_color_free (color_current);
               g_hash_table_iter_remove (&iter);
               p2tr_point_unref (pt);
             }
@@ -348,32 +367,40 @@ sc_context_sample_point (ScRenderInfo *info,
 
 #undef sc_rect_contains
 
-      gegl_buffer_sample (cci->fg,
+      gegl_buffer_sample (info->fg,
                           pt->x, pt->y,
                           NULL, fg_c, format,
                           GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
 
       /* Sample the BG with the offset */
-      gegl_buffer_sample (cci->bg,
+      gegl_buffer_sample (info->bg,
                           pt->x + info->xoff, pt->y + info->yoff,
-                          NULL, input_c, format,
+                          NULL, bg_c, format,
                           GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
 
-#define sc_color_expr(I)  dest_c[I] += weight * (input_c[I] - aux_c[I]) 
+#define sc_color_expr(I)  dest_c[I] += weight * (bg_c[I] - fg_c[I]) 
       sc_color_process();
 #undef  sc_color_expr
       weightT += weight;
     }
 
+  if (weightT == 0)
+    return FALSE;
+
 #define sc_color_expr(I)  dest[I] = dest_c[I] / weightT
   sc_color_process();
 #undef  sc_color_expr
   dest[SC_COLOR_ALPHA_INDEX] = 1;
+  return TRUE;
 }
 
 static void
 sc_context_render_cache_pt2col_free (ScContext *context)
 {
+  GHashTableIter iter;
+  ScColor       *color_current = NULL;
+  P2trPoint     *pt            = NULL;
+
   if (context->render_cache->pt2col == NULL)
     return;
 
@@ -382,14 +409,14 @@ sc_context_render_cache_pt2col_free (ScContext *context)
                                 (gpointer*) &pt,
                                 (gpointer*) &color_current))
     {
-      g_slice_free (ScColor, color_current);
+      sc_color_free (color_current);
       g_hash_table_iter_remove (&iter);
       p2tr_point_unref (pt);
     }
 
   g_hash_table_destroy (context->render_cache->pt2col);
 
-  context->pt2col = NULL;
+  context->render_cache->pt2col = NULL;
 }
 
 static GeglBuffer*
@@ -437,7 +464,7 @@ sc_context_set_uvt_cache (ScContext *context,
     }
 }
 
-void
+gboolean
 sc_context_render (ScContext           *context,
                    const GeglRectangle *part_rect,
                    GeglBuffer          *part)
@@ -513,8 +540,8 @@ sc_context_render (ScContext           *context,
   out_index = 0;
   
   gegl_rectangle_set (&to_render_fg,
-      to_render.x - fg_xoff, to_render.y - fg_yoff,
-      to_render.width,       to_render.height);
+      to_render.x - xoff, to_render.y - yoff,
+      to_render.width,    to_render.height);
 
   if (context->uvt)
     {
@@ -600,7 +627,7 @@ sc_point_to_color_func (P2trPoint *point,
                         gpointer   pt2col_p)
 {
   GHashTable *pt2col  = (GHashTable*) pt2col_p;
-  gfloat     *col_cpy = g_hash_table_lookup (cci->pt2col, point);
+  ScColor    *col_cpy = g_hash_table_lookup (pt2col, point);
   guint       i;
 
   g_assert (col_cpy != NULL);
@@ -621,7 +648,7 @@ sc_context_render_cache_free (ScContext *context)
 }
 
 void
-sc_context_free (ScCotnext *context)
+sc_context_free (ScContext *context)
 {
   if (context->render_cache)
     sc_context_render_cache_free (context);
diff --git a/libs/seamless-clone/sc-context.h b/operations/common/seamless-clone/sc-context.h
similarity index 98%
rename from libs/seamless-clone/sc-context.h
rename to operations/common/seamless-clone/sc-context.h
index f501e5b..c5f915c 100644
--- a/libs/seamless-clone/sc-context.h
+++ b/operations/common/seamless-clone/sc-context.h
@@ -91,7 +91,7 @@ void       sc_context_set_uvt_cache  (ScContext           *context,
  * cloning composition. This call must be preceeded by a call to
  * the prepare function.
  */
-void       sc_context_render         (ScContext           *context,
+gboolean   sc_context_render         (ScContext           *context,
                                       const GeglRectangle *part_rect,
                                       GeglBuffer          *part);
 
diff --git a/libs/seamless-clone/sc-outline.c b/operations/common/seamless-clone/sc-outline.c
similarity index 100%
rename from libs/seamless-clone/sc-outline.c
rename to operations/common/seamless-clone/sc-outline.c
diff --git a/libs/seamless-clone/sc-outline.h b/operations/common/seamless-clone/sc-outline.h
similarity index 100%
rename from libs/seamless-clone/sc-outline.h
rename to operations/common/seamless-clone/sc-outline.h
diff --git a/libs/seamless-clone/sc-sample.c b/operations/common/seamless-clone/sc-sample.c
similarity index 100%
rename from libs/seamless-clone/sc-sample.c
rename to operations/common/seamless-clone/sc-sample.c
diff --git a/libs/seamless-clone/sc-sample.h b/operations/common/seamless-clone/sc-sample.h
similarity index 98%
rename from libs/seamless-clone/sc-sample.h
rename to operations/common/seamless-clone/sc-sample.h
index 6d3373b..e42e10d 100644
--- a/libs/seamless-clone/sc-sample.h
+++ b/operations/common/seamless-clone/sc-sample.h
@@ -21,7 +21,7 @@
 #define __GEGL_SC_SAMPLE_H__
 
 #include <glib.h>
-#include <poly2tri/refine/refine.h>
+#include <poly2tri-c/refine/refine.h>
 
 #include "sc-outline.h"
 



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