2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2000-04-29 09:46:27 +08:00
|
|
|
* Copyright (C) 1999 Manish Singh <yosh@gimp.org>
|
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2002-03-15 06:42:50 +08:00
|
|
|
|
2000-04-29 09:46:27 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-05-05 21:29:46 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-02-05 22:10:20 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2002-03-15 06:42:50 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2002-10-21 22:15:02 +08:00
|
|
|
#include "libgimpmodule/gimpmodule.h"
|
2002-03-15 06:42:50 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2000-05-27 09:30:21 +08:00
|
|
|
|
2002-10-30 23:12:30 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2000-05-05 21:29:46 +08:00
|
|
|
|
|
|
|
|
2004-07-04 08:21:03 +08:00
|
|
|
#define DEFAULT_CONTRAST 1.0
|
2002-10-23 22:55:07 +08:00
|
|
|
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
#define CDISPLAY_TYPE_CONTRAST (cdisplay_contrast_type)
|
|
|
|
#define CDISPLAY_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_CONTRAST, CdisplayContrast))
|
|
|
|
#define CDISPLAY_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_CONTRAST, CdisplayContrastClass))
|
|
|
|
#define CDISPLAY_IS_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_CONTRAST))
|
|
|
|
#define CDISPLAY_IS_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_CONTRAST))
|
|
|
|
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
typedef struct _CdisplayContrast CdisplayContrast;
|
|
|
|
typedef struct _CdisplayContrastClass CdisplayContrastClass;
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
struct _CdisplayContrast
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
GimpColorDisplay parent_instance;
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
gdouble contrast;
|
2004-07-04 08:21:03 +08:00
|
|
|
guchar lookup[256];
|
2000-04-29 09:46:27 +08:00
|
|
|
};
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
struct _CdisplayContrastClass
|
2000-05-04 17:14:43 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
GimpColorDisplayClass parent_instance;
|
2000-04-29 09:46:27 +08:00
|
|
|
};
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2004-07-04 08:21:03 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_CONTRAST
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-06 05:51:47 +08:00
|
|
|
static GType cdisplay_contrast_get_type (GTypeModule *module);
|
|
|
|
static void cdisplay_contrast_class_init (CdisplayContrastClass *klass);
|
|
|
|
|
|
|
|
static void cdisplay_contrast_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void cdisplay_contrast_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void cdisplay_contrast_convert (GimpColorDisplay *display,
|
|
|
|
guchar *buf,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gint bpp,
|
|
|
|
gint bpl);
|
|
|
|
static GtkWidget * cdisplay_contrast_configure (GimpColorDisplay *display);
|
|
|
|
static void cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
|
|
|
|
gdouble value);
|
2002-10-20 18:14:17 +08:00
|
|
|
|
|
|
|
|
2003-11-19 07:44:35 +08:00
|
|
|
static const GimpModuleInfo cdisplay_contrast_info =
|
2000-05-04 17:14:43 +08:00
|
|
|
{
|
2003-01-03 01:44:28 +08:00
|
|
|
GIMP_MODULE_ABI_VERSION,
|
2000-04-29 09:46:27 +08:00
|
|
|
N_("High Contrast color display filter"),
|
2006-01-12 08:50:44 +08:00
|
|
|
"Jay Cox <jaycox@gimp.org>",
|
2000-10-16 20:07:55 +08:00
|
|
|
"v0.2",
|
2000-04-29 09:46:27 +08:00
|
|
|
"(c) 2000, released under the GPL",
|
2000-10-16 20:07:55 +08:00
|
|
|
"October 14, 2000"
|
2000-04-29 09:46:27 +08:00
|
|
|
};
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static GType cdisplay_contrast_type = 0;
|
|
|
|
static GimpColorDisplayClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2002-10-20 20:40:30 +08:00
|
|
|
G_MODULE_EXPORT const GimpModuleInfo *
|
|
|
|
gimp_module_query (GTypeModule *module)
|
|
|
|
{
|
|
|
|
return &cdisplay_contrast_info;
|
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
G_MODULE_EXPORT gboolean
|
2002-10-20 20:40:30 +08:00
|
|
|
gimp_module_register (GTypeModule *module)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
cdisplay_contrast_get_type (module);
|
|
|
|
|
|
|
|
return TRUE;
|
2000-04-29 09:46:27 +08:00
|
|
|
}
|
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static GType
|
|
|
|
cdisplay_contrast_get_type (GTypeModule *module)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2002-10-20 18:14:17 +08:00
|
|
|
if (! cdisplay_contrast_type)
|
|
|
|
{
|
2006-10-18 21:17:50 +08:00
|
|
|
const GTypeInfo display_info =
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
|
|
|
sizeof (CdisplayContrastClass),
|
2006-11-25 00:15:50 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) cdisplay_contrast_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (CdisplayContrast),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
NULL /* instance_init */
|
2002-10-20 18:14:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
cdisplay_contrast_type =
|
|
|
|
g_type_module_register_type (module,
|
|
|
|
GIMP_TYPE_COLOR_DISPLAY,
|
|
|
|
"CdisplayContrast",
|
2002-12-18 23:37:56 +08:00
|
|
|
&display_info, 0);
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
return cdisplay_contrast_type;
|
|
|
|
}
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
static void
|
|
|
|
cdisplay_contrast_class_init (CdisplayContrastClass *klass)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2002-10-20 18:14:17 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2005-02-06 05:51:47 +08:00
|
|
|
object_class->get_property = cdisplay_contrast_get_property;
|
|
|
|
object_class->set_property = cdisplay_contrast_set_property;
|
2004-07-04 08:21:03 +08:00
|
|
|
|
2005-02-05 22:10:20 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_CONTRAST,
|
|
|
|
"contrast", NULL,
|
|
|
|
0.01, 10.0, DEFAULT_CONTRAST,
|
2006-01-31 00:58:42 +08:00
|
|
|
0);
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2005-02-06 05:51:47 +08:00
|
|
|
display_class->name = _("Contrast");
|
|
|
|
display_class->help_id = "gimp-colordisplay-contrast";
|
2006-10-02 01:31:42 +08:00
|
|
|
display_class->stock_id = GIMP_STOCK_DISPLAY_FILTER_CONTRAST;
|
|
|
|
|
2005-02-06 05:51:47 +08:00
|
|
|
display_class->convert = cdisplay_contrast_convert;
|
|
|
|
display_class->configure = cdisplay_contrast_configure;
|
2000-04-29 09:46:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-04 08:21:03 +08:00
|
|
|
cdisplay_contrast_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2003-11-22 00:46:17 +08:00
|
|
|
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2004-07-04 08:21:03 +08:00
|
|
|
switch (property_id)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
case PROP_CONTRAST:
|
|
|
|
g_value_set_double (value, contrast->contrast);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
2000-04-29 09:46:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-04 08:21:03 +08:00
|
|
|
static void
|
|
|
|
cdisplay_contrast_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_CONTRAST:
|
|
|
|
cdisplay_contrast_set_contrast (contrast, g_value_get_double (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2000-04-29 09:46:27 +08:00
|
|
|
static void
|
2002-10-20 18:14:17 +08:00
|
|
|
cdisplay_contrast_convert (GimpColorDisplay *display,
|
|
|
|
guchar *buf,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint bpp,
|
|
|
|
gint bpl)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2003-11-22 00:46:17 +08:00
|
|
|
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
|
|
|
|
gint i, j = height;
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2003-11-19 07:44:35 +08:00
|
|
|
/* You will not be using the entire buffer most of the time.
|
2000-04-29 09:46:27 +08:00
|
|
|
* Hence, the simplistic code for this is as follows:
|
|
|
|
*
|
|
|
|
* for (j = 0; j < height; j++)
|
|
|
|
* {
|
|
|
|
* for (i = 0; i < width * bpp; i++)
|
|
|
|
* buf[i] = lookup[buf[i]];
|
|
|
|
* buf += bpl;
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
|
|
|
width *= bpp;
|
|
|
|
bpl -= width;
|
|
|
|
|
|
|
|
while (j--)
|
|
|
|
{
|
|
|
|
i = width;
|
|
|
|
while (i--)
|
2006-11-25 00:15:50 +08:00
|
|
|
{
|
|
|
|
*buf = contrast->lookup[*buf];
|
|
|
|
buf++;
|
|
|
|
}
|
2000-04-29 09:46:27 +08:00
|
|
|
buf += bpl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
static GtkWidget *
|
|
|
|
cdisplay_contrast_configure (GimpColorDisplay *display)
|
2000-04-29 09:46:27 +08:00
|
|
|
{
|
2003-11-22 00:46:17 +08:00
|
|
|
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
|
2005-02-06 05:51:47 +08:00
|
|
|
GtkWidget *hbox;
|
2002-10-20 18:14:17 +08:00
|
|
|
GtkWidget *label;
|
2002-10-23 22:55:07 +08:00
|
|
|
GtkWidget *spinbutton;
|
2000-04-29 09:46:27 +08:00
|
|
|
|
2005-02-06 05:51:47 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2002-10-23 22:55:07 +08:00
|
|
|
|
2005-08-23 07:39:12 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("Contrast c_ycles:"));
|
2005-02-06 05:51:47 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
2002-10-23 22:55:07 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2005-02-05 22:10:20 +08:00
|
|
|
spinbutton = gimp_prop_spin_button_new (G_OBJECT (contrast), "contrast",
|
|
|
|
0.1, 1.0, 3);
|
2005-02-06 05:51:47 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
2002-10-23 22:55:07 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
2003-11-23 07:53:48 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
|
|
|
|
|
2005-02-06 06:04:40 +08:00
|
|
|
return hbox;
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-04 08:21:03 +08:00
|
|
|
cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
|
|
|
|
gdouble value)
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
if (value <= 0.0)
|
|
|
|
value = 1.0;
|
2002-10-20 18:14:17 +08:00
|
|
|
|
2004-07-04 08:21:03 +08:00
|
|
|
if (value != contrast->contrast)
|
2002-10-20 18:14:17 +08:00
|
|
|
{
|
2004-07-04 08:21:03 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
contrast->contrast = value;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
contrast->lookup[i] = (guchar) (gint)
|
|
|
|
(255 * .5 * (1 + sin (value * 2 * G_PI * i / 255.0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (contrast), "contrast");
|
|
|
|
gimp_color_display_changed (GIMP_COLOR_DISPLAY (contrast));
|
2002-10-20 18:14:17 +08:00
|
|
|
}
|
|
|
|
}
|