gimp/plug-ins/lighting/lighting-main.c

841 lines
41 KiB
C
Raw Normal View History

/* Lighting Effects 0.2.2 -- image filter plug-in for GIMP
*
* Copyright (C) 1996-98 Tom Bech
* Copyright (C) 1996-98 Federico Mena Quintero
*
* E-mail: tomb@gimp.org (Tom) or quartic@gimp.org (Federico)
*
* 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 <gtk/gtk.h>
#include <libgimp/gimp.h>
#include "lighting-apply.h"
#include "lighting-image.h"
#include "lighting-main.h"
#include "lighting-preview.h"
#include "lighting-shade.h"
#include "lighting-ui.h"
1998-06-11 06:04:59 +00:00
#include "libgimp/stdplugins-intl.h"
1998-06-11 06:04:59 +00:00
1998-06-11 06:04:59 +00:00
LightingValues mapvals;
2019-09-03 19:58:18 +02:00
typedef struct _Lighting Lighting;
typedef struct _LightingClass LightingClass;
struct _Lighting
{
GimpPlugIn parent_instance;
};
struct _LightingClass
{
GimpPlugInClass parent_class;
};
#define LIGHTING_TYPE (lighting_get_type ())
#define LIGHTING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIGHTING_TYPE, Lighting))
2019-09-03 19:58:18 +02:00
GType lighting_get_type (void) G_GNUC_CONST;
static GList * lighting_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * lighting_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * lighting_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GimpDrawable **drawables,
GimpProcedureConfig *config,
2019-09-03 19:58:18 +02:00
gpointer run_data);
static void set_default_settings (void);
static void check_drawables (void);
G_DEFINE_TYPE (Lighting, lighting, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (LIGHTING_TYPE)
DEFINE_STD_SET_I18N
2019-09-03 19:58:18 +02:00
static void
lighting_class_init (LightingClass *klass)
{
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
plug_in_class->query_procedures = lighting_query_procedures;
plug_in_class->create_procedure = lighting_create_procedure;
plug_in_class->set_i18n = STD_SET_I18N;
2019-09-03 19:58:18 +02:00
}
static void
lighting_init (Lighting *lighting)
{
}
static GList *
lighting_query_procedures (GimpPlugIn *plug_in)
{
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
}
static GimpProcedure *
lighting_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
if (! strcmp (name, PLUG_IN_PROC))
{
GeglColor *default_color_1;
GeglColor *default_color_2;
GeglColor *default_color_3;
GeglColor *default_color_4;
GeglColor *default_color_5;
GeglColor *default_color_6;
gegl_init (NULL, NULL);
default_color_1 = gegl_color_new ("white");
default_color_2 = gegl_color_new ("white");
default_color_3 = gegl_color_new ("white");
default_color_4 = gegl_color_new ("white");
default_color_5 = gegl_color_new ("white");
default_color_6 = gegl_color_new ("white");
2019-09-03 19:58:18 +02:00
procedure = gimp_image_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
lighting_run, NULL, NULL);
2019-09-03 19:58:18 +02:00
gimp_procedure_set_image_types (procedure, "RGB*");
gimp_procedure_set_sensitivity_mask (procedure,
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
2019-09-03 19:58:18 +02:00
gimp_procedure_set_menu_label (procedure, _("_Lighting Effects..."));
2019-09-03 19:58:18 +02:00
gimp_procedure_add_menu_path (procedure,
"<Image>/Filters/Light and Shadow/[Light]");
2019-09-03 19:58:18 +02:00
gimp_procedure_set_documentation (procedure,
_("Apply various lighting effects "
"to an image"),
2019-09-03 19:58:18 +02:00
"No help yet",
name);
gimp_procedure_set_attribution (procedure,
"Tom Bech & Federico Mena Quintero",
"Tom Bech & Federico Mena Quintero",
"Version 0.2.0, March 15 1998");
gimp_procedure_add_drawable_argument (procedure, "bump-drawable",
_("B_ump map image"),
_("Bumpmap drawable (set to NULL if disabled)"),
TRUE,
G_PARAM_READWRITE);
gimp_procedure_add_drawable_argument (procedure, "env-drawable",
_("Enviro_nment map image"),
_("Environmentmap drawable "
"(set to NULL if disabled)"),
TRUE,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "do-bumpmap",
_("Enable bump mappi_ng"),
_("Enable bumpmapping"),
TRUE,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "do-envmap",
_("Enable en_vironment mapping"),
_("Enable envmapping"),
TRUE,
G_PARAM_READWRITE);
gimp_procedure_add_choice_argument (procedure, "bumpmap-type",
_("Cur_ve"),
_("Type of mapping"),
gimp_choice_new_with_values ("bumpmap-linear", LINEAR_MAP, _("Linear"), NULL,
"bumpmap-log", LOGARITHMIC_MAP, _("Logarithmic"), NULL,
"bumpmap-sinusoidal", SINUSOIDAL_MAP, _("Sinusoidal"), NULL,
"bumpmap-spherical", SPHERICAL_MAP, _("Spherical"), NULL,
NULL),
"bumpmap-linear",
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "bumpmap-max-height",
_("Ma_ximum height"),
_("The maximum height of the bumpmap"),
0.0, G_MAXFLOAT, 0.1,
G_PARAM_READWRITE);
gimp_procedure_add_choice_aux_argument (procedure, "which-light",
_("Active"),
_("Which light is active in the GUI"),
gimp_choice_new_with_values ("light-1", 0, _("Light 1"), NULL,
"light-2", 1, _("Light 2"), NULL,
"light-3", 2, _("Light 3"), NULL,
"light-4", 3, _("Light 4"), NULL,
"light-5", 4, _("Light 5"), NULL,
"light-6", 5, _("Light 6"), NULL,
NULL),
"light-1",
G_PARAM_READWRITE);
gimp_procedure_add_boolean_aux_argument (procedure, "isolate",
_("Isolate"),
_("Only show the active lighting in "
"the preview"),
FALSE,
G_PARAM_READWRITE);
gimp_procedure_add_choice_argument (procedure, "light-type-1",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-point",
G_PARAM_READWRITE);
gimp_procedure_add_color_argument (procedure, "light-color-1",
_("Color"),
_("Light source color"),
TRUE, default_color_1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-intensity-1",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-position-x-1",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-position-y-1",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-position-z-1",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-direction-x-1",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-direction-y-1",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "light-direction-z-1",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "ambient-intensity",
_("Ambient intensity"),
_("Material ambient intensity "
"(Glowing)"),
0, 1, 0.2,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "diffuse-intensity",
_("Diffuse intensity"),
_("Material diffuse intensity "
"(Bright)"),
0, 1, 0.5,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "diffuse-reflectivity",
_("Diffuse reflectivity"),
_("Material diffuse reflectivity"),
0, 1, 0.4,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "specular-reflectivity",
_("Specular reflectivity"),
_("Material specular reflectivity"),
0, 1, 0.5,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "highlight",
_("Highlight"),
_("Material highlight (note, it's exponential) "
"(Polished)"),
0, G_MAXDOUBLE, 27.0,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "metallic",
_("Metallic"),
_("Make surfaces look metallic"),
FALSE,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "antialiasing",
_("_Antialiasing"),
_("Apply antialiasing"),
FALSE,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "new-image",
_("Create new ima_ge"),
_("Create a new image"),
FALSE,
G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "transparent-background",
_("Trans_parent background"),
_("Make background transparent"),
FALSE,
G_PARAM_READWRITE);
gimp_procedure_add_double_argument (procedure, "distance",
_("_Distance"),
_("Distance of observer from surface"),
0, 2.0, 0.25,
G_PARAM_READWRITE);
/* GUI-only arguments for additional light sources */
gimp_procedure_add_choice_aux_argument (procedure, "light-type-2",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-none",
G_PARAM_READWRITE);
gimp_procedure_add_color_aux_argument (procedure, "light-color-2",
_("Color"),
_("Light source color"),
TRUE, default_color_2,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-intensity-2",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-x-2",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -2,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-y-2",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-z-2",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-x-2",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-y-2",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, -1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-z-2",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_choice_aux_argument (procedure, "light-type-3",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-none",
G_PARAM_READWRITE);
gimp_procedure_add_color_aux_argument (procedure, "light-color-3",
_("Color"),
_("Light source color"),
TRUE, default_color_3,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-intensity-3",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-x-3",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-y-3",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 2,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-z-3",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-x-3",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-y-3",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-z-3",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_choice_aux_argument (procedure, "light-type-4",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-none",
G_PARAM_READWRITE);
gimp_procedure_add_color_aux_argument (procedure, "light-color-4",
_("Color"),
_("Light source color"),
TRUE, default_color_4,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-intensity-4",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-x-4",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-y-4",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-z-4",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-x-4",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-y-4",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-z-4",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_choice_aux_argument (procedure, "light-type-5",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-none",
G_PARAM_READWRITE);
gimp_procedure_add_color_aux_argument (procedure, "light-color-5",
_("Color"),
_("Light source color"),
TRUE, default_color_5,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-intensity-5",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-x-5",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-y-5",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-z-5",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-x-5",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-y-5",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-z-5",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_choice_aux_argument (procedure, "light-type-6",
_("Type"),
_("Type of light source"),
gimp_choice_new_with_values ("light-none", NO_LIGHT, _("None"), NULL,
"light-directional", DIRECTIONAL_LIGHT, _("Directional"), NULL,
"light-point", POINT_LIGHT, _("Point"), NULL,
"light-spot", SPOT_LIGHT, _("Spot"), NULL,
NULL),
"light-none",
G_PARAM_READWRITE);
gimp_procedure_add_color_aux_argument (procedure, "light-color-6",
_("Color"),
_("Light source color"),
TRUE, default_color_6,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-intensity-6",
_("Intensity"),
_("Light source intensity"),
0, 100.0, 1.0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-x-6",
_("Light position X"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-y-6",
_("Light position Y"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-position-z-6",
_("Light position Z"),
_("Light source position (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-x-6",
_("Light direction X"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-y-6",
_("Light direction Y"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
G_PARAM_READWRITE);
gimp_procedure_add_double_aux_argument (procedure, "light-direction-z-6",
_("Light direction Z"),
_("Light source direction (x,y,z)"),
-G_MAXDOUBLE, G_MAXDOUBLE, 1,
G_PARAM_READWRITE);
g_object_unref (default_color_1);
g_object_unref (default_color_2);
g_object_unref (default_color_3);
g_object_unref (default_color_4);
g_object_unref (default_color_5);
g_object_unref (default_color_6);
2019-09-03 19:58:18 +02:00
}
return procedure;
}
1998-06-11 06:04:59 +00:00
static void
set_default_settings (void)
1998-06-11 06:04:59 +00:00
{
gint k;
mapvals.update_enabled = TRUE;
mapvals.light_selected = 0;
mapvals.light_isolated = FALSE;
gimp_vector3_set (&mapvals.viewpoint, 0.5, 0.5, 0.25);
gimp_vector3_set (&mapvals.planenormal, 0.0, 0.0, 1.0);
renamed gimp_drawable_image() to gimp_drawable_get_image() for symmetry 2003-12-04 Michael Natterer <mitch@gimp.org> * tools/pdbgen/pdb/drawable.pdb: renamed gimp_drawable_image() to gimp_drawable_get_image() for symmetry with gimp_drawable_set_image(). * libgimp/gimpchannel.h: removed gimp_channel_get_image_id #define. * libgimp/gimpdrawable.h: removed gimp_drawable_image_id #define. * libgimp/gimplayer.h:: removed gimp_layer_get_image_id #define. * libgimp/gimpcompat.h: added the old stuff here. * app/pdb/drawable_cmds.c * libgimp/gimpdrawable_pdb.[ch]: regenerated. * libgimp/gimpmiscui.c * plug-ins/Lighting/lighting_main.c * plug-ins/MapObject/mapobject_main.c * plug-ins/common/curve_bend.c * plug-ins/common/film.c * plug-ins/common/newsprint.c * plug-ins/common/pixelize.c * plug-ins/common/ps.c * plug-ins/common/sample_colorize.c * plug-ins/common/smooth_palette.c * plug-ins/common/warp.c * plug-ins/imagemap/imap_cmd_gimp_guides.c * plug-ins/imagemap/imap_main.c * plug-ins/imagemap/imap_preview.c * plug-ins/maze/maze.c * plug-ins/pygimp/pygimp-drawable.c * plug-ins/rcm/rcm_misc.c * plug-ins/script-fu/scripts/addborder.scm * plug-ins/script-fu/scripts/carve-it.scm * plug-ins/script-fu/scripts/weave.scm: changed accordingly. * plug-ins/maze/maze.c: completely reindented. * plug-ins/script-fu/siod/trace.c: removed trailing whitespace. 2003-12-04 Michael Natterer <mitch@gimp.org> * libgimp/libgimp-sections.txt * libgimp/tmpl/gimpchannel.sgml * libgimp/tmpl/gimpdrawable.sgml * libgimp/tmpl/gimplayer.sgml: updated after gimp_drawable_get_image() cleanup.
2003-12-04 13:21:27 +00:00
gimp_vector3_set (&mapvals.lightsource[0].position, -1.0, -1.0, 1.0);
gimp_vector3_set (&mapvals.lightsource[0].direction, -1.0, -1.0, 1.0);
for (gint i = 0; i < 4; i++)
mapvals.lightsource[0].color[i] = 1.0;
mapvals.lightsource[0].intensity = 1.0;
mapvals.lightsource[0].type = POINT_LIGHT;
mapvals.lightsource[0].active = TRUE;
/* init lights 2 and 3 pos to upper left and below */
gimp_vector3_set (&mapvals.lightsource[1].position, 2.0, -1.0, 1.0);
gimp_vector3_set (&mapvals.lightsource[1].direction, 1.0, -1.0, 1.0);
1998-06-11 06:04:59 +00:00
gimp_vector3_set (&mapvals.lightsource[2].position, 1.0, 2.0, 1.0);
gimp_vector3_set (&mapvals.lightsource[2].direction, 0.0, 1.0, 1.0);
/* init any remaining lights to directly overhead */
for (k = 3; k < NUM_LIGHTS; k++)
{
gimp_vector3_set (&mapvals.lightsource[k].position, 0.0, 0.0, 1.0);
gimp_vector3_set (&mapvals.lightsource[k].direction, 0.0, 0.0, 1.0);
}
for (k = 1; k < NUM_LIGHTS; k++)
{
for (gint i = 0; i < 4; i++)
mapvals.lightsource[k].color[i] = 1.0;
mapvals.lightsource[k].intensity = 1.0;
mapvals.lightsource[k].type = NO_LIGHT;
mapvals.lightsource[k].active = TRUE;
}
1998-06-11 06:04:59 +00:00
mapvals.material.ambient_int = 0.2;
mapvals.material.diffuse_int = 0.5;
mapvals.material.diffuse_ref = 0.4;
mapvals.material.specular_ref = 0.5;
mapvals.material.highlight = 27.0;
mapvals.material.metallic = FALSE;
1998-06-11 06:04:59 +00:00
mapvals.pixel_threshold = 0.25;
mapvals.max_depth = 3.0;
mapvals.preview_zoom_factor = 1.0;
mapvals.bumpmaptype = 0;
mapvals.bumpmin = 0.0;
mapvals.bumpmax = 0.1;
1998-06-11 06:04:59 +00:00
mapvals.antialiasing = FALSE;
mapvals.create_new_image = FALSE;
1998-06-11 06:04:59 +00:00
mapvals.transparent_background = FALSE;
mapvals.bump_mapped = FALSE;
mapvals.env_mapped = FALSE;
mapvals.ref_mapped = FALSE;
mapvals.previewquality = FALSE;
mapvals.interactive_preview = TRUE;
mapvals.bumpmap_id = -1;
mapvals.envmap_id = -1;
1998-06-11 06:04:59 +00:00
}
static void
check_drawables (void)
1998-06-11 06:04:59 +00:00
{
GimpDrawable *drawable;
GimpDrawable *map;
1998-06-11 06:04:59 +00:00
if (mapvals.bump_mapped)
{
if (! gimp_item_id_is_drawable (mapvals.bumpmap_id))
{
mapvals.bump_mapped = FALSE;
mapvals.bumpmap_id = -1;
}
else
1998-06-11 06:04:59 +00:00
{
drawable = gimp_drawable_get_by_id (mapvals.drawable_id);
map = gimp_drawable_get_by_id (mapvals.bumpmap_id);
if (gimp_drawable_is_indexed (map) ||
(gimp_drawable_get_width (drawable) != gimp_drawable_get_width (map)) ||
(gimp_drawable_get_height (drawable) != gimp_drawable_get_height (map)))
{
mapvals.bump_mapped = FALSE;
mapvals.bumpmap_id = -1;
}
1998-06-11 06:04:59 +00:00
}
}
if (mapvals.env_mapped)
{
if (! gimp_item_id_is_drawable (mapvals.envmap_id))
{
mapvals.env_mapped = FALSE;
mapvals.envmap_id = -1;
}
else
1998-06-11 06:04:59 +00:00
{
map = gimp_drawable_get_by_id (mapvals.envmap_id);
if (gimp_drawable_is_gray (map) ||
gimp_drawable_has_alpha (map))
{
mapvals.env_mapped = FALSE;
mapvals.envmap_id = -1;
}
1998-06-11 06:04:59 +00:00
}
}
}
2019-09-03 19:58:18 +02:00
static GimpValueArray *
lighting_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GimpDrawable **drawables,
GimpProcedureConfig *config,
2019-09-03 19:58:18 +02:00
gpointer run_data)
1998-06-11 06:04:59 +00:00
{
GimpDrawable *drawable;
2019-07-10 12:19:13 +02:00
gegl_init (NULL, NULL);
if (gimp_core_object_array_get_length ((GObject **) drawables) != 1)
{
GError *error = NULL;
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
_("Procedure '%s' only works with one drawable."),
gimp_procedure_get_name (procedure));
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
error);
}
else
{
drawable = drawables[0];
}
set_default_settings ();
1998-06-11 06:04:59 +00:00
mapvals.drawable_id = gimp_item_get_id (GIMP_ITEM (drawable));
1998-06-11 06:04:59 +00:00
check_drawables ();
1998-06-11 06:04:59 +00:00
2019-09-03 19:58:18 +02:00
if (gimp_drawable_is_rgb (drawable))
1998-06-11 06:04:59 +00:00
{
mapvals.config = config;
copy_from_config (config);
2019-09-03 19:58:18 +02:00
switch (run_mode)
{
2019-09-03 19:58:18 +02:00
case GIMP_RUN_INTERACTIVE:
if (! main_dialog (procedure, config, drawable))
1998-06-11 06:04:59 +00:00
{
2019-09-03 19:58:18 +02:00
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL,
NULL);
1998-06-11 06:04:59 +00:00
}
2019-09-03 19:58:18 +02:00
compute_image ();
gimp_displays_flush ();
break;
case GIMP_RUN_WITH_LAST_VALS:
if (image_setup (drawable, FALSE))
compute_image ();
gimp_displays_flush ();
break;
case GIMP_RUN_NONINTERACTIVE:
check_drawables ();
if (image_setup (drawable, FALSE))
compute_image ();
default:
break;
2019-07-10 12:19:13 +02:00
}
1998-06-11 06:04:59 +00:00
}
2019-09-03 19:58:18 +02:00
else
{
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
NULL);
}
applied gimp-lecorfec-99041[02]-0, changes follow * applied gimp-lecorfec-99041[02]-0, changes follow * plug-ins/FractalExplorer/Dialogs.h (make_color_map): replaced free with g_free to fix segfault. * plug-ins/Lighting/lighting_preview.c (compute_preview): allocate xpostab and ypostab only when needed (it could also be allocated on stack with a compilation-fixed size like MapObject). It avoids to lose some Kb on each preview :) Also reindented (unfortunate C-c C-q) some other lines. * plug-ins/Lighting/lighting_main.c (run): release allocated postabs. * plug-ins/Lighting/lighting_ui.c: callbacks now have only one argument because gck widget use gtk_signal_connect_object. Caused segfault for scale widget. * plug-ins/autocrop/autocrop.c (doit): return if image has only background (thus fixing a segfault). * plug-ins/emboss/emboss.c (pluginCore, emboss_do_preview): replaced malloc/free with g_malloc/g_free (unneeded, but shouldn't everyone use glib calls ? :) * plug-ins/flame/flame.c : replaced a segfaulting free, and several harmless malloc/free pairs. * plug-ins/flame/megawidget.c (mw_preview_build): replaced harmless malloc/free pair. Note : mwp->bits is malloc'ed but seems to be never freed. * plug-ins/fractaltrace/fractaltrace.c (pixels_free): replaced a bunch of segfaulting free. (pixels_get, dialog_show): replaced gtk_signal_connect_object with gtk_signal_connect to accomodate callbacks (caused STRANGE dialog behaviour, coz you destroyed buttons one by one). * plug-ins/illusion/illusion.c (dialog): same gtk_signal_connect_object replacement for same reasons. * plug-ins/libgck/gck/gckcolor.c : changed all gck_rgb_to_color* functions to use a static GdkColor instead of a malloc'ed area. Provided reentrant functions with the old behaviour (gck_rgb_to_color*_r). Made some private functions static, too. gck_rgb_to_gdkcolor now use the new functions while gck_rgb_to_gdkcolor_r is the reentrant version. Also affected by this change: gck_gc_set_foreground and gck_gc_set_background (no more free(color)). * plug-ins/libgck/gck/gckcolor.h : added the gck_rgb_to_gdkcolor_r proto. * plug-ins/lic/lic.c (ok_button_clicked, cancel_button_clicked) : segfault on gtk_widget_destroy, now calls gtk_main_quit. (dialog_destroy) : segfault on window closure when called by "destroy" event. Now called by "delete_event". * plug-ins/megawidget/megawidget.c (mw_preview_build): replaced harmless malloc/free pair. Note : mwp->bits is malloc'ed but seems to be never freed. * plug-ins/png/png.c (load_image): replaced 2 segfaulting free. * plug-ins/print/print-ps.c (ps_print): replaced a segfaulting free (called many times :). * plug-ins/sgi/sgi.c (load_image, save_image): replaced a bunch of segfaulting free, and did some harmless inits to avoid a few gcc warnings. * plug-ins/wind/wind.c (render_wind): replaced a segfaulting free. (render_blast): replaced harmless malloc/free pair. * plug-ins/bmp/bmpread.c (ReadImage): yet another free()/g_free() problem fixed. * plug-ins/exchange/exchange.c (real_exchange): ditto. * plug-ins/fp/fp.h: added Frames_Check_Button_In_A_Box proto. * plug-ins/fp/fp_gtk.c: closing subdialogs via window manager wasn't handled, thus leading to errors and crashes. Now delete_event signals the dialog control button to close a dialog with the good way. * plug-ins/ifscompose/ifscompose.c (value_pair_create): tried to set events mask on scale widget (a NO_WINDOW widget). * plug-ins/png/png.c (save_image): Replaced 2 free() with g_free() for g_malloc'ed memory. Mysteriously I corrected the loading bug but not the saving one :) -Yosh
1999-04-15 21:49:09 +00:00
g_free (xpostab);
g_free (ypostab);
1998-06-11 06:04:59 +00:00
2019-09-03 19:58:18 +02:00
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}