2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* Destripe filter
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* Copyright 1997 Marc Lehmann, heavily modified from a filter by
|
|
|
|
* Michael Sweet.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* 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.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* 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.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-01-07 00:40:17 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-07-14 14:15:10 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
2005-08-14 05:39:56 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-destripe"
|
|
|
|
#define PLUG_IN_BINARY "destripe"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-destripe"
|
2005-08-14 05:39:56 +08:00
|
|
|
#define PLUG_IN_VERSION "0.2"
|
|
|
|
#define MAX_AVG 100
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-01 19:10:56 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
typedef struct _Destripe Destripe;
|
|
|
|
typedef struct _DestripeClass DestripeClass;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
struct _Destripe
|
2000-01-15 23:32:28 +08:00
|
|
|
{
|
2019-08-30 21:01:56 +08:00
|
|
|
GimpPlugIn parent_instance;
|
2000-01-15 23:32:28 +08:00
|
|
|
};
|
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
struct _DestripeClass
|
2003-10-01 19:10:56 +08:00
|
|
|
{
|
2019-08-30 21:01:56 +08:00
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define DESTRIPE_TYPE (destripe_get_type ())
|
|
|
|
#define DESTRIPE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DESTRIPE_TYPE, Destripe))
|
|
|
|
|
|
|
|
GType destripe_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * destripe_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * destripe_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * destripe_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2021-04-02 08:55:46 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2023-06-21 07:09:41 +08:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-30 21:01:56 +08:00
|
|
|
gpointer run_data);
|
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
static void destripe (GObject *config,
|
|
|
|
GimpDrawable *drawable,
|
2019-08-30 21:01:56 +08:00
|
|
|
GimpPreview *preview);
|
2023-04-09 19:49:13 +08:00
|
|
|
static void destripe_preview (GtkWidget *widget,
|
|
|
|
GObject *config);
|
2019-08-30 21:01:56 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
static gboolean destripe_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpDrawable *drawable);
|
2019-08-30 21:01:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Destripe, destripe, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (DESTRIPE_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-30 21:01:56 +08:00
|
|
|
|
2003-10-01 19:10:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2019-08-30 21:01:56 +08:00
|
|
|
destripe_class_init (DestripeClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-30 21:01:56 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = destripe_query_procedures;
|
|
|
|
plug_in_class->create_procedure = destripe_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-30 21:01:56 +08:00
|
|
|
destripe_init (Destripe *destripe)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-08-30 21:01:56 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
static GList *
|
|
|
|
destripe_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
destripe_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
if (! strcmp (name, PLUG_IN_PROC))
|
|
|
|
{
|
2023-06-21 07:09:41 +08:00
|
|
|
procedure = gimp_image_procedure_new2 (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
destripe_run, NULL, NULL);
|
2019-08-30 21:01:56 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "RGB*, GRAY*");
|
2021-04-02 08:55:46 +08:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE);
|
2019-08-30 21:01:56 +08:00
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Des_tripe..."));
|
2019-08-30 21:01:56 +08:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Tone Mapping");
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-05 04:50:53 +08:00
|
|
|
_("Remove vertical stripe artifacts "
|
|
|
|
"from the image"),
|
2023-04-09 19:49:13 +08:00
|
|
|
_("This plug-in tries to remove vertical "
|
|
|
|
"stripes from an image."),
|
2019-08-30 21:01:56 +08:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Marc Lehmann <pcg@goof.com>",
|
|
|
|
"Marc Lehmann <pcg@goof.com>",
|
|
|
|
PLUG_IN_VERSION);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_INT (procedure, "avg-width",
|
2023-04-09 19:49:13 +08:00
|
|
|
_("_Width"),
|
|
|
|
_("Averaging filter width"),
|
2019-08-30 21:01:56 +08:00
|
|
|
2, MAX_AVG, 36,
|
|
|
|
G_PARAM_READWRITE);
|
2023-04-09 19:49:13 +08:00
|
|
|
|
|
|
|
GIMP_PROC_ARG_BOOLEAN (procedure,
|
|
|
|
"create-histogram",
|
|
|
|
_("Create _histogram"),
|
|
|
|
_("Output a histogram"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-30 21:01:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
destripe_run (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
2021-04-02 08:55:46 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2023-06-21 07:09:41 +08:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-30 21:01:56 +08:00
|
|
|
gpointer run_data)
|
|
|
|
{
|
2023-06-21 07:09:41 +08:00
|
|
|
GimpDrawable *drawable;
|
2021-04-02 08:55:46 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
gegl_init (NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2021-04-02 08:55:46 +08:00
|
|
|
if (n_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];
|
|
|
|
}
|
|
|
|
|
2023-06-21 07:09:41 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE && ! destripe_dialog (procedure, G_OBJECT (config), drawable))
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-06-21 07:09:41 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable)|| gimp_drawable_is_gray (drawable))
|
|
|
|
destripe (G_OBJECT (config), drawable, NULL);
|
2019-08-30 21:01:56 +08:00
|
|
|
else
|
2023-06-21 07:09:41 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-06-21 07:09:41 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
2023-04-09 19:49:13 +08:00
|
|
|
|
2019-08-30 21:01:56 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-04-09 19:49:13 +08:00
|
|
|
destripe (GObject *config,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPreview *preview)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-07-13 18:47:11 +08:00
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
GeglBuffer *dest_buffer;
|
|
|
|
const Babl *format;
|
|
|
|
guchar *src_rows; /* image data */
|
|
|
|
gdouble progress, progress_inc;
|
|
|
|
gint x1, x2, y1;
|
|
|
|
gint width, height;
|
|
|
|
gint bpp;
|
|
|
|
glong *hist, *corr; /* "histogram" data */
|
|
|
|
gint tile_width = gimp_tile_width ();
|
|
|
|
gint i, x, y, ox, cols;
|
2023-04-09 19:49:13 +08:00
|
|
|
gint avg_width;
|
|
|
|
gboolean histogram;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
"avg-width", &avg_width,
|
|
|
|
"create-histogram", &histogram,
|
|
|
|
NULL);
|
2019-07-13 18:47:11 +08:00
|
|
|
|
|
|
|
progress = 0.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
progress_inc = 0.0;
|
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
if (preview)
|
|
|
|
{
|
|
|
|
gimp_preview_get_position (preview, &x1, &y1);
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
|
|
|
}
|
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-30 16:16:10 +08:00
|
|
|
gimp_progress_init (_("Destriping"));
|
2019-07-13 18:47:11 +08:00
|
|
|
|
2019-08-13 23:31:13 +08:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable,
|
2011-05-07 07:11:56 +08:00
|
|
|
&x1, &y1, &width, &height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-07-13 18:47:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
progress = 0;
|
2004-10-04 05:40:16 +08:00
|
|
|
progress_inc = 0.5 * tile_width / width;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2011-05-07 07:11:56 +08:00
|
|
|
x2 = x1 + width;
|
|
|
|
|
2019-08-13 23:31:13 +08:00
|
|
|
if (gimp_drawable_is_rgb (drawable))
|
2019-07-13 18:47:11 +08:00
|
|
|
{
|
2019-08-13 23:31:13 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2019-07-13 18:47:11 +08:00
|
|
|
format = babl_format ("R'G'B'A u8");
|
|
|
|
else
|
|
|
|
format = babl_format ("R'G'B' u8");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-13 23:31:13 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2019-07-13 18:47:11 +08:00
|
|
|
format = babl_format ("Y'A u8");
|
|
|
|
else
|
|
|
|
format = babl_format ("Y' u8");
|
|
|
|
}
|
|
|
|
|
|
|
|
bpp = babl_format_get_bytes_per_pixel (format);
|
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
/*
|
|
|
|
* Setup for filter...
|
|
|
|
*/
|
|
|
|
|
2019-08-13 23:31:13 +08:00
|
|
|
src_buffer = gimp_drawable_get_buffer (drawable);
|
|
|
|
dest_buffer = gimp_drawable_get_shadow_buffer (drawable);
|
2003-10-01 19:10:56 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
hist = g_new (long, width * bpp);
|
|
|
|
corr = g_new (long, width * bpp);
|
|
|
|
src_rows = g_new (guchar, tile_width * height * bpp);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
memset (hist, 0, width * bpp * sizeof (long));
|
2003-10-01 19:10:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/*
|
|
|
|
* collect "histogram" data.
|
|
|
|
*/
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
for (ox = x1; ox < x2; ox += tile_width)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guchar *rows = src_rows;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
cols = x2 - ox;
|
1997-11-25 06:05:25 +08:00
|
|
|
if (cols > tile_width)
|
|
|
|
cols = tile_width;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
gegl_buffer_get (src_buffer, GEGL_RECTANGLE (ox, y1, cols, height), 1.0,
|
|
|
|
format, rows,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
for (y = 0; y < height; y++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-10-04 05:40:16 +08:00
|
|
|
long *h = hist + (ox - x1) * bpp;
|
|
|
|
guchar *row_end = rows + cols * bpp;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
while (rows < row_end)
|
|
|
|
*h++ += *rows++;
|
|
|
|
}
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
if (! preview)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_progress_update (progress += progress_inc);
|
|
|
|
}
|
2003-10-01 19:10:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/*
|
|
|
|
* average out histogram
|
|
|
|
*/
|
2003-10-01 19:10:56 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
{
|
2023-04-09 19:49:13 +08:00
|
|
|
gint extend = (avg_width / 2) * bpp;
|
2004-10-04 05:40:16 +08:00
|
|
|
|
|
|
|
for (i = 0; i < MIN (3, bpp); i++)
|
|
|
|
{
|
|
|
|
long *h = hist - extend + i;
|
|
|
|
long *c = corr - extend + i;
|
|
|
|
long sum = 0;
|
|
|
|
gint cnt = 0;
|
|
|
|
|
|
|
|
for (x = -extend; x < width * bpp; x += bpp)
|
|
|
|
{
|
|
|
|
if (x + extend < width * bpp)
|
|
|
|
{
|
|
|
|
sum += h[ extend]; cnt++;
|
|
|
|
}
|
2019-07-13 18:47:11 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
if (x - extend >= 0)
|
|
|
|
{
|
|
|
|
sum -= h[-extend]; cnt--;
|
|
|
|
}
|
2019-07-13 18:47:11 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
if (x >= 0)
|
|
|
|
{
|
|
|
|
if (*h)
|
|
|
|
*c = ((sum / cnt - *h) << 10) / *h;
|
|
|
|
else
|
|
|
|
*c = G_MAXINT;
|
|
|
|
}
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
h += bpp;
|
|
|
|
c += bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-13 23:39:26 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/*
|
|
|
|
* remove stripes.
|
|
|
|
*/
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
for (ox = x1; ox < x2; ox += tile_width)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guchar *rows = src_rows;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
cols = x2 - ox;
|
1997-11-25 06:05:25 +08:00
|
|
|
if (cols > tile_width)
|
|
|
|
cols = tile_width;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
gegl_buffer_get (src_buffer, GEGL_RECTANGLE (ox, y1, cols, height), 1.0,
|
|
|
|
format, rows,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
if (! preview)
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_progress_update (progress += progress_inc);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
for (y = 0; y < height; y++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-10-04 05:40:16 +08:00
|
|
|
long *c = corr + (ox - x1) * bpp;
|
|
|
|
guchar *row_end = rows + cols * bpp;
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
if (histogram)
|
2019-07-13 18:47:11 +08:00
|
|
|
{
|
|
|
|
while (rows < row_end)
|
|
|
|
{
|
|
|
|
*rows = MIN (255, MAX (0, 128 + (*rows * *c >> 10)));
|
|
|
|
c++; rows++;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2019-07-13 18:47:11 +08:00
|
|
|
{
|
|
|
|
while (rows < row_end)
|
|
|
|
{
|
|
|
|
*rows = MIN (255, MAX (0, *rows + (*rows * *c >> 10) ));
|
|
|
|
c++; rows++;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (ox, y1, cols, height), 0,
|
|
|
|
format, src_rows,
|
|
|
|
GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
|
|
|
if (! preview)
|
2004-10-04 05:40:16 +08:00
|
|
|
gimp_progress_update (progress += progress_inc);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-13 23:39:26 +08:00
|
|
|
|
|
|
|
g_free (src_rows);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
g_object_unref (src_buffer);
|
2000-01-13 23:39:26 +08:00
|
|
|
|
2004-10-04 05:40:16 +08:00
|
|
|
if (preview)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2019-07-13 18:47:11 +08:00
|
|
|
guchar *buffer = g_new (guchar, width * height * bpp);
|
|
|
|
|
|
|
|
gegl_buffer_get (dest_buffer, GEGL_RECTANGLE (x1, y1, width, height), 1.0,
|
|
|
|
format, buffer,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
|
|
|
gimp_preview_draw_buffer (GIMP_PREVIEW (preview),
|
|
|
|
buffer, width * bpp);
|
|
|
|
|
|
|
|
g_free (buffer);
|
|
|
|
g_object_unref (dest_buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-13 18:47:11 +08:00
|
|
|
g_object_unref (dest_buffer);
|
|
|
|
|
2011-04-11 01:05:08 +08:00
|
|
|
gimp_progress_update (1.0);
|
2019-07-13 18:47:11 +08:00
|
|
|
|
2019-08-13 23:31:13 +08:00
|
|
|
gimp_drawable_merge_shadow (drawable, TRUE);
|
|
|
|
gimp_drawable_update (drawable,
|
2004-10-04 05:40:16 +08:00
|
|
|
x1, y1, width, height);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2019-07-13 18:47:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (hist);
|
|
|
|
g_free (corr);
|
|
|
|
}
|
|
|
|
|
2019-07-13 18:47:11 +08:00
|
|
|
static void
|
2023-04-09 19:49:13 +08:00
|
|
|
destripe_preview (GtkWidget *widget,
|
|
|
|
GObject *config)
|
2019-07-13 18:47:11 +08:00
|
|
|
{
|
2023-04-09 19:49:13 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
|
|
|
GimpDrawable *drawable = g_object_get_data (config, "drawable");
|
|
|
|
|
|
|
|
destripe (config, drawable, preview);
|
2019-07-13 18:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-19 05:21:23 +08:00
|
|
|
static gboolean
|
2023-04-09 19:49:13 +08:00
|
|
|
destripe_dialog (GimpProcedure *procedure,
|
|
|
|
GObject *config,
|
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2010-10-23 02:31:20 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *preview;
|
2020-10-31 07:53:26 +08:00
|
|
|
GtkWidget *scale;
|
2010-10-23 02:31:20 +08:00
|
|
|
GtkWidget *button;
|
|
|
|
gboolean run;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
dialog = gimp_procedure_dialog_new (procedure,
|
|
|
|
GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
_("Destripe"));
|
2000-01-07 00:40:17 +08:00
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2023-04-14 10:25:36 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
2005-08-14 05:39:56 +08:00
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2019-08-13 23:31:13 +08:00
|
|
|
preview = gimp_drawable_preview_new_from_drawable (drawable);
|
2023-04-09 19:49:13 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
preview, TRUE, TRUE, 0);
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_widget_show (preview);
|
2008-07-21 21:41:00 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
scale = gimp_procedure_dialog_get_scale_entry (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"avg-width", 1.0);
|
|
|
|
gtk_widget_set_margin_bottom (scale, 12);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
button = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"create-histogram",
|
|
|
|
GTK_TYPE_CHECK_BUTTON);
|
|
|
|
gtk_widget_set_margin_bottom (button, 12);
|
|
|
|
|
2023-04-14 10:25:36 +08:00
|
|
|
g_object_set_data (config, "drawable", drawable);
|
|
|
|
|
|
|
|
g_signal_connect (preview, "invalidated",
|
|
|
|
G_CALLBACK (destripe_preview),
|
|
|
|
config);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (config, "notify",
|
|
|
|
G_CALLBACK (gimp_preview_invalidate),
|
|
|
|
preview);
|
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"avg-width", "create-histogram",
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
gtk_widget_show (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-04-09 19:49:13 +08:00
|
|
|
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|