Commit 7f82dcf7 authored by Barak Itkin's avatar Barak Itkin
Browse files

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

parent 7738fe2b
make-mesh.h
sc-context.h
sc-context-private.h
sc-outline.h
......@@ -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)
......
/*
* 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
......@@ -7,9 +32,11 @@
#define SC_COLOR_BABL_NAME "R'G'B'A float"
/**
* The type used for individual color channels
* 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 ScColorChannel;
typedef gfloat ScColor;
/**
* The amount of channels per color
......@@ -17,33 +44,32 @@ typedef gfloat ScColorChannel;
#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
/**
* The type used for a whole color
*/
typedef ScColorChannel ScColor[SC_COLORA_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); \
{ \
sc_color_expr(0); \
sc_color_expr(1); \
sc_color_expr(2); \
} \
G_STMT_END
typedef struct {
GeglBuffer *bg;
GeglRectangle *bg_rect;
GeglRectangle bg_rect;
GeglBuffer *fg;
GeglRectangle *fg_rect;
GeglRectangle fg_rect;
gint xoff;
gint yoff;
......@@ -51,7 +77,4 @@ typedef struct {
gboolean render_bg;
} ScRenderInfo;
typedef struct {
gint x;
gint y;
} ScPoint;
#endif
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment