2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-08-16 05:15:59 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-08-16 05:15:59 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-08-16 05:15:59 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
#include "paint-types.h"
|
|
|
|
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2007-12-12 03:31:46 +08:00
|
|
|
#include "core/gimpbrush.h"
|
2008-11-12 18:56:06 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2009-10-11 21:41:54 +08:00
|
|
|
#include "core/gimpdynamics.h"
|
|
|
|
#include "core/gimpdynamicsoutput.h"
|
2008-11-12 18:56:06 +08:00
|
|
|
#include "core/gimperror.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimppickable.h"
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
#include "gimpheal.h"
|
2006-09-04 23:40:56 +08:00
|
|
|
#include "gimpsourceoptions.h"
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2006-09-04 23:40:56 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
|
|
|
|
/* NOTES
|
|
|
|
*
|
|
|
|
* The method used here is similar to the lighting invariant correctin
|
|
|
|
* method but slightly different: we do not divide the RGB components,
|
|
|
|
* but substract them I2 = I0 - I1, where I0 is the sample image to be
|
|
|
|
* corrected, I1 is the reference pattern. Then we solve DeltaI=0
|
|
|
|
* (Laplace) with I2 Dirichlet conditions at the borders of the
|
|
|
|
* mask. The solver is a unoptimized red/black checker Gauss-Siedel
|
|
|
|
* with an over-relaxation factor of 1.8. It can benefit from a
|
|
|
|
* multi-grid evaluation of an initial solution before the main
|
|
|
|
* iteration loop.
|
2006-09-03 02:54:35 +08:00
|
|
|
*
|
2011-10-18 03:47:01 +08:00
|
|
|
* I reduced the convergence criteria to 0.1% (0.001) as we are
|
|
|
|
* dealing here with RGB integer components, more is overkill.
|
|
|
|
*
|
|
|
|
* Jean-Yves Couleaud cjyves@free.fr
|
2006-09-03 02:54:35 +08:00
|
|
|
*/
|
|
|
|
|
2007-12-12 03:31:46 +08:00
|
|
|
static gboolean gimp_heal_start (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2009-04-18 04:29:25 +08:00
|
|
|
const GimpCoords *coords,
|
2007-12-12 03:31:46 +08:00
|
|
|
GError **error);
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
static void gimp_heal_sub (PixelRegion *topPR,
|
2007-12-12 03:31:46 +08:00
|
|
|
PixelRegion *bottomPR,
|
|
|
|
gdouble *result);
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
static void gimp_heal_add (gdouble *first,
|
2007-12-12 03:31:46 +08:00
|
|
|
PixelRegion *secondPR,
|
|
|
|
PixelRegion *resultPR);
|
|
|
|
|
|
|
|
static gdouble gimp_heal_laplace_iteration (gdouble *matrix,
|
|
|
|
gint height,
|
|
|
|
gint depth,
|
|
|
|
gint width,
|
|
|
|
gdouble *solution,
|
|
|
|
guchar *mask);
|
|
|
|
|
|
|
|
static void gimp_heal_laplace_loop (gdouble *matrix,
|
|
|
|
gint height,
|
|
|
|
gint depth,
|
|
|
|
gint width,
|
|
|
|
gdouble *solution,
|
|
|
|
guchar *mask);
|
|
|
|
|
|
|
|
static PixelRegion *gimp_heal_region (PixelRegion *tempPR,
|
|
|
|
PixelRegion *srcPR,
|
2011-04-06 04:11:27 +08:00
|
|
|
const TempBuf *mask_buf);
|
2007-12-12 03:31:46 +08:00
|
|
|
|
|
|
|
static void gimp_heal_motion (GimpSourceCore *source_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2009-05-03 18:08:21 +08:00
|
|
|
const GimpCoords *coords,
|
2007-12-12 03:31:46 +08:00
|
|
|
gdouble opacity,
|
|
|
|
GimpPickable *src_pickable,
|
2012-03-31 04:11:46 +08:00
|
|
|
GeglBuffer *src_buffer,
|
2012-03-31 21:40:21 +08:00
|
|
|
GeglRectangle *src_rect,
|
2007-12-12 03:31:46 +08:00
|
|
|
gint src_offset_x,
|
|
|
|
gint src_offset_y,
|
2012-04-02 03:02:49 +08:00
|
|
|
GeglBuffer *paint_buffer,
|
|
|
|
gint paint_buffer_x,
|
|
|
|
gint paint_buffer_y,
|
2007-12-12 03:31:46 +08:00
|
|
|
gint paint_area_offset_x,
|
|
|
|
gint paint_area_offset_y,
|
|
|
|
gint paint_area_width,
|
|
|
|
gint paint_area_height);
|
|
|
|
|
|
|
|
|
2006-09-04 23:40:56 +08:00
|
|
|
G_DEFINE_TYPE (GimpHeal, gimp_heal, GIMP_TYPE_SOURCE_CORE)
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2006-09-04 23:40:56 +08:00
|
|
|
#define parent_class gimp_heal_parent_class
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2006-09-03 02:54:35 +08:00
|
|
|
|
2006-08-16 05:15:59 +08:00
|
|
|
void
|
|
|
|
gimp_heal_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
2006-09-04 23:40:56 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_HEAL,
|
|
|
|
GIMP_TYPE_SOURCE_OPTIONS,
|
|
|
|
"gimp-heal",
|
|
|
|
_("Heal"),
|
|
|
|
"gimp-tool-heal");
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_heal_class_init (GimpHealClass *klass)
|
|
|
|
{
|
2006-09-27 04:55:40 +08:00
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
2006-09-04 23:40:56 +08:00
|
|
|
GimpSourceCoreClass *source_core_class = GIMP_SOURCE_CORE_CLASS (klass);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2006-09-27 04:55:40 +08:00
|
|
|
paint_core_class->start = gimp_heal_start;
|
|
|
|
|
2006-09-04 23:40:56 +08:00
|
|
|
source_core_class->motion = gimp_heal_motion;
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-09-04 23:40:56 +08:00
|
|
|
gimp_heal_init (GimpHeal *heal)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-09-27 04:55:40 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_heal_start (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2009-04-18 04:29:25 +08:00
|
|
|
const GimpCoords *coords,
|
2006-09-27 04:55:40 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
|
|
|
|
|
|
|
|
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
|
|
|
|
paint_options, coords,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! source_core->set_source && gimp_drawable_is_indexed (drawable))
|
|
|
|
{
|
2008-11-12 18:56:06 +08:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2011-10-18 03:47:01 +08:00
|
|
|
_("Healing does not operate on indexed layers."));
|
2006-09-27 04:55:40 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Subtract bottomPR from topPR and store the result as a double
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
|
|
|
static void
|
2011-10-18 03:47:01 +08:00
|
|
|
gimp_heal_sub (PixelRegion *topPR,
|
|
|
|
PixelRegion *bottomPR,
|
|
|
|
gdouble *result)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
|
|
|
gint i, j, k;
|
|
|
|
|
|
|
|
gint height = topPR->h;
|
|
|
|
gint width = topPR->w;
|
|
|
|
gint depth = topPR->bytes;
|
|
|
|
|
|
|
|
guchar *t_data = topPR->data;
|
|
|
|
guchar *b_data = bottomPR->data;
|
|
|
|
|
|
|
|
guchar *t;
|
|
|
|
guchar *b;
|
|
|
|
gdouble *r = result;
|
2006-09-03 02:54:35 +08:00
|
|
|
|
2007-12-11 03:26:36 +08:00
|
|
|
g_assert (topPR->bytes == bottomPR->bytes);
|
|
|
|
|
2006-09-03 02:54:35 +08:00
|
|
|
for (i = 0; i < height; i++)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
|
|
|
t = t_data;
|
|
|
|
b = b_data;
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < depth; k++)
|
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
r[k] = (gdouble) (t[k]) - (gdouble) (b[k]);
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|
|
|
|
t += depth;
|
|
|
|
b += depth;
|
|
|
|
r += depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
t_data += topPR->rowstride;
|
|
|
|
b_data += bottomPR->rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Add first to secondPR and store the result as a PixelRegion
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
|
|
|
static void
|
2011-10-18 03:47:01 +08:00
|
|
|
gimp_heal_add (gdouble *first,
|
|
|
|
PixelRegion *secondPR,
|
|
|
|
PixelRegion *resultPR)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
|
|
|
gint i, j, k;
|
|
|
|
|
|
|
|
gint height = secondPR->h;
|
|
|
|
gint width = secondPR->w;
|
|
|
|
gint depth = secondPR->bytes;
|
|
|
|
|
|
|
|
guchar *s_data = secondPR->data;
|
|
|
|
guchar *r_data = resultPR->data;
|
|
|
|
|
|
|
|
gdouble *f = first;
|
|
|
|
guchar *s;
|
|
|
|
guchar *r;
|
|
|
|
|
2007-12-11 03:26:36 +08:00
|
|
|
g_assert (secondPR->bytes == resultPR->bytes);
|
|
|
|
|
2006-09-03 02:54:35 +08:00
|
|
|
for (i = 0; i < height; i++)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
|
|
|
s = s_data;
|
|
|
|
r = r_data;
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < depth; k++)
|
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
r[k] = (guchar) CLAMP0255 (ROUND (((gdouble) (f[k])) +
|
|
|
|
((gdouble) (s[k]))));
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
f += depth;
|
|
|
|
s += depth;
|
|
|
|
r += depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_data += secondPR->rowstride;
|
|
|
|
r_data += resultPR->rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Perform one iteration of the laplace solver for matrix. Store the
|
2007-03-30 17:53:43 +08:00
|
|
|
* result in solution and return the square of the cummulative error
|
|
|
|
* of the solution.
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
2006-10-30 18:13:06 +08:00
|
|
|
static gdouble
|
2006-08-16 05:15:59 +08:00
|
|
|
gimp_heal_laplace_iteration (gdouble *matrix,
|
|
|
|
gint height,
|
|
|
|
gint depth,
|
|
|
|
gint width,
|
2007-12-12 03:31:46 +08:00
|
|
|
gdouble *solution,
|
|
|
|
guchar *mask)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
const gint rowstride = width * depth;
|
|
|
|
gint i, j, k, off, offm, offm0, off0;
|
|
|
|
gdouble tmp, diff;
|
|
|
|
gdouble err = 0.0;
|
|
|
|
const gdouble w = 1.80 * 0.25; /* Over-relaxation = 1.8 */
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* we use a red/black checker model of the discretization grid */
|
|
|
|
|
|
|
|
/* do reds */
|
2006-08-16 05:15:59 +08:00
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
off0 = i * rowstride;
|
|
|
|
offm0 = i * width;
|
|
|
|
|
|
|
|
for (j = i % 2; j < width; j += 2)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
off = off0 + j * depth;
|
|
|
|
offm = offm0 + j;
|
|
|
|
|
|
|
|
if ((0 == mask[offm]) ||
|
2009-10-17 04:06:34 +08:00
|
|
|
(i == 0) || (i == (height - 1)) ||
|
|
|
|
(j == 0) || (j == (width - 1)))
|
2006-09-05 07:24:31 +08:00
|
|
|
{
|
2007-12-12 03:31:46 +08:00
|
|
|
/* do nothing at the boundary or outside mask */
|
2006-09-05 07:24:31 +08:00
|
|
|
for (k = 0; k < depth; k++)
|
2011-10-18 03:47:01 +08:00
|
|
|
solution[off + k] = matrix[off + k];
|
2006-09-05 07:24:31 +08:00
|
|
|
}
|
2006-08-16 05:15:59 +08:00
|
|
|
else
|
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Use Gauss Siedel to get the correction factor then
|
|
|
|
* over-relax it
|
|
|
|
*/
|
2006-08-16 05:15:59 +08:00
|
|
|
for (k = 0; k < depth; k++)
|
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
tmp = solution[off + k];
|
|
|
|
solution[off + k] = (matrix[off + k] +
|
|
|
|
w *
|
|
|
|
(matrix[off - depth + k] + /* west */
|
|
|
|
matrix[off + depth + k] + /* east */
|
|
|
|
matrix[off - rowstride + k] + /* north */
|
|
|
|
matrix[off + rowstride + k] - 4.0 *
|
|
|
|
matrix[off+k])); /* south */
|
|
|
|
|
|
|
|
diff = solution[off + k] - tmp;
|
|
|
|
err += diff * diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Do blacks
|
|
|
|
*
|
|
|
|
* As we've done the reds earlier, we can use them right now to
|
|
|
|
* accelerate the convergence. So we have "solution" in the solver
|
|
|
|
* instead of "matrix" above
|
|
|
|
*/
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
off0 = i * rowstride;
|
|
|
|
offm0 = i * width;
|
|
|
|
|
2012-04-22 03:59:42 +08:00
|
|
|
for (j = (i % 2) ? 0 : 1; j < width; j += 2)
|
2011-10-18 03:47:01 +08:00
|
|
|
{
|
|
|
|
off = off0 + j * depth;
|
|
|
|
offm = offm0 + j;
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
if ((0 == mask[offm]) ||
|
|
|
|
(i == 0) || (i == (height - 1)) ||
|
|
|
|
(j == 0) || (j == (width - 1)))
|
|
|
|
{
|
|
|
|
/* do nothing at the boundary or outside mask */
|
|
|
|
for (k = 0; k < depth; k++)
|
|
|
|
solution[off + k] = matrix[off + k];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use Gauss Siedel to get the correction factor then
|
|
|
|
* over-relax it
|
|
|
|
*/
|
|
|
|
for (k = 0; k < depth; k++)
|
|
|
|
{
|
|
|
|
tmp = solution[off + k];
|
|
|
|
solution[off + k] = (matrix[off + k] +
|
|
|
|
w *
|
|
|
|
(solution[off - depth + k] + /* west */
|
|
|
|
solution[off + depth + k] + /* east */
|
|
|
|
solution[off - rowstride + k] + /* north */
|
|
|
|
solution[off + rowstride + k] - 4.0 *
|
|
|
|
matrix[off+k])); /* south */
|
|
|
|
|
|
|
|
diff = solution[off + k] - tmp;
|
2006-08-16 05:15:59 +08:00
|
|
|
err += diff*diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 17:53:43 +08:00
|
|
|
return err;
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Solve the laplace equation for matrix and store the result in solution.
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
2006-10-30 18:13:06 +08:00
|
|
|
static void
|
2006-08-16 05:15:59 +08:00
|
|
|
gimp_heal_laplace_loop (gdouble *matrix,
|
|
|
|
gint height,
|
|
|
|
gint depth,
|
|
|
|
gint width,
|
2007-12-12 03:31:46 +08:00
|
|
|
gdouble *solution,
|
|
|
|
guchar *mask)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2011-10-18 03:47:01 +08:00
|
|
|
#define EPSILON 0.001
|
2006-09-03 02:54:35 +08:00
|
|
|
#define MAX_ITER 500
|
2007-03-30 17:53:43 +08:00
|
|
|
gint i;
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
/* repeat until convergence or max iterations */
|
2007-03-30 17:53:43 +08:00
|
|
|
for (i = 0; i < MAX_ITER; i++)
|
2006-09-03 02:54:35 +08:00
|
|
|
{
|
2007-03-30 17:53:43 +08:00
|
|
|
gdouble sqr_err;
|
|
|
|
|
|
|
|
/* do one iteration and store the amount of error */
|
2007-12-12 03:31:46 +08:00
|
|
|
sqr_err = gimp_heal_laplace_iteration (matrix, height, depth, width,
|
|
|
|
solution, mask);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2007-03-30 17:53:43 +08:00
|
|
|
/* copy solution to matrix */
|
|
|
|
memcpy (matrix, solution, width * height * depth * sizeof (double));
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
if (sqr_err < EPSILON)
|
2006-08-16 05:15:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* Original Algorithm Design:
|
2006-09-03 02:54:35 +08:00
|
|
|
*
|
2011-10-18 03:47:01 +08:00
|
|
|
* T. Georgiev, "Photoshop Healing Brush: a Tool for Seamless Cloning
|
|
|
|
* http://www.tgeorgiev.net/Photoshop_Healing.pdf
|
2006-08-16 05:15:59 +08:00
|
|
|
*/
|
2006-10-30 18:13:06 +08:00
|
|
|
static PixelRegion *
|
2011-04-06 04:11:27 +08:00
|
|
|
gimp_heal_region (PixelRegion *tempPR,
|
|
|
|
PixelRegion *srcPR,
|
|
|
|
const TempBuf *mask_buf)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2007-12-12 03:31:46 +08:00
|
|
|
gdouble *i_1 = g_new (gdouble, tempPR->h * tempPR->bytes * tempPR->w);
|
|
|
|
gdouble *i_2 = g_new (gdouble, tempPR->h * tempPR->bytes * tempPR->w);
|
2008-12-13 18:35:53 +08:00
|
|
|
guchar *mask = temp_buf_get_data (mask_buf);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* substract pattern to image and store the result as a double in i_1 */
|
|
|
|
gimp_heal_sub (tempPR, srcPR, i_1);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
|
|
|
/* FIXME: is a faster implementation needed? */
|
2007-12-12 03:31:46 +08:00
|
|
|
gimp_heal_laplace_loop (i_1, tempPR->h, tempPR->bytes, tempPR->w, i_2, mask);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* add solution to original image and store in tempPR */
|
|
|
|
gimp_heal_add (i_2, srcPR, tempPR);
|
2006-09-03 02:54:35 +08:00
|
|
|
|
2011-10-18 03:47:01 +08:00
|
|
|
/* clean up */
|
2006-08-16 05:15:59 +08:00
|
|
|
g_free (i_1);
|
|
|
|
g_free (i_2);
|
|
|
|
|
|
|
|
return tempPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-09-04 23:40:56 +08:00
|
|
|
gimp_heal_motion (GimpSourceCore *source_core,
|
|
|
|
GimpDrawable *drawable,
|
2006-09-05 06:54:50 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
2009-05-03 18:08:21 +08:00
|
|
|
const GimpCoords *coords,
|
2006-09-05 06:54:50 +08:00
|
|
|
gdouble opacity,
|
|
|
|
GimpPickable *src_pickable,
|
2012-03-31 04:11:46 +08:00
|
|
|
GeglBuffer *src_buffer,
|
2012-03-31 21:40:21 +08:00
|
|
|
GeglRectangle *src_rect,
|
2006-09-07 17:35:52 +08:00
|
|
|
gint src_offset_x,
|
|
|
|
gint src_offset_y,
|
2012-04-02 03:02:49 +08:00
|
|
|
GeglBuffer *paint_buffer,
|
|
|
|
gint paint_buffer_x,
|
|
|
|
gint paint_buffer_y,
|
2006-09-05 06:54:50 +08:00
|
|
|
gint paint_area_offset_x,
|
2006-09-07 16:49:52 +08:00
|
|
|
gint paint_area_offset_y,
|
|
|
|
gint paint_area_width,
|
|
|
|
gint paint_area_height)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2011-03-04 01:43:56 +08:00
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (source_core);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
|
|
|
GimpDynamics *dynamics = GIMP_BRUSH_CORE (paint_core)->dynamics;
|
|
|
|
GimpDynamicsOutput *hardness_output;
|
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2012-03-31 04:11:46 +08:00
|
|
|
TempBuf *src_temp_buf;
|
|
|
|
TempBuf *dest_temp_buf;
|
2012-04-02 03:02:49 +08:00
|
|
|
GeglBuffer *dest_buffer;
|
2012-03-31 04:11:46 +08:00
|
|
|
PixelRegion srcPR;
|
2011-03-04 01:43:56 +08:00
|
|
|
PixelRegion destPR;
|
2011-04-06 04:11:27 +08:00
|
|
|
const TempBuf *mask_buf;
|
2011-03-04 01:43:56 +08:00
|
|
|
gdouble fade_point;
|
|
|
|
gdouble hardness;
|
|
|
|
|
|
|
|
hardness_output = gimp_dynamics_get_output (dynamics,
|
|
|
|
GIMP_DYNAMICS_OUTPUT_HARDNESS);
|
2008-05-23 00:38:57 +08:00
|
|
|
|
2009-10-14 03:02:10 +08:00
|
|
|
fade_point = gimp_paint_options_get_fade (paint_options, image,
|
|
|
|
paint_core->pixel_dist);
|
2009-10-03 23:53:25 +08:00
|
|
|
|
2011-03-04 01:43:56 +08:00
|
|
|
hardness = gimp_dynamics_output_get_linear_value (hardness_output,
|
2009-10-27 21:30:20 +08:00
|
|
|
coords,
|
2009-12-19 23:29:42 +08:00
|
|
|
paint_options,
|
2009-10-14 03:02:10 +08:00
|
|
|
fade_point);
|
2007-12-12 03:31:46 +08:00
|
|
|
|
2008-03-30 21:38:59 +08:00
|
|
|
mask_buf = gimp_brush_core_get_brush_mask (GIMP_BRUSH_CORE (source_core),
|
2009-05-18 04:45:06 +08:00
|
|
|
coords,
|
2008-05-23 00:38:57 +08:00
|
|
|
GIMP_BRUSH_HARD,
|
|
|
|
hardness);
|
2006-09-05 06:54:50 +08:00
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
/* copy the source buffer because we are going to modify it */
|
|
|
|
{
|
|
|
|
GeglBuffer *tmp;
|
|
|
|
|
2012-03-31 21:40:21 +08:00
|
|
|
src_temp_buf = temp_buf_new (src_rect->width, src_rect->height,
|
2012-03-31 04:11:46 +08:00
|
|
|
gimp_drawable_bytes_with_alpha (drawable),
|
|
|
|
0, 0, NULL);
|
|
|
|
|
2012-03-31 22:19:46 +08:00
|
|
|
tmp = gimp_temp_buf_create_buffer (src_temp_buf,
|
|
|
|
gimp_drawable_get_format_with_alpha (drawable));
|
2012-03-31 04:11:46 +08:00
|
|
|
|
2012-03-31 21:40:21 +08:00
|
|
|
gegl_buffer_copy (src_buffer, src_rect,
|
|
|
|
tmp, GIMP_GEGL_RECT (0, 0, 0, 0));
|
2012-03-31 04:11:46 +08:00
|
|
|
g_object_unref (tmp);
|
|
|
|
}
|
|
|
|
|
2012-04-02 03:02:49 +08:00
|
|
|
dest_temp_buf = temp_buf_new (gegl_buffer_get_width (paint_buffer),
|
|
|
|
gegl_buffer_get_height (paint_buffer),
|
|
|
|
gimp_drawable_bytes_with_alpha (drawable),
|
|
|
|
0, 0, NULL);
|
2012-03-31 04:11:46 +08:00
|
|
|
|
2012-04-02 03:02:49 +08:00
|
|
|
dest_buffer =
|
|
|
|
gimp_temp_buf_create_buffer (dest_temp_buf,
|
|
|
|
gimp_drawable_get_format_with_alpha (drawable));
|
2012-03-31 04:11:46 +08:00
|
|
|
|
2012-04-02 03:02:49 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
|
|
|
|
GIMP_GEGL_RECT (paint_buffer_x, paint_buffer_y,
|
|
|
|
gegl_buffer_get_width (paint_buffer),
|
|
|
|
gegl_buffer_get_height (paint_buffer)),
|
|
|
|
dest_buffer,
|
|
|
|
GIMP_GEGL_RECT (0, 0, 0, 0));
|
2012-03-31 04:11:46 +08:00
|
|
|
|
|
|
|
/* check that srcPR, tempPR, destPR, and mask_buf are the same size */
|
|
|
|
if (src_temp_buf->width != dest_temp_buf->width ||
|
|
|
|
src_temp_buf->height != dest_temp_buf->height)
|
2006-08-16 05:15:59 +08:00
|
|
|
{
|
2007-12-11 03:26:36 +08:00
|
|
|
/* this generally means that the source point has hit the edge of the
|
|
|
|
layer, so it is not an error and we should not complain, just
|
|
|
|
don't do anything */
|
2008-03-30 21:38:59 +08:00
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
temp_buf_free (src_temp_buf);
|
|
|
|
temp_buf_free (dest_temp_buf);
|
2008-03-30 21:38:59 +08:00
|
|
|
|
2006-08-16 05:15:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
pixel_region_init_temp_buf (&srcPR, src_temp_buf,
|
|
|
|
0, 0,
|
|
|
|
mask_buf->width, mask_buf->height);
|
|
|
|
pixel_region_init_temp_buf (&destPR, dest_temp_buf,
|
|
|
|
0, 0,
|
|
|
|
mask_buf->width, mask_buf->height);
|
2008-04-25 21:39:36 +08:00
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
/* heal destPR using srcPR */
|
|
|
|
gimp_heal_region (&destPR, &srcPR, mask_buf);
|
2006-08-16 05:15:59 +08:00
|
|
|
|
2012-04-02 03:02:49 +08:00
|
|
|
gegl_buffer_copy (dest_buffer,
|
|
|
|
GIMP_GEGL_RECT (0, 0, mask_buf->width, mask_buf->height),
|
|
|
|
paint_buffer,
|
|
|
|
GIMP_GEGL_RECT (paint_area_offset_x,
|
|
|
|
paint_area_offset_y,
|
|
|
|
paint_area_width,
|
|
|
|
paint_area_height));
|
2008-04-25 21:39:36 +08:00
|
|
|
|
2006-09-03 02:54:35 +08:00
|
|
|
/* replace the canvas with our healed data */
|
2009-05-18 04:45:06 +08:00
|
|
|
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
|
|
|
|
coords,
|
2006-08-16 05:15:59 +08:00
|
|
|
MIN (opacity, GIMP_OPACITY_OPAQUE),
|
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_paint_options_get_brush_mode (paint_options),
|
2008-05-23 00:38:57 +08:00
|
|
|
hardness,
|
2007-12-11 03:26:36 +08:00
|
|
|
GIMP_PAINT_INCREMENTAL);
|
2006-08-16 05:15:59 +08:00
|
|
|
}
|