2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-05-26 04:41:09 +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
|
2004-05-26 04:41:09 +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
|
2004-05-26 04:41:09 +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/>.
|
2004-05-26 04:41:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
#include "paint-types.h"
|
|
|
|
|
2006-11-16 23:11:27 +08:00
|
|
|
#include "base/boundary.h"
|
2004-05-26 04:41:09 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2008-01-23 04:06:01 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
2008-11-12 18:56:06 +08:00
|
|
|
#include "core/gimperror.h"
|
2004-05-26 04:41:09 +08:00
|
|
|
#include "core/gimpimage.h"
|
2004-06-23 20:19:28 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
#include "gimpbrushcore.h"
|
|
|
|
#include "gimpbrushcore-kernels.h"
|
2004-05-26 17:32:03 +08:00
|
|
|
#include "gimppaintoptions.h"
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define EPSILON 0.00001
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SET_BRUSH,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2008-09-09 03:06:32 +08:00
|
|
|
static void gimp_brush_core_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_brush_core_start (GimpPaintCore *core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2009-04-18 04:29:25 +08:00
|
|
|
const GimpCoords *coords,
|
2008-09-09 03:06:32 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean gimp_brush_core_pre_paint (GimpPaintCore *core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_brush_core_post_paint (GimpPaintCore *core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_brush_core_interpolate (GimpPaintCore *core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
guint32 time);
|
|
|
|
|
|
|
|
static TempBuf *gimp_brush_core_get_paint_area (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
|
|
|
|
|
|
|
static void gimp_brush_core_real_set_brush (GimpBrushCore *core,
|
|
|
|
GimpBrush *brush);
|
|
|
|
|
|
|
|
static inline void rotate_pointers (gulong **p,
|
|
|
|
guint32 n);
|
|
|
|
static TempBuf * gimp_brush_core_subsample_mask (GimpBrushCore *core,
|
|
|
|
TempBuf *mask,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static TempBuf * gimp_brush_core_pressurize_mask (GimpBrushCore *core,
|
|
|
|
TempBuf *brush_mask,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble pressure);
|
|
|
|
static TempBuf * gimp_brush_core_solidify_mask (GimpBrushCore *core,
|
|
|
|
TempBuf *brush_mask,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
static gdouble gimp_brush_core_clamp_brush_scale (GimpBrushCore *core,
|
|
|
|
gdouble scale);
|
2009-02-01 19:08:22 +08:00
|
|
|
static TempBuf * gimp_brush_core_transform_mask (GimpBrushCore *core,
|
2008-09-09 03:06:32 +08:00
|
|
|
GimpBrush *brush);
|
2009-02-01 19:08:22 +08:00
|
|
|
static TempBuf * gimp_brush_core_transform_pixmap (GimpBrushCore *core,
|
2008-09-09 03:06:32 +08:00
|
|
|
GimpBrush *brush);
|
|
|
|
|
|
|
|
static void gimp_brush_core_invalidate_cache (GimpBrush *brush,
|
|
|
|
GimpBrushCore *core);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* brush pipe utility functions */
|
2008-09-09 03:06:32 +08:00
|
|
|
static void paint_line_pixmap_mask (GimpImage *dest,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
TempBuf *pixmap_mask,
|
|
|
|
TempBuf *brush_mask,
|
|
|
|
guchar *d,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint bytes,
|
|
|
|
gint width,
|
|
|
|
GimpBrushApplicationMode mode);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpBrushCore, gimp_brush_core, GIMP_TYPE_PAINT_CORE)
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2005-12-08 05:11:53 +08:00
|
|
|
#define parent_class gimp_brush_core_parent_class
|
2004-06-23 20:19:28 +08:00
|
|
|
|
2005-12-08 05:11:53 +08:00
|
|
|
static guint core_signals[LAST_SIGNAL] = { 0, };
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_core_class_init (GimpBrushCoreClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
core_signals[SET_BRUSH] =
|
|
|
|
g_signal_new ("set-brush",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GimpBrushCoreClass, set_brush),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GIMP_TYPE_BRUSH);
|
2004-06-23 20:19:28 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
object_class->finalize = gimp_brush_core_finalize;
|
|
|
|
|
|
|
|
paint_core_class->start = gimp_brush_core_start;
|
|
|
|
paint_core_class->pre_paint = gimp_brush_core_pre_paint;
|
2004-06-14 20:52:33 +08:00
|
|
|
paint_core_class->post_paint = gimp_brush_core_post_paint;
|
2004-05-26 04:41:09 +08:00
|
|
|
paint_core_class->interpolate = gimp_brush_core_interpolate;
|
|
|
|
paint_core_class->get_paint_area = gimp_brush_core_get_paint_area;
|
2004-05-26 17:32:03 +08:00
|
|
|
|
2009-02-06 05:47:57 +08:00
|
|
|
klass->handles_changing_brush = FALSE;
|
|
|
|
klass->handles_transforming_brush = TRUE;
|
|
|
|
klass->set_brush = gimp_brush_core_real_set_brush;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_core_init (GimpBrushCore *core)
|
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->main_brush = NULL;
|
|
|
|
core->brush = NULL;
|
|
|
|
core->spacing = 1.0;
|
|
|
|
core->scale = 1.0;
|
2009-02-06 05:47:57 +08:00
|
|
|
core->angle = 1.0;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->pressure_brush = NULL;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->last_solid_brush = NULL;
|
|
|
|
core->solid_cache_invalid = FALSE;
|
|
|
|
|
|
|
|
core->transform_brush = NULL;
|
|
|
|
core->last_transform_brush = NULL;
|
|
|
|
core->last_transform_width = 0;
|
|
|
|
core->last_transform_height = 0;
|
|
|
|
core->last_scale = 1.0;
|
|
|
|
|
|
|
|
core->transform_pixmap = NULL;
|
|
|
|
core->last_transform_pixmap = NULL;
|
|
|
|
core->last_transform_pixmap_width = 0;
|
|
|
|
core->last_transform_pixmap_height = 0;
|
|
|
|
|
|
|
|
core->last_brush_mask = NULL;
|
|
|
|
core->cache_invalid = FALSE;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->rand = g_rand_new ();
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->brush_bound_segs = NULL;
|
|
|
|
core->n_brush_bound_segs = 0;
|
|
|
|
core->brush_bound_width = 0;
|
|
|
|
core->brush_bound_height = 0;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
for (i = 0; i < BRUSH_CORE_SOLID_SUBSAMPLE; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
|
|
|
|
{
|
|
|
|
core->solid_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-07-04 14:30:34 +08:00
|
|
|
for (i = 0; i < BRUSH_CORE_JITTER_LUTSIZE - 1; ++i)
|
|
|
|
{
|
|
|
|
core->jitter_lut_y[i] = cos (gimp_deg_to_rad (i * 360 /
|
|
|
|
BRUSH_CORE_JITTER_LUTSIZE));
|
|
|
|
core->jitter_lut_x[i] = sin (gimp_deg_to_rad (i * 360 /
|
|
|
|
BRUSH_CORE_JITTER_LUTSIZE));
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
g_assert (BRUSH_CORE_SUBSAMPLE == KERNEL_SUBSAMPLE);
|
|
|
|
|
|
|
|
for (i = 0; i < KERNEL_SUBSAMPLE + 1; i++)
|
2009-02-01 19:08:22 +08:00
|
|
|
{
|
|
|
|
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
|
|
|
|
{
|
|
|
|
core->kernel_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2006-11-23 04:22:32 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_core_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (object);
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
if (core->pressure_brush)
|
|
|
|
{
|
|
|
|
temp_buf_free (core->pressure_brush);
|
|
|
|
core->pressure_brush = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < BRUSH_CORE_SOLID_SUBSAMPLE; i++)
|
|
|
|
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
|
|
|
|
if (core->solid_brushes[i][j])
|
|
|
|
{
|
|
|
|
temp_buf_free (core->solid_brushes[i][j]);
|
|
|
|
core->solid_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
if (core->transform_brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2009-02-01 19:08:22 +08:00
|
|
|
temp_buf_free (core->transform_brush);
|
|
|
|
core->transform_brush = NULL;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
if (core->transform_pixmap)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2009-02-01 19:08:22 +08:00
|
|
|
temp_buf_free (core->transform_pixmap);
|
|
|
|
core->transform_pixmap = NULL;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2006-11-23 04:22:32 +08:00
|
|
|
if (core->rand)
|
|
|
|
{
|
|
|
|
g_rand_free (core->rand);
|
|
|
|
core->rand = NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
for (i = 0; i < KERNEL_SUBSAMPLE + 1; i++)
|
|
|
|
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
|
|
|
|
if (core->kernel_brushes[i][j])
|
|
|
|
{
|
|
|
|
temp_buf_free (core->kernel_brushes[i][j]);
|
|
|
|
core->kernel_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-14 20:52:33 +08:00
|
|
|
if (core->main_brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2004-06-14 20:52:33 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (core->main_brush,
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_invalidate_cache,
|
|
|
|
core);
|
2004-06-14 20:52:33 +08:00
|
|
|
g_object_unref (core->main_brush);
|
|
|
|
core->main_brush = NULL;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (core->brush_bound_segs)
|
|
|
|
{
|
|
|
|
g_free (core->brush_bound_segs);
|
|
|
|
core->brush_bound_segs = NULL;
|
|
|
|
core->n_brush_bound_segs = 0;
|
2004-06-23 20:19:28 +08:00
|
|
|
core->brush_bound_width = 0;
|
|
|
|
core->brush_bound_height = 0;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-07-19 22:37:40 +08:00
|
|
|
gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
if (paint_state == GIMP_PAINT_STATE_MOTION)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
/* If we current point == last point, check if the brush
|
|
|
|
* wants to be painted in that case. (Direction dependent
|
|
|
|
* pixmap brush pipes don't, as they don't know which
|
|
|
|
* pixmap to select.)
|
|
|
|
*/
|
|
|
|
if (paint_core->last_coords.x == paint_core->cur_coords.x &&
|
2006-04-12 20:49:29 +08:00
|
|
|
paint_core->last_coords.y == paint_core->cur_coords.y &&
|
|
|
|
! gimp_brush_want_null_motion (core->main_brush,
|
2004-05-26 04:41:09 +08:00
|
|
|
&paint_core->last_coords,
|
|
|
|
&paint_core->cur_coords))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-05-28 04:48:49 +08:00
|
|
|
if (GIMP_BRUSH_CORE_GET_CLASS (paint_core)->handles_changing_brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2004-06-14 20:52:33 +08:00
|
|
|
core->brush = gimp_brush_select_brush (core->main_brush,
|
2004-05-26 04:41:09 +08:00
|
|
|
&paint_core->last_coords,
|
|
|
|
&paint_core->cur_coords);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-14 20:52:33 +08:00
|
|
|
static void
|
2004-07-19 22:37:40 +08:00
|
|
|
gimp_brush_core_post_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
2004-06-14 20:52:33 +08:00
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
if (paint_state == GIMP_PAINT_STATE_MOTION)
|
2004-06-14 20:52:33 +08:00
|
|
|
{
|
|
|
|
core->brush = core->main_brush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
static gboolean
|
2006-09-27 04:55:40 +08:00
|
|
|
gimp_brush_core_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)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
|
2004-06-23 20:19:28 +08:00
|
|
|
GimpBrush *brush;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
if (core->main_brush != brush)
|
|
|
|
gimp_brush_core_set_brush (core, brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-06-14 20:52:33 +08:00
|
|
|
if (! core->main_brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2008-11-12 18:56:06 +08:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2008-11-04 20:33:09 +08:00
|
|
|
_("No brushes available for use with this tool."));
|
2004-06-23 20:19:28 +08:00
|
|
|
return FALSE;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2009-02-06 05:47:57 +08:00
|
|
|
if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_transforming_brush)
|
|
|
|
{
|
2009-04-26 01:53:09 +08:00
|
|
|
core->scale = gimp_paint_options_get_dynamic_size (paint_options,
|
|
|
|
coords,
|
|
|
|
TRUE);
|
|
|
|
core->angle = gimp_paint_options_get_dynamic_angle (paint_options,
|
|
|
|
coords);
|
|
|
|
core->aspect_ratio =
|
|
|
|
gimp_paint_options_get_dynamic_aspect_ratio (paint_options,
|
|
|
|
coords);
|
2009-02-06 05:47:57 +08:00
|
|
|
}
|
2004-06-14 20:52:33 +08:00
|
|
|
core->spacing = (gdouble) gimp_brush_get_spacing (core->main_brush) / 100.0;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-06-14 20:52:33 +08:00
|
|
|
core->brush = core->main_brush;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2005-10-05 04:16:52 +08:00
|
|
|
core->jitter =
|
|
|
|
gimp_paint_options_get_jitter (paint_options,
|
|
|
|
gimp_item_get_image (GIMP_ITEM (drawable)));
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_avoid_exact_integer
|
|
|
|
* @x: points to a gdouble
|
|
|
|
*
|
|
|
|
* Adjusts *x such that it is not too close to an integer. This is used
|
|
|
|
* for decision algorithms that would be vulnerable to rounding glitches
|
|
|
|
* if exact integers were input.
|
|
|
|
*
|
|
|
|
* Side effects: Changes the value of *x
|
|
|
|
**/
|
|
|
|
static void
|
|
|
|
gimp_avoid_exact_integer (gdouble *x)
|
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
const gdouble integral = floor (*x);
|
|
|
|
const gdouble fractional = *x - integral;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if (fractional < EPSILON)
|
2007-12-26 19:45:50 +08:00
|
|
|
{
|
|
|
|
*x = integral + EPSILON;
|
|
|
|
}
|
|
|
|
else if (fractional > (1 -EPSILON))
|
|
|
|
{
|
|
|
|
*x = integral + (1 - EPSILON);
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_core_interpolate (GimpPaintCore *paint_core,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpDrawable *drawable,
|
2004-05-27 00:13:53 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
guint32 time)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
GimpVector2 delta_vec;
|
|
|
|
gdouble delta_pressure;
|
|
|
|
gdouble delta_xtilt, delta_ytilt;
|
|
|
|
gdouble delta_wheel;
|
2008-05-10 18:03:21 +08:00
|
|
|
gdouble delta_velocity;
|
2009-02-08 20:55:20 +08:00
|
|
|
gdouble temp_direction;
|
2006-12-10 07:46:16 +08:00
|
|
|
GimpVector2 temp_vec;
|
2004-05-26 04:41:09 +08:00
|
|
|
gint n, num_points;
|
|
|
|
gdouble t0, dt, tn;
|
|
|
|
gdouble st_factor, st_offset;
|
|
|
|
gdouble initial;
|
|
|
|
gdouble dist;
|
|
|
|
gdouble total;
|
|
|
|
gdouble pixel_dist;
|
|
|
|
gdouble pixel_initial;
|
|
|
|
gdouble xd, yd;
|
|
|
|
gdouble mag;
|
|
|
|
|
2007-07-26 18:20:54 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BRUSH (core->brush));
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_avoid_exact_integer (&paint_core->last_coords.x);
|
|
|
|
gimp_avoid_exact_integer (&paint_core->last_coords.y);
|
|
|
|
gimp_avoid_exact_integer (&paint_core->cur_coords.x);
|
|
|
|
gimp_avoid_exact_integer (&paint_core->cur_coords.y);
|
|
|
|
|
|
|
|
delta_vec.x = paint_core->cur_coords.x - paint_core->last_coords.x;
|
|
|
|
delta_vec.y = paint_core->cur_coords.y - paint_core->last_coords.y;
|
|
|
|
delta_pressure = paint_core->cur_coords.pressure - paint_core->last_coords.pressure;
|
|
|
|
delta_xtilt = paint_core->cur_coords.xtilt - paint_core->last_coords.xtilt;
|
|
|
|
delta_ytilt = paint_core->cur_coords.ytilt - paint_core->last_coords.ytilt;
|
|
|
|
delta_wheel = paint_core->cur_coords.wheel - paint_core->last_coords.wheel;
|
2008-05-10 18:03:21 +08:00
|
|
|
delta_velocity = paint_core->cur_coords.velocity - paint_core->last_coords.velocity;
|
2009-02-08 20:55:20 +08:00
|
|
|
temp_direction = paint_core->cur_coords.direction;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* return if there has been no motion */
|
|
|
|
if (! delta_vec.x &&
|
|
|
|
! delta_vec.y &&
|
|
|
|
! delta_pressure &&
|
|
|
|
! delta_xtilt &&
|
|
|
|
! delta_ytilt &&
|
2008-05-10 18:03:21 +08:00
|
|
|
! delta_wheel &&
|
|
|
|
! delta_velocity)
|
2004-05-26 04:41:09 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* calculate the distance traveled in the coordinate space of the brush */
|
2006-12-10 07:46:16 +08:00
|
|
|
temp_vec = core->brush->x_axis;
|
2007-03-19 04:13:55 +08:00
|
|
|
gimp_vector2_mul (&temp_vec, core->scale);
|
2006-12-10 07:46:16 +08:00
|
|
|
|
|
|
|
mag = gimp_vector2_length (&temp_vec);
|
|
|
|
xd = gimp_vector2_inner_product (&delta_vec, &temp_vec) / (mag * mag);
|
|
|
|
|
|
|
|
temp_vec = core->brush->y_axis;
|
2007-03-19 04:13:55 +08:00
|
|
|
gimp_vector2_mul (&temp_vec, core->scale);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2006-12-10 07:46:16 +08:00
|
|
|
mag = gimp_vector2_length (&temp_vec);
|
|
|
|
yd = gimp_vector2_inner_product (&delta_vec, &temp_vec) / (mag * mag);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
dist = 0.5 * sqrt (xd * xd + yd * yd);
|
|
|
|
total = dist + paint_core->distance;
|
|
|
|
initial = paint_core->distance;
|
|
|
|
|
|
|
|
pixel_dist = gimp_vector2_length (&delta_vec);
|
|
|
|
pixel_initial = paint_core->pixel_dist;
|
|
|
|
|
2006-12-10 07:46:16 +08:00
|
|
|
/* FIXME: need to adapt the spacing to the size */
|
|
|
|
/* lastscale = MIN (paint_core->last_coords.pressure, 1/256); */
|
|
|
|
/* curscale = MIN (paint_core->cur_coords.pressure, 1/256); */
|
|
|
|
/* spacing = core->spacing * sqrt (0.5 * (lastscale + curscale)); */
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* Compute spacing parameters such that a brush position will be
|
|
|
|
* made each time the line crosses the *center* of a pixel row or
|
|
|
|
* column, according to whether the line is mostly horizontal or
|
|
|
|
* mostly vertical. The term "stripe" will mean "column" if the
|
|
|
|
* line is horizontalish; "row" if the line is verticalish.
|
|
|
|
*
|
|
|
|
* We start by deriving coefficients for a new parameter 's':
|
|
|
|
* s = t * st_factor + st_offset
|
|
|
|
* such that the "nice" brush positions are the ones with *integer*
|
|
|
|
* s values. (Actually the value of s will be 1/2 less than the nice
|
|
|
|
* brush position's x or y coordinate - note that st_factor may
|
|
|
|
* be negative!)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (delta_vec.x * delta_vec.x > delta_vec.y * delta_vec.y)
|
|
|
|
{
|
|
|
|
st_factor = delta_vec.x;
|
|
|
|
st_offset = paint_core->last_coords.x - 0.5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
st_factor = delta_vec.y;
|
|
|
|
st_offset = paint_core->last_coords.y - 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fabs (st_factor) > dist / core->spacing)
|
|
|
|
{
|
|
|
|
/* The stripe principle leads to brush positions that are spaced
|
|
|
|
* *closer* than the official brush spacing. Use the official
|
|
|
|
* spacing instead. This is the common case when the brush spacing
|
|
|
|
* is large.
|
|
|
|
* The net effect is then to put a lower bound on the spacing, but
|
|
|
|
* one that varies with the slope of the line. This is suppose to
|
|
|
|
* make thin lines (say, with a 1x1 brush) prettier while leaving
|
|
|
|
* lines with larger brush spacing as they used to look in 1.2.x.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dt = core->spacing / dist;
|
|
|
|
n = (gint) (initial / core->spacing + 1.0 + EPSILON);
|
|
|
|
t0 = (n * core->spacing - initial) / dist;
|
|
|
|
num_points = 1 + (gint) floor ((1 + EPSILON - t0) / dt);
|
|
|
|
|
|
|
|
/* if we arnt going to paint anything this time and the brush
|
|
|
|
* has only moved on one axis return without updating the brush
|
|
|
|
* position, distance etc. so that we can more accurately space
|
|
|
|
* brush strokes when curves are supplied to us in single pixel
|
|
|
|
* chunks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (num_points == 0 && (delta_vec.x == 0 || delta_vec.y == 0))
|
2006-04-12 20:49:29 +08:00
|
|
|
return;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
else if (fabs (st_factor) < EPSILON)
|
|
|
|
{
|
|
|
|
/* Hm, we've hardly moved at all. Don't draw anything, but reset the
|
|
|
|
* old coordinates and hope we've gone longer the next time.
|
|
|
|
*/
|
|
|
|
paint_core->cur_coords.x = paint_core->last_coords.x;
|
|
|
|
paint_core->cur_coords.y = paint_core->last_coords.y;
|
|
|
|
/* ... but go along with the current pressure, tilt and wheel */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint direction = st_factor > 0 ? 1 : -1;
|
|
|
|
gint x, y;
|
|
|
|
gint s0, sn;
|
|
|
|
|
|
|
|
/* Choose the first and last stripe to paint.
|
|
|
|
* FIRST PRIORITY is to avoid gaps painting with a 1x1 aliasing
|
|
|
|
* brush when a horizontalish line segment follows a verticalish
|
|
|
|
* one or vice versa - no matter what the angle between the two
|
|
|
|
* lines is. This will also limit the local thinning that a 1x1
|
|
|
|
* subsampled brush may suffer in the same situation.
|
|
|
|
* SECOND PRIORITY is to avoid making free-hand drawings
|
|
|
|
* unpleasantly fat by plotting redundant points.
|
|
|
|
* These are achieved by the following rules, but it is a little
|
|
|
|
* tricky to see just why. Do not change this algorithm unless you
|
|
|
|
* are sure you know what you're doing!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Basic case: round the beginning and ending point to nearest
|
|
|
|
* stripe center.
|
|
|
|
*/
|
|
|
|
s0 = (gint) floor (st_offset + 0.5);
|
|
|
|
sn = (gint) floor (st_offset + st_factor + 0.5);
|
|
|
|
|
|
|
|
t0 = (s0 - st_offset) / st_factor;
|
|
|
|
tn = (sn - st_offset) / st_factor;
|
|
|
|
|
|
|
|
x = (gint) floor (paint_core->last_coords.x + t0 * delta_vec.x);
|
|
|
|
y = (gint) floor (paint_core->last_coords.y + t0 * delta_vec.y);
|
2007-07-04 14:30:34 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
if (t0 < 0.0 && !( x == (gint) floor (paint_core->last_coords.x) &&
|
|
|
|
y == (gint) floor (paint_core->last_coords.y) ))
|
|
|
|
{
|
|
|
|
/* Exception A: If the first stripe's brush position is
|
|
|
|
* EXTRApolated into a different pixel square than the
|
|
|
|
* ideal starting point, dont't plot it.
|
|
|
|
*/
|
|
|
|
s0 += direction;
|
|
|
|
}
|
|
|
|
else if (x == (gint) floor (paint_core->last_paint.x) &&
|
|
|
|
y == (gint) floor (paint_core->last_paint.y))
|
|
|
|
{
|
|
|
|
/* Exception B: If first stripe's brush position is within the
|
|
|
|
* same pixel square as the last plot of the previous line,
|
|
|
|
* don't plot it either.
|
|
|
|
*/
|
|
|
|
s0 += direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = (gint) floor (paint_core->last_coords.x + tn * delta_vec.x);
|
|
|
|
y = (gint) floor (paint_core->last_coords.y + tn * delta_vec.y);
|
2007-07-04 14:30:34 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
if (tn > 1.0 && !( x == (gint) floor (paint_core->cur_coords.x) &&
|
|
|
|
y == (gint) floor (paint_core->cur_coords.y)))
|
|
|
|
{
|
|
|
|
/* Exception C: If the last stripe's brush position is
|
|
|
|
* EXTRApolated into a different pixel square than the
|
|
|
|
* ideal ending point, don't plot it.
|
|
|
|
*/
|
|
|
|
sn -= direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
t0 = (s0 - st_offset) / st_factor;
|
|
|
|
tn = (sn - st_offset) / st_factor;
|
|
|
|
dt = direction * 1.0 / st_factor;
|
|
|
|
num_points = 1 + direction * (sn - s0);
|
|
|
|
|
|
|
|
if (num_points >= 1)
|
|
|
|
{
|
|
|
|
/* Hack the reported total distance such that it looks to the
|
|
|
|
* next line as if the the last pixel plotted were at an integer
|
|
|
|
* multiple of the brush spacing. This helps prevent artifacts
|
|
|
|
* for connected lines when the brush spacing is such that some
|
|
|
|
* slopes will use the stripe regime and other slopes will use
|
|
|
|
* the nominal brush spacing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tn < 1)
|
|
|
|
total = initial + tn * dist;
|
|
|
|
|
|
|
|
total = core->spacing * (gint) (total / core->spacing + 0.5);
|
|
|
|
total += (1.0 - tn) * dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < num_points; n++)
|
|
|
|
{
|
2004-06-14 20:52:33 +08:00
|
|
|
gdouble t = t0 + n * dt;
|
|
|
|
gdouble p = (gdouble) n / num_points;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-08 20:55:20 +08:00
|
|
|
paint_core->cur_coords.x = (paint_core->last_coords.x +
|
|
|
|
t * delta_vec.x);
|
|
|
|
paint_core->cur_coords.y = (paint_core->last_coords.y +
|
|
|
|
t * delta_vec.y);
|
|
|
|
paint_core->cur_coords.pressure = (paint_core->last_coords.pressure +
|
|
|
|
p * delta_pressure);
|
|
|
|
paint_core->cur_coords.xtilt = (paint_core->last_coords.xtilt +
|
|
|
|
p * delta_xtilt);
|
|
|
|
paint_core->cur_coords.ytilt = (paint_core->last_coords.ytilt +
|
|
|
|
p * delta_ytilt);
|
|
|
|
paint_core->cur_coords.wheel = (paint_core->last_coords.wheel +
|
|
|
|
p * delta_wheel);
|
|
|
|
paint_core->cur_coords.velocity = (paint_core->last_coords.velocity +
|
|
|
|
p * delta_velocity);
|
|
|
|
paint_core->cur_coords.direction = temp_direction;
|
2005-10-05 04:16:52 +08:00
|
|
|
|
2005-10-04 03:03:14 +08:00
|
|
|
if (core->jitter > 0.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2007-07-04 14:30:34 +08:00
|
|
|
gdouble jitter_dist;
|
|
|
|
gint32 jitter_angle;
|
2005-10-05 04:16:52 +08:00
|
|
|
|
2007-07-04 14:30:34 +08:00
|
|
|
jitter_dist = g_rand_double_range (core->rand, 0, core->jitter);
|
|
|
|
jitter_angle = g_rand_int_range (core->rand,
|
|
|
|
0, BRUSH_CORE_JITTER_LUTSIZE);
|
2005-10-04 03:03:14 +08:00
|
|
|
|
2006-12-18 18:47:39 +08:00
|
|
|
paint_core->cur_coords.x +=
|
2007-03-19 04:13:55 +08:00
|
|
|
(core->brush->x_axis.x + core->brush->y_axis.x) *
|
2007-07-04 14:30:34 +08:00
|
|
|
jitter_dist * core->jitter_lut_x[jitter_angle] * core->scale;
|
2007-03-19 04:13:55 +08:00
|
|
|
|
2006-12-18 18:47:39 +08:00
|
|
|
paint_core->cur_coords.y +=
|
2007-03-19 04:13:55 +08:00
|
|
|
(core->brush->y_axis.y + core->brush->x_axis.y) *
|
2007-07-04 14:30:34 +08:00
|
|
|
jitter_dist * core->jitter_lut_y[jitter_angle] * core->scale;
|
2005-10-05 04:16:52 +08:00
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2005-10-05 04:16:52 +08:00
|
|
|
paint_core->distance = initial + t * dist;
|
|
|
|
paint_core->pixel_dist = pixel_initial + t * pixel_dist;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-27 00:13:53 +08:00
|
|
|
gimp_paint_core_paint (paint_core, drawable, paint_options,
|
2004-07-19 22:37:40 +08:00
|
|
|
GIMP_PAINT_STATE_MOTION, time);
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
paint_core->cur_coords.x = paint_core->last_coords.x + delta_vec.x;
|
|
|
|
paint_core->cur_coords.y = paint_core->last_coords.y + delta_vec.y;
|
|
|
|
paint_core->cur_coords.pressure = paint_core->last_coords.pressure + delta_pressure;
|
|
|
|
paint_core->cur_coords.xtilt = paint_core->last_coords.xtilt + delta_xtilt;
|
|
|
|
paint_core->cur_coords.ytilt = paint_core->last_coords.ytilt + delta_ytilt;
|
|
|
|
paint_core->cur_coords.wheel = paint_core->last_coords.wheel + delta_wheel;
|
2008-05-10 18:03:21 +08:00
|
|
|
paint_core->cur_coords.velocity = paint_core->last_coords.velocity + delta_velocity;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
paint_core->distance = total;
|
|
|
|
paint_core->pixel_dist = pixel_initial + pixel_dist;
|
|
|
|
|
|
|
|
paint_core->last_coords = paint_core->cur_coords;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TempBuf *
|
2004-05-26 17:32:03 +08:00
|
|
|
gimp_brush_core_get_paint_area (GimpPaintCore *paint_core,
|
2004-05-28 17:34:13 +08:00
|
|
|
GimpDrawable *drawable,
|
2004-05-26 17:32:03 +08:00
|
|
|
GimpPaintOptions *paint_options)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
|
|
|
|
gint x, y;
|
|
|
|
gint x1, y1, x2, y2;
|
2004-05-28 17:34:13 +08:00
|
|
|
gint drawable_width, drawable_height;
|
|
|
|
gint brush_width, brush_height;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-06 05:47:57 +08:00
|
|
|
if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_transforming_brush)
|
|
|
|
{
|
2009-04-26 01:53:09 +08:00
|
|
|
core->scale = gimp_paint_options_get_dynamic_size (paint_options,
|
|
|
|
&paint_core->cur_coords,
|
|
|
|
TRUE);
|
2009-02-06 05:47:57 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
core->angle = gimp_paint_options_get_dynamic_angle (paint_options,
|
|
|
|
&paint_core->cur_coords);
|
|
|
|
|
|
|
|
core->aspect_ratio =
|
|
|
|
gimp_paint_options_get_dynamic_aspect_ratio (paint_options,
|
|
|
|
&paint_core->cur_coords);
|
2009-02-06 05:47:57 +08:00
|
|
|
}
|
2008-07-18 03:00:13 +08:00
|
|
|
|
2008-09-09 03:06:32 +08:00
|
|
|
core->scale = gimp_brush_core_clamp_brush_scale (core, core->scale);
|
2004-05-26 17:32:03 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
gimp_brush_transform_size (core->brush, core->scale, core->aspect_ratio, core->angle, &brush_width, &brush_height);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* adjust the x and y coordinates to the upper left corner of the brush */
|
2007-03-14 08:18:01 +08:00
|
|
|
x = (gint) floor (paint_core->cur_coords.x) - (brush_width / 2);
|
|
|
|
y = (gint) floor (paint_core->cur_coords.y) - (brush_height / 2);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
drawable_width = gimp_item_get_width (GIMP_ITEM (drawable));
|
|
|
|
drawable_height = gimp_item_get_height (GIMP_ITEM (drawable));
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
x1 = CLAMP (x - 1, 0, drawable_width);
|
|
|
|
y1 = CLAMP (y - 1, 0, drawable_height);
|
|
|
|
x2 = CLAMP (x + brush_width + 1, 0, drawable_width);
|
|
|
|
y2 = CLAMP (y + brush_height + 1, 0, drawable_height);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* configure the canvas buffer */
|
|
|
|
if ((x2 - x1) && (y2 - y1))
|
2006-12-10 07:46:16 +08:00
|
|
|
{
|
|
|
|
gint bytes;
|
|
|
|
|
|
|
|
bytes = gimp_drawable_bytes_with_alpha (drawable);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2006-12-10 07:46:16 +08:00
|
|
|
paint_core->canvas_buf = temp_buf_resize (paint_core->canvas_buf, bytes,
|
|
|
|
x1, y1,
|
|
|
|
(x2 - x1), (y2 - y1));
|
|
|
|
|
|
|
|
return paint_core->canvas_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_core_real_set_brush (GimpBrushCore *core,
|
|
|
|
GimpBrush *brush)
|
|
|
|
{
|
|
|
|
if (core->main_brush)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (core->main_brush,
|
|
|
|
gimp_brush_core_invalidate_cache,
|
|
|
|
core);
|
|
|
|
g_object_unref (core->main_brush);
|
|
|
|
core->main_brush = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (core->brush_bound_segs)
|
|
|
|
{
|
|
|
|
g_free (core->brush_bound_segs);
|
|
|
|
core->brush_bound_segs = NULL;
|
|
|
|
core->n_brush_bound_segs = 0;
|
|
|
|
core->brush_bound_width = 0;
|
|
|
|
core->brush_bound_height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
core->main_brush = brush;
|
|
|
|
|
|
|
|
if (core->main_brush)
|
|
|
|
{
|
|
|
|
g_object_ref (core->main_brush);
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (core->main_brush, "invalidate-preview",
|
2004-06-23 20:19:28 +08:00
|
|
|
G_CALLBACK (gimp_brush_core_invalidate_cache),
|
|
|
|
core);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_brush_core_set_brush (GimpBrushCore *core,
|
|
|
|
GimpBrush *brush)
|
|
|
|
{
|
2006-08-30 04:19:28 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_CORE (core));
|
|
|
|
g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
g_signal_emit (core, core_signals[SET_BRUSH], 0, brush);
|
|
|
|
}
|
|
|
|
|
2006-11-16 23:11:27 +08:00
|
|
|
void
|
|
|
|
gimp_brush_core_create_bound_segs (GimpBrushCore *core,
|
|
|
|
GimpPaintOptions *paint_options)
|
|
|
|
{
|
|
|
|
TempBuf *mask = NULL;
|
2007-12-26 19:45:50 +08:00
|
|
|
gdouble scale;
|
2009-02-06 05:47:57 +08:00
|
|
|
gdouble angle;
|
2009-04-26 01:53:09 +08:00
|
|
|
gdouble aspect_ratio;
|
2006-11-16 23:11:27 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_CORE (core));
|
|
|
|
g_return_if_fail (core->main_brush != NULL);
|
|
|
|
g_return_if_fail (core->brush_bound_segs == NULL);
|
|
|
|
|
2007-11-13 17:30:46 +08:00
|
|
|
scale = paint_options->brush_scale;
|
2009-02-06 05:47:57 +08:00
|
|
|
angle = paint_options->brush_angle;
|
2009-04-26 01:53:09 +08:00
|
|
|
aspect_ratio = paint_options->brush_aspect_ratio;
|
2006-11-16 23:11:27 +08:00
|
|
|
|
|
|
|
if (scale > 0.0)
|
2008-09-09 03:06:32 +08:00
|
|
|
{
|
|
|
|
scale = gimp_brush_core_clamp_brush_scale (core, scale);
|
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
mask = gimp_brush_transform_mask (core->main_brush, scale, aspect_ratio, angle);
|
2008-09-09 03:06:32 +08:00
|
|
|
}
|
2006-11-16 23:11:27 +08:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
PixelRegion PR = { 0, };
|
|
|
|
BoundSeg *boundary;
|
|
|
|
gint num_groups;
|
|
|
|
|
|
|
|
pixel_region_init_temp_buf (&PR, mask,
|
2006-11-23 04:22:32 +08:00
|
|
|
0, 0, mask->width, mask->height);
|
2006-11-16 23:11:27 +08:00
|
|
|
|
2008-02-04 23:37:33 +08:00
|
|
|
/* Large, complex brush outlines are a performance problem.
|
|
|
|
* Smooth the mask in order to obtain a simpler boundary.
|
|
|
|
*/
|
|
|
|
if (mask->width > 32 && mask->height > 32)
|
|
|
|
smooth_region (&PR);
|
|
|
|
|
|
|
|
|
2006-11-16 23:11:27 +08:00
|
|
|
boundary = boundary_find (&PR, BOUNDARY_WITHIN_BOUNDS,
|
|
|
|
0, 0, PR.w, PR.h,
|
|
|
|
0,
|
|
|
|
&core->n_brush_bound_segs);
|
|
|
|
|
|
|
|
core->brush_bound_segs = boundary_sort (boundary,
|
|
|
|
core->n_brush_bound_segs,
|
|
|
|
&num_groups);
|
|
|
|
|
|
|
|
core->n_brush_bound_segs += num_groups;
|
|
|
|
|
|
|
|
g_free (boundary);
|
|
|
|
|
|
|
|
core->brush_bound_width = mask->width;
|
|
|
|
core->brush_bound_height = mask->height;
|
|
|
|
|
|
|
|
temp_buf_free (mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
void
|
|
|
|
gimp_brush_core_paste_canvas (GimpBrushCore *core,
|
2006-08-30 04:19:28 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
gdouble brush_opacity,
|
|
|
|
gdouble image_opacity,
|
2004-05-28 17:34:13 +08:00
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
GimpBrushApplicationMode brush_hardness,
|
2008-05-23 00:38:57 +08:00
|
|
|
gdouble dynamic_hardness,
|
2004-05-28 17:34:13 +08:00
|
|
|
GimpPaintApplicationMode mode)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
|
2008-05-23 00:38:57 +08:00
|
|
|
brush_hardness,
|
|
|
|
dynamic_hardness);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if (brush_mask)
|
2004-05-26 19:37:23 +08:00
|
|
|
{
|
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
|
|
|
PixelRegion brush_maskPR;
|
|
|
|
gint x;
|
|
|
|
gint y;
|
2005-09-04 01:16:58 +08:00
|
|
|
gint off_x;
|
|
|
|
gint off_y;
|
2004-05-26 19:37:23 +08:00
|
|
|
|
|
|
|
x = (gint) floor (paint_core->cur_coords.x) - (brush_mask->width >> 1);
|
|
|
|
y = (gint) floor (paint_core->cur_coords.y) - (brush_mask->height >> 1);
|
|
|
|
|
2005-09-04 01:16:58 +08:00
|
|
|
off_x = (x < 0) ? -x : 0;
|
|
|
|
off_y = (y < 0) ? -y : 0;
|
2004-05-26 19:37:23 +08:00
|
|
|
|
2005-09-04 01:16:58 +08:00
|
|
|
pixel_region_init_temp_buf (&brush_maskPR, brush_mask,
|
|
|
|
off_x, off_y,
|
|
|
|
paint_core->canvas_buf->width,
|
|
|
|
paint_core->canvas_buf->height);
|
2004-05-26 19:37:23 +08:00
|
|
|
|
|
|
|
gimp_paint_core_paste (paint_core, &brush_maskPR, drawable,
|
|
|
|
brush_opacity,
|
|
|
|
image_opacity, paint_mode,
|
|
|
|
mode);
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
/* Similar to gimp_brush_core_paste_canvas, but replaces the alpha channel
|
2004-05-26 04:41:09 +08:00
|
|
|
* rather than using it to composite (i.e. transparent over opaque
|
|
|
|
* becomes transparent rather than opauqe.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_brush_core_replace_canvas (GimpBrushCore *core,
|
2006-08-30 04:19:28 +08:00
|
|
|
GimpDrawable *drawable,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble brush_opacity,
|
|
|
|
gdouble image_opacity,
|
|
|
|
GimpBrushApplicationMode brush_hardness,
|
2008-05-23 00:38:57 +08:00
|
|
|
gdouble dynamic_hardness,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpPaintApplicationMode mode)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
|
2008-05-23 00:38:57 +08:00
|
|
|
brush_hardness,
|
|
|
|
dynamic_hardness);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if (brush_mask)
|
2004-05-26 19:37:23 +08:00
|
|
|
{
|
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
|
|
|
PixelRegion brush_maskPR;
|
|
|
|
gint x;
|
|
|
|
gint y;
|
2004-05-28 17:34:13 +08:00
|
|
|
gint off_x;
|
|
|
|
gint off_y;
|
2004-05-26 19:37:23 +08:00
|
|
|
|
|
|
|
x = (gint) floor (paint_core->cur_coords.x) - (brush_mask->width >> 1);
|
|
|
|
y = (gint) floor (paint_core->cur_coords.y) - (brush_mask->height >> 1);
|
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
off_x = (x < 0) ? -x : 0;
|
|
|
|
off_y = (y < 0) ? -y : 0;
|
2004-05-26 19:37:23 +08:00
|
|
|
|
2005-09-04 01:16:58 +08:00
|
|
|
pixel_region_init_temp_buf (&brush_maskPR, brush_mask,
|
|
|
|
off_x, off_y,
|
|
|
|
paint_core->canvas_buf->width,
|
|
|
|
paint_core->canvas_buf->height);
|
2004-05-26 19:37:23 +08:00
|
|
|
|
|
|
|
gimp_paint_core_replace (paint_core, &brush_maskPR, drawable,
|
|
|
|
brush_opacity,
|
|
|
|
image_opacity,
|
|
|
|
mode);
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_core_invalidate_cache (GimpBrush *brush,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpBrushCore *core)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
/* Make sure we don't cache data for a brush that has changed */
|
|
|
|
|
|
|
|
core->cache_invalid = TRUE;
|
|
|
|
core->solid_cache_invalid = TRUE;
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
/* Set the same brush again so the "set-brush" signal is emitted */
|
|
|
|
|
|
|
|
gimp_brush_core_set_brush (core, brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2007-03-19 03:48:36 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
/************************************************************
|
|
|
|
* LOCAL FUNCTION DEFINITIONS *
|
|
|
|
************************************************************/
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rotate_pointers (gulong **p,
|
2006-04-12 20:49:29 +08:00
|
|
|
guint32 n)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
guint32 i;
|
|
|
|
gulong *tmp;
|
|
|
|
|
|
|
|
tmp = p[0];
|
2007-12-26 19:45:50 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
for (i = 0; i < n-1; i++)
|
2007-12-26 19:45:50 +08:00
|
|
|
p[i] = p[i+1];
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
p[i] = tmp;
|
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
static TempBuf *
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_subsample_mask (GimpBrushCore *core,
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *mask,
|
2006-04-12 20:49:29 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
TempBuf *dest;
|
|
|
|
gdouble left;
|
|
|
|
const guchar *m;
|
|
|
|
guchar *d;
|
|
|
|
const gint *k;
|
|
|
|
gint index1;
|
|
|
|
gint index2;
|
|
|
|
gint dest_offset_x = 0;
|
|
|
|
gint dest_offset_y = 0;
|
|
|
|
const gint *kernel;
|
|
|
|
gint i, j;
|
|
|
|
gint r, s;
|
|
|
|
gulong *accum[KERNEL_HEIGHT];
|
|
|
|
const guchar empty = TRANSPARENT_OPACITY;
|
|
|
|
gint offs;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2005-01-01 00:20:51 +08:00
|
|
|
while (x < 0)
|
|
|
|
x += mask->width;
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
left = x - floor (x);
|
|
|
|
index1 = (gint) (left * (gdouble) (KERNEL_SUBSAMPLE + 1));
|
|
|
|
|
2005-01-01 00:20:51 +08:00
|
|
|
while (y < 0)
|
|
|
|
y += mask->height;
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
left = y - floor (y);
|
|
|
|
index2 = (gint) (left * (gdouble) (KERNEL_SUBSAMPLE + 1));
|
|
|
|
|
|
|
|
|
|
|
|
if ((mask->width % 2) == 0)
|
|
|
|
{
|
|
|
|
index1 += KERNEL_SUBSAMPLE >> 1;
|
|
|
|
|
|
|
|
if (index1 > KERNEL_SUBSAMPLE)
|
|
|
|
{
|
|
|
|
index1 -= KERNEL_SUBSAMPLE + 1;
|
|
|
|
dest_offset_x = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mask->height % 2) == 0)
|
|
|
|
{
|
|
|
|
index2 += KERNEL_SUBSAMPLE >> 1;
|
|
|
|
|
|
|
|
if (index2 > KERNEL_SUBSAMPLE)
|
|
|
|
{
|
|
|
|
index2 -= KERNEL_SUBSAMPLE + 1;
|
|
|
|
dest_offset_y = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kernel = subsample[index2][index1];
|
|
|
|
|
|
|
|
if (mask == core->last_brush_mask && ! core->cache_invalid)
|
|
|
|
{
|
|
|
|
if (core->kernel_brushes[index2][index1])
|
2006-04-12 20:49:29 +08:00
|
|
|
return core->kernel_brushes[index2][index1];
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < KERNEL_SUBSAMPLE + 1; i++)
|
2004-05-28 17:34:13 +08:00
|
|
|
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
|
2004-05-26 04:41:09 +08:00
|
|
|
if (core->kernel_brushes[i][j])
|
|
|
|
{
|
2007-04-13 22:04:37 +08:00
|
|
|
temp_buf_free (core->kernel_brushes[i][j]);
|
2004-05-26 04:41:09 +08:00
|
|
|
core->kernel_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
core->last_brush_mask = mask;
|
|
|
|
core->cache_invalid = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
dest = temp_buf_new (mask->width + 2,
|
|
|
|
mask->height + 2,
|
|
|
|
1, 0, 0, &empty);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* Allocate and initialize the accum buffer */
|
|
|
|
for (i = 0; i < KERNEL_HEIGHT ; i++)
|
2004-12-28 22:20:26 +08:00
|
|
|
accum[i] = g_new0 (gulong, dest->width + 1);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
core->kernel_brushes[index2][index1] = dest;
|
|
|
|
|
2008-12-13 18:35:53 +08:00
|
|
|
m = temp_buf_get_data (mask);
|
2004-05-26 04:41:09 +08:00
|
|
|
for (i = 0; i < mask->height; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < mask->width; j++)
|
2004-05-28 17:34:13 +08:00
|
|
|
{
|
|
|
|
k = kernel;
|
|
|
|
for (r = 0; r < KERNEL_HEIGHT; r++)
|
|
|
|
{
|
|
|
|
offs = j + dest_offset_x;
|
|
|
|
s = KERNEL_WIDTH;
|
2004-12-28 22:20:26 +08:00
|
|
|
while (s--)
|
2005-01-01 00:20:51 +08:00
|
|
|
accum[r][offs++] += *m * *k++;
|
2004-05-28 17:34:13 +08:00
|
|
|
}
|
|
|
|
m++;
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* store the accum buffer into the destination mask */
|
2008-12-13 18:35:53 +08:00
|
|
|
d = temp_buf_get_data (dest) + (i + dest_offset_y) * dest->width;
|
2004-05-26 04:41:09 +08:00
|
|
|
for (j = 0; j < dest->width; j++)
|
2005-01-01 00:20:51 +08:00
|
|
|
*d++ = (accum[0][j] + 127) / KERNEL_SUM;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
rotate_pointers (accum, KERNEL_HEIGHT);
|
|
|
|
|
|
|
|
memset (accum[KERNEL_HEIGHT - 1], 0, sizeof (gulong) * dest->width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store the rest of the accum buffer into the dest mask */
|
|
|
|
while (i + dest_offset_y < dest->height)
|
|
|
|
{
|
2008-12-13 18:35:53 +08:00
|
|
|
d = temp_buf_get_data (dest) + (i + dest_offset_y) * dest->width;
|
2004-05-26 04:41:09 +08:00
|
|
|
for (j = 0; j < dest->width; j++)
|
2005-01-01 00:20:51 +08:00
|
|
|
*d++ = (accum[0][j] + (KERNEL_SUM / 2)) / KERNEL_SUM;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
rotate_pointers (accum, KERNEL_HEIGHT);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < KERNEL_HEIGHT ; i++)
|
|
|
|
g_free (accum[i]);
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* #define FANCY_PRESSURE */
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
static TempBuf *
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_pressurize_mask (GimpBrushCore *core,
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *brush_mask,
|
2004-05-28 17:34:13 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble pressure)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2004-05-28 17:34:13 +08:00
|
|
|
static guchar mapi[256];
|
2007-12-26 19:45:50 +08:00
|
|
|
const guchar *source;
|
2004-05-28 17:34:13 +08:00
|
|
|
guchar *dest;
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *subsample_mask;
|
2007-12-26 19:45:50 +08:00
|
|
|
const guchar empty = TRANSPARENT_OPACITY;
|
2004-05-28 17:34:13 +08:00
|
|
|
gint i;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* Get the raw subsampled mask */
|
|
|
|
subsample_mask = gimp_brush_core_subsample_mask (core,
|
|
|
|
brush_mask,
|
|
|
|
x, y);
|
|
|
|
|
|
|
|
/* Special case pressure = 0.5 */
|
2004-05-28 17:34:13 +08:00
|
|
|
if ((gint) (pressure * 100 + 0.5) == 50)
|
2004-05-26 04:41:09 +08:00
|
|
|
return subsample_mask;
|
|
|
|
|
|
|
|
if (core->pressure_brush)
|
2007-04-13 22:04:37 +08:00
|
|
|
temp_buf_free (core->pressure_brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
core->pressure_brush = temp_buf_new (brush_mask->width + 2,
|
|
|
|
brush_mask->height + 2,
|
|
|
|
1, 0, 0, &empty);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
#ifdef FANCY_PRESSURE
|
2007-03-19 04:47:12 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
/* Create the pressure profile
|
2004-05-28 17:34:13 +08:00
|
|
|
*
|
|
|
|
* It is: I'(I) = tanh (20 * (pressure - 0.5) * I) : pressure > 0.5
|
|
|
|
* I'(I) = 1 - tanh (20 * (0.5 - pressure) * (1 - I)) : pressure < 0.5
|
|
|
|
*
|
|
|
|
* It looks like:
|
|
|
|
*
|
|
|
|
* low pressure medium pressure high pressure
|
|
|
|
*
|
2007-03-19 04:47:12 +08:00
|
|
|
* | / --
|
|
|
|
* | / /
|
|
|
|
* / / |
|
|
|
|
* -- / |
|
2004-05-28 17:34:13 +08:00
|
|
|
*/
|
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
gdouble map[256];
|
|
|
|
gdouble ds, s, c;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
ds = (pressure - 0.5) * (20.0 / 256.0);
|
|
|
|
s = 0;
|
|
|
|
c = 1.0;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
if (ds > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
map[i] = s / c;
|
|
|
|
s += c * ds;
|
|
|
|
c += s * ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
mapi[i] = (gint) (255 * map[i] / map[255]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ds = -ds;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
for (i = 255; i >= 0; i--)
|
|
|
|
{
|
|
|
|
map[i] = s / c;
|
|
|
|
s += c * ds;
|
|
|
|
c += s * ds;
|
2007-03-19 04:47:12 +08:00
|
|
|
}
|
2004-05-28 17:34:13 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
mapi[i] = (gint) (255 * (1 - map[i] / map[0]));
|
|
|
|
}
|
2007-03-19 04:47:12 +08:00
|
|
|
}
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
#else /* ! FANCY_PRESSURE */
|
|
|
|
|
2004-06-10 10:53:19 +08:00
|
|
|
{
|
|
|
|
gdouble j, k;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-06-10 10:53:19 +08:00
|
|
|
j = pressure + pressure;
|
|
|
|
k = 0;
|
2005-01-01 00:20:51 +08:00
|
|
|
|
2004-06-10 10:53:19 +08:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
if (k > 255)
|
|
|
|
mapi[i] = 255;
|
|
|
|
else
|
|
|
|
mapi[i] = (guchar) k;
|
|
|
|
|
|
|
|
k += j;
|
|
|
|
}
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
#endif /* FANCY_PRESSURE */
|
|
|
|
|
|
|
|
/* Now convert the brush */
|
|
|
|
|
2008-12-13 18:35:53 +08:00
|
|
|
source = temp_buf_get_data (subsample_mask);
|
|
|
|
dest = temp_buf_get_data (core->pressure_brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
i = subsample_mask->width * subsample_mask->height;
|
|
|
|
while (i--)
|
2005-01-01 00:20:51 +08:00
|
|
|
*dest++ = mapi[(*source++)];
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
return core->pressure_brush;
|
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
static TempBuf *
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_solidify_mask (GimpBrushCore *core,
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *brush_mask,
|
2004-05-26 04:41:09 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
TempBuf *dest;
|
|
|
|
const guchar *m;
|
|
|
|
guchar *d;
|
|
|
|
gint dest_offset_x = 0;
|
|
|
|
gint dest_offset_y = 0;
|
|
|
|
gint i, j;
|
|
|
|
const guchar empty = TRANSPARENT_OPACITY;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if ((brush_mask->width % 2) == 0)
|
|
|
|
{
|
2005-01-01 00:20:51 +08:00
|
|
|
while (x < 0)
|
|
|
|
x += brush_mask->width;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if ((x - floor (x)) >= 0.5)
|
|
|
|
dest_offset_x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((brush_mask->height % 2) == 0)
|
|
|
|
{
|
2005-01-01 00:20:51 +08:00
|
|
|
while (y < 0)
|
|
|
|
y += brush_mask->height;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if ((y - floor (y)) >= 0.5)
|
|
|
|
dest_offset_y++;
|
|
|
|
}
|
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
if (! core->solid_cache_invalid &&
|
|
|
|
brush_mask == core->last_solid_brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
if (core->solid_brushes[dest_offset_y][dest_offset_x])
|
|
|
|
return core->solid_brushes[dest_offset_y][dest_offset_x];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < BRUSH_CORE_SOLID_SUBSAMPLE; i++)
|
2004-05-28 17:34:13 +08:00
|
|
|
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
|
2004-05-26 04:41:09 +08:00
|
|
|
if (core->solid_brushes[i][j])
|
|
|
|
{
|
2007-04-13 22:04:37 +08:00
|
|
|
temp_buf_free (core->solid_brushes[i][j]);
|
2004-05-26 04:41:09 +08:00
|
|
|
core->solid_brushes[i][j] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
core->last_solid_brush = brush_mask;
|
|
|
|
core->solid_cache_invalid = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
dest = temp_buf_new (brush_mask->width + 2,
|
|
|
|
brush_mask->height + 2,
|
|
|
|
1, 0, 0, &empty);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
core->solid_brushes[dest_offset_y][dest_offset_x] = dest;
|
|
|
|
|
2008-12-13 18:35:53 +08:00
|
|
|
m = temp_buf_get_data (brush_mask);
|
|
|
|
d = (temp_buf_get_data (dest) +
|
2004-05-26 04:41:09 +08:00
|
|
|
(dest_offset_y + 1) * dest->width +
|
|
|
|
(dest_offset_x + 1));
|
|
|
|
|
|
|
|
for (i = 0; i < brush_mask->height; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < brush_mask->width; j++)
|
2005-01-01 00:20:51 +08:00
|
|
|
*d++ = (*m++) ? OPAQUE_OPACITY : TRANSPARENT_OPACITY;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
d += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2008-09-09 03:06:32 +08:00
|
|
|
static gdouble
|
|
|
|
gimp_brush_core_clamp_brush_scale (GimpBrushCore *core,
|
|
|
|
gdouble scale)
|
|
|
|
{
|
|
|
|
TempBuf *mask = core->main_brush->mask;
|
|
|
|
|
|
|
|
/* ensure that the final brush mask remains >= 0.5 pixel along both axes */
|
|
|
|
return MAX (0.5 / (gfloat) MIN (mask->width, mask->height), scale);
|
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
static TempBuf *
|
2009-02-01 19:08:22 +08:00
|
|
|
gimp_brush_core_transform_mask (GimpBrushCore *core,
|
|
|
|
GimpBrush *brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-03-19 04:47:12 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-03-19 04:13:55 +08:00
|
|
|
if (core->scale <= 0.0)
|
2008-09-09 03:06:32 +08:00
|
|
|
return NULL; /* Should never happen now, with scale clamping. */
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
if ((core->scale == 1.0) && (core->angle == 0.0) && (core->aspect_ratio == 1.0))
|
2006-11-09 22:54:49 +08:00
|
|
|
return brush->mask;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
gimp_brush_transform_size (brush, core->scale, core->aspect_ratio, core->angle, &width, &height);
|
2008-05-18 21:55:57 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
if (! core->cache_invalid &&
|
|
|
|
core->transform_brush &&
|
|
|
|
brush->mask == core->last_transform_brush &&
|
|
|
|
width == core->last_transform_width &&
|
|
|
|
height == core->last_transform_height &&
|
|
|
|
core->scale == core->last_scale &&
|
|
|
|
core->angle == core->last_angle &&
|
|
|
|
core->aspect_ratio == core->last_aspect_ratio)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2009-02-01 19:08:22 +08:00
|
|
|
return core->transform_brush;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->last_transform_brush = brush->mask;
|
|
|
|
core->last_transform_width = width;
|
|
|
|
core->last_transform_height = height;
|
2008-05-18 21:10:23 +08:00
|
|
|
core->last_scale = core->scale;
|
2009-02-06 05:47:57 +08:00
|
|
|
core->last_angle = core->angle;
|
2009-04-26 01:53:09 +08:00
|
|
|
core->last_aspect_ratio = core->aspect_ratio;
|
2009-02-06 05:47:57 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
if (core->transform_brush)
|
|
|
|
temp_buf_free (core->transform_brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
core->transform_brush = gimp_brush_transform_mask (brush, core->scale, core->aspect_ratio, core->angle);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
core->cache_invalid = TRUE;
|
|
|
|
core->solid_cache_invalid = TRUE;
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
return core->transform_brush;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2007-04-13 22:04:37 +08:00
|
|
|
static TempBuf *
|
2009-02-01 19:08:22 +08:00
|
|
|
gimp_brush_core_transform_pixmap (GimpBrushCore *core,
|
2007-03-19 04:13:55 +08:00
|
|
|
GimpBrush *brush)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-03-19 04:47:12 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2007-03-19 04:13:55 +08:00
|
|
|
if (core->scale <= 0.0)
|
2004-05-26 04:41:09 +08:00
|
|
|
return NULL;
|
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
if ((core->scale == 1.0) && (core->angle == 0.0) && (core->aspect_ratio == 1.0))
|
2006-11-09 22:54:49 +08:00
|
|
|
return brush->pixmap;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
gimp_brush_transform_size (brush, core->scale, core->aspect_ratio, core->angle, &width, &height);
|
2009-02-06 05:47:57 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
if (! core->cache_invalid &&
|
|
|
|
core->transform_pixmap &&
|
|
|
|
brush->pixmap == core->last_transform_pixmap &&
|
|
|
|
width == core->last_transform_pixmap_width &&
|
|
|
|
height == core->last_transform_pixmap_height &&
|
|
|
|
core->angle == core->last_angle &&
|
|
|
|
core->aspect_ratio == core->last_aspect_ratio)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2009-02-01 19:08:22 +08:00
|
|
|
return core->transform_pixmap;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
core->last_transform_pixmap = brush->pixmap;
|
|
|
|
core->last_transform_pixmap_width = width;
|
|
|
|
core->last_transform_pixmap_height = height;
|
2009-02-06 05:47:57 +08:00
|
|
|
core->last_angle = core->angle;
|
2009-04-26 01:53:09 +08:00
|
|
|
core->last_aspect_ratio = core->aspect_ratio;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
if (core->transform_pixmap)
|
|
|
|
temp_buf_free (core->transform_pixmap);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-06 05:47:57 +08:00
|
|
|
|
2009-04-26 01:53:09 +08:00
|
|
|
core->transform_pixmap = gimp_brush_transform_pixmap (brush, core->scale, core->aspect_ratio, core->angle);
|
2004-05-28 17:34:13 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
core->cache_invalid = TRUE;
|
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
return core->transform_pixmap;
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
|
2007-12-12 03:31:46 +08:00
|
|
|
TempBuf *
|
2004-05-26 04:41:09 +08:00
|
|
|
gimp_brush_core_get_brush_mask (GimpBrushCore *core,
|
2008-05-23 00:38:57 +08:00
|
|
|
GimpBrushApplicationMode brush_hardness,
|
|
|
|
gdouble dynamic_hardness)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
2007-04-13 22:04:37 +08:00
|
|
|
TempBuf *mask;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2009-02-01 19:08:22 +08:00
|
|
|
mask = gimp_brush_core_transform_mask (core, core->brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
if (! mask)
|
2004-05-26 04:41:09 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (brush_hardness)
|
|
|
|
{
|
|
|
|
case GIMP_BRUSH_SOFT:
|
|
|
|
mask = gimp_brush_core_subsample_mask (core, mask,
|
2004-05-28 17:34:13 +08:00
|
|
|
paint_core->cur_coords.x,
|
2004-05-26 04:41:09 +08:00
|
|
|
paint_core->cur_coords.y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_HARD:
|
|
|
|
mask = gimp_brush_core_solidify_mask (core, mask,
|
|
|
|
paint_core->cur_coords.x,
|
|
|
|
paint_core->cur_coords.y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BRUSH_PRESSURE:
|
2008-05-10 18:03:21 +08:00
|
|
|
mask = gimp_brush_core_pressurize_mask (core, mask,
|
|
|
|
paint_core->cur_coords.x,
|
|
|
|
paint_core->cur_coords.y,
|
2008-05-23 00:38:57 +08:00
|
|
|
dynamic_hardness);
|
2004-05-26 04:41:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* Brush pipe utility functions */
|
|
|
|
/**************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
|
2004-05-28 17:34:13 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
TempBuf *area,
|
|
|
|
GimpBrushApplicationMode mode)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
2007-03-19 03:58:57 +08:00
|
|
|
GimpImage *image;
|
2004-05-26 04:41:09 +08:00
|
|
|
PixelRegion destPR;
|
|
|
|
void *pr;
|
|
|
|
guchar *d;
|
|
|
|
gint ulx;
|
|
|
|
gint uly;
|
|
|
|
gint offsetx;
|
|
|
|
gint offsety;
|
|
|
|
gint y;
|
|
|
|
TempBuf *pixmap_mask;
|
|
|
|
TempBuf *brush_mask;
|
2006-08-16 01:21:18 +08:00
|
|
|
gdouble X = paint_core->cur_coords.x;
|
|
|
|
gdouble Y = paint_core->cur_coords.y;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH (core->brush));
|
|
|
|
g_return_if_fail (core->brush->pixmap != NULL);
|
|
|
|
|
2007-03-19 03:58:57 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
/* scale the brushes */
|
2009-02-01 19:08:22 +08:00
|
|
|
pixmap_mask = gimp_brush_core_transform_pixmap (core, core->brush);
|
2006-11-09 22:54:49 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
if (! pixmap_mask)
|
2004-05-26 04:41:09 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mode != GIMP_BRUSH_HARD)
|
2009-02-01 19:08:22 +08:00
|
|
|
brush_mask = gimp_brush_core_transform_mask (core, core->brush);
|
2004-05-26 04:41:09 +08:00
|
|
|
else
|
|
|
|
brush_mask = NULL;
|
|
|
|
|
2005-09-04 01:16:58 +08:00
|
|
|
pixel_region_init_temp_buf (&destPR, area,
|
|
|
|
0, 0, area->width, area->height);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
pr = pixel_regions_register (1, &destPR);
|
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
/* Calculate upper left corner of brush as in
|
|
|
|
* gimp_paint_core_get_paint_area. Ugly to have to do this here, too.
|
2004-05-26 04:41:09 +08:00
|
|
|
*/
|
2006-08-16 01:21:18 +08:00
|
|
|
ulx = (gint) floor (X) - (pixmap_mask->width >> 1);
|
|
|
|
uly = (gint) floor (Y) - (pixmap_mask->height >> 1);
|
|
|
|
|
|
|
|
/* Not sure why this is necessary, but empirically the code does
|
|
|
|
* not work without it for even-sided brushes. See bug #166622.
|
|
|
|
*/
|
|
|
|
if (pixmap_mask->width %2 == 0)
|
|
|
|
ulx += ROUND (X) - floor (X);
|
|
|
|
if (pixmap_mask->height %2 == 0)
|
|
|
|
uly += ROUND (Y) - floor (Y);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
offsetx = area->x - ulx;
|
|
|
|
offsety = area->y - uly;
|
|
|
|
|
|
|
|
for (; pr != NULL; pr = pixel_regions_process (pr))
|
|
|
|
{
|
|
|
|
d = destPR.data;
|
2004-05-28 17:34:13 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
for (y = 0; y < destPR.h; y++)
|
2004-05-28 17:34:13 +08:00
|
|
|
{
|
2007-03-19 03:58:57 +08:00
|
|
|
paint_line_pixmap_mask (image, drawable, pixmap_mask, brush_mask,
|
2004-05-28 17:34:13 +08:00
|
|
|
d, offsetx, y + offsety,
|
|
|
|
destPR.bytes, destPR.w, mode);
|
|
|
|
d += destPR.rowstride;
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint_line_pixmap_mask (GimpImage *dest,
|
2004-05-28 17:34:13 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
TempBuf *pixmap_mask,
|
|
|
|
TempBuf *brush_mask,
|
|
|
|
guchar *d,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint bytes,
|
|
|
|
gint width,
|
|
|
|
GimpBrushApplicationMode mode)
|
2004-05-26 04:41:09 +08:00
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
const guchar *mask;
|
|
|
|
guchar *b;
|
|
|
|
guchar *p;
|
|
|
|
gdouble alpha;
|
|
|
|
const gdouble factor = 0.00392156986; /* 1.0 / 255.0 */
|
|
|
|
gint x_index;
|
|
|
|
gint i;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
/* Make sure x, y are positive */
|
|
|
|
while (x < 0)
|
|
|
|
x += pixmap_mask->width;
|
|
|
|
while (y < 0)
|
|
|
|
y += pixmap_mask->height;
|
|
|
|
|
|
|
|
/* Point to the approriate scanline */
|
2008-12-13 18:35:53 +08:00
|
|
|
b = (temp_buf_get_data (pixmap_mask) +
|
2004-05-28 17:34:13 +08:00
|
|
|
(y % pixmap_mask->height) * pixmap_mask->width * pixmap_mask->bytes);
|
2004-05-26 04:41:09 +08:00
|
|
|
|
|
|
|
if (mode == GIMP_BRUSH_SOFT && brush_mask)
|
|
|
|
{
|
2004-05-28 17:34:13 +08:00
|
|
|
/* ditto, except for the brush mask, so we can pre-multiply the
|
|
|
|
* alpha value
|
|
|
|
*/
|
2008-12-13 18:35:53 +08:00
|
|
|
mask = (temp_buf_get_data (brush_mask) +
|
2004-05-28 17:34:13 +08:00
|
|
|
(y % brush_mask->height) * brush_mask->width);
|
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
for (i = 0; i < width; i++)
|
2004-05-28 17:34:13 +08:00
|
|
|
{
|
2007-12-26 19:45:50 +08:00
|
|
|
gint byte_loop;
|
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
/* attempt to avoid doing this calc twice in the loop */
|
|
|
|
x_index = ((i + x) % pixmap_mask->width);
|
|
|
|
p = b + x_index * pixmap_mask->bytes;
|
|
|
|
d[bytes - 1] = mask[x_index];
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2004-05-28 17:34:13 +08:00
|
|
|
/* multiply alpha into the pixmap data
|
2004-05-26 04:41:09 +08:00
|
|
|
* maybe we could do this at tool creation or brush switch time?
|
|
|
|
* and compute it for the whole brush at once and cache it?
|
|
|
|
*/
|
2004-05-28 17:34:13 +08:00
|
|
|
alpha = d[bytes - 1] * factor;
|
|
|
|
if (alpha)
|
|
|
|
for (byte_loop = 0; byte_loop < bytes - 1; byte_loop++)
|
|
|
|
d[byte_loop] *= alpha;
|
2004-05-26 04:41:09 +08:00
|
|
|
|
2006-10-26 06:14:36 +08:00
|
|
|
gimp_image_transform_color (dest, gimp_drawable_type (drawable), d,
|
|
|
|
GIMP_RGB, p);
|
2004-05-28 17:34:13 +08:00
|
|
|
d += bytes;
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < width; i++)
|
2004-05-28 17:34:13 +08:00
|
|
|
{
|
|
|
|
/* attempt to avoid doing this calc twice in the loop */
|
|
|
|
x_index = ((i + x) % pixmap_mask->width);
|
|
|
|
p = b + x_index * pixmap_mask->bytes;
|
|
|
|
d[bytes - 1] = 255;
|
|
|
|
|
|
|
|
/* multiply alpha into the pixmap data
|
|
|
|
* maybe we could do this at tool creation or brush switch time?
|
|
|
|
* and compute it for the whole brush at once and cache it?
|
|
|
|
*/
|
2006-10-26 06:14:36 +08:00
|
|
|
gimp_image_transform_color (dest, gimp_drawable_type (drawable), d,
|
|
|
|
GIMP_RGB, p);
|
2004-05-28 17:34:13 +08:00
|
|
|
d += bytes;
|
|
|
|
}
|
2004-05-26 04:41:09 +08:00
|
|
|
}
|
|
|
|
}
|