79
static void query (void);
80
static void run (const gchar *name,
82
const GimpParam *param,
86
static gint emboss (GimpDrawable *drawable,
87
GimpPreview *preview);
88
static gint emboss_dialog (GimpDrawable *drawable);
90
static inline void EmbossInit (gdouble azimuth,
93
static inline void EmbossRow (guchar *src,
76
static void query (void);
77
static void run (const gchar *name,
79
const GimpParam *param,
83
static void emboss (GimpDrawable *drawable,
84
GimpPreview *preview);
85
static gboolean emboss_dialog (GimpDrawable *drawable);
87
static void emboss_init (gdouble azimuth,
90
static void emboss_row (const guchar *src,
91
const guchar *texture,
100
98
#define DtoR(d) ((d)*(G_PI/(gdouble)180))
102
GimpPlugInInfo PLUG_IN_INFO =
101
const GimpPlugInInfo PLUG_IN_INFO =
115
static GimpParamDef args[] =
114
static const GimpParamDef args[] =
117
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
118
{ GIMP_PDB_IMAGE, "img", "The Image" },
119
{ GIMP_PDB_DRAWABLE, "drw", "The Drawable" },
120
{ GIMP_PDB_FLOAT, "azimuth", "The Light Angle (degrees)" },
121
{ GIMP_PDB_FLOAT, "elevation", "The Elevation Angle (degrees)" },
122
{ GIMP_PDB_INT32, "depth", "The Filter Width" },
123
{ GIMP_PDB_INT32, "embossp", "Emboss or Bumpmap" }
116
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
117
{ GIMP_PDB_IMAGE, "image", "The Image" },
118
{ GIMP_PDB_DRAWABLE, "drawable", "The Drawable" },
119
{ GIMP_PDB_FLOAT, "azimuth", "The Light Angle (degrees)" },
120
{ GIMP_PDB_FLOAT, "elevation", "The Elevation Angle (degrees)" },
121
{ GIMP_PDB_INT32, "depth", "The Filter Width" },
122
{ GIMP_PDB_INT32, "emboss", "Emboss or Bumpmap" }
126
gimp_install_procedure ("plug_in_emboss",
125
gimp_install_procedure (PLUG_IN_PROC,
126
N_("Simulate an image created by embossing"),
128
127
"Emboss or Bumpmap the given drawable, specifying "
129
128
"the angle and elevation for the light source.",
130
129
"Eric L. Hernes, John Schlag",
164
163
switch (param[0].data.d_int32)
166
165
case GIMP_RUN_INTERACTIVE:
167
gimp_get_data ("plug_in_emboss", &evals);
166
gimp_get_data (PLUG_IN_PROC, &evals);
169
if (emboss_dialog (drawable) == -1)
168
if (! emboss_dialog (drawable))
171
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
170
rvals[0].data.d_status = GIMP_PDB_CANCEL;
175
gimp_set_data ("plug_in_emboss", &evals, sizeof (piArgs));
174
gimp_set_data (PLUG_IN_PROC, &evals, sizeof (piArgs));
189
188
evals.depth = param[5].data.d_int32;
190
189
evals.embossp = param[6].data.d_int32;
192
if (emboss (drawable, NULL)==-1)
194
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
191
emboss (drawable, NULL);
199
194
case GIMP_RUN_WITH_LAST_VALS:
200
gimp_get_data ("plug_in_emboss", &evals);
195
gimp_get_data (PLUG_IN_PROC, &evals);
201
196
/* use this image and drawable, even with last args */
202
if (emboss (drawable, NULL)==-1)
204
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
197
emboss (drawable, NULL);
248
240
* The unary case ('texture' == NULL) uses the shading result as output.
249
241
* The binary case multiples the optional 'texture' image by the shade.
250
242
* Images are in row major order with interleaved color components (rgbrgb...).
251
* E.g., component c of pixel x,y of 'dst' is dst[3*(y*xSize + x) + c].
243
* E.g., component c of pixel x,y of 'dst' is dst[3*(y*width + x) + c].
256
EmbossRow (guchar *src,
248
emboss_row (const guchar *src,
249
const guchar *texture,
264
guchar *s1, *s2, *s3;
268
259
/* mung pixels, avoiding edge pixels */
270
s2 = s1 + (xSize * bypp);
271
s3 = s2 + (xSize * bypp);
261
s[1] = s[0] + (width * bypp);
262
s[2] = s[1] + (width * bypp);
274
265
bytes = (alpha) ? bypp - 1 : bypp;
268
texture += (width + 1) * bypp;
279
for (x = 1; x < xSize - 1; x++, s1 += bypp, s2 += bypp, s3 += bypp)
270
for (x = 1; x < width - 1; x++)
282
* compute the normal from the src map. the type of the
283
* expression before the cast is compiler dependent. in
284
* some cases the sum is unsigned, in others it is
285
* signed. ergo, cast to signed.
287
Nx = (int) (s1[-(int)bypp] + s2[-(int)bypp] + s3[-(int)bypp]
288
- s1[bypp] - s2[bypp] - s3[bypp]);
289
Ny = (int) (s3[-(int)bypp] + s3[0] + s3[bypp] - s1[-(int)bypp]
277
for (i = 0; i < 3; i++)
278
for (j = 0; j < 3; j++)
281
for (b = 0; b < bytes; b++)
283
for (i = 0; i < 3; i++)
284
for (j = 0; j < 3; j++)
287
a = s[i][j * bypp + bytes] / 255.0;
291
M[i][j] += a * s[i][j * bypp + b];
295
Nx = M[0][0] + M[1][0] + M[2][0] - M[0][2] - M[1][2] - M[2][2];
296
Ny = M[2][0] + M[2][1] + M[2][2] - M[0][0] - M[0][1] - M[0][2];
292
298
/* shade with distant light source */
293
299
if ( Nx == 0 && Ny == 0 )
371
381
srcbuf = g_new0 (guchar, rowsize * 3);
372
382
dstbuf = g_new0 (guchar, rowsize);
374
EmbossInit (DtoR(evals.azimuth), DtoR(evals.elevation), evals.depth);
384
emboss_init (DtoR(evals.azimuth), DtoR(evals.elevation), evals.depth);
376
386
gimp_progress_init (_("Emboss"));
379
389
gimp_pixel_rgn_get_rect (&src, srcbuf, x1, y1, width, 3);
380
390
memcpy (srcbuf, srcbuf + rowsize, rowsize);
381
EmbossRow (srcbuf, evals.embossp ? (guchar *) 0 : srcbuf,
382
dstbuf, width, bypp, has_alpha);
391
emboss_row (srcbuf, evals.embossp ? NULL : srcbuf,
392
dstbuf, width, bypp, has_alpha);
383
393
gimp_pixel_rgn_set_row (&dst, dstbuf, 0, 0, width);
396
for (y = 0; y < height - 2; y++)
398
if (! preview && (y % p_update == 0))
399
gimp_progress_update ((gdouble) y / (gdouble) height);
401
gimp_pixel_rgn_get_rect (&src, srcbuf, x1, y1 + y, width, 3);
402
emboss_row (srcbuf, evals.embossp ? NULL : srcbuf,
403
dstbuf, width, bypp, has_alpha);
404
gimp_pixel_rgn_set_row (&dst, dstbuf, x1, y1 + y + 1, width);
386
gimp_pixel_rgn_get_rect (&src, srcbuf, x1, y2-3, width, 3);
408
gimp_pixel_rgn_get_rect (&src, srcbuf, x1, y2 - 3, width, 3);
387
409
memcpy (srcbuf + rowsize * 2, srcbuf + rowsize, rowsize);
388
EmbossRow (srcbuf, evals.embossp ? (guchar *) 0 : srcbuf,
389
dstbuf, width, bypp, has_alpha);
390
gimp_pixel_rgn_set_row (&dst, dstbuf, x1, y2-1, width);
392
for (y = 0; y < height - 2; y++)
394
if (! preview && (y % p_update == 0))
395
gimp_progress_update ((gdouble) y / (gdouble) height);
397
gimp_pixel_rgn_get_rect (&src, srcbuf, x1, y1+y, width, 3);
398
EmbossRow (srcbuf, evals.embossp ? (guchar *) 0 : srcbuf,
399
dstbuf, width, bypp, has_alpha);
400
gimp_pixel_rgn_set_row (&dst, dstbuf, x1, y1+y+1, width);
410
emboss_row (srcbuf, evals.embossp ? NULL : srcbuf,
411
dstbuf, width, bypp, has_alpha);
412
gimp_pixel_rgn_set_row (&dst, dstbuf, x1, y2 - 1, width);
437
gimp_ui_init ("emboss", TRUE);
446
gimp_ui_init (PLUG_IN_BINARY, TRUE);
439
dialog = gimp_dialog_new (_("Emboss"), "emboss",
448
dialog = gimp_dialog_new (_("Emboss"), PLUG_IN_BINARY,
441
gimp_standard_help_func, "plug-in-emboss",
450
gimp_standard_help_func, PLUG_IN_PROC,
443
452
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
444
453
GTK_STOCK_OK, GTK_RESPONSE_OK,
457
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
462
gimp_window_set_transient (GTK_WINDOW (dialog));
448
464
main_vbox = gtk_vbox_new (FALSE, 12);
449
465
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
450
466
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
486
502
evals.azimuth, 0.0, 360.0, 1.0, 10.0, 2,
489
g_signal_connect (adj, "value_changed",
505
g_signal_connect (adj, "value-changed",
490
506
G_CALLBACK (gimp_double_adjustment_update),
492
g_signal_connect_swapped (adj, "value_changed",
508
g_signal_connect_swapped (adj, "value-changed",
493
509
G_CALLBACK (gimp_preview_invalidate),
498
514
evals.elevation, 0.0, 180.0, 1.0, 10.0, 2,
501
g_signal_connect (adj, "value_changed",
517
g_signal_connect (adj, "value-changed",
502
518
G_CALLBACK (gimp_double_adjustment_update),
503
519
&evals.elevation);
504
g_signal_connect_swapped (adj, "value_changed",
520
g_signal_connect_swapped (adj, "value-changed",
505
521
G_CALLBACK (gimp_preview_invalidate),
510
526
evals.depth, 1.0, 100.0, 1.0, 5.0, 0,
513
g_signal_connect (adj, "value_changed",
529
g_signal_connect (adj, "value-changed",
514
530
G_CALLBACK (gimp_int_adjustment_update),
516
g_signal_connect_swapped (adj, "value_changed",
532
g_signal_connect_swapped (adj, "value-changed",
517
533
G_CALLBACK (gimp_preview_invalidate),