1
/* The GIMP -- an 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.
25
#include "libgimpbase/gimpbase.h"
26
#include "libgimpmath/gimpmath.h"
27
#include "libgimpmodule/gimpmodule.h"
28
#include "libgimpwidgets/gimpwidgets.h"
30
#include "libgimp/libgimp-intl.h"
33
#define DEFAULT_CONTRAST 1.0
36
#define CDISPLAY_TYPE_CONTRAST (cdisplay_contrast_type)
37
#define CDISPLAY_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_CONTRAST, CdisplayContrast))
38
#define CDISPLAY_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_CONTRAST, CdisplayContrastClass))
39
#define CDISPLAY_IS_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_CONTRAST))
40
#define CDISPLAY_IS_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_CONTRAST))
43
typedef struct _CdisplayContrast CdisplayContrast;
44
typedef struct _CdisplayContrastClass CdisplayContrastClass;
46
struct _CdisplayContrast
48
GimpColorDisplay parent_instance;
54
GtkObject *adjustment;
57
struct _CdisplayContrastClass
59
GimpColorDisplayClass parent_instance;
70
static GType cdisplay_contrast_get_type (GTypeModule *module);
71
static void cdisplay_contrast_class_init (CdisplayContrastClass *klass);
73
static void cdisplay_contrast_dispose (GObject *object);
74
static void cdisplay_contrast_set_property (GObject *object,
78
static void cdisplay_contrast_get_property (GObject *object,
83
static GimpColorDisplay * cdisplay_contrast_clone (GimpColorDisplay *display);
84
static void cdisplay_contrast_convert (GimpColorDisplay *display,
90
static void cdisplay_contrast_load_state (GimpColorDisplay *display,
92
static GimpParasite * cdisplay_contrast_save_state (GimpColorDisplay *display);
93
static GtkWidget * cdisplay_contrast_configure (GimpColorDisplay *display);
94
static void cdisplay_contrast_configure_reset (GimpColorDisplay *display);
96
static void cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
98
static void cdisplay_contrast_adj_callback (GtkAdjustment *adj,
99
CdisplayContrast *contrast);
102
static const GimpModuleInfo cdisplay_contrast_info =
104
GIMP_MODULE_ABI_VERSION,
105
N_("High Contrast color display filter"),
106
"Jay Cox <jaycox@earthlink.net>",
108
"(c) 2000, released under the GPL",
112
static GType cdisplay_contrast_type = 0;
113
static GimpColorDisplayClass *parent_class = NULL;
116
G_MODULE_EXPORT const GimpModuleInfo *
117
gimp_module_query (GTypeModule *module)
119
return &cdisplay_contrast_info;
122
G_MODULE_EXPORT gboolean
123
gimp_module_register (GTypeModule *module)
125
cdisplay_contrast_get_type (module);
131
cdisplay_contrast_get_type (GTypeModule *module)
133
if (! cdisplay_contrast_type)
135
static const GTypeInfo display_info =
137
sizeof (CdisplayContrastClass),
138
(GBaseInitFunc) NULL,
139
(GBaseFinalizeFunc) NULL,
140
(GClassInitFunc) cdisplay_contrast_class_init,
141
NULL, /* class_finalize */
142
NULL, /* class_data */
143
sizeof (CdisplayContrast),
145
NULL /* instance_init */
148
cdisplay_contrast_type =
149
g_type_module_register_type (module,
150
GIMP_TYPE_COLOR_DISPLAY,
155
return cdisplay_contrast_type;
159
cdisplay_contrast_class_init (CdisplayContrastClass *klass)
161
GObjectClass *object_class = G_OBJECT_CLASS (klass);
162
GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
164
parent_class = g_type_class_peek_parent (klass);
166
object_class->dispose = cdisplay_contrast_dispose;
167
object_class->get_property = cdisplay_contrast_get_property;
168
object_class->set_property = cdisplay_contrast_set_property;
170
g_object_class_install_property (object_class, PROP_CONTRAST,
171
g_param_spec_double ("contrast", NULL, NULL,
176
GIMP_MODULE_PARAM_SERIALIZE));
178
display_class->name = _("Contrast");
179
display_class->help_id = "gimp-colordisplay-contrast";
180
display_class->clone = cdisplay_contrast_clone;
181
display_class->convert = cdisplay_contrast_convert;
182
display_class->load_state = cdisplay_contrast_load_state;
183
display_class->save_state = cdisplay_contrast_save_state;
184
display_class->configure = cdisplay_contrast_configure;
185
display_class->configure_reset = cdisplay_contrast_configure_reset;
189
cdisplay_contrast_dispose (GObject *object)
191
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
194
gtk_widget_destroy (contrast->hbox);
196
G_OBJECT_CLASS (parent_class)->dispose (object);
200
cdisplay_contrast_get_property (GObject *object,
205
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
210
g_value_set_double (value, contrast->contrast);
213
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
219
cdisplay_contrast_set_property (GObject *object,
224
CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
229
cdisplay_contrast_set_contrast (contrast, g_value_get_double (value));
232
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
237
static GimpColorDisplay *
238
cdisplay_contrast_clone (GimpColorDisplay *display)
240
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
241
CdisplayContrast *copy;
243
copy = CDISPLAY_CONTRAST (gimp_color_display_new (G_TYPE_FROM_INSTANCE (contrast)));
245
copy->contrast = contrast->contrast;
247
memcpy (copy->lookup, contrast->lookup, sizeof (guchar) * 256);
249
return GIMP_COLOR_DISPLAY (copy);
253
cdisplay_contrast_convert (GimpColorDisplay *display,
260
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
263
/* You will not be using the entire buffer most of the time.
264
* Hence, the simplistic code for this is as follows:
266
* for (j = 0; j < height; j++)
268
* for (i = 0; i < width * bpp; i++)
269
* buf[i] = lookup[buf[i]];
282
*buf = contrast->lookup[*buf];
290
cdisplay_contrast_load_state (GimpColorDisplay *display,
295
#if G_BYTE_ORDER == G_BIG_ENDIAN
296
memcpy (&value, gimp_parasite_data (state), sizeof (gdouble));
302
data = gimp_parasite_data (state);
304
buf[0] = g_ntohl (data[1]);
305
buf[1] = g_ntohl (data[0]);
307
memcpy (&value, buf, sizeof (gdouble));
311
cdisplay_contrast_set_contrast (CDISPLAY_CONTRAST (display), value);
314
static GimpParasite *
315
cdisplay_contrast_save_state (GimpColorDisplay *display)
317
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
320
memcpy (buf, &contrast->contrast, sizeof (double));
322
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
326
tmp = g_htonl (buf[0]);
327
buf[0] = g_htonl (buf[1]);
332
return gimp_parasite_new ("Display/Contrast", GIMP_PARASITE_PERSISTENT,
333
sizeof (double), &buf);
337
cdisplay_contrast_configure (GimpColorDisplay *display)
339
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
341
GtkWidget *spinbutton;
344
gtk_widget_destroy (contrast->hbox);
346
contrast->hbox = gtk_hbox_new (FALSE, 6);
348
g_signal_connect (contrast->hbox, "destroy",
349
G_CALLBACK (gtk_widget_destroyed),
352
label = gtk_label_new_with_mnemonic (_("Contrast C_ycles:"));
353
gtk_box_pack_start (GTK_BOX (contrast->hbox), label, FALSE, FALSE, 0);
354
gtk_widget_show (label);
356
spinbutton = gimp_spin_button_new (&contrast->adjustment,
358
0.01, 10.0, 0.01, 0.1, 0.0,
360
gtk_box_pack_start (GTK_BOX (contrast->hbox), spinbutton, FALSE, FALSE, 0);
361
gtk_widget_show (spinbutton);
363
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
365
g_signal_connect (contrast->adjustment, "value_changed",
366
G_CALLBACK (cdisplay_contrast_adj_callback),
369
return contrast->hbox;
373
cdisplay_contrast_configure_reset (GimpColorDisplay *display)
375
CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
377
if (contrast->adjustment)
378
gtk_adjustment_set_value (GTK_ADJUSTMENT (contrast->adjustment),
383
cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
389
if (value != contrast->contrast)
393
contrast->contrast = value;
395
for (i = 0; i < 256; i++)
397
contrast->lookup[i] = (guchar) (gint)
398
(255 * .5 * (1 + sin (value * 2 * G_PI * i / 255.0)));
401
g_object_notify (G_OBJECT (contrast), "contrast");
402
gimp_color_display_changed (GIMP_COLOR_DISPLAY (contrast));
407
cdisplay_contrast_adj_callback (GtkAdjustment *adj,
408
CdisplayContrast *contrast)
410
cdisplay_contrast_set_contrast (contrast, adj->value);