2018-04-19 05:44:34 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-04-19 05:44:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2018-04-25 23:12:47 +08:00
|
|
|
#include "operations/layer-modes/gimp-layer-modes.h"
|
|
|
|
|
2018-12-02 15:59:24 +08:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
|
|
|
|
|
|
|
#include "gimpchannel.h"
|
2018-04-19 05:44:34 +08:00
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpdrawable-edit.h"
|
2019-03-28 03:38:06 +08:00
|
|
|
#include "gimpdrawablefilter.h"
|
2018-04-19 05:44:34 +08:00
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpfilloptions.h"
|
2018-12-02 15:59:24 +08:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimppattern.h"
|
|
|
|
#include "gimptempbuf.h"
|
2018-04-19 05:44:34 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2018-12-02 15:59:24 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static gboolean gimp_drawable_edit_can_fill_direct (GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options);
|
|
|
|
static void gimp_drawable_edit_fill_direct (GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
const gchar *undo_desc);
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_drawable_edit_can_fill_direct (GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options)
|
|
|
|
{
|
2018-12-02 16:22:41 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GimpContext *context;
|
|
|
|
gdouble opacity;
|
2018-12-03 22:52:49 +08:00
|
|
|
GimpComponentMask affect;
|
2018-12-02 16:22:41 +08:00
|
|
|
GimpLayerMode mode;
|
|
|
|
GimpLayerCompositeMode composite_mode;
|
|
|
|
GimpLayerCompositeRegion composite_region;
|
|
|
|
|
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
context = GIMP_CONTEXT (options);
|
|
|
|
opacity = gimp_context_get_opacity (context);
|
2018-12-03 22:52:49 +08:00
|
|
|
affect = gimp_drawable_get_active_mask (drawable);
|
2018-12-02 16:22:41 +08:00
|
|
|
mode = gimp_context_get_paint_mode (context);
|
|
|
|
composite_mode = gimp_layer_mode_get_paint_composite_mode (mode);
|
|
|
|
composite_region = gimp_layer_mode_get_included_region (mode, composite_mode);
|
2018-12-02 15:59:24 +08:00
|
|
|
|
|
|
|
if (gimp_channel_is_empty (gimp_image_get_mask (image)) &&
|
|
|
|
opacity == GIMP_OPACITY_OPAQUE &&
|
2018-12-03 22:52:49 +08:00
|
|
|
affect == GIMP_COMPONENT_MASK_ALL &&
|
2018-12-02 15:59:24 +08:00
|
|
|
gimp_layer_mode_is_trivial (mode) &&
|
2018-12-02 16:22:41 +08:00
|
|
|
(! gimp_layer_mode_is_subtractive (mode) ^
|
|
|
|
! (composite_region & GIMP_LAYER_COMPOSITE_REGION_SOURCE)))
|
2018-12-02 15:59:24 +08:00
|
|
|
{
|
2018-12-02 16:41:16 +08:00
|
|
|
switch (gimp_fill_options_get_style (options))
|
2018-12-02 15:59:24 +08:00
|
|
|
{
|
2022-08-07 19:47:30 +08:00
|
|
|
case GIMP_FILL_STYLE_FG_COLOR:
|
|
|
|
case GIMP_FILL_STYLE_BG_COLOR:
|
2018-12-02 16:41:16 +08:00
|
|
|
return TRUE;
|
2018-12-02 15:59:24 +08:00
|
|
|
|
2018-12-02 16:41:16 +08:00
|
|
|
case GIMP_FILL_STYLE_PATTERN:
|
|
|
|
{
|
|
|
|
GimpPattern *pattern;
|
|
|
|
GimpTempBuf *mask;
|
|
|
|
const Babl *format;
|
2018-12-02 15:59:24 +08:00
|
|
|
|
2018-12-02 16:41:16 +08:00
|
|
|
pattern = gimp_context_get_pattern (context);
|
|
|
|
mask = gimp_pattern_get_mask (pattern);
|
|
|
|
format = gimp_temp_buf_get_format (mask);
|
2018-12-02 15:59:24 +08:00
|
|
|
|
2018-12-02 16:41:16 +08:00
|
|
|
return ! babl_format_has_alpha (format);
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 15:59:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_edit_fill_direct (GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
const gchar *undo_desc)
|
|
|
|
{
|
app: remove "Edit -> Fade..."
This commit completely removes the "Edit -> Fade..." feature,
because...
- The main reason is that "fade" requires us to keep two buffers,
instead of one, for each fadeable undo step, doubling (or worse,
since the extra buffer might have higher precision than the
drawable) the space consumed by these steps. This has notable
impact when editing large images. This overhead is incurred even
when not actually using "fade", and since it seems to be very
rarely used, this is too wasteful.
- "Fade" is broken in 2.10: when comitting a filter, we copy the
cached parts of the result into the apply buffer. However, the
result cache sits after the mode node, while the apply buffer
should contain the result of the filter *before* the mode node,
which can lead to wrong results in the general case.
- The same behavior can be trivially achieved "manually", by
duplicating the layer, editing the duplicate, and changing its
opacity/mode.
- If we really want this feature, now that most filters are GEGL
ops, it makes more sense to just add opacity/mode options to the
filter tool, instead of having this be a separate step.
2018-12-28 00:16:04 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpContext *context;
|
|
|
|
GimpLayerMode mode;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
|
|
|
context = GIMP_CONTEXT (options);
|
|
|
|
mode = gimp_context_get_paint_mode (context);
|
|
|
|
width = gimp_item_get_width (GIMP_ITEM (drawable));
|
|
|
|
height = gimp_item_get_height (GIMP_ITEM (drawable));
|
2018-12-02 15:59:24 +08:00
|
|
|
|
|
|
|
gimp_drawable_push_undo (drawable, undo_desc,
|
|
|
|
NULL, 0, 0, width, height);
|
|
|
|
|
|
|
|
if (! gimp_layer_mode_is_subtractive (mode))
|
|
|
|
gimp_fill_options_fill_buffer (options, drawable, buffer, 0, 0);
|
|
|
|
else
|
|
|
|
gimp_gegl_clear (buffer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-19 05:44:34 +08:00
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_edit_clear (GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
GimpFillOptions *options;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
|
|
|
|
|
|
|
options = gimp_fill_options_new (context->gimp, NULL, FALSE);
|
|
|
|
|
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_TRANSPARENT, NULL);
|
|
|
|
else
|
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_BACKGROUND, NULL);
|
|
|
|
|
|
|
|
gimp_drawable_edit_fill (drawable, options, C_("undo-type", "Clear"));
|
|
|
|
|
|
|
|
g_object_unref (options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_edit_fill (GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
const gchar *undo_desc)
|
|
|
|
{
|
2018-12-31 18:33:01 +08:00
|
|
|
GimpContext *context;
|
2018-12-31 17:26:25 +08:00
|
|
|
gint x, y, width, height;
|
2018-04-19 05:44:34 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_FILL_OPTIONS (options));
|
|
|
|
|
2018-12-02 15:59:24 +08:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable),
|
|
|
|
&x, &y, &width, &height))
|
|
|
|
{
|
|
|
|
return; /* nothing to do, but the fill succeeded */
|
|
|
|
}
|
2018-04-19 05:44:34 +08:00
|
|
|
|
2018-12-31 18:33:01 +08:00
|
|
|
context = GIMP_CONTEXT (options);
|
|
|
|
|
2018-12-31 17:26:25 +08:00
|
|
|
if (gimp_layer_mode_is_alpha_only (gimp_context_get_paint_mode (context)))
|
|
|
|
{
|
|
|
|
if (! gimp_drawable_has_alpha (drawable) ||
|
|
|
|
! (gimp_drawable_get_active_mask (drawable) &
|
|
|
|
GIMP_COMPONENT_MASK_ALPHA))
|
|
|
|
{
|
|
|
|
return; /* nothing to do, but the fill succeeded */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-19 05:44:34 +08:00
|
|
|
if (! undo_desc)
|
|
|
|
undo_desc = gimp_fill_options_get_undo_desc (options);
|
|
|
|
|
2018-12-02 15:59:24 +08:00
|
|
|
/* check if we can fill the drawable's buffer directly */
|
|
|
|
if (gimp_drawable_edit_can_fill_direct (drawable, options))
|
|
|
|
{
|
|
|
|
gimp_drawable_edit_fill_direct (drawable, options, undo_desc);
|
2019-03-28 03:38:06 +08:00
|
|
|
|
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
2018-12-02 15:59:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 04:34:26 +08:00
|
|
|
GeglNode *operation;
|
|
|
|
GimpDrawableFilter *filter;
|
|
|
|
gdouble opacity;
|
|
|
|
GimpLayerMode mode;
|
|
|
|
GimpLayerCompositeMode composite_mode;
|
2018-12-02 15:59:24 +08:00
|
|
|
|
|
|
|
opacity = gimp_context_get_opacity (context);
|
|
|
|
mode = gimp_context_get_paint_mode (context);
|
|
|
|
composite_mode = gimp_layer_mode_get_paint_composite_mode (mode);
|
|
|
|
|
2019-03-28 03:38:06 +08:00
|
|
|
operation = gegl_node_new_child (NULL,
|
|
|
|
"operation", "gimp:fill-source",
|
|
|
|
"options", options,
|
|
|
|
"drawable", drawable,
|
|
|
|
"pattern-offset-x", -x,
|
|
|
|
"pattern-offset-y", -y,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
filter = gimp_drawable_filter_new (drawable, undo_desc, operation, NULL);
|
2018-04-19 05:44:34 +08:00
|
|
|
|
2019-03-28 03:38:06 +08:00
|
|
|
gimp_drawable_filter_set_opacity (filter, opacity);
|
|
|
|
gimp_drawable_filter_set_mode (filter,
|
|
|
|
mode,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
composite_mode);
|
|
|
|
|
|
|
|
gimp_drawable_filter_apply (filter, NULL);
|
2023-06-19 22:54:21 +08:00
|
|
|
gimp_drawable_filter_commit (filter, FALSE, NULL, FALSE);
|
2019-03-28 03:38:06 +08:00
|
|
|
|
|
|
|
g_object_unref (filter);
|
|
|
|
g_object_unref (operation);
|
|
|
|
}
|
2018-04-19 05:44:34 +08:00
|
|
|
}
|