app: add gegl:focus-blur to Filters -> Blur

gegl:focus-blur blurs the image around a focal point.  It can be
used to create fake depth-of-field effects.

Add a prop-gui constructor which uses a FOCUS controller to control
the focus geometry.
This commit is contained in:
Ell 2020-05-15 00:22:35 +03:00
parent 721f2d8c27
commit 60d4d25b93
11 changed files with 216 additions and 0 deletions

View File

@ -354,6 +354,11 @@ static const GimpStringActionEntry filters_interactive_actions[] =
"gegl:fattal02", "gegl:fattal02",
GIMP_HELP_FILTER_FATTAL_2002 }, GIMP_HELP_FILTER_FATTAL_2002 },
{ "filters-focus-blur", GIMP_ICON_GEGL,
NC_("filters-action", "_Focus Blur..."), NULL, NULL,
"gegl:focus-blur",
GIMP_HELP_FILTER_FOCUS_BLUR },
{ "filters-fractal-trace", GIMP_ICON_GEGL, { "filters-fractal-trace", GIMP_ICON_GEGL,
NC_("filters-action", "_Fractal Trace..."), NULL, NULL, NC_("filters-action", "_Fractal Trace..."), NULL, NULL,
"gegl:fractal-trace", "gegl:fractal-trace",
@ -928,6 +933,7 @@ filters_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("filters-erode", writable); SET_SENSITIVE ("filters-erode", writable);
SET_SENSITIVE ("filters-exposure", writable); SET_SENSITIVE ("filters-exposure", writable);
SET_SENSITIVE ("filters-fattal-2002", writable); SET_SENSITIVE ("filters-fattal-2002", writable);
SET_SENSITIVE ("filters-focus-blur", writable);
SET_SENSITIVE ("filters-fractal-trace", writable); SET_SENSITIVE ("filters-fractal-trace", writable);
SET_SENSITIVE ("filters-gaussian-blur", writable); SET_SENSITIVE ("filters-gaussian-blur", writable);
SET_SENSITIVE ("filters-gaussian-blur-selective", writable); SET_SENSITIVE ("filters-gaussian-blur-selective", writable);

View File

@ -33,6 +33,8 @@ libapppropgui_a_SOURCES = \
gimppropgui-diffraction-patterns.h \ gimppropgui-diffraction-patterns.h \
gimppropgui-eval.c \ gimppropgui-eval.c \
gimppropgui-eval.h \ gimppropgui-eval.h \
gimppropgui-focus-blur.c \
gimppropgui-focus-blur.h \
gimppropgui-generic.c \ gimppropgui-generic.c \
gimppropgui-generic.h \ gimppropgui-generic.h \
gimppropgui-hue-saturation.c \ gimppropgui-hue-saturation.c \

View File

@ -0,0 +1,163 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimppropgui-focus-blur.c
* Copyright (C) 2020 Ell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "propgui-types.h"
#include "core/gimpcontext.h"
#include "gimppropgui.h"
#include "gimppropgui-generic.h"
#include "gimppropgui-focus-blur.h"
#include "gimp-intl.h"
static void
focus_callback (GObject *config,
GeglRectangle *area,
GimpLimitType type,
gdouble x,
gdouble y,
gdouble radius,
gdouble aspect_ratio,
gdouble angle,
gdouble inner_limit,
gdouble midpoint)
{
g_object_set_data_full (G_OBJECT (config), "area",
g_memdup (area, sizeof (GeglRectangle)),
(GDestroyNotify) g_free);
g_object_set (config,
"shape", type,
"x", x / area->width,
"y", y / area->height,
"radius", 2.0 * radius / area->width,
"focus", inner_limit,
"midpoint", midpoint,
"aspect-ratio", aspect_ratio,
"rotation", fmod (
fmod (angle * 180.0 / G_PI + 180.0, 360.0) +
360.0,
360.0) - 180.0,
NULL);
}
static void
config_notify (GObject *config,
const GParamSpec *pspec,
gpointer set_data)
{
GimpControllerFocusCallback set_func;
GeglRectangle *area;
GimpLimitType shape;
gdouble radius;
gdouble focus;
gdouble midpoint;
gdouble x, y;
gdouble aspect_ratio;
gdouble rotation;
set_func = g_object_get_data (G_OBJECT (config), "set-func");
area = g_object_get_data (G_OBJECT (config), "area");
g_object_get (config,
"shape", &shape,
"radius", &radius,
"focus", &focus,
"midpoint", &midpoint,
"x", &x,
"y", &y,
"aspect-ratio", &aspect_ratio,
"rotation", &rotation,
NULL);
set_func (set_data, area,
shape,
x * area->width,
y * area->height,
radius * area->width / 2.0,
aspect_ratio,
rotation / 180.0 * G_PI,
focus,
midpoint);
}
GtkWidget *
_gimp_prop_gui_new_focus_blur (GObject *config,
GParamSpec **param_specs,
guint n_param_specs,
GeglRectangle *area,
GimpContext *context,
GimpCreatePickerFunc create_picker_func,
GimpCreateControllerFunc create_controller_func,
gpointer creator)
{
GtkWidget *vbox;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (param_specs != NULL, NULL);
g_return_val_if_fail (n_param_specs > 0, NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
vbox = _gimp_prop_gui_new_generic (config,
param_specs, n_param_specs,
area, context,
create_picker_func,
create_controller_func,
creator);
if (create_controller_func)
{
GCallback set_func;
gpointer set_data;
set_func = create_controller_func (creator,
GIMP_CONTROLLER_TYPE_FOCUS,
_("Focus Blur: "),
(GCallback) focus_callback,
config,
&set_data);
g_object_set_data (G_OBJECT (config), "set-func", set_func);
g_object_set_data_full (G_OBJECT (config), "area",
g_memdup (area, sizeof (GeglRectangle)),
(GDestroyNotify) g_free);
config_notify (config, NULL, set_data);
g_signal_connect (config, "notify",
G_CALLBACK (config_notify),
set_data);
}
return vbox;
}

View File

@ -0,0 +1,36 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimppropgui-focus-blur.h
* Copyright (C) 2020 Ell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_PROP_GUI_FOCUS_BLUR_H__
#define __GIMP_PROP_GUI_FOCUS_BLUR_H__
GtkWidget *
_gimp_prop_gui_new_focus_blur (GObject *config,
GParamSpec **param_specs,
guint n_param_specs,
GeglRectangle *area,
GimpContext *context,
GimpCreatePickerFunc create_picker_func,
GimpCreateControllerFunc create_controller_func,
gpointer creator);
#endif /* __GIMP_PROP_GUI_FOCUS_BLUR_H__ */

View File

@ -52,6 +52,7 @@
#include "gimppropgui-convolution-matrix.h" #include "gimppropgui-convolution-matrix.h"
#include "gimppropgui-diffraction-patterns.h" #include "gimppropgui-diffraction-patterns.h"
#include "gimppropgui-eval.h" #include "gimppropgui-eval.h"
#include "gimppropgui-focus-blur.h"
#include "gimppropgui-generic.h" #include "gimppropgui-generic.h"
#include "gimppropgui-hue-saturation.h" #include "gimppropgui-hue-saturation.h"
#include "gimppropgui-motion-blur-circular.h" #include "gimppropgui-motion-blur-circular.h"
@ -470,6 +471,8 @@ gui_new_funcs[] =
_gimp_prop_gui_new_channel_mixer }, _gimp_prop_gui_new_channel_mixer },
{ "GimpGegl-gegl-diffraction-patterns-config", { "GimpGegl-gegl-diffraction-patterns-config",
_gimp_prop_gui_new_diffraction_patterns }, _gimp_prop_gui_new_diffraction_patterns },
{ "GimpGegl-gegl-focus-blur-config",
_gimp_prop_gui_new_focus_blur },
{ "GimpGegl-gegl-motion-blur-circular-config", { "GimpGegl-gegl-motion-blur-circular-config",
_gimp_prop_gui_new_motion_blur_circular }, _gimp_prop_gui_new_motion_blur_circular },
{ "GimpGegl-gegl-motion-blur-linear-config", { "GimpGegl-gegl-motion-blur-linear-config",

View File

@ -6,6 +6,7 @@ libapppropgui_sources = [
'gimppropgui-convolution-matrix.c', 'gimppropgui-convolution-matrix.c',
'gimppropgui-diffraction-patterns.c', 'gimppropgui-diffraction-patterns.c',
'gimppropgui-eval.c', 'gimppropgui-eval.c',
'gimppropgui-focus-blur.c',
'gimppropgui-generic.c', 'gimppropgui-generic.c',
'gimppropgui-hue-saturation.c', 'gimppropgui-hue-saturation.c',
'gimppropgui-motion-blur-circular.c', 'gimppropgui-motion-blur-circular.c',

View File

@ -640,6 +640,7 @@ sanity_check_gegl_ops (void)
"gegl:engrave", "gegl:engrave",
"gegl:exposure", "gegl:exposure",
"gegl:fattal02", "gegl:fattal02",
"gegl:focus-blur",
"gegl:fractal-trace", "gegl:fractal-trace",
"gegl:gaussian-blur", "gegl:gaussian-blur",
"gegl:gaussian-blur-selective", "gegl:gaussian-blur-selective",

View File

@ -180,6 +180,7 @@ gimp_gegl_tool_operation_blacklisted (const gchar *name,
"gegl:engrave", "gegl:engrave",
"gegl:exposure", "gegl:exposure",
"gegl:fattal02", "gegl:fattal02",
"gegl:focus-blur",
"gegl:fractal-trace", "gegl:fractal-trace",
"gegl:gaussian-blur", "gegl:gaussian-blur",
"gegl:gaussian-blur-selective", "gegl:gaussian-blur-selective",

View File

@ -379,6 +379,7 @@
#define GIMP_HELP_FILTER_ERODE "gimp-filter-erode" #define GIMP_HELP_FILTER_ERODE "gimp-filter-erode"
#define GIMP_HELP_FILTER_EXPOSURE "gimp-filter-exposure" #define GIMP_HELP_FILTER_EXPOSURE "gimp-filter-exposure"
#define GIMP_HELP_FILTER_FATTAL_2002 "gimp-filter-fattal-2002" #define GIMP_HELP_FILTER_FATTAL_2002 "gimp-filter-fattal-2002"
#define GIMP_HELP_FILTER_FOCUS_BLUR "gimp-filter-focus-blur"
#define GIMP_HELP_FILTER_FRACTAL_TRACE "gimp-filter-fractal-trace" #define GIMP_HELP_FILTER_FRACTAL_TRACE "gimp-filter-fractal-trace"
#define GIMP_HELP_FILTER_GAUSSIAN_BLUR "gimp-filter-gaussian-blur" #define GIMP_HELP_FILTER_GAUSSIAN_BLUR "gimp-filter-gaussian-blur"
#define GIMP_HELP_FILTER_GAUSSIAN_BLUR_SELECTIVE "gimp-filter-gaussian-blur-selective" #define GIMP_HELP_FILTER_GAUSSIAN_BLUR_SELECTIVE "gimp-filter-gaussian-blur-selective"

View File

@ -700,6 +700,7 @@
<menuitem action="plug-in-reset-all" /> <menuitem action="plug-in-reset-all" />
<separator /> <separator />
<menu action="filters-blur-menu" name="Blur"> <menu action="filters-blur-menu" name="Blur">
<menuitem action="filters-focus-blur" />
<menuitem action="filters-gaussian-blur" /> <menuitem action="filters-gaussian-blur" />
<menuitem action="filters-mean-curvature-blur" /> <menuitem action="filters-mean-curvature-blur" />
<menuitem action="filters-median-blur" /> <menuitem action="filters-median-blur" />

View File

@ -394,6 +394,7 @@ app/propgui/gimppropgui-color-rotate.c
app/propgui/gimppropgui-color-to-alpha.c app/propgui/gimppropgui-color-to-alpha.c
app/propgui/gimppropgui-convolution-matrix.c app/propgui/gimppropgui-convolution-matrix.c
app/propgui/gimppropgui-diffraction-patterns.c app/propgui/gimppropgui-diffraction-patterns.c
app/propgui/gimppropgui-focus-blur.c
app/propgui/gimppropgui-generic.c app/propgui/gimppropgui-generic.c
app/propgui/gimppropgui-hue-saturation.c app/propgui/gimppropgui-hue-saturation.c
app/propgui/gimppropgui-motion-blur-circular.c app/propgui/gimppropgui-motion-blur-circular.c