1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1999 Manish Singh <yosh@gimp.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpconfig/gimpconfig.h"
24
#include "libgimpmath/gimpmath.h"
25
#include "libgimpmodule/gimpmodule.h"
26
#include "libgimpwidgets/gimpwidgets.h"
28
#include "libgimp/libgimp-intl.h"
31
#define DEFAULT_CONTRAST 1.0
34
#define CDISPLAY_TYPE_CONTRAST (cdisplay_contrast_type)
35
#define CDISPLAY_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_CONTRAST, CdisplayContrast))
36
#define CDISPLAY_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_CONTRAST, CdisplayContrastClass))
37
#define CDISPLAY_IS_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_CONTRAST))
38
#define CDISPLAY_IS_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_CONTRAST))
41
typedef struct _CdisplayContrast CdisplayContrast;
42
typedef struct _CdisplayContrastClass CdisplayContrastClass;
44
struct _CdisplayContrast
46
GimpColorDisplay parent_instance;
52
struct _CdisplayContrastClass
54
GimpColorDisplayClass parent_instance;
65
static GType cdisplay_contrast_get_type (GTypeModule *module);
66
static void cdisplay_contrast_class_init (CdisplayContrastClass *klass);
68
static void cdisplay_contrast_set_property (GObject *object,
72
static void cdisplay_contrast_get_property (GObject *object,
77
static void cdisplay_contrast_convert (GimpColorDisplay *display,
83
static GtkWidget * cdisplay_contrast_configure (GimpColorDisplay *display);
84
static void cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
88
static const GimpModuleInfo cdisplay_contrast_info =
90
GIMP_MODULE_ABI_VERSION,
91
N_("High Contrast color display filter"),
92
"Jay Cox <jaycox@gimp.org>",
94
"(c) 2000, released under the GPL",
98
static GType cdisplay_contrast_type = 0;
99
static GimpColorDisplayClass *parent_class = NULL;
102
G_MODULE_EXPORT const GimpModuleInfo *
103
gimp_module_query (GTypeModule *module)
105
return &cdisplay_contrast_info;
108
G_MODULE_EXPORT gboolean
109
gimp_module_register (GTypeModule *module)
111
cdisplay_contrast_get_type (module);
117
cdisplay_contrast_get_type (GTypeModule *module)
119
if (! cdisplay_contrast_type)
121
const GTypeInfo display_info =
123
sizeof (CdisplayContrastClass),
124
(GBaseInitFunc) NULL,
125
(GBaseFinalizeFunc) NULL,
126
(GClassInitFunc) cdisplay_contrast_class_init,
127
NULL, /* class_finalize */
128
NULL, /* class_data */
129
sizeof (CdisplayContrast),
131
NULL /* instance_init */
134
cdisplay_contrast_type =
135
g_type_module_register_type (module,
136
GIMP_TYPE_COLOR_DISPLAY,
141
return cdisplay_contrast_type;
145
cdisplay_contrast_class_init (CdisplayContrastClass *klass)
147
GObjectClass *object_class = G_OBJECT_CLASS (klass);
148
GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
150
parent_class = g_type_class_peek_parent (klass);
152
object_class->get_property = cdisplay_contrast_get_property;
153
object_class->set_property = cdisplay_contrast_set_property;
155
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_CONTRAST,
157
0.01, 10.0, DEFAULT_CONTRAST,
160
display_class->name = _("Contrast");
161
display_class->help_id = "gimp-colordisplay-contrast";
162
display_class->stock_id = GIMP_STOCK_DISPLAY_FILTER_CONTRAST;
164
display_class->convert = cdisplay_contrast_convert;
165
display_class->configure = cdisplay_contrast_configure;
169
cdisplay_contrast_get_property (GObject *object,
174
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
179
g_value_set_double (value, contrast->contrast);
182
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
188
cdisplay_contrast_set_property (GObject *object,
193
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
198
cdisplay_contrast_set_contrast (contrast, g_value_get_double (value));
201
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
207
cdisplay_contrast_convert (GimpColorDisplay *display,
214
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
217
/* You will not be using the entire buffer most of the time.
218
* Hence, the simplistic code for this is as follows:
220
* for (j = 0; j < height; j++)
222
* for (i = 0; i < width * bpp; i++)
223
* buf[i] = lookup[buf[i]];
236
*buf = contrast->lookup[*buf];
244
cdisplay_contrast_configure (GimpColorDisplay *display)
246
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
249
GtkWidget *spinbutton;
251
hbox = gtk_hbox_new (FALSE, 6);
253
label = gtk_label_new_with_mnemonic (_("Contrast c_ycles:"));
254
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
255
gtk_widget_show (label);
257
spinbutton = gimp_prop_spin_button_new (G_OBJECT (contrast), "contrast",
259
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
260
gtk_widget_show (spinbutton);
262
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
268
cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
274
if (value != contrast->contrast)
278
contrast->contrast = value;
280
for (i = 0; i < 256; i++)
282
contrast->lookup[i] = (guchar) (gint)
283
(255 * .5 * (1 + sin (value * 2 * G_PI * i / 255.0)));
286
g_object_notify (G_OBJECT (contrast), "contrast");
287
gimp_color_display_changed (GIMP_COLOR_DISPLAY (contrast));