gimp/plug-ins/common/border-average.c

455 lines
16 KiB
C
Raw Normal View History

/* borderaverage 0.01 - image processing plug-in for GIMP.
*
* Copyright (C) 1998 Philipp Klaus (webmaster@access.ch)
*
*
* 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 <https://www.gnu.org/licenses/>.
*/
2000-01-11 15:48:00 +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"
#define PLUG_IN_PROC "plug-in-borderaverage"
Renamed tons of plug-ins to make more sense and to be consistent: 2008-03-24 Michael Natterer <mitch@gimp.org> Renamed tons of plug-ins to make more sense and to be consistent: * plug-ins/common/AlienMap2.c -> alien-map.c * plug-ins/common/CEL.c -> cel.c * plug-ins/common/CML_explorer.c -> cml-explorer.c * plug-ins/common/align_layers.c -> align-layers.c * plug-ins/common/animationplay.c -> animation-play.c * plug-ins/common/animoptimize.c -> animation-optimize.c * plug-ins/common/apply_lens.c -> lens-apply.c * plug-ins/common/autocrop.c -> crop-auto.c * plug-ins/common/autostretch_hsv.c -> contrast-stretch-hsv.c * plug-ins/common/borderaverage.c -> border-average.c * plug-ins/common/bumpmap.c -> bump-map.c * plug-ins/common/c_astretch.c -> contrast-stretch.c * plug-ins/common/ccanalyze.c -> color-cube-analyze.c * plug-ins/common/channel_mixer.c -> channel-mixer.c * plug-ins/common/color_enhance.c -> color-enhance.c * plug-ins/common/colortoalpha.c -> color-to-alpha.c * plug-ins/common/convmatrix.c -> convolution-matrix.c * plug-ins/common/curve_bend.c -> curve-bend.c * plug-ins/common/depthmerge.c -> depth-merge.c * plug-ins/common/dog.c -> edge-dog.c * plug-ins/common/exchange.c -> color-exchange.c * plug-ins/common/flarefx.c -> lens-flare.c * plug-ins/common/fp.c -> filter-pack.c * plug-ins/common/fractaltrace.c -> fractal-trace.c * plug-ins/common/gauss.c -> blur-gauss.c * plug-ins/common/gee_zoom.c -> gee-zoom.c * plug-ins/common/glasstile.c -> tile-glass.c * plug-ins/common/gqbist.c -> qbist.c * plug-ins/common/gradmap.c -> gradient-map.c * plug-ins/common/laplace.c -> edge-laplace.c * plug-ins/common/lens.c -> lens-distortion.c * plug-ins/common/lic.c -> van-gogh-lic.c * plug-ins/common/max_rgb.c -> max-rgb.c * plug-ins/common/mblur.c -> blur-motion.c * plug-ins/common/nlfilt.c -> nl-filter.c * plug-ins/common/noisify.c -> noise-rgb.c * plug-ins/common/normalize.c -> contrast-normalize.c * plug-ins/common/papertile.c -> tile-paper.c * plug-ins/common/polar.c -> polar-coords.c * plug-ins/common/randomize.c -> noise-randomize.c * plug-ins/common/redeye.c -> red-eye-removal.c * plug-ins/common/retinex.c -> contrast-retinex.c * plug-ins/common/sample_colorize.c -> sample-colorize.c * plug-ins/common/scatter_hsv.c -> noise-hsv.c * plug-ins/common/sel_gauss.c -> blur-gauss-selective.c * plug-ins/common/semiflatten.c -> semi-flatten.c * plug-ins/common/smooth_palette.c -> smooth-palette.c * plug-ins/common/snoise.c -> noise-solid.c * plug-ins/common/sobel.c -> edge-sobel.c * plug-ins/common/spheredesigner.c -> sphere-designer.c * plug-ins/common/spread.c -> noise-spread.c * plug-ins/common/struc.c -> apply-canvas.c * plug-ins/common/threshold_alpha.c -> threshold-alpha.c * plug-ins/common/tileit.c -> tile-small.c * plug-ins/common/tiler.c -> tile-seamless.c * plug-ins/common/uniteditor.c -> unit-editor.c * plug-ins/common/unsharp.c -> unsharp-mask.c * plug-ins/common/vinvert.c -> value-invert.c * plug-ins/common/vpropagate.c -> value-propagate.c * plug-ins/common/webbrowser.c -> web-browser.c * plug-ins/common/whirlpinch.c -> whirl-pinch.c * plug-ins/common/zealouscrop.c -> crop-zealous.c * plug-ins/common/plugin-defs.pl: changed accordingly. * plug-ins/common/Makefile.am: regenerated. svn path=/trunk/; revision=25192
2008-03-24 15:29:55 +00:00
#define PLUG_IN_BINARY "border-average"
#define PLUG_IN_ROLE "gimp-border-average"
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 **drawables,
GimpProcedureConfig *config,
gpointer run_data);
static void borderaverage (GObject *config,
GeglBuffer *buffer,
GimpDrawable *drawable,
GeglColor *result);
static gboolean borderaverage_dialog (GimpProcedure *procedure,
GObject *config,
GimpImage *image,
GimpDrawable *drawable);
2013-07-15 22:48:41 +02:00
static void add_new_color (const guchar *buffer,
gint *cube,
gint bucket_expo);
G_DEFINE_TYPE (BorderAverage, border_average, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (BORDER_AVERAGE_TYPE)
DEFINE_STD_SET_I18N
static void
border_average_class_init (BorderAverageClass *klass)
{
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;
plug_in_class->set_i18n = STD_SET_I18N;
}
static void
border_average_init (BorderAverage *film)
{
}
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;
GeglColor *default_return_color;
gegl_init (NULL, NULL);
default_return_color = gegl_color_new ("none");
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_image_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
border_average_run, NULL, NULL);
gimp_procedure_set_image_types (procedure, "RGB*");
gimp_procedure_set_sensitivity_mask (procedure,
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
gimp_procedure_set_menu_label (procedure, _("_Border Average..."));
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Info");
gimp_procedure_set_documentation (procedure,
_("Set foreground to the average color of the image border"),
"",
name);
gimp_procedure_set_attribution (procedure,
"Philipp Klaus",
"Internet Access AG",
"1998");
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 (),
GIMP_PARAM_READWRITE);
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,
"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);
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);
}
g_object_unref (default_return_color);
return procedure;
}
static GimpValueArray *
border_average_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GimpDrawable **drawables,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpDrawable *drawable;
GimpValueArray *return_vals = NULL;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GeglColor *result_color;
GeglBuffer *buffer;
2013-07-15 22:48:41 +02:00
gegl_init (NULL, NULL);
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-29 16:35:47 +00:00
if (gimp_core_object_array_get_length ((GObject **) drawables) != 1)
{
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];
}
result_color = gegl_color_new ("transparent");
buffer = gimp_drawable_get_buffer (drawable);
2000-01-11 15:48:00 +00:00
if (run_mode == GIMP_RUN_INTERACTIVE &&
! borderaverage_dialog (procedure, G_OBJECT (config), image, drawable))
{
g_object_unref (result_color);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL);
}
2000-01-11 15:48:00 +00:00
if (status == GIMP_PDB_SUCCESS)
2000-01-11 15:48:00 +00:00
{
app/gimpui.[ch] removed & renamed some functions from gimpui.[ch] (see 2000-01-13 Michael Natterer <mitch@gimp.org> * app/gimpui.[ch] * app/preferences_dialog.c: removed & renamed some functions from gimpui.[ch] (see below). * libgimp/Makefile.am * libgimp/gimpwidgets.[ch]; new files. Functions moved from app/gimpui.[ch]. Added a constructor for the label + hscale + entry combination used in many plugins (now hscale + spinbutton). * libgimp/gimpui.h: include gimpwidgets.h * plug-ins/megawidget/megawidget.[ch]: removed all functions except the preview stuff (I'm not yet sure how to implement this in libgimp because the libgimp preview should be general enough to replace all the other plugin previews, too). * plug-ins/borderaverage/Makefile.am * plug-ins/borderaverage/borderaverage.c * plug-ins/common/plugin-defs.pl * plug-ins/common/Makefile.am * plug-ins/common/aa.c * plug-ins/common/align_layers.c * plug-ins/common/animationplay.c * plug-ins/common/apply_lens.c * plug-ins/common/blinds.c * plug-ins/common/bumpmap.c * plug-ins/common/checkerboard.c * plug-ins/common/colorify.c * plug-ins/common/convmatrix.c * plug-ins/common/cubism.c * plug-ins/common/curve_bend.c * plug-ins/common/deinterlace.c * plug-ins/common/despeckle.c * plug-ins/common/destripe.c * plug-ins/common/displace.c * plug-ins/common/edge.c * plug-ins/common/emboss.c * plug-ins/common/hot.c * plug-ins/common/nlfilt.c * plug-ins/common/pixelize.c * plug-ins/common/waves.c * plug-ins/sgi/sgi.c * plug-ins/sinus/sinus.c: ui updates like removing megawidget, using the dialog constructor, I18N fixes, indentation, ...
2000-01-13 15:39:26 +00:00
/* Make sure that the drawable is RGB color */
if (gimp_drawable_is_rgb (drawable))
{
gimp_progress_init ( _("Border Average"));
borderaverage (G_OBJECT (config), buffer, drawable, result_color);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_context_set_foreground (result_color);
}
2000-01-11 15:48:00 +00:00
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
2000-01-11 15:48:00 +00:00
}
g_object_unref (buffer);
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 15:27:05 +00:00
return_vals = gimp_procedure_new_return_values (procedure, status, NULL);
if (status == GIMP_PDB_SUCCESS)
GIMP_VALUES_SET_COLOR (return_vals, 1, result_color);
return return_vals;
}
static void
borderaverage (GObject *config,
GeglBuffer *buffer,
GimpDrawable *drawable,
GeglColor *result)
{
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];
gint borderaverage_thickness;
gint borderaverage_bucket_exponent;
g_object_get (config,
"thickness", &borderaverage_thickness,
NULL);
borderaverage_bucket_exponent =
gimp_procedure_config_get_choice_id (GIMP_PROCEDURE_CONFIG (config),
"bucket-exponent");
2000-01-11 15:48:00 +00:00
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
{
gegl_color_set_rgba (result, 0.0, 0.0, 0.0, 1.0);
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;
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
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++)
{
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"),
GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE, 1);
2013-07-15 22:48:41 +02:00
while (gegl_buffer_iterator_next (gi))
{
guint k;
guchar *data;
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);
}
}
}
}
2000-01-11 15:48:00 +00:00
max = 0; r = 0; g = 0; b = 0;
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++)
{
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];
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
}
2000-01-11 15:48:00 +00:00
/* return the color */
gegl_color_set_rgba (result, r / 255.0, g / 255.0, b / 255.0, 1.0);
2000-01-11 15:48:00 +00:00
g_free (cube);
}
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 15:27:05 +00:00
static void
2013-07-15 22:48:41 +02:00
add_new_color (const guchar *buffer,
gint *cube,
gint bucket_expo)
{
2000-01-11 15:48:00 +00:00
guchar r, g, b;
gint bucket_rexpo;
2000-01-11 15:48:00 +00:00
bucket_rexpo = 8 - bucket_expo;
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]++;
}
static gboolean
borderaverage_dialog (GimpProcedure *procedure,
GObject *config,
GimpImage *image,
GimpDrawable *drawable)
{
GtkWidget *dialog;
GtkWidget *size_entry;
gboolean run;
gdouble xres, yres;
GeglBuffer *buffer = NULL;
gimp_ui_init (PLUG_IN_BINARY);
dialog = gimp_procedure_dialog_new (procedure,
GIMP_PROCEDURE_CONFIG (config),
_("Border Average"));
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
"border-size-label",
_("Border Size"),
FALSE, FALSE);
/* Get the image resolution */
gimp_image_get_resolution (image, &xres, &yres);
size_entry = gimp_procedure_dialog_get_size_entry (GIMP_PROCEDURE_DIALOG (dialog),
"thickness", TRUE,
"thickness-unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE,
xres);
/* set the size (in pixels) that will be treated as 0% and 100% */
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),
gegl_buffer_get_height (buffer)));
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);
app/gimpui.[ch] removed & renamed some functions from gimpui.[ch] (see 2000-01-13 Michael Natterer <mitch@gimp.org> * app/gimpui.[ch] * app/preferences_dialog.c: removed & renamed some functions from gimpui.[ch] (see below). * libgimp/Makefile.am * libgimp/gimpwidgets.[ch]; new files. Functions moved from app/gimpui.[ch]. Added a constructor for the label + hscale + entry combination used in many plugins (now hscale + spinbutton). * libgimp/gimpui.h: include gimpwidgets.h * plug-ins/megawidget/megawidget.[ch]: removed all functions except the preview stuff (I'm not yet sure how to implement this in libgimp because the libgimp preview should be general enough to replace all the other plugin previews, too). * plug-ins/borderaverage/Makefile.am * plug-ins/borderaverage/borderaverage.c * plug-ins/common/plugin-defs.pl * plug-ins/common/Makefile.am * plug-ins/common/aa.c * plug-ins/common/align_layers.c * plug-ins/common/animationplay.c * plug-ins/common/apply_lens.c * plug-ins/common/blinds.c * plug-ins/common/bumpmap.c * plug-ins/common/checkerboard.c * plug-ins/common/colorify.c * plug-ins/common/convmatrix.c * plug-ins/common/cubism.c * plug-ins/common/curve_bend.c * plug-ins/common/deinterlace.c * plug-ins/common/despeckle.c * plug-ins/common/destripe.c * plug-ins/common/displace.c * plug-ins/common/edge.c * plug-ins/common/emboss.c * plug-ins/common/hot.c * plug-ins/common/nlfilt.c * plug-ins/common/pixelize.c * plug-ins/common/waves.c * plug-ins/sgi/sgi.c * plug-ins/sinus/sinus.c: ui updates like removing megawidget, using the dialog constructor, I18N fixes, indentation, ...
2000-01-13 15:39:26 +00:00
gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
"border-size-frame", "border-size-label",
FALSE, "thickness");
app/gimpui.[ch] removed & renamed some functions from gimpui.[ch] (see 2000-01-13 Michael Natterer <mitch@gimp.org> * app/gimpui.[ch] * app/preferences_dialog.c: removed & renamed some functions from gimpui.[ch] (see below). * libgimp/Makefile.am * libgimp/gimpwidgets.[ch]; new files. Functions moved from app/gimpui.[ch]. Added a constructor for the label + hscale + entry combination used in many plugins (now hscale + spinbutton). * libgimp/gimpui.h: include gimpwidgets.h * plug-ins/megawidget/megawidget.[ch]: removed all functions except the preview stuff (I'm not yet sure how to implement this in libgimp because the libgimp preview should be general enough to replace all the other plugin previews, too). * plug-ins/borderaverage/Makefile.am * plug-ins/borderaverage/borderaverage.c * plug-ins/common/plugin-defs.pl * plug-ins/common/Makefile.am * plug-ins/common/aa.c * plug-ins/common/align_layers.c * plug-ins/common/animationplay.c * plug-ins/common/apply_lens.c * plug-ins/common/blinds.c * plug-ins/common/bumpmap.c * plug-ins/common/checkerboard.c * plug-ins/common/colorify.c * plug-ins/common/convmatrix.c * plug-ins/common/cubism.c * plug-ins/common/curve_bend.c * plug-ins/common/deinterlace.c * plug-ins/common/despeckle.c * plug-ins/common/destripe.c * plug-ins/common/displace.c * plug-ins/common/edge.c * plug-ins/common/emboss.c * plug-ins/common/hot.c * plug-ins/common/nlfilt.c * plug-ins/common/pixelize.c * plug-ins/common/waves.c * plug-ins/sgi/sgi.c * plug-ins/sinus/sinus.c: ui updates like removing megawidget, using the dialog constructor, I18N fixes, indentation, ...
2000-01-13 15:39:26 +00:00
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
"bucket-size-label",
_("Number of Colors"),
FALSE, FALSE);
gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
"bucket-size-frame", "bucket-size-label",
FALSE, "bucket-exponent");
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
"border-size-frame",
"bucket-size-frame",
NULL);
2000-01-11 15:48:00 +00:00
gtk_widget_show (dialog);
2000-01-11 15:48:00 +00:00
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 15:27:05 +00:00
gtk_widget_destroy (dialog);
2000-01-11 15:48:00 +00:00
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 15:27:05 +00:00
return run;
2000-01-11 15:48:00 +00:00
}