plug-ins: port border-average to new API.
This commit is contained in:
parent
f75b63fa80
commit
1b992e98d3
3 changed files with 129 additions and 85 deletions
|
|
@ -296,8 +296,6 @@ blinds_LDADD = \
|
|||
$(INTLLIBS) \
|
||||
$(blinds_RC)
|
||||
|
||||
border_average_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
|
||||
|
||||
border_average_SOURCES = \
|
||||
border-average.c
|
||||
|
||||
|
|
|
|||
|
|
@ -30,22 +30,44 @@
|
|||
#define PLUG_IN_ROLE "gimp-border-average"
|
||||
|
||||
|
||||
/* Declare local functions.
|
||||
*/
|
||||
static void query (void);
|
||||
static void run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
typedef struct _BorderAverage BorderAverage;
|
||||
typedef struct _BorderAverageClass BorderAverageClass;
|
||||
|
||||
struct _BorderAverage
|
||||
{
|
||||
GimpPlugIn parent_instance;
|
||||
};
|
||||
|
||||
struct _BorderAverageClass
|
||||
{
|
||||
GimpPlugInClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
#define BORDER_AVERAGE_TYPE (border_average_get_type ())
|
||||
#define BORDER_AVERAGE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BORDER_AVERAGE_TYPE, BorderAverage))
|
||||
|
||||
|
||||
GType border_average_get_type (void) G_GNUC_CONST;
|
||||
|
||||
static GList * border_average_query_procedures (GimpPlugIn *plug_in);
|
||||
static GimpProcedure * border_average_create_procedure (GimpPlugIn *plug_in,
|
||||
const gchar *name);
|
||||
|
||||
static GimpValueArray * border_average_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
|
||||
|
||||
static void borderaverage (GeglBuffer *buffer,
|
||||
gint32 drawable_id,
|
||||
GimpDrawable *drawable,
|
||||
GimpRGB *result);
|
||||
|
||||
static gboolean borderaverage_dialog (gint32 image_ID,
|
||||
gint32 drawable_id);
|
||||
static gboolean borderaverage_dialog (GimpImage *image,
|
||||
GimpDrawable *drawable);
|
||||
|
||||
static void add_new_color (const guchar *buffer,
|
||||
gint *cube,
|
||||
|
|
@ -54,13 +76,11 @@ static void add_new_color (const guchar *buffer,
|
|||
static void thickness_callback (GtkWidget *widget,
|
||||
gpointer data);
|
||||
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
NULL, /* init */
|
||||
NULL, /* quit */
|
||||
query, /* query */
|
||||
run, /* run */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (BorderAverage, border_average, GIMP_TYPE_PLUG_IN)
|
||||
|
||||
GIMP_MAIN (BORDER_AVERAGE_TYPE)
|
||||
|
||||
|
||||
static gint borderaverage_thickness = 3;
|
||||
static gint borderaverage_bucket_exponent = 4;
|
||||
|
|
@ -77,63 +97,90 @@ static borderaverage_data =
|
|||
4
|
||||
};
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
query (void)
|
||||
border_average_class_init (BorderAverageClass *klass)
|
||||
{
|
||||
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, "thickness", "Border size to take in count" },
|
||||
{ GIMP_PDB_INT32, "bucket-exponent", "Bits for bucket size (default=4: 16 Levels)" },
|
||||
};
|
||||
static const GimpParamDef return_vals[] =
|
||||
{
|
||||
{ GIMP_PDB_COLOR, "borderaverage", "The average color of the specified border." },
|
||||
};
|
||||
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
||||
|
||||
gimp_install_procedure (PLUG_IN_PROC,
|
||||
N_("Set foreground to the average color of the image border"),
|
||||
"",
|
||||
"Philipp Klaus",
|
||||
"Internet Access AG",
|
||||
"1998",
|
||||
N_("_Border Average..."),
|
||||
"RGB*",
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (args),
|
||||
G_N_ELEMENTS (return_vals),
|
||||
args, return_vals);
|
||||
|
||||
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Info");
|
||||
plug_in_class->query_procedures = border_average_query_procedures;
|
||||
plug_in_class->create_procedure = border_average_create_procedure;
|
||||
}
|
||||
|
||||
static void
|
||||
run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
border_average_init (BorderAverage *film)
|
||||
{
|
||||
static GimpParam values[3];
|
||||
gint32 image_ID;
|
||||
}
|
||||
|
||||
static GList *
|
||||
border_average_query_procedures (GimpPlugIn *plug_in)
|
||||
{
|
||||
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
|
||||
}
|
||||
|
||||
static GimpProcedure *
|
||||
border_average_create_procedure (GimpPlugIn *plug_in,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpProcedure *procedure = NULL;
|
||||
|
||||
if (! strcmp (name, PLUG_IN_PROC))
|
||||
{
|
||||
procedure = gimp_image_procedure_new (plug_in, name, GIMP_PLUGIN,
|
||||
border_average_run, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_image_types (procedure, "RGB*");
|
||||
|
||||
gimp_procedure_set_menu_label (procedure, N_("_Border Average..."));
|
||||
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Info");
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
N_("Set foreground to the average color of the image border"),
|
||||
"",
|
||||
name);
|
||||
gimp_procedure_set_attribution (procedure,
|
||||
"Philipp Klaus",
|
||||
"Internet Access AG",
|
||||
"1998");
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "thickness",
|
||||
"Border size to take in count",
|
||||
"Border size to take in count",
|
||||
0, G_MAXINT, 3,
|
||||
G_PARAM_READWRITE);
|
||||
GIMP_PROC_ARG_INT (procedure, "bucket-exponent",
|
||||
"Bits for bucket size (default=4: 16 Levels)",
|
||||
"Bits for bucket size (default=4: 16 Levels)",
|
||||
0, G_MAXINT, 4,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_VAL_RGB (procedure, "borderaverage",
|
||||
"The average color of the specified border.",
|
||||
"The average color of the specified border.",
|
||||
TRUE, NULL,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
|
||||
return procedure;
|
||||
}
|
||||
|
||||
|
||||
static GimpValueArray *
|
||||
border_average_run (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpValueArray *return_vals = NULL;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GimpRGB result_color = { 0.0, };
|
||||
GimpRunMode run_mode;
|
||||
gint32 drawable_id;
|
||||
GeglBuffer *buffer;
|
||||
|
||||
INIT_I18N ();
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_id = param[2].data.d_drawable;
|
||||
|
||||
buffer = gimp_drawable_get_buffer (drawable_id);
|
||||
buffer = gimp_drawable_get_buffer (drawable);
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
|
|
@ -141,17 +188,17 @@ run (const gchar *name,
|
|||
gimp_get_data (PLUG_IN_PROC, &borderaverage_data);
|
||||
borderaverage_thickness = borderaverage_data.thickness;
|
||||
borderaverage_bucket_exponent = borderaverage_data.bucket_exponent;
|
||||
if (! borderaverage_dialog (image_ID, drawable_id))
|
||||
if (! borderaverage_dialog (image, drawable))
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
break;
|
||||
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
if (nparams != 5)
|
||||
if (gimp_value_array_length (args) != 2)
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
borderaverage_thickness = param[3].data.d_int32;
|
||||
borderaverage_bucket_exponent = param[4].data.d_int32;
|
||||
borderaverage_thickness = GIMP_VALUES_GET_INT (args, 0);
|
||||
borderaverage_bucket_exponent = GIMP_VALUES_GET_INT (args, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -168,10 +215,10 @@ run (const gchar *name,
|
|||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
/* Make sure that the drawable is RGB color */
|
||||
if (gimp_drawable_is_rgb (drawable_id))
|
||||
if (gimp_drawable_is_rgb (drawable))
|
||||
{
|
||||
gimp_progress_init ( _("Border Average"));
|
||||
borderaverage (buffer, drawable_id, &result_color);
|
||||
borderaverage (buffer, drawable, &result_color);
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
{
|
||||
|
|
@ -190,22 +237,21 @@ run (const gchar *name,
|
|||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
}
|
||||
*nreturn_vals = 3;
|
||||
*return_vals = values;
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
values[0].data.d_status = status;
|
||||
|
||||
values[1].type = GIMP_PDB_COLOR;
|
||||
values[1].data.d_color = result_color;
|
||||
|
||||
g_object_unref (buffer);
|
||||
|
||||
return_vals = gimp_procedure_new_return_values (procedure, status, NULL);
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
GIMP_VALUES_SET_RGB (return_vals, 1, &result_color);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
borderaverage (GeglBuffer *buffer,
|
||||
gint32 drawable_id,
|
||||
GimpDrawable *drawable,
|
||||
GimpRGB *result)
|
||||
{
|
||||
gint x, y, width, height;
|
||||
|
|
@ -216,7 +262,7 @@ borderaverage (GeglBuffer *buffer,
|
|||
gint i, j, k;
|
||||
GeglRectangle border[4];
|
||||
|
||||
if (! gimp_drawable_mask_intersect (drawable_id, &x, &y, &width, &height))
|
||||
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
||||
{
|
||||
gimp_rgba_set_uchar (result, 0, 0, 0, 255);
|
||||
return;
|
||||
|
|
@ -334,8 +380,8 @@ add_new_color (const guchar *buffer,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
borderaverage_dialog (gint32 image_ID,
|
||||
gint32 drawable_id)
|
||||
borderaverage_dialog (GimpImage *image,
|
||||
GimpDrawable *drawable)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *frame;
|
||||
|
|
@ -395,8 +441,8 @@ borderaverage_dialog (gint32 image_ID,
|
|||
g_object_unref (group);
|
||||
|
||||
/* Get the image resolution and unit */
|
||||
gimp_image_get_resolution (image_ID, &xres, &yres);
|
||||
unit = gimp_image_get_unit (image_ID);
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
unit = gimp_image_get_unit (image);
|
||||
|
||||
size_entry = gimp_size_entry_new (1, unit, "%a", TRUE, TRUE, FALSE, 4,
|
||||
GIMP_SIZE_ENTRY_UPDATE_SIZE);
|
||||
|
|
@ -406,7 +452,7 @@ borderaverage_dialog (gint32 image_ID,
|
|||
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_entry), 0, xres, TRUE);
|
||||
|
||||
/* set the size (in pixels) that will be treated as 0% and 100% */
|
||||
buffer = gimp_drawable_get_buffer (drawable_id);
|
||||
buffer = gimp_drawable_get_buffer (drawable);
|
||||
if (buffer)
|
||||
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_entry), 0, 0.0,
|
||||
MIN (gegl_buffer_get_width (buffer),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
'animation-optimize' => { gegl => 1, old_api => 1 },
|
||||
'animation-play' => { ui => 1, gegl => 1 },
|
||||
'blinds' => { ui => 1, gegl => 1 },
|
||||
'border-average' => { ui => 1, gegl => 1, old_api => 1 },
|
||||
'border-average' => { ui => 1, gegl => 1 },
|
||||
'busy-dialog' => { ui => 1, gegl => 1, old_api => 1 },
|
||||
'checkerboard' => { ui => 1, gegl => 1 },
|
||||
'cml-explorer' => { ui => 1, gegl => 1, old_api => 1 },
|
||||
|
|
|
|||
Loading…
Reference in a new issue