gimp/plug-ins/Lighting/lighting_apply.c

186 lines
4.2 KiB
C
Raw Normal View History

1998-06-11 14:04:59 +08:00
/******************************************************/
/* Apply mapping and shading on the whole input image */
/******************************************************/
#include "config.h"
Libgimp cleanup part II (with a little help from Yosh who moved the CVS 2000-05-27 Michael Natterer <mitch@gimp.org> Libgimp cleanup part II (with a little help from Yosh who moved the CVS files). * libgimp/Makefile.am * libgimp/gimpchannel_pdb.c * libgimp/gimpdisplay_pdb.c * libgimp/gimpdrawable_pdb.c * libgimp/gimpgradient_pdb.c * libgimp/gimphelp_pdb.c * libgimp/gimpimage_pdb.c * libgimp/gimplayer_pdb.c * libgimp/gimppalette_pdb.c * libgimp/gimpparasite_pdb.c * libgimp/gimpselection_pdb.c * libgimp/gimpunit_pdb.c: new names of all files which contain PDB wrappers. * modules/Makefile.am * libgimp/gimpcolordisplay.h * libgimp/gimpcolorselector.h * modules/gimpmodregister.[ch]: renamed. * libgimp/gimpparasiteF.h * libgimp/gimpparasiteP.h: removed because gimp.h had to include the private header anyway. * app/color_notebook.c * app/color_select.c * app/gdisplay_color.[ch] * app/gdisplay_color_ui.c * app/gimpbrushpipe.c * app/gimpdrawable.[ch] * app/gimpimage.c * app/gimpimage.h * app/gimpparasite.[ch] * app/gimprc.c * app/image_new.c * app/layer.c * app/parasite_cmds.c * app/parasitelist.[ch] * app/plug_in.c * app/procedural_db.c * app/undo.c * app/xcf.c * libgimp/gimp.[ch] * libgimp/gimpcolordisplay.h * libgimp/gimpparasite.[ch] * modules/cdisplay_gamma.c * modules/cdisplay_highcontrast.c * modules/colorsel_gtk.c * modules/colorsel_triangle.c * modules/colorsel_water.c * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/Events.c * plug-ins/Lighting/lighting_apply.c * plug-ins/Lighting/lighting_shade.c * plug-ins/MapObject/mapobject_image.c * plug-ins/common/gpb.c * plug-ins/common/psp.c * plug-ins/sel2path/sel2path.c * po-libgimp/POTFILES.in * tools/pdbgen/pdb.pl * tools/pdbgen/pdb/parasite.pdb: changed includes accordingly.
2000-05-27 09:30:21 +08:00
#include <sys/types.h>
#include <libgimp/gimp.h>
#include <gck/gck.h>
#include "lighting_main.h"
#include "lighting_image.h"
1998-06-11 14:04:59 +08:00
#include "lighting_shade.h"
/*************/
/* Main loop */
/*************/
get_ray_func ray_func;
void
init_compute (void)
1998-06-11 14:04:59 +08:00
{
}
/*
static void
render (gdouble x,
gdouble y,
plug-ins/libgck/gck/gck.h removed the GckRGB color type and all it's 2001-01-01 Michael Natterer <mitch@gimp.org> * plug-ins/libgck/gck/gck.h * plug-ins/libgck/gck/gckcolor.c: removed the GckRGB color type and all it's functions. * libgimp/Makefile.am * libgimp/gimpcolor.[ch]: new files containing the new GimpRGB color type and assorted functions. * libgimp/gimpcolorspace.[ch]: colorspace conversion routines for the new GimpRGB type. Also taken from LibGCK. * libgimp/gimp.h * libgimp/gimptypes.h: #include "gimpcolor.h". It's ugly to include it in both files but unavoidable to follow our new "*.c" file include policy. This will go away as libgimp will be chopped up into pieces anyway. * app/apptypes.h * app/asupsample.[ch] * app/blend.c * app/color_transfer.h * app/gradient_header.h: removed "color_t" and use GimpRGB instead. * plug-ins/Lighting/lighting_apply.c * plug-ins/Lighting/lighting_image.c * plug-ins/Lighting/lighting_image.h * plug-ins/Lighting/lighting_main.c * plug-ins/Lighting/lighting_main.h * plug-ins/Lighting/lighting_preview.c * plug-ins/Lighting/lighting_shade.c * plug-ins/Lighting/lighting_shade.h * plug-ins/MapObject/mapobject_apply.c * plug-ins/MapObject/mapobject_image.c * plug-ins/MapObject/mapobject_image.h * plug-ins/MapObject/mapobject_main.c * plug-ins/MapObject/mapobject_main.h * plug-ins/MapObject/mapobject_preview.c * plug-ins/MapObject/mapobject_shade.c * plug-ins/MapObject/mapobject_shade.h * modules/colorsel_triangle.c: s/GckRGB/GimpRGB/g * plug-ins/gdyntext/gdyntextcompat.h: check also for GIMP's minor version when deciding if to add a missing PDB wrapper. (All this compat cruft including libgimp/gimpcompat.h should go away ASAP)
2001-01-02 02:35:09 +08:00
GimpRGB *col)
1998-06-11 14:04:59 +08:00
{
GimpVector3 pos;
1998-06-11 14:04:59 +08:00
pos=int_to_pos(x,y);
*col=(*ray_func)(&pos);
}
static void
show_progress (gint min,
gint max,
gint curr)
1998-06-11 14:04:59 +08:00
{
gimp_progress_update ((gdouble)curr / (gdouble)max);
1998-06-11 14:04:59 +08:00
}
*/
1998-06-11 14:04:59 +08:00
void
compute_image (void)
1998-06-11 14:04:59 +08:00
{
gint xcount, ycount;
plug-ins/libgck/gck/gck.h removed the GckRGB color type and all it's 2001-01-01 Michael Natterer <mitch@gimp.org> * plug-ins/libgck/gck/gck.h * plug-ins/libgck/gck/gckcolor.c: removed the GckRGB color type and all it's functions. * libgimp/Makefile.am * libgimp/gimpcolor.[ch]: new files containing the new GimpRGB color type and assorted functions. * libgimp/gimpcolorspace.[ch]: colorspace conversion routines for the new GimpRGB type. Also taken from LibGCK. * libgimp/gimp.h * libgimp/gimptypes.h: #include "gimpcolor.h". It's ugly to include it in both files but unavoidable to follow our new "*.c" file include policy. This will go away as libgimp will be chopped up into pieces anyway. * app/apptypes.h * app/asupsample.[ch] * app/blend.c * app/color_transfer.h * app/gradient_header.h: removed "color_t" and use GimpRGB instead. * plug-ins/Lighting/lighting_apply.c * plug-ins/Lighting/lighting_image.c * plug-ins/Lighting/lighting_image.h * plug-ins/Lighting/lighting_main.c * plug-ins/Lighting/lighting_main.h * plug-ins/Lighting/lighting_preview.c * plug-ins/Lighting/lighting_shade.c * plug-ins/Lighting/lighting_shade.h * plug-ins/MapObject/mapobject_apply.c * plug-ins/MapObject/mapobject_image.c * plug-ins/MapObject/mapobject_image.h * plug-ins/MapObject/mapobject_main.c * plug-ins/MapObject/mapobject_main.h * plug-ins/MapObject/mapobject_preview.c * plug-ins/MapObject/mapobject_shade.c * plug-ins/MapObject/mapobject_shade.h * modules/colorsel_triangle.c: s/GckRGB/GimpRGB/g * plug-ins/gdyntext/gdyntextcompat.h: check also for GIMP's minor version when deciding if to add a missing PDB wrapper. (All this compat cruft including libgimp/gimpcompat.h should go away ASAP)
2001-01-02 02:35:09 +08:00
GimpRGB color;
glong progress_counter = 0;
GimpVector3 p;
gint32 new_image_id = -1;
gint32 new_layer_id = -1;
gint32 index;
guchar *row = NULL;
guchar obpp;
1998-06-11 14:04:59 +08:00
gint has_alpha;
init_compute ();
1998-06-11 14:04:59 +08:00
if (mapvals.create_new_image == TRUE ||
(mapvals.transparent_background == TRUE &&
! gimp_drawable_has_alpha (input_drawable->id)))
1998-06-11 14:04:59 +08:00
{
/* Create a new image */
/* ================== */
new_image_id = gimp_image_new (width, height, GIMP_RGB);
1998-06-11 14:04:59 +08:00
if (mapvals.transparent_background == TRUE)
1998-06-11 14:04:59 +08:00
{
/* Add a layer with an alpha channel */
/* ================================= */
new_layer_id = gimp_layer_new (new_image_id, "Background",
width, height,
GIMP_RGBA_IMAGE,
100.0,
GIMP_NORMAL_MODE);
1998-06-11 14:04:59 +08:00
}
else
{
/* Create a "normal" layer */
/* ======================= */
new_layer_id = gimp_layer_new (new_image_id, "Background",
width, height,
GIMP_RGB_IMAGE,
100.0,
GIMP_NORMAL_MODE);
1998-06-11 14:04:59 +08:00
}
gimp_image_add_layer (new_image_id, new_layer_id, 0);
output_drawable = gimp_drawable_get (new_layer_id);
1998-06-11 14:04:59 +08:00
}
if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1)
1998-06-11 14:04:59 +08:00
{
gimp_pixel_rgn_init (&bump_region, gimp_drawable_get (mapvals.bumpmap_id),
0, 0, width, height, FALSE, FALSE);
1998-06-11 14:04:59 +08:00
}
precompute_init (width, height);
if (!mapvals.env_mapped || mapvals.envmap_id == -1)
{
ray_func = get_ray_color;
}
1998-06-11 14:04:59 +08:00
else
{
env_width = gimp_drawable_width (mapvals.envmap_id);
env_height = gimp_drawable_height (mapvals.envmap_id);
gimp_pixel_rgn_init (&env_region, gimp_drawable_get (mapvals.envmap_id),
0, 0, env_width, env_height, FALSE, FALSE);
1998-06-11 14:04:59 +08:00
ray_func = get_ray_color_ref;
}
gimp_pixel_rgn_init (&dest_region, output_drawable,
0, 0, width, height, TRUE, TRUE);
1998-06-11 14:04:59 +08:00
obpp = gimp_drawable_bpp (output_drawable->id);
has_alpha = gimp_drawable_has_alpha (output_drawable->id);
1998-06-11 14:04:59 +08:00
row = g_new (guchar, obpp * width);
1998-06-11 14:04:59 +08:00
gimp_progress_init ("Lighting Effects");
1998-06-11 14:04:59 +08:00
/* if (mapvals.antialiasing==FALSE)
{ */
for (ycount = 0; ycount < height; ycount++)
{
if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1)
precompute_normals (0, width, ycount);
1998-06-11 14:04:59 +08:00
index = 0;
1998-06-11 14:04:59 +08:00
for (xcount = 0; xcount < width; xcount++)
{
p = int_to_pos (xcount, ycount);
color = (* ray_func) (&p);
1998-06-11 14:04:59 +08:00
row[index++] = (guchar) (color.r * 255.0);
row[index++] = (guchar) (color.g * 255.0);
row[index++] = (guchar) (color.b * 255.0);
if (has_alpha)
row[index++] = (guchar) (color.a * 255.0);
if ((progress_counter++ % width) == 0)
gimp_progress_update ((gdouble) progress_counter /
(gdouble) maxcounter);
}
gimp_pixel_rgn_set_row (&dest_region, row, 0, ycount, width);
}
1998-06-11 14:04:59 +08:00
/* }
else
gck_adaptive_supersample_area(0,0,width-1,height-1,(gint)mapvals.max_depth,
mapvals.pixel_treshold,render,poke,show_progress); */
g_free (row);
1998-06-11 14:04:59 +08:00
/* Update image */
/* ============ */
gimp_drawable_flush (output_drawable);
gimp_drawable_merge_shadow (output_drawable->id, TRUE);
gimp_drawable_update (output_drawable->id, 0, 0, width, height);
1998-06-11 14:04:59 +08:00
if (new_image_id!=-1)
{
gimp_display_new (new_image_id);
gimp_displays_flush ();
gimp_drawable_detach (output_drawable);
1998-06-11 14:04:59 +08:00
}
}