Commit cee39b09 authored by Michael Natterer's avatar Michael Natterer 😴

Add more GimpCoords* parameters to reduce usage of global paint_core states

Add GimpCoords* to GimpPaintCore::get_paint_area(),
gimp_brush_core_paste_canvas(), gimp_brush_core_replace_canvas(),
gimp_brush_core_get_brush_mask(), gimp_brush_core_color_area_with_pixmap()
and change callers accordingly.
parent 45145464
......@@ -79,7 +79,8 @@ static void gimp_brush_core_interpolate (GimpPaintCore *core,
static TempBuf *gimp_brush_core_get_paint_area (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
GimpPaintOptions *paint_options,
const GimpCoords *coords);
static void gimp_brush_core_real_set_brush (GimpBrushCore *core,
GimpBrush *brush);
......@@ -709,29 +710,24 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
static TempBuf *
gimp_brush_core_get_paint_area (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options)
GimpPaintOptions *paint_options,
const GimpCoords *coords)
{
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
GimpCoords current_coords;
gint x, y;
gint x1, y1, x2, y2;
gint drawable_width, drawable_height;
gint brush_width, brush_height;
gimp_paint_core_get_current_coords (paint_core, &current_coords);
if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_transforming_brush)
{
core->scale = gimp_paint_options_get_dynamic_size (paint_options,
&current_coords,
core->scale = gimp_paint_options_get_dynamic_size (paint_options, coords,
TRUE);
core->angle = gimp_paint_options_get_dynamic_angle (paint_options,
&current_coords);
core->angle = gimp_paint_options_get_dynamic_angle (paint_options, coords);
core->aspect_ratio =
gimp_paint_options_get_dynamic_aspect_ratio (paint_options,
&current_coords);
gimp_paint_options_get_dynamic_aspect_ratio (paint_options, coords);
}
core->scale = gimp_brush_core_clamp_brush_scale (core, core->scale);
......@@ -741,8 +737,8 @@ gimp_brush_core_get_paint_area (GimpPaintCore *paint_core,
&brush_width, &brush_height);
/* adjust the x and y coordinates to the upper left corner of the brush */
x = (gint) floor (current_coords.x) - (brush_width / 2);
y = (gint) floor (current_coords.y) - (brush_height / 2);
x = (gint) floor (coords->x) - (brush_width / 2);
y = (gint) floor (coords->y) - (brush_height / 2);
drawable_width = gimp_item_get_width (GIMP_ITEM (drawable));
drawable_height = gimp_item_get_height (GIMP_ITEM (drawable));
......@@ -876,6 +872,7 @@ gimp_brush_core_create_bound_segs (GimpBrushCore *core,
void
gimp_brush_core_paste_canvas (GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
gdouble brush_opacity,
gdouble image_opacity,
GimpLayerModeEffects paint_mode,
......@@ -884,23 +881,21 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
GimpPaintApplicationMode mode)
{
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
coords,
brush_hardness,
dynamic_hardness);
if (brush_mask)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
GimpCoords current_coords;
PixelRegion brush_maskPR;
gint x;
gint y;
gint off_x;
gint off_y;
gimp_paint_core_get_current_coords (paint_core, &current_coords);
x = (gint) floor (current_coords.x) - (brush_mask->width >> 1);
y = (gint) floor (current_coords.y) - (brush_mask->height >> 1);
x = (gint) floor (coords->x) - (brush_mask->width >> 1);
y = (gint) floor (coords->y) - (brush_mask->height >> 1);
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
......@@ -924,6 +919,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
void
gimp_brush_core_replace_canvas (GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
gdouble brush_opacity,
gdouble image_opacity,
GimpBrushApplicationMode brush_hardness,
......@@ -931,23 +927,21 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
GimpPaintApplicationMode mode)
{
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
coords,
brush_hardness,
dynamic_hardness);
if (brush_mask)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
GimpCoords current_coords;
PixelRegion brush_maskPR;
gint x;
gint y;
gint off_x;
gint off_y;
gimp_paint_core_get_current_coords (paint_core, &current_coords);
x = (gint) floor (current_coords.x) - (brush_mask->width >> 1);
y = (gint) floor (current_coords.y) - (brush_mask->height >> 1);
x = (gint) floor (coords->x) - (brush_mask->width >> 1);
y = (gint) floor (coords->y) - (brush_mask->height >> 1);
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
......@@ -1433,38 +1427,35 @@ gimp_brush_core_transform_pixmap (GimpBrushCore *core,
TempBuf *
gimp_brush_core_get_brush_mask (GimpBrushCore *core,
const GimpCoords *coords,
GimpBrushApplicationMode brush_hardness,
gdouble dynamic_hardness)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
GimpCoords current_coords;
TempBuf *mask;
TempBuf *mask;
mask = gimp_brush_core_transform_mask (core, core->brush);
if (! mask)
return NULL;
gimp_paint_core_get_current_coords (paint_core, &current_coords);
switch (brush_hardness)
{
case GIMP_BRUSH_SOFT:
mask = gimp_brush_core_subsample_mask (core, mask,
current_coords.x,
current_coords.y);
coords->x,
coords->y);
break;
case GIMP_BRUSH_HARD:
mask = gimp_brush_core_solidify_mask (core, mask,
current_coords.x,
current_coords.y);
coords->x,
coords->y);
break;
case GIMP_BRUSH_PRESSURE:
mask = gimp_brush_core_pressurize_mask (core, mask,
current_coords.x,
current_coords.y,
coords->x,
coords->y,
dynamic_hardness);
break;
......@@ -1483,22 +1474,21 @@ gimp_brush_core_get_brush_mask (GimpBrushCore *core,
void
gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
TempBuf *area,
GimpBrushApplicationMode mode)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
GimpCoords current_coords;
GimpImage *image;
PixelRegion destPR;
void *pr;
guchar *d;
gint ulx;
gint uly;
gint offsetx;
gint offsety;
gint y;
TempBuf *pixmap_mask;
TempBuf *brush_mask;
GimpImage *image;
PixelRegion destPR;
void *pr;
guchar *d;
gint ulx;
gint uly;
gint offsetx;
gint offsety;
gint y;
TempBuf *pixmap_mask;
TempBuf *brush_mask;
g_return_if_fail (GIMP_IS_BRUSH (core->brush));
g_return_if_fail (core->brush->pixmap != NULL);
......@@ -1511,8 +1501,6 @@ gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
if (! pixmap_mask)
return;
gimp_paint_core_get_current_coords (paint_core, &current_coords);
if (mode != GIMP_BRUSH_HARD)
brush_mask = gimp_brush_core_transform_mask (core, core->brush);
else
......@@ -1526,16 +1514,16 @@ gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
/* Calculate upper left corner of brush as in
* gimp_paint_core_get_paint_area. Ugly to have to do this here, too.
*/
ulx = (gint) floor (current_coords.x) - (pixmap_mask->width >> 1);
uly = (gint) floor (current_coords.y) - (pixmap_mask->height >> 1);
ulx = (gint) floor (coords->x) - (pixmap_mask->width >> 1);
uly = (gint) floor (coords->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 (current_coords.x) - floor (current_coords.x);
ulx += ROUND (coords->x) - floor (coords->x);
if (pixmap_mask->height %2 == 0)
uly += ROUND (current_coords.y) - floor (current_coords.y);
uly += ROUND (coords->y) - floor (coords->y);
offsetx = area->x - ulx;
offsety = area->y - uly;
......
......@@ -111,6 +111,7 @@ void gimp_brush_core_create_bound_segs (GimpBrushCore *core,
void gimp_brush_core_paste_canvas (GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
gdouble brush_opacity,
gdouble image_opacity,
GimpLayerModeEffects paint_mode,
......@@ -119,6 +120,7 @@ void gimp_brush_core_paste_canvas (GimpBrushCore *core,
GimpPaintApplicationMode mode);
void gimp_brush_core_replace_canvas (GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
gdouble brush_opacity,
gdouble image_opacity,
GimpBrushApplicationMode brush_hardness,
......@@ -128,10 +130,12 @@ void gimp_brush_core_replace_canvas (GimpBrushCore *core,
void gimp_brush_core_color_area_with_pixmap
(GimpBrushCore *core,
GimpDrawable *drawable,
const GimpCoords *coords,
TempBuf *area,
GimpBrushApplicationMode mode);
TempBuf * gimp_brush_core_get_brush_mask (GimpBrushCore *core,
const GimpCoords *coords,
GimpBrushApplicationMode brush_hardness,
gdouble dynamic_hardness);
......
......@@ -243,6 +243,7 @@ gimp_clone_motion (GimpSourceCore *source_core,
hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords);
gimp_brush_core_paste_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_context_get_paint_mode (context),
......
......@@ -121,7 +121,7 @@ static void
gimp_convolve_motion (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
const GimpCoords *coords)
const GimpCoords *coords)
{
GimpConvolve *convolve = GIMP_CONVOLVE (paint_core);
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core);
......@@ -147,7 +147,8 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
if (opacity == 0.0)
return;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return;
......@@ -209,6 +210,7 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
g_free (buffer);
gimp_brush_core_replace_canvas (brush_core, drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_paint_options_get_brush_mode (paint_options),
......
......@@ -185,7 +185,8 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
if (opacity == 0.0)
return;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return;
......@@ -245,6 +246,7 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
/* Replace the newly dodgedburned area (canvas_buf) to the image */
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_paint_options_get_brush_mode (paint_options),
......
......@@ -120,7 +120,8 @@ gimp_eraser_motion (GimpPaintCore *paint_core,
if (opacity == 0.0)
return;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return;
......@@ -139,6 +140,7 @@ gimp_eraser_motion (GimpPaintCore *paint_core,
hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords);
gimp_brush_core_paste_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
(options->anti_erase ?
......
......@@ -442,6 +442,7 @@ gimp_heal_motion (GimpSourceCore *source_core,
hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords);
mask_buf = gimp_brush_core_get_brush_mask (GIMP_BRUSH_CORE (source_core),
coords,
GIMP_BRUSH_HARD,
hardness);
......@@ -549,8 +550,8 @@ gimp_heal_motion (GimpSourceCore *source_core,
opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords);
/* replace the canvas with our healed data */
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core),
drawable,
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_paint_options_get_brush_mode (paint_options),
......
......@@ -57,7 +57,8 @@ static void gimp_ink_paint (GimpPaintCore *paint_core,
guint32 time);
static TempBuf * gimp_ink_get_paint_area (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
GimpPaintOptions *paint_options,
const GimpCoords *coords);
static GimpUndo* gimp_ink_push_undo (GimpPaintCore *core,
GimpImage *image,
const gchar *undo_desc);
......@@ -192,7 +193,8 @@ gimp_ink_paint (GimpPaintCore *paint_core,
static TempBuf *
gimp_ink_get_paint_area (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options)
GimpPaintOptions *paint_options,
const GimpCoords *coords)
{
GimpInk *ink = GIMP_INK (paint_core);
gint x, y;
......@@ -292,7 +294,8 @@ gimp_ink_motion (GimpPaintCore *paint_core,
/* Get the buffer */
ink->cur_blob = blob_to_render;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
ink->cur_blob = NULL;
if (! area)
......
......@@ -124,7 +124,8 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
if (opacity == 0.0)
return;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return;
......@@ -156,6 +157,7 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
else if (brush_core->brush && brush_core->brush->pixmap)
{
gimp_brush_core_color_area_with_pixmap (brush_core, drawable,
coords,
area,
gimp_paint_options_get_brush_mode (paint_options));
......@@ -180,6 +182,7 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
/* finally, let the brush core paste the colored area on the canvas */
gimp_brush_core_paste_canvas (brush_core, drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_context_get_paint_mode (context),
......
......@@ -96,7 +96,8 @@ static void gimp_paint_core_real_interpolate (GimpPaintCore *core,
guint32 time);
static TempBuf * gimp_paint_core_real_get_paint_area (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *options);
GimpPaintOptions *options,
const GimpCoords *coords);
static GimpUndo* gimp_paint_core_real_push_undo (GimpPaintCore *core,
GimpImage *image,
const gchar *undo_desc);
......@@ -274,7 +275,8 @@ gimp_paint_core_real_interpolate (GimpPaintCore *core,
static TempBuf *
gimp_paint_core_real_get_paint_area (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options)
GimpPaintOptions *paint_options,
const GimpCoords *coords)
{
return NULL;
}
......@@ -659,15 +661,18 @@ gimp_paint_core_round_line (GimpPaintCore *core,
TempBuf *
gimp_paint_core_get_paint_area (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options)
GimpPaintOptions *paint_options,
const GimpCoords *coords)
{
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), NULL);
g_return_val_if_fail (coords != NULL, NULL);
return GIMP_PAINT_CORE_GET_CLASS (core)->get_paint_area (core, drawable,
paint_options);
paint_options,
coords);
}
TempBuf *
......
......@@ -100,7 +100,8 @@ struct _GimpPaintCoreClass
TempBuf * (* get_paint_area) (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
GimpPaintOptions *paint_options,
const GimpCoords *coords);
GimpUndo * (* push_undo) (GimpPaintCore *core,
GimpImage *image,
......@@ -152,7 +153,8 @@ void gimp_paint_core_round_line (GimpPaintCore *core,
TempBuf * gimp_paint_core_get_paint_area (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *options);
GimpPaintOptions *options,
const GimpCoords *coords);
TempBuf * gimp_paint_core_get_orig_image (GimpPaintCore *core,
GimpDrawable *drawable,
gint x1,
......
......@@ -171,7 +171,8 @@ gimp_smudge_start (GimpPaintCore *paint_core,
if (gimp_drawable_is_indexed (drawable))
return FALSE;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return FALSE;
......@@ -257,7 +258,8 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
return;
/* Get the paint area */
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options,
coords);
if (! area)
return;
......@@ -314,6 +316,7 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords);
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,
MIN (opacity, GIMP_OPACITY_OPAQUE),
gimp_context_get_opacity (context),
gimp_paint_options_get_brush_mode (paint_options),
......
......@@ -387,7 +387,7 @@ gimp_source_core_motion (GimpSourceCore *source_core,
}
paint_area = gimp_paint_core_get_paint_area (paint_core, drawable,
paint_options);
paint_options, coords);
if (! paint_area)
return;
......
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