2007-06-06 08:44:52 +00:00
|
|
|
/* borderaverage 0.01 - image processing plug-in for GIMP.
|
1998-10-22 11:39:32 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Philipp Klaus (webmaster@access.ch)
|
|
|
|
*
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-10-22 11:39:32 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-10-22 11:39:32 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-10-22 11:39:32 +00:00
|
|
|
*/
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2005-03-04 15:12:29 +00:00
|
|
|
#include "config.h"
|
2000-01-11 15:48:00 +00:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
|
|
|
2005-08-13 18:29:14 +00:00
|
|
|
#define PLUG_IN_PROC "plug-in-borderaverage"
|
2008-03-24 15:29:55 +00:00
|
|
|
#define PLUG_IN_BINARY "border-average"
|
2011-04-08 20:31:34 +02:00
|
|
|
#define PLUG_IN_ROLE "gimp-border-average"
|
2005-08-13 18:29:14 +00:00
|
|
|
|
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
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 ())
|
2023-10-18 18:29:37 +02:00
|
|
|
#define BORDER_AVERAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BORDER_AVERAGE_TYPE, BorderAverage))
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpDrawable **drawables,
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-28 12:23:16 +02:00
|
|
|
gpointer run_data);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
static void borderaverage (GObject *config,
|
|
|
|
GeglBuffer *buffer,
|
2019-08-28 12:23:16 +02:00
|
|
|
GimpDrawable *drawable,
|
2024-03-25 02:21:54 +00:00
|
|
|
GeglColor *result);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
static gboolean borderaverage_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
static void add_new_color (const guchar *buffer,
|
2004-10-16 23:42:02 +00:00
|
|
|
gint *cube,
|
|
|
|
gint bucket_expo);
|
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (BorderAverage, border_average, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (BORDER_AVERAGE_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-28 12:23:16 +02:00
|
|
|
|
1998-10-22 11:39:32 +00:00
|
|
|
|
|
|
|
static void
|
2019-08-28 12:23:16 +02:00
|
|
|
border_average_class_init (BorderAverageClass *klass)
|
1998-10-22 11:39:32 +00:00
|
|
|
{
|
2019-08-28 12:23:16 +02:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = border_average_query_procedures;
|
|
|
|
plug_in_class->create_procedure = border_average_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
1998-10-22 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-28 12:23:16 +02:00
|
|
|
border_average_init (BorderAverage *film)
|
1998-10-22 11:39:32 +00:00
|
|
|
{
|
2019-08-28 12:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-07-01 22:30:25 +02:00
|
|
|
const gchar *name)
|
2019-08-28 12:23:16 +02:00
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
2024-03-28 13:51:55 +00:00
|
|
|
GeglColor *default_return_color;
|
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
default_return_color = gegl_color_new ("none");
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
if (! strcmp (name, PLUG_IN_PROC))
|
|
|
|
{
|
2023-10-01 18:23:57 +02:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
border_average_run, NULL, NULL);
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "RGB*");
|
2021-04-02 02:55:46 +02:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
|
2019-08-28 12:23:16 +02:00
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("_Border Average..."));
|
2019-08-28 12:23:16 +02:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Info");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-04 22:50:53 +02:00
|
|
|
_("Set foreground to the average color of the image border"),
|
2019-08-28 12:23:16 +02:00
|
|
|
"",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Philipp Klaus",
|
|
|
|
"Internet Access AG",
|
|
|
|
"1998");
|
|
|
|
|
2024-06-12 16:53:12 +00:00
|
|
|
gimp_procedure_add_int_argument (procedure, "thickness",
|
|
|
|
_("_Thickness"),
|
|
|
|
_("Border size to take in count"),
|
|
|
|
0, G_MAXINT, 3,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
gimp_procedure_add_unit_aux_argument (procedure, "thickness-unit",
|
|
|
|
_("Thickness unit of measure"),
|
|
|
|
_("Border size unit of measure"),
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
TRUE, TRUE, gimp_unit_pixel (),
|
2024-06-12 16:53:12 +00:00
|
|
|
GIMP_PARAM_READWRITE);
|
2024-07-26 18:56:53 +00:00
|
|
|
gimp_procedure_add_choice_argument (procedure, "bucket-exponent",
|
|
|
|
_("Bucket Si_ze"),
|
|
|
|
_("Bits for bucket size"),
|
|
|
|
gimp_choice_new_with_values ("levels-1", 0, _("1"), NULL,
|
|
|
|
"levels-2", 1, _("2"), NULL,
|
|
|
|
"levels-4", 2, _("4"), NULL,
|
2024-07-28 13:10:05 +02:00
|
|
|
"levels-8", 3, _("8"), NULL,
|
2024-07-26 18:56:53 +00:00
|
|
|
"levels-16", 4, _("16"), NULL,
|
|
|
|
"levels-32", 5, _("32"), NULL,
|
|
|
|
"levels-64", 6, _("64"), NULL,
|
|
|
|
"levels-128", 7, _("128"), NULL,
|
|
|
|
"levels-256", 8, _("256"), NULL,
|
|
|
|
NULL),
|
|
|
|
"levels-16",
|
|
|
|
G_PARAM_READWRITE);
|
2024-06-12 16:53:12 +00:00
|
|
|
|
|
|
|
gimp_procedure_add_color_return_value (procedure, "borderaverage",
|
|
|
|
_("The average color of the specified border."),
|
|
|
|
_("The average color of the specified border."),
|
|
|
|
TRUE, default_return_color,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-28 12:23:16 +02:00
|
|
|
}
|
2024-03-28 13:51:55 +00:00
|
|
|
g_object_unref (default_return_color);
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
border_average_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2021-04-02 02:55:46 +02:00
|
|
|
GimpDrawable **drawables,
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-28 12:23:16 +02:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpValueArray *return_vals = NULL;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2024-03-25 02:21:54 +00:00
|
|
|
GeglColor *result_color;
|
2023-07-01 22:30:25 +02:00
|
|
|
GeglBuffer *buffer;
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
gegl_init (NULL, NULL);
|
1999-05-29 16:35:47 +00:00
|
|
|
|
2024-10-28 12:16:13 +01:00
|
|
|
if (gimp_core_object_array_get_length ((GObject **) drawables) != 1)
|
2021-04-02 02:55:46 +02:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
|
|
|
|
_("Procedure '%s' only works with one drawable."),
|
|
|
|
PLUG_IN_PROC);
|
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawable = drawables[0];
|
|
|
|
}
|
|
|
|
|
2024-03-25 02:21:54 +00:00
|
|
|
result_color = gegl_color_new ("transparent");
|
2019-08-28 12:23:16 +02:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE &&
|
|
|
|
! borderaverage_dialog (procedure, G_OBJECT (config), image, drawable))
|
2024-03-25 02:21:54 +00:00
|
|
|
{
|
|
|
|
g_object_unref (result_color);
|
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL);
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2000-01-11 15:48:00 +00:00
|
|
|
{
|
2000-01-13 15:39:26 +00:00
|
|
|
/* Make sure that the drawable is RGB color */
|
2019-08-28 12:23:16 +02:00
|
|
|
if (gimp_drawable_is_rgb (drawable))
|
2003-12-23 22:07:06 +00:00
|
|
|
{
|
2005-09-30 08:16:10 +00:00
|
|
|
gimp_progress_init ( _("Border Average"));
|
2024-03-25 02:21:54 +00:00
|
|
|
borderaverage (G_OBJECT (config), buffer, drawable, result_color);
|
2003-12-23 22:07:06 +00:00
|
|
|
|
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2024-03-25 02:21:54 +00:00
|
|
|
gimp_context_set_foreground (result_color);
|
2003-12-23 22:07:06 +00:00
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
else
|
2003-12-23 22:07:06 +00:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
}
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
g_object_unref (buffer);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
return_vals = gimp_procedure_new_return_values (procedure, status, NULL);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2024-03-25 02:21:54 +00:00
|
|
|
GIMP_VALUES_SET_COLOR (return_vals, 1, result_color);
|
2019-08-28 12:23:16 +02:00
|
|
|
|
|
|
|
return return_vals;
|
1998-10-22 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
2004-05-25 20:16:07 +00:00
|
|
|
|
|
|
|
static void
|
2023-04-06 03:38:16 +00:00
|
|
|
borderaverage (GObject *config,
|
|
|
|
GeglBuffer *buffer,
|
2019-08-28 12:23:16 +02:00
|
|
|
GimpDrawable *drawable,
|
2024-03-25 02:21:54 +00:00
|
|
|
GeglColor *result)
|
1999-11-23 20:29:20 +00:00
|
|
|
{
|
2013-07-15 22:48:41 +02:00
|
|
|
gint x, y, width, height;
|
|
|
|
gint max;
|
|
|
|
guchar r, g, b;
|
|
|
|
gint bucket_num, bucket_expo, bucket_rexpo;
|
|
|
|
gint *cube;
|
|
|
|
gint i, j, k;
|
|
|
|
GeglRectangle border[4];
|
2023-04-06 03:38:16 +00:00
|
|
|
gint borderaverage_thickness;
|
|
|
|
gint borderaverage_bucket_exponent;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
"thickness", &borderaverage_thickness,
|
|
|
|
NULL);
|
2024-07-26 18:56:53 +00:00
|
|
|
borderaverage_bucket_exponent =
|
|
|
|
gimp_procedure_config_get_choice_id (GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
"bucket-exponent");
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2019-08-28 12:23:16 +02:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
2015-08-30 11:22:27 +10:00
|
|
|
{
|
2024-03-25 02:21:54 +00:00
|
|
|
gegl_color_set_rgba (result, 0.0, 0.0, 0.0, 1.0);
|
2015-08-30 11:22:27 +10:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
/* allocate and clear the cube before */
|
|
|
|
bucket_expo = borderaverage_bucket_exponent;
|
|
|
|
bucket_rexpo = 8 - bucket_expo;
|
2013-07-15 22:48:41 +02:00
|
|
|
cube = g_new (gint, 1 << (bucket_rexpo * 3));
|
2000-01-11 15:48:00 +00:00
|
|
|
bucket_num = 1 << bucket_rexpo;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
for (i = 0; i < bucket_num; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < bucket_num; j++)
|
2003-12-23 22:07:06 +00:00
|
|
|
{
|
|
|
|
for (k = 0; k < bucket_num; k++)
|
|
|
|
{
|
|
|
|
cube[(i << (bucket_rexpo << 1)) + (j << bucket_rexpo) + k] = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
/* Top */
|
|
|
|
border[0].x = x;
|
|
|
|
border[0].y = y;
|
|
|
|
border[0].width = width;
|
|
|
|
border[0].height = borderaverage_thickness;
|
|
|
|
|
|
|
|
/* Bottom */
|
|
|
|
border[1].x = x;
|
|
|
|
border[1].y = y + height - borderaverage_thickness;
|
|
|
|
border[1].width = width;
|
|
|
|
border[1].height = borderaverage_thickness;
|
|
|
|
|
|
|
|
/* Left */
|
|
|
|
border[2].x = x;
|
|
|
|
border[2].y = y + borderaverage_thickness;
|
|
|
|
border[2].width = borderaverage_thickness;
|
|
|
|
border[2].height = height - 2 * borderaverage_thickness;
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
/* Right */
|
|
|
|
border[3].x = x + width - borderaverage_thickness;
|
|
|
|
border[3].y = y + borderaverage_thickness;
|
|
|
|
border[3].width = borderaverage_thickness;
|
|
|
|
border[3].height = height - 2 * borderaverage_thickness;
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
/* Fill the cube */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (border[i].width > 0 && border[i].height > 0)
|
|
|
|
{
|
|
|
|
GeglBufferIterator *gi;
|
|
|
|
|
|
|
|
gi = gegl_buffer_iterator_new (buffer, &border[i], 0, babl_format ("R'G'B' u8"),
|
2018-09-11 01:52:18 +02:00
|
|
|
GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE, 1);
|
2002-05-03 16:12:40 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
while (gegl_buffer_iterator_next (gi))
|
|
|
|
{
|
|
|
|
guint k;
|
|
|
|
guchar *data;
|
|
|
|
|
2018-09-11 01:52:18 +02:00
|
|
|
data = (guchar*) gi->items[0].data;
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2013-07-15 22:48:41 +02:00
|
|
|
for (k = 0; k < gi->length; k++)
|
|
|
|
{
|
|
|
|
add_new_color (data + k * 3,
|
|
|
|
cube,
|
|
|
|
bucket_expo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
max = 0; r = 0; g = 0; b = 0;
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
/* get max of cube */
|
|
|
|
for (i = 0; i < bucket_num; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < bucket_num; j++)
|
2003-12-23 22:07:06 +00:00
|
|
|
{
|
|
|
|
for (k = 0; k < bucket_num; k++)
|
|
|
|
{
|
|
|
|
if (cube[(i << (bucket_rexpo << 1)) +
|
|
|
|
(j << bucket_rexpo) + k] > max)
|
|
|
|
{
|
|
|
|
max = cube[(i << (bucket_rexpo << 1)) +
|
2013-07-15 22:48:41 +02:00
|
|
|
(j << bucket_rexpo) + k];
|
2003-12-23 22:07:06 +00:00
|
|
|
r = (i<<bucket_expo) + (1<<(bucket_expo - 1));
|
|
|
|
g = (j<<bucket_expo) + (1<<(bucket_expo - 1));
|
|
|
|
b = (k<<bucket_expo) + (1<<(bucket_expo - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
}
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
/* return the color */
|
2024-03-25 02:21:54 +00:00
|
|
|
gegl_color_set_rgba (result, r / 255.0, g / 255.0, b / 255.0, 1.0);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
g_free (cube);
|
|
|
|
}
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
static void
|
2013-07-15 22:48:41 +02:00
|
|
|
add_new_color (const guchar *buffer,
|
2004-10-16 23:42:02 +00:00
|
|
|
gint *cube,
|
2004-05-25 20:16:07 +00:00
|
|
|
gint bucket_expo)
|
1999-11-23 20:29:20 +00:00
|
|
|
{
|
2000-01-11 15:48:00 +00:00
|
|
|
guchar r, g, b;
|
2003-12-23 22:07:06 +00:00
|
|
|
gint bucket_rexpo;
|
2000-01-11 15:48:00 +00:00
|
|
|
|
|
|
|
bucket_rexpo = 8 - bucket_expo;
|
2004-05-25 20:16:07 +00:00
|
|
|
r = buffer[0] >> bucket_expo;
|
2013-07-15 22:48:41 +02:00
|
|
|
g = buffer[1] >> bucket_expo;
|
|
|
|
b = buffer[2] >> bucket_expo;
|
2000-01-11 15:48:00 +00:00
|
|
|
cube[(r << (bucket_rexpo << 1)) + (g << bucket_rexpo) + b]++;
|
|
|
|
}
|
|
|
|
|
2004-05-18 18:13:48 +00:00
|
|
|
static gboolean
|
2023-04-06 03:38:16 +00:00
|
|
|
borderaverage_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable)
|
1999-11-23 20:29:20 +00:00
|
|
|
{
|
2024-07-26 18:56:53 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *size_entry;
|
|
|
|
gboolean run;
|
|
|
|
gdouble xres, yres;
|
|
|
|
GeglBuffer *buffer = NULL;
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2019-09-20 19:39:00 +02:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
dialog = gimp_procedure_dialog_new (procedure,
|
|
|
|
GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
_("Border Average"));
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"border-size-label",
|
2023-07-18 00:06:26 +02:00
|
|
|
_("Border Size"),
|
|
|
|
FALSE, FALSE);
|
1998-10-22 11:39:32 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
/* Get the image resolution */
|
2019-08-28 12:23:16 +02:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2023-04-06 03:38:16 +00:00
|
|
|
size_entry = gimp_procedure_dialog_get_size_entry (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"thickness", TRUE,
|
|
|
|
"thickness-unit", "%a",
|
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
|
|
|
xres);
|
2004-09-28 18:48:12 +00:00
|
|
|
|
|
|
|
/* set the size (in pixels) that will be treated as 0% and 100% */
|
2019-08-28 12:23:16 +02:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable);
|
2016-07-30 21:17:16 -06:00
|
|
|
if (buffer)
|
2016-08-03 23:41:58 +02:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_entry), 0, 0.0,
|
|
|
|
MIN (gegl_buffer_get_width (buffer),
|
|
|
|
gegl_buffer_get_height (buffer)));
|
2023-06-21 17:33:04 +02:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_entry), 0, 1.0,
|
|
|
|
MIN (gegl_buffer_get_width (buffer),
|
|
|
|
gegl_buffer_get_height (buffer)) / 2);
|
2000-01-13 15:39:26 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"border-size-frame", "border-size-label",
|
|
|
|
FALSE, "thickness");
|
2000-01-13 15:39:26 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"bucket-size-label",
|
2023-07-18 00:06:26 +02:00
|
|
|
_("Number of Colors"),
|
|
|
|
FALSE, FALSE);
|
2004-05-18 18:13:48 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"bucket-size-frame", "bucket-size-label",
|
|
|
|
FALSE, "bucket-exponent");
|
2004-04-20 12:21:17 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"border-size-frame",
|
|
|
|
"bucket-size-frame",
|
|
|
|
NULL);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-10-16 23:42:02 +00:00
|
|
|
gtk_widget_show (dialog);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2023-04-06 03:38:16 +00:00
|
|
|
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2004-10-16 23:42:02 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
return run;
|
2000-01-11 15:48:00 +00:00
|
|
|
}
|