1997-11-24 22:05:25 +00:00
|
|
|
/*
|
2007-06-06 08:44:52 +00:00
|
|
|
* This is a plug-in for GIMP.
|
1997-11-24 22:05:25 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Brent Burton & the Edward Blevins
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +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
|
1997-11-24 22:05:25 +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/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-01-06 16:40:17 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-01-13 15:39:26 +00:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1999-05-29 16:35:47 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2000-04-30 21:03:44 +00:00
|
|
|
|
2005-08-13 18:29:14 +00:00
|
|
|
#define PLUG_IN_PROC "plug-in-checkerboard"
|
|
|
|
#define PLUG_IN_BINARY "checkerboard"
|
2011-04-08 20:31:34 +02:00
|
|
|
#define PLUG_IN_ROLE "gimp-checkerboard"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
typedef struct _Checkerboard Checkerboard;
|
|
|
|
typedef struct _CheckerboardClass CheckerboardClass;
|
|
|
|
|
|
|
|
struct _Checkerboard
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-30 14:12:41 +02:00
|
|
|
GimpPlugIn parent_instance;
|
1997-11-24 22:05:25 +00:00
|
|
|
};
|
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
struct _CheckerboardClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECKERBOARD_TYPE (checkerboard_get_type ())
|
2023-10-18 18:29:37 +02:00
|
|
|
#define CHECKERBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHECKERBOARD_TYPE, Checkerboard))
|
2019-08-30 14:12:41 +02:00
|
|
|
|
|
|
|
GType checkerboard_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * checkerboard_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * checkerboard_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * checkerboard_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-30 14:12:41 +02:00
|
|
|
gpointer run_data);
|
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
static void do_checkerboard_pattern (GObject *config,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void do_checkerboard_preview (GtkWidget *widget,
|
|
|
|
GObject *config);
|
|
|
|
static gint inblock (gint pos,
|
|
|
|
gint size);
|
2019-08-30 14:12:41 +02:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
static gboolean checkerboard_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable);
|
2019-08-30 14:12:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Checkerboard, checkerboard, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (CHECKERBOARD_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-30 14:12:41 +02:00
|
|
|
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
static void
|
2019-08-30 14:12:41 +02:00
|
|
|
checkerboard_class_init (CheckerboardClass *klass)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-30 14:12:41 +02:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = checkerboard_query_procedures;
|
|
|
|
plug_in_class->create_procedure = checkerboard_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-30 14:12:41 +02:00
|
|
|
checkerboard_init (Checkerboard *checkerboard)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
checkerboard_query_procedures (GimpPlugIn *plug_in)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-30 14:12:41 +02:00
|
|
|
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
static GimpProcedure *
|
|
|
|
checkerboard_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-30 14:12:41 +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,
|
|
|
|
checkerboard_run, NULL, NULL);
|
2019-08-30 14:12:41 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "RGB*, GRAY*");
|
2021-04-02 02:55:46 +02:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
|
2019-08-30 14:12:41 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure,
|
2023-06-23 14:13:29 +00:00
|
|
|
_("_Checkerboard (legacy)..."));
|
2019-08-30 14:12:41 +02:00
|
|
|
gimp_procedure_add_menu_path (procedure,
|
|
|
|
"<Image>/Filters/Render/Pattern");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2023-06-23 14:13:29 +00:00
|
|
|
_("Create a checkerboard pattern"),
|
2019-08-30 14:12:41 +02:00
|
|
|
"More here later",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Brent Burton & the Edward Blevins",
|
|
|
|
"Brent Burton & the Edward Blevins",
|
|
|
|
"1997");
|
|
|
|
|
2024-06-12 16:53:12 +00:00
|
|
|
gimp_procedure_add_boolean_argument (procedure, "psychobilly",
|
|
|
|
_("_Psychobilly"),
|
|
|
|
_("Render a psychobilly checkerboard"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_int_argument (procedure, "check-size",
|
|
|
|
_("_Size"),
|
|
|
|
_("Size of the checks"),
|
|
|
|
1, GIMP_MAX_IMAGE_SIZE, 10,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_unit_aux_argument (procedure, "check-size-unit",
|
|
|
|
_("Check size unit of measure"),
|
|
|
|
_("Check 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);
|
2019-08-30 14:12:41 +02:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
return procedure;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
static GimpValueArray *
|
|
|
|
checkerboard_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-30 14:12:41 +02:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
2023-07-01 22:30:25 +02:00
|
|
|
GimpDrawable *drawable;
|
2021-04-02 02:55:46 +02:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
gegl_init (NULL, NULL);
|
1997-11-24 22:05:25 +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];
|
|
|
|
}
|
|
|
|
|
2023-07-01 22:30:25 +02:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE &&
|
|
|
|
! checkerboard_dialog (procedure, G_OBJECT (config), image, drawable))
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
if (gimp_drawable_is_rgb (drawable) ||
|
2019-08-13 17:31:13 +02:00
|
|
|
gimp_drawable_is_gray (drawable))
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2023-06-23 14:13:29 +00:00
|
|
|
do_checkerboard_pattern (G_OBJECT (config), drawable, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2005-08-13 16:17:43 +00:00
|
|
|
gimp_displays_flush ();
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-30 14:12:41 +02:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 14:12:41 +02:00
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2003-09-13 18:07:44 +00:00
|
|
|
guchar fg[4];
|
|
|
|
guchar bg[4];
|
|
|
|
} CheckerboardParam_t;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
static void
|
2005-08-13 16:17:43 +00:00
|
|
|
checkerboard_func (gint x,
|
|
|
|
gint y,
|
|
|
|
guchar *dest,
|
|
|
|
gint bpp,
|
2023-06-23 14:13:29 +00:00
|
|
|
gint size,
|
|
|
|
gboolean mode,
|
2005-08-13 16:17:43 +00:00
|
|
|
gpointer data)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2003-09-13 18:07:44 +00:00
|
|
|
CheckerboardParam_t *param = (CheckerboardParam_t*) data;
|
2005-08-13 16:17:43 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
gint val, xp, yp;
|
|
|
|
gint b;
|
2001-01-15 00:06:43 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
if (mode)
|
2003-09-13 18:07:44 +00:00
|
|
|
{
|
|
|
|
/* Psychobilly Mode */
|
2023-06-23 14:13:29 +00:00
|
|
|
val = (inblock (x, size) != inblock (y, size));
|
2003-09-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Normal, regular checkerboard mode.
|
|
|
|
* Determine base factor (even or odd) of block
|
|
|
|
* this x/y position is in.
|
|
|
|
*/
|
2023-06-23 14:13:29 +00:00
|
|
|
xp = x / size;
|
|
|
|
yp = y / size;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
/* if both even or odd, color sqr */
|
|
|
|
val = ( (xp & 1) != (yp & 1) );
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
for (b = 0; b < bpp; b++)
|
|
|
|
dest[b] = val ? param->fg[b] : param->bg[b];
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
static void
|
2023-06-23 14:13:29 +00:00
|
|
|
do_checkerboard_pattern (GObject *config,
|
|
|
|
GimpDrawable *drawable,
|
2019-08-13 17:31:13 +02:00
|
|
|
GimpPreview *preview)
|
2003-09-13 18:07:44 +00:00
|
|
|
{
|
2004-03-12 22:46:25 +00:00
|
|
|
CheckerboardParam_t param;
|
2023-11-14 20:04:14 +01:00
|
|
|
GeglColor *color;
|
2024-09-02 02:41:47 +00:00
|
|
|
guchar fg[4] = {0, 0, 0, 0};
|
|
|
|
guchar bg[4] = {0, 0, 0, 0};
|
|
|
|
guchar fg_lum[1] = {0};
|
|
|
|
guchar bg_lum[1] = {0};
|
2019-07-07 16:04:07 +02:00
|
|
|
const Babl *format;
|
|
|
|
gint bpp;
|
2023-06-23 14:13:29 +00:00
|
|
|
gboolean mode = FALSE;
|
|
|
|
gint size = 10;
|
|
|
|
|
|
|
|
if (config)
|
|
|
|
g_object_get (config,
|
2024-06-12 16:53:12 +00:00
|
|
|
"check-size", &size,
|
|
|
|
"psychobilly", &mode,
|
2023-06-23 14:13:29 +00:00
|
|
|
NULL);
|
2003-09-13 18:07:44 +00:00
|
|
|
|
2023-11-14 20:04:14 +01:00
|
|
|
color = gimp_context_get_background ();
|
2024-09-02 02:41:47 +00:00
|
|
|
gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A u8", NULL), bg);
|
|
|
|
gegl_color_get_pixel (color, babl_format_with_space ("Y' u8", NULL), bg_lum);
|
2023-11-14 20:04:14 +01:00
|
|
|
g_object_unref (color);
|
|
|
|
color = gimp_context_get_foreground ();
|
2024-09-02 02:41:47 +00:00
|
|
|
gegl_color_get_pixel (color, babl_format_with_space ("R'G'B'A u8", NULL), fg);
|
|
|
|
gegl_color_get_pixel (color, babl_format_with_space ("Y' u8", NULL), fg_lum);
|
2023-11-14 20:04:14 +01:00
|
|
|
g_object_unref (color);
|
2004-03-12 22:46:25 +00:00
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
if (gimp_drawable_is_gray (drawable))
|
2019-06-27 13:37:04 +02:00
|
|
|
{
|
2024-09-02 02:41:47 +00:00
|
|
|
param.bg[0] = bg_lum[0];
|
|
|
|
param.bg[1] = bg[3];
|
2019-07-07 16:04:07 +02:00
|
|
|
|
2024-09-02 02:41:47 +00:00
|
|
|
param.fg[0] = fg_lum[0];
|
|
|
|
param.fg[1] = fg[3];
|
2019-07-07 16:04:07 +02:00
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2024-09-02 02:41:47 +00:00
|
|
|
format = babl_format ("Y'A u8");
|
2019-07-07 16:04:07 +02:00
|
|
|
else
|
2024-09-02 02:41:47 +00:00
|
|
|
format = babl_format ("Y' u8");
|
2019-06-27 13:37:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-09-02 02:41:47 +00:00
|
|
|
for (gint i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
param.bg[i] = bg[i];
|
|
|
|
param.fg[i] = fg[i];
|
|
|
|
}
|
2019-07-07 16:04:07 +02:00
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2024-09-02 02:41:47 +00:00
|
|
|
format = babl_format ("R'G'B'A u8");
|
2019-07-07 16:04:07 +02:00
|
|
|
else
|
2024-09-02 02:41:47 +00:00
|
|
|
format = babl_format ("R'G'B' u8");
|
2019-06-27 13:37:04 +02:00
|
|
|
}
|
2002-05-31 11:39:27 +00:00
|
|
|
|
2019-07-07 16:04:07 +02:00
|
|
|
bpp = babl_format_get_bytes_per_pixel (format);
|
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
if (size < 1)
|
2003-03-11 23:54:49 +00:00
|
|
|
{
|
|
|
|
/* make size 1 to prevent division by zero */
|
2023-06-23 14:13:29 +00:00
|
|
|
size = 1;
|
2003-03-11 23:54:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
if (preview)
|
|
|
|
{
|
|
|
|
gint x1, y1;
|
|
|
|
gint width, height;
|
|
|
|
gint i;
|
|
|
|
guchar *buffer;
|
|
|
|
|
|
|
|
gimp_preview_get_position (preview, &x1, &y1);
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2021-04-06 14:28:40 +02:00
|
|
|
bpp = gimp_drawable_get_bpp (drawable);
|
2005-08-13 16:17:43 +00:00
|
|
|
buffer = g_new (guchar, width * height * bpp);
|
|
|
|
|
|
|
|
for (i = 0; i < width * height; i++)
|
|
|
|
{
|
|
|
|
checkerboard_func (x1 + i % width,
|
|
|
|
y1 + i / width,
|
|
|
|
buffer + i * bpp,
|
2023-06-23 14:13:29 +00:00
|
|
|
bpp, size, mode,
|
|
|
|
¶m);
|
2005-08-13 16:17:43 +00:00
|
|
|
}
|
2019-07-07 16:04:07 +02:00
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
gimp_preview_draw_buffer (preview, buffer, width * bpp);
|
|
|
|
g_free (buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-07 16:04:07 +02:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
GeglBufferIterator *iter;
|
|
|
|
gint x, y, w, h;
|
|
|
|
gint progress_total;
|
|
|
|
gint progress_done = 0;
|
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &w, &h))
|
2019-07-07 16:04:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
progress_total = w * h;
|
|
|
|
|
|
|
|
gimp_progress_init (_("Checkerboard"));
|
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
buffer = gimp_drawable_get_shadow_buffer (drawable);
|
2019-07-07 16:04:07 +02:00
|
|
|
|
|
|
|
iter = gegl_buffer_iterator_new (buffer,
|
|
|
|
GEGL_RECTANGLE (x, y, w, h), 0,
|
|
|
|
format,
|
|
|
|
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE, 1);
|
|
|
|
|
|
|
|
while (gegl_buffer_iterator_next (iter))
|
|
|
|
{
|
|
|
|
GeglRectangle roi = iter->items[0].roi;
|
|
|
|
guchar *dest = iter->items[0].data;
|
|
|
|
guchar *d;
|
|
|
|
gint y1, x1;
|
|
|
|
|
|
|
|
d = dest;
|
|
|
|
|
|
|
|
for (y1 = 0; y1 < roi.height; y1++)
|
|
|
|
{
|
|
|
|
for (x1 = 0; x1 < roi.width; x1++)
|
|
|
|
{
|
|
|
|
checkerboard_func (roi.x + x1,
|
|
|
|
roi.y + y1,
|
|
|
|
d + x1 * bpp,
|
2023-06-23 14:13:29 +00:00
|
|
|
bpp, size, mode,
|
|
|
|
¶m);
|
2019-07-07 16:04:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d += roi.width * bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
progress_done += roi.width * roi.height;
|
|
|
|
gimp_progress_update ((gdouble) progress_done /
|
|
|
|
(gdouble) progress_total);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2019-08-13 17:31:13 +02:00
|
|
|
gimp_drawable_merge_shadow (drawable, TRUE);
|
|
|
|
gimp_drawable_update (drawable, x, y, w, h);
|
2005-08-13 16:17:43 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 16:04:07 +02:00
|
|
|
static void
|
2023-06-23 14:13:29 +00:00
|
|
|
do_checkerboard_preview (GtkWidget *widget,
|
|
|
|
GObject *config)
|
2019-07-07 16:04:07 +02:00
|
|
|
{
|
2023-06-23 14:13:29 +00:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
|
|
|
GimpDrawable *drawable = g_object_get_data (config, "drawable");
|
|
|
|
|
|
|
|
do_checkerboard_pattern (config, drawable, preview);
|
2019-07-07 16:04:07 +02:00
|
|
|
}
|
|
|
|
|
2000-01-13 15:39:26 +00:00
|
|
|
static gint
|
2003-11-06 15:27:05 +00:00
|
|
|
inblock (gint pos,
|
2005-08-13 16:17:43 +00:00
|
|
|
gint size)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2005-08-13 16:17:43 +00:00
|
|
|
static gint *in = NULL; /* initialized first time */
|
|
|
|
static gint len = -1;
|
2000-01-13 15:39:26 +00:00
|
|
|
|
|
|
|
/* avoid a FP exception */
|
|
|
|
if (size == 1)
|
|
|
|
size = 2;
|
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
if (in && len != size * size)
|
|
|
|
{
|
|
|
|
g_free (in);
|
|
|
|
in = NULL;
|
|
|
|
}
|
|
|
|
len = size * size;
|
2019-07-07 16:04:07 +02:00
|
|
|
|
|
|
|
/* Initialize the array; since we'll be called thousands of
|
2000-01-13 15:39:26 +00:00
|
|
|
* times with the same size value, precompute the array.
|
|
|
|
*/
|
|
|
|
if (in == NULL)
|
|
|
|
{
|
2005-08-13 16:17:43 +00:00
|
|
|
gint cell = 1; /* cell value */
|
2002-05-31 11:39:27 +00:00
|
|
|
gint i, j, k;
|
|
|
|
|
2000-01-13 15:39:26 +00:00
|
|
|
in = g_new (gint, len);
|
2002-05-31 11:39:27 +00:00
|
|
|
|
2019-07-07 16:04:07 +02:00
|
|
|
/* i is absolute index into in[]
|
2002-05-31 11:39:27 +00:00
|
|
|
* j is current number of blocks to fill in with a 1 or 0.
|
|
|
|
* k is just counter for the j cells.
|
|
|
|
*/
|
2005-08-13 16:17:43 +00:00
|
|
|
i = 0;
|
|
|
|
for (j = 1; j <= size; j++)
|
|
|
|
{ /* first half */
|
|
|
|
for (k = 0; k < j; k++)
|
|
|
|
{
|
|
|
|
in[i++] = cell;
|
|
|
|
}
|
|
|
|
cell = !cell;
|
|
|
|
}
|
|
|
|
for (j = size - 1; j >= 1; j--)
|
|
|
|
{ /* second half */
|
|
|
|
for (k = 0; k < j; k++)
|
|
|
|
{
|
|
|
|
in[i++] = cell;
|
|
|
|
}
|
|
|
|
cell = !cell;
|
|
|
|
}
|
2000-01-13 15:39:26 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2000-01-13 15:39:26 +00:00
|
|
|
/* place pos within 0..(len-1) grid and return the value. */
|
2005-08-13 16:17:43 +00:00
|
|
|
return in[pos % (len - 1)];
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-24 12:38:19 +00:00
|
|
|
static gboolean
|
2023-06-23 14:13:29 +00:00
|
|
|
checkerboard_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2005-08-13 16:17:43 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *preview;
|
1997-11-24 22:05:25 +00:00
|
|
|
GtkWidget *toggle;
|
2002-05-31 11:39:27 +00:00
|
|
|
GtkWidget *size_entry;
|
2005-08-13 16:17:43 +00:00
|
|
|
gint size, width, height;
|
2002-05-31 11:39:27 +00:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
2003-11-06 15:27:05 +00:00
|
|
|
gboolean run;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-09-20 19:39:00 +02:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
dialog = gimp_procedure_dialog_new (procedure,
|
|
|
|
GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
_("Checkerboard"));
|
2002-05-31 11:39:27 +00:00
|
|
|
|
2018-05-10 17:04:37 +02:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-08-13 16:17:43 +00:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2002-09-07 16:31:32 +00:00
|
|
|
|
2005-09-09 18:07:31 +00:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-05 21:40:29 +00:00
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
/* Get the image resolution and unit */
|
2019-08-13 17:31:13 +02:00
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2005-08-13 16:17:43 +00:00
|
|
|
|
2021-04-06 14:28:40 +02:00
|
|
|
width = gimp_drawable_get_width (drawable);
|
|
|
|
height = gimp_drawable_get_height (drawable);
|
2005-08-13 16:17:43 +00:00
|
|
|
size = MIN (width, height);
|
2001-12-29 13:26:29 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
size_entry =
|
|
|
|
gimp_procedure_dialog_get_size_entry (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"check-size", TRUE,
|
|
|
|
"check-size-unit", "%a",
|
|
|
|
GIMP_SIZE_ENTRY_UPDATE_SIZE,
|
|
|
|
xres);
|
|
|
|
gtk_widget_set_margin_bottom (size_entry, 12);
|
2002-05-31 11:39:27 +00:00
|
|
|
|
|
|
|
/* set the size (in pixels) that will be treated as 0% and 100% */
|
2002-09-07 16:31:32 +00:00
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (size_entry), 0, 0.0, size);
|
2002-05-31 11:39:27 +00:00
|
|
|
|
|
|
|
/* set upper and lower limits (in pixels) */
|
2002-09-07 16:31:32 +00:00
|
|
|
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (size_entry), 0,
|
|
|
|
1.0, size);
|
2002-05-31 11:39:27 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
toggle = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
|
2024-06-12 16:53:12 +00:00
|
|
|
"psychobilly",
|
2023-06-23 14:13:29 +00:00
|
|
|
GTK_TYPE_CHECK_BUTTON);
|
|
|
|
gtk_widget_set_margin_bottom (toggle, 12);
|
2002-05-31 11:39:27 +00:00
|
|
|
|
2024-02-03 20:09:46 +06:00
|
|
|
preview = gimp_procedure_dialog_get_drawable_preview (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"preview", drawable);
|
2023-06-23 14:13:29 +00:00
|
|
|
g_object_set_data (config, "drawable", drawable);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
g_signal_connect (preview, "invalidated",
|
|
|
|
G_CALLBACK (do_checkerboard_preview),
|
|
|
|
config);
|
2000-01-13 15:39:26 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
g_signal_connect_swapped (config, "notify",
|
2007-04-26 14:30:07 +00:00
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
2002-09-07 16:31:32 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
|
2024-06-12 16:53:12 +00:00
|
|
|
"preview", "check-size", "psychobilly",
|
2023-06-23 14:13:29 +00:00
|
|
|
NULL);
|
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
gtk_widget_show (dialog);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2023-06-23 14:13:29 +00:00
|
|
|
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2005-08-13 16:17:43 +00:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
return run;
|
2002-05-31 11:39:27 +00:00
|
|
|
}
|