mirror of https://github.com/GNOME/gimp.git
plug-ins, pdb: remove the engrave plug-in and add a PDB compat procedure
This commit is contained in:
parent
be5e2e6991
commit
4d5e42ac1a
|
@ -28,7 +28,7 @@
|
|||
#include "internal-procs.h"
|
||||
|
||||
|
||||
/* 747 procedures registered total */
|
||||
/* 748 procedures registered total */
|
||||
|
||||
void
|
||||
internal_procs_init (GimpPDB *pdb)
|
||||
|
|
|
@ -953,6 +953,49 @@ plug_in_deinterlace_invoker (GimpProcedure *procedure,
|
|||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
plug_in_engrave_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
GimpContext *context,
|
||||
GimpProgress *progress,
|
||||
const GimpValueArray *args,
|
||||
GError **error)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GimpDrawable *drawable;
|
||||
gint32 height;
|
||||
gboolean limit;
|
||||
|
||||
drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
|
||||
height = g_value_get_int (gimp_value_array_index (args, 3));
|
||||
limit = g_value_get_boolean (gimp_value_array_index (args, 4));
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
|
||||
GIMP_PDB_ITEM_CONTENT, error) &&
|
||||
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
|
||||
{
|
||||
GeglNode *node;
|
||||
|
||||
node = gegl_node_new_child (NULL,
|
||||
"operation", "gegl:engrave",
|
||||
"row-height", height,
|
||||
"limit", limit,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_apply_operation (drawable, progress,
|
||||
C_("undo-type", "Engrave"),
|
||||
node);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success,
|
||||
error ? *error : NULL);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
plug_in_exchange_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
|
@ -3660,6 +3703,54 @@ register_plug_in_compat_procs (GimpPDB *pdb)
|
|||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-plug-in-engrave
|
||||
*/
|
||||
procedure = gimp_procedure_new (plug_in_engrave_invoker);
|
||||
gimp_object_set_static_name (GIMP_OBJECT (procedure),
|
||||
"plug-in-engrave");
|
||||
gimp_procedure_set_static_strings (procedure,
|
||||
"plug-in-engrave",
|
||||
"Simulate an antique engraving",
|
||||
"Creates a black-and-white 'engraved' version of an image as seen in old illustrations.",
|
||||
"Compatibility procedure. Please see 'gegl:engrave' for credits.",
|
||||
"Compatibility procedure. Please see 'gegl:engrave' for credits.",
|
||||
"2014",
|
||||
NULL);
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_enum ("run-mode",
|
||||
"run mode",
|
||||
"The run mode",
|
||||
GIMP_TYPE_RUN_MODE,
|
||||
GIMP_RUN_INTERACTIVE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_image_id ("image",
|
||||
"image",
|
||||
"Input image (unused)",
|
||||
pdb->gimp, FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_drawable_id ("drawable",
|
||||
"drawable",
|
||||
"Input drawable",
|
||||
pdb->gimp, FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
gimp_param_spec_int32 ("height",
|
||||
"height",
|
||||
"Resolution in pixels",
|
||||
2, 16, 2,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_procedure_add_argument (procedure,
|
||||
g_param_spec_boolean ("limit",
|
||||
"limit",
|
||||
"Limit line width",
|
||||
FALSE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
gimp_pdb_register_procedure (pdb, procedure);
|
||||
g_object_unref (procedure);
|
||||
|
||||
/*
|
||||
* gimp-plug-in-exchange
|
||||
*/
|
||||
|
|
|
@ -62,8 +62,6 @@
|
|||
/edge-neon.exe
|
||||
/emboss
|
||||
/emboss.exe
|
||||
/engrave
|
||||
/engrave.exe
|
||||
/file-aa
|
||||
/file-aa.exe
|
||||
/file-cel
|
||||
|
|
|
@ -74,7 +74,6 @@ libexec_PROGRAMS = \
|
|||
edge-dog \
|
||||
edge-neon \
|
||||
emboss \
|
||||
engrave \
|
||||
$(FILE_AA) \
|
||||
file-cel \
|
||||
file-compressor \
|
||||
|
@ -691,23 +690,6 @@ emboss_LDADD = \
|
|||
$(INTLLIBS) \
|
||||
$(emboss_RC)
|
||||
|
||||
engrave_SOURCES = \
|
||||
engrave.c
|
||||
|
||||
engrave_LDADD = \
|
||||
$(libgimpui) \
|
||||
$(libgimpwidgets) \
|
||||
$(libgimpmodule) \
|
||||
$(libgimp) \
|
||||
$(libgimpmath) \
|
||||
$(libgimpconfig) \
|
||||
$(libgimpcolor) \
|
||||
$(libgimpbase) \
|
||||
$(GTK_LIBS) \
|
||||
$(RT_LIBS) \
|
||||
$(INTLLIBS) \
|
||||
$(engrave_RC)
|
||||
|
||||
file_aa_SOURCES = \
|
||||
file-aa.c
|
||||
|
||||
|
|
|
@ -1,586 +0,0 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
* Copyright (C) 1997 Eiichi Takamori
|
||||
* Copyright (C) 1996, 1997 Torsten Martinsen
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <libgimp/gimp.h>
|
||||
#include <libgimp/gimpui.h>
|
||||
|
||||
#include "libgimp/stdplugins-intl.h"
|
||||
|
||||
|
||||
/* Some useful macros */
|
||||
|
||||
#define PLUG_IN_PROC "plug-in-engrave"
|
||||
#define PLUG_IN_BINARY "engrave"
|
||||
#define PLUG_IN_ROLE "gimp-engrave"
|
||||
#define SCALE_WIDTH 125
|
||||
#define TILE_CACHE_SIZE 16
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint height;
|
||||
gboolean limit;
|
||||
} EngraveValues;
|
||||
|
||||
static void query (void);
|
||||
static void run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static gboolean engrave_dialog (GimpDrawable *drawable);
|
||||
|
||||
static void engrave (GimpDrawable *drawable,
|
||||
GimpPreview *preview);
|
||||
|
||||
#if 0
|
||||
static void engrave_large (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gboolean limit,
|
||||
GimpPreview *preview);
|
||||
#endif
|
||||
|
||||
static void engrave_small (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gboolean limit,
|
||||
gint tile_width,
|
||||
GimpPreview *preview);
|
||||
|
||||
static void engrave_sub (gint height,
|
||||
gboolean limit,
|
||||
gint bpp,
|
||||
gint num_channels);
|
||||
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
query, /* query_proc */
|
||||
run, /* run_proc */
|
||||
};
|
||||
|
||||
static EngraveValues pvals =
|
||||
{
|
||||
10, /* height */
|
||||
FALSE /* limit */
|
||||
};
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
query (void)
|
||||
{
|
||||
static const GimpParamDef args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
|
||||
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
||||
{ GIMP_PDB_INT32, "height", "Resolution in pixels" },
|
||||
{ GIMP_PDB_INT32, "limit", "Limit line width { TRUE, FALSE }" }
|
||||
};
|
||||
|
||||
gimp_install_procedure (PLUG_IN_PROC,
|
||||
N_("Simulate an antique engraving"),
|
||||
"Creates a black-and-white 'engraved' version of an image as seen in old illustrations",
|
||||
"Spencer Kimball & Peter Mattis, Eiichi Takamori, Torsten Martinsen",
|
||||
"Spencer Kimball & Peter Mattis, Eiichi Takamori, Torsten Martinsen",
|
||||
"1995,1996,1997",
|
||||
N_("En_grave..."),
|
||||
"RGBA, GRAYA",
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (args), 0,
|
||||
args, NULL);
|
||||
|
||||
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Distorts");
|
||||
}
|
||||
|
||||
static void
|
||||
run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[1];
|
||||
GimpDrawable *drawable;
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
INIT_I18N ();
|
||||
|
||||
*nreturn_vals = 1;
|
||||
*return_vals = values;
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
values[0].data.d_status = status;
|
||||
|
||||
/* Get the specified drawable */
|
||||
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
||||
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
/* Possibly retrieve data */
|
||||
gimp_get_data (PLUG_IN_PROC, &pvals);
|
||||
|
||||
/* First acquire information with a dialog */
|
||||
if (!engrave_dialog (drawable))
|
||||
{
|
||||
gimp_drawable_detach (drawable);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
/* Make sure all the arguments are there! */
|
||||
if (nparams != 5)
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
pvals.height = param[3].data.d_int32;
|
||||
pvals.limit = (param[4].data.d_int32) ? TRUE : FALSE;
|
||||
}
|
||||
if ((status == GIMP_PDB_SUCCESS) &&
|
||||
pvals.height < 0)
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
/* Possibly retrieve data */
|
||||
gimp_get_data (PLUG_IN_PROC, &pvals);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
gimp_progress_init (_("Engraving"));
|
||||
|
||||
engrave (drawable, NULL);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
|
||||
/* Store data */
|
||||
if (run_mode == GIMP_RUN_INTERACTIVE)
|
||||
gimp_set_data (PLUG_IN_PROC, &pvals, sizeof (EngraveValues));
|
||||
}
|
||||
values[0].data.d_status = status;
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
engrave_dialog (GimpDrawable *drawable)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *main_vbox;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *table;
|
||||
GtkWidget *toggle;
|
||||
GtkObject *adj;
|
||||
gboolean run;
|
||||
|
||||
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
||||
|
||||
dialog = gimp_dialog_new (_("Engrave"), PLUG_IN_ROLE,
|
||||
NULL, 0,
|
||||
gimp_standard_help_func, PLUG_IN_PROC,
|
||||
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
||||
|
||||
NULL);
|
||||
|
||||
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
||||
GTK_RESPONSE_OK,
|
||||
GTK_RESPONSE_CANCEL,
|
||||
-1);
|
||||
|
||||
gimp_window_set_transient (GTK_WINDOW (dialog));
|
||||
|
||||
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||||
main_vbox, TRUE, TRUE, 0);
|
||||
gtk_widget_show (main_vbox);
|
||||
|
||||
preview = gimp_drawable_preview_new (drawable, NULL);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
|
||||
gtk_widget_show (preview);
|
||||
|
||||
g_signal_connect_swapped (preview, "invalidated",
|
||||
G_CALLBACK (engrave),
|
||||
drawable);
|
||||
|
||||
table = gtk_table_new (1, 3, FALSE);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
|
||||
gtk_widget_show (table);
|
||||
|
||||
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
||||
_("_Height:"), SCALE_WIDTH, 0,
|
||||
pvals.height, 2.0, 16.0, 1.0, 4.0, 0,
|
||||
TRUE, 0, 0,
|
||||
NULL, NULL);
|
||||
g_signal_connect (adj, "value-changed",
|
||||
G_CALLBACK (gimp_int_adjustment_update),
|
||||
&pvals.height);
|
||||
g_signal_connect_swapped (adj, "value-changed",
|
||||
G_CALLBACK (gimp_preview_invalidate),
|
||||
preview);
|
||||
|
||||
toggle = gtk_check_button_new_with_mnemonic (_("_Limit line width"));
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), toggle, FALSE, FALSE, 0);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), pvals.limit);
|
||||
gtk_widget_show (toggle);
|
||||
|
||||
g_signal_connect (toggle, "toggled",
|
||||
G_CALLBACK (gimp_toggle_button_update),
|
||||
&pvals.limit);
|
||||
g_signal_connect_swapped (toggle, "toggled",
|
||||
G_CALLBACK (gimp_preview_invalidate),
|
||||
preview);
|
||||
|
||||
gtk_widget_show (dialog);
|
||||
|
||||
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
return run;
|
||||
}
|
||||
|
||||
/* Engrave interface functions */
|
||||
|
||||
static void
|
||||
engrave (GimpDrawable *drawable,
|
||||
GimpPreview *preview)
|
||||
{
|
||||
gint tile_width;
|
||||
gint height;
|
||||
gboolean limit;
|
||||
|
||||
tile_width = gimp_tile_width();
|
||||
height = pvals.height;
|
||||
limit = pvals.limit;
|
||||
/* [DindinX] this test is always false since
|
||||
* tile_width == 64 and height <= 16 */
|
||||
#if 0
|
||||
if (height >= tile_width)
|
||||
engrave_large (drawable, height, limit, preview);
|
||||
else
|
||||
#endif
|
||||
engrave_small (drawable, height, limit, tile_width, preview);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
engrave_large (GimpDrawable *drawable,
|
||||
gint height,
|
||||
gboolean limit,
|
||||
GimpPreview *preview)
|
||||
{
|
||||
GimpPixelRgn src_rgn, dest_rgn;
|
||||
guchar *src_row, *dest_row;
|
||||
guchar *src, *dest;
|
||||
gulong *average;
|
||||
gint row, col, b, bpp;
|
||||
gint x, y, y_step, inten, v;
|
||||
gulong count;
|
||||
gint x1, y1, x2, y2;
|
||||
gint progress, max_progress;
|
||||
gpointer pr;
|
||||
|
||||
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
||||
|
||||
bpp = (gimp_drawable_is_rgb (drawable->drawable_id)) ? 3 : 1;
|
||||
average = g_new (gulong, bpp);
|
||||
|
||||
/* Initialize progress */
|
||||
progress = 0;
|
||||
max_progress = 2 * (x2 - x1) * (y2 - y1);
|
||||
|
||||
for (y = y1; y < y2; y += height - (y % height))
|
||||
{
|
||||
for (x = x1; x < x2; ++x)
|
||||
{
|
||||
y_step = height - (y % height);
|
||||
y_step = MIN (y_step, x2 - x);
|
||||
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable, x, y, 1, y_step,
|
||||
FALSE, FALSE);
|
||||
for (b = 0; b < bpp; b++)
|
||||
average[b] = 0;
|
||||
count = 0;
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process(pr))
|
||||
{
|
||||
src_row = src_rgn.data;
|
||||
for (row = 0; row < src_rgn.h; row++)
|
||||
{
|
||||
src = src_row;
|
||||
for (col = 0; col < src_rgn.w; col++)
|
||||
{
|
||||
for (b = 0; b < bpp; b++)
|
||||
average[b] += src[b];
|
||||
src += src_rgn.bpp;
|
||||
count += 1;
|
||||
}
|
||||
src_row += src_rgn.rowstride;
|
||||
}
|
||||
/* Update progress */
|
||||
progress += src_rgn.w * src_rgn.h;
|
||||
gimp_progress_update ((double) progress / (double) max_progress);
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
for (b = 0; b < bpp; b++)
|
||||
average[b] = (guchar) (average[b] / count);
|
||||
|
||||
if (bpp < 3)
|
||||
inten = average[0] / 254.0 * height;
|
||||
else
|
||||
inten = GIMP_RGB_LUMINANCE (average[0],
|
||||
average[1],
|
||||
average[2]) / 254.0 * height;
|
||||
|
||||
gimp_pixel_rgn_init (&dest_rgn,
|
||||
drawable, x, y, 1, y_step, TRUE, TRUE);
|
||||
for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process(pr))
|
||||
{
|
||||
dest_row = dest_rgn.data;
|
||||
for (row = 0; row < dest_rgn.h; row++)
|
||||
{
|
||||
dest = dest_row;
|
||||
v = inten > row ? 255 : 0;
|
||||
if (limit)
|
||||
{
|
||||
if (row == 0)
|
||||
v = 255;
|
||||
else if (row == height-1)
|
||||
v = 0;
|
||||
}
|
||||
for (b = 0; b < bpp; b++)
|
||||
dest[b] = v;
|
||||
dest_row += dest_rgn.rowstride;
|
||||
}
|
||||
/* Update progress */
|
||||
progress += dest_rgn.w * dest_rgn.h;
|
||||
gimp_progress_update((double) progress / (double) max_progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free (average);
|
||||
|
||||
/* update the engraved region */
|
||||
gimp_drawable_flush( drawable);
|
||||
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint x, y, h;
|
||||
gint width;
|
||||
guchar *data;
|
||||
} PixelArea;
|
||||
|
||||
static PixelArea area;
|
||||
|
||||
static void
|
||||
engrave_small (GimpDrawable *drawable,
|
||||
gint line_height,
|
||||
gboolean limit,
|
||||
gint tile_width,
|
||||
GimpPreview *preview)
|
||||
{
|
||||
GimpPixelRgn src_rgn, dest_rgn;
|
||||
gint bpp, num_channels;
|
||||
gint x1, y1, x2, y2;
|
||||
gint width, height;
|
||||
gint progress, max_progress;
|
||||
|
||||
/*
|
||||
For speed efficiency, operates on PixelAreas, whose each width and
|
||||
height are less than tile size.
|
||||
|
||||
If both ends of area cannot be divided by line_height ( as
|
||||
x1%line_height != 0 etc.), operates on the remainder pixels.
|
||||
*/
|
||||
|
||||
if (preview)
|
||||
{
|
||||
gimp_preview_get_position (preview, &x1, &y1);
|
||||
gimp_preview_get_size (preview, &width, &height);
|
||||
|
||||
x2 = x1 + width;
|
||||
y2 = y1 + height;
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
|
||||
|
||||
width = x2 - x1;
|
||||
height = y2 - y1;
|
||||
}
|
||||
gimp_pixel_rgn_init (&src_rgn, drawable,
|
||||
x1, y1, width, height, FALSE, FALSE);
|
||||
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
||||
x1, y1, width, height, (preview == NULL), TRUE);
|
||||
|
||||
/* Initialize progress */
|
||||
progress = 0;
|
||||
max_progress = width * height;
|
||||
|
||||
bpp = drawable->bpp;
|
||||
num_channels = (gimp_drawable_is_rgb (drawable->drawable_id)) ? 3 : 1;
|
||||
|
||||
area.width = (tile_width / line_height) * line_height;
|
||||
area.data = g_new(guchar, (glong) bpp * area.width * area.width);
|
||||
|
||||
for (area.y = y1; area.y < y2;
|
||||
area.y += area.width - (area.y % area.width))
|
||||
{
|
||||
area.h = area.width - (area.y % area.width);
|
||||
area.h = MIN(area.h, y2 - area.y);
|
||||
for (area.x = x1; area.x < x2; ++area.x)
|
||||
{
|
||||
gimp_pixel_rgn_get_rect (&src_rgn, area.data, area.x, area.y, 1,
|
||||
area.h);
|
||||
|
||||
engrave_sub (line_height, limit, bpp, num_channels);
|
||||
|
||||
gimp_pixel_rgn_set_rect (&dest_rgn, area.data,
|
||||
area.x, area.y, 1, area.h);
|
||||
}
|
||||
if (!preview)
|
||||
{
|
||||
/* Update progress */
|
||||
progress += area.h * width;
|
||||
gimp_progress_update ((double) progress / (double) max_progress);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(area.data);
|
||||
|
||||
/* update the engraved region */
|
||||
if (preview)
|
||||
{
|
||||
gimp_drawable_preview_draw_region (GIMP_DRAWABLE_PREVIEW (preview),
|
||||
&dest_rgn);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_progress_update (1.0);
|
||||
gimp_drawable_flush (drawable);
|
||||
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
engrave_sub (gint height,
|
||||
gint limit,
|
||||
gint bpp,
|
||||
gint num_channels)
|
||||
{
|
||||
glong average[3]; /* num_channels <= 3 */
|
||||
gint y, h, inten, v;
|
||||
guchar *buf_row, *buf;
|
||||
gint row;
|
||||
gint rowstride;
|
||||
gint count;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail ((num_channels == 1) || (num_channels == 3));
|
||||
|
||||
/*
|
||||
Since there's so many nested FOR's,
|
||||
put a few of them here...
|
||||
*/
|
||||
|
||||
rowstride = bpp;
|
||||
|
||||
for (y = area.y; y < area.y + area.h; y += height - (y % height))
|
||||
{
|
||||
h = height - (y % height);
|
||||
h = MIN(h, area.y + area.h - y);
|
||||
|
||||
for (i = 0; i < num_channels; i++)
|
||||
average[i] = 0;
|
||||
count = 0;
|
||||
|
||||
/* Read */
|
||||
buf_row = area.data + (y - area.y) * rowstride;
|
||||
|
||||
for (row = 0; row < h; row++)
|
||||
{
|
||||
buf = buf_row;
|
||||
for (i = 0; i < num_channels; i++)
|
||||
average[i] += buf[i];
|
||||
count++;
|
||||
buf_row += rowstride;
|
||||
}
|
||||
|
||||
/* Average */
|
||||
if (count > 0)
|
||||
for (i = 0; i < num_channels; i++)
|
||||
average[i] /= count;
|
||||
|
||||
if (num_channels == 1)
|
||||
inten = average[0] / 254.0 * height;
|
||||
else
|
||||
inten = GIMP_RGB_LUMINANCE (average[0],
|
||||
average[1],
|
||||
average[2]) / 254.0 * height;
|
||||
|
||||
/* Write */
|
||||
buf_row = area.data + (y - area.y) * rowstride;
|
||||
|
||||
for (row = 0; row < h; row++)
|
||||
{
|
||||
buf = buf_row;
|
||||
v = inten > row ? 255 : 0;
|
||||
if (limit)
|
||||
{
|
||||
if (row == 0)
|
||||
v = 255;
|
||||
else if (row == height-1)
|
||||
v = 0;
|
||||
}
|
||||
for (i = 0; i < num_channels; i++)
|
||||
buf[i] = v;
|
||||
buf_row += rowstride;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ edge_RC = edge.rc.o
|
|||
edge_dog_RC = edge-dog.rc.o
|
||||
edge_neon_RC = edge-neon.rc.o
|
||||
emboss_RC = emboss.rc.o
|
||||
engrave_RC = engrave.rc.o
|
||||
file_aa_RC = file-aa.rc.o
|
||||
file_cel_RC = file-cel.rc.o
|
||||
file_compressor_RC = file-compressor.rc.o
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
'edge-dog' => { ui => 1 },
|
||||
'edge-neon' => { ui => 1 },
|
||||
'emboss' => { ui => 1 },
|
||||
'engrave' => { ui => 1 },
|
||||
'file-aa' => { ui => 1, gegl => 1, optional => 1, libs => 'AA_LIBS' },
|
||||
'file-cel' => { ui => 1, gegl => 1 },
|
||||
'file-csource' => { ui => 1, gegl => 1 },
|
||||
|
|
|
@ -33,7 +33,6 @@ plug-ins/common/edge.c
|
|||
plug-ins/common/edge-dog.c
|
||||
plug-ins/common/edge-neon.c
|
||||
plug-ins/common/emboss.c
|
||||
plug-ins/common/engrave.c
|
||||
plug-ins/common/file-aa.c
|
||||
plug-ins/common/file-cel.c
|
||||
plug-ins/common/file-csource.c
|
||||
|
|
|
@ -857,6 +857,56 @@ CODE
|
|||
);
|
||||
}
|
||||
|
||||
sub plug_in_engrave {
|
||||
$blurb = 'Simulate an antique engraving';
|
||||
|
||||
$help = <<'HELP';
|
||||
Creates a black-and-white 'engraved' version of an image as seen in
|
||||
old illustrations.
|
||||
HELP
|
||||
|
||||
&std_pdb_compat('gegl:engrave');
|
||||
$date = '2014';
|
||||
|
||||
@inargs = (
|
||||
{ name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
|
||||
desc => 'The run mode' },
|
||||
{ name => 'image', type => 'image', dead => 1,
|
||||
desc => 'Input image (unused)' },
|
||||
{ name => 'drawable', type => 'drawable',
|
||||
desc => 'Input drawable' },
|
||||
{ name => 'height', type => '2 <= int32 <= 16',
|
||||
desc => 'Resolution in pixels' },
|
||||
{ name => 'limit', type => 'boolean',
|
||||
desc => 'Limit line width' }
|
||||
);
|
||||
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
|
||||
GIMP_PDB_ITEM_CONTENT, error) &&
|
||||
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
|
||||
{
|
||||
GeglNode *node;
|
||||
|
||||
node = gegl_node_new_child (NULL,
|
||||
"operation", "gegl:engrave",
|
||||
"row-height", height,
|
||||
"limit", limit,
|
||||
NULL);
|
||||
|
||||
gimp_drawable_apply_operation (drawable, progress,
|
||||
C_("undo-type", "Engrave"),
|
||||
node);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
}
|
||||
CODE
|
||||
);
|
||||
}
|
||||
|
||||
sub plug_in_exchange {
|
||||
$blurb = 'Swap one color with another';
|
||||
|
||||
|
@ -3330,6 +3380,7 @@ CODE
|
|||
plug_in_convmatrix
|
||||
plug_in_cubism
|
||||
plug_in_deinterlace
|
||||
plug_in_engrave
|
||||
plug_in_exchange
|
||||
plug_in_gauss
|
||||
plug_in_gauss_iir
|
||||
|
|
Loading…
Reference in New Issue