~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to modules/cdisplay_highcontrast.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1999 Manish Singh <yosh@gimp.org>
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
18
18
 
19
19
#include "config.h"
20
20
 
21
 
#include <string.h>
22
 
 
23
21
#include <gtk/gtk.h>
24
22
 
25
 
#include "libgimpbase/gimpbase.h"
 
23
#include "libgimpconfig/gimpconfig.h"
26
24
#include "libgimpmath/gimpmath.h"
27
25
#include "libgimpmodule/gimpmodule.h"
28
26
#include "libgimpwidgets/gimpwidgets.h"
49
47
 
50
48
  gdouble           contrast;
51
49
  guchar            lookup[256];
52
 
 
53
 
  GtkWidget        *hbox;
54
 
  GtkObject        *adjustment;
55
50
};
56
51
 
57
52
struct _CdisplayContrastClass
67
62
};
68
63
 
69
64
 
70
 
static GType   cdisplay_contrast_get_type     (GTypeModule        *module);
71
 
static void    cdisplay_contrast_class_init   (CdisplayContrastClass *klass);
72
 
 
73
 
static void    cdisplay_contrast_dispose      (GObject            *object);
74
 
static void    cdisplay_contrast_set_property (GObject            *object,
75
 
                                               guint               property_id,
76
 
                                               const GValue       *value,
77
 
                                               GParamSpec         *pspec);
78
 
static void    cdisplay_contrast_get_property (GObject            *object,
79
 
                                               guint               property_id,
80
 
                                               GValue             *value,
81
 
                                               GParamSpec         *pspec);
82
 
 
83
 
static GimpColorDisplay * cdisplay_contrast_clone  (GimpColorDisplay *display);
84
 
static void    cdisplay_contrast_convert           (GimpColorDisplay *display,
85
 
                                                    guchar           *buf,
86
 
                                                    gint              w,
87
 
                                                    gint              h,
88
 
                                                    gint              bpp,
89
 
                                                    gint              bpl);
90
 
static void    cdisplay_contrast_load_state        (GimpColorDisplay *display,
91
 
                                                    GimpParasite     *state);
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);
95
 
 
96
 
static void    cdisplay_contrast_set_contrast      (CdisplayContrast *contrast,
97
 
                                                    gdouble           value);
98
 
static void    cdisplay_contrast_adj_callback      (GtkAdjustment    *adj,
99
 
                                                    CdisplayContrast *contrast);
 
65
static GType       cdisplay_contrast_get_type     (GTypeModule           *module);
 
66
static void        cdisplay_contrast_class_init   (CdisplayContrastClass *klass);
 
67
 
 
68
static void        cdisplay_contrast_set_property (GObject          *object,
 
69
                                                   guint             property_id,
 
70
                                                   const GValue     *value,
 
71
                                                   GParamSpec       *pspec);
 
72
static void        cdisplay_contrast_get_property (GObject          *object,
 
73
                                                   guint             property_id,
 
74
                                                   GValue           *value,
 
75
                                                   GParamSpec       *pspec);
 
76
 
 
77
static void        cdisplay_contrast_convert      (GimpColorDisplay *display,
 
78
                                                   guchar           *buf,
 
79
                                                   gint              w,
 
80
                                                   gint              h,
 
81
                                                   gint              bpp,
 
82
                                                   gint              bpl);
 
83
static GtkWidget * cdisplay_contrast_configure    (GimpColorDisplay *display);
 
84
static void        cdisplay_contrast_set_contrast (CdisplayContrast *contrast,
 
85
                                                   gdouble           value);
100
86
 
101
87
 
102
88
static const GimpModuleInfo cdisplay_contrast_info =
103
89
{
104
90
  GIMP_MODULE_ABI_VERSION,
105
91
  N_("High Contrast color display filter"),
106
 
  "Jay Cox <jaycox@earthlink.net>",
 
92
  "Jay Cox <jaycox@gimp.org>",
107
93
  "v0.2",
108
94
  "(c) 2000, released under the GPL",
109
95
  "October 14, 2000"
132
118
{
133
119
  if (! cdisplay_contrast_type)
134
120
    {
135
 
      static const GTypeInfo display_info =
 
121
      const GTypeInfo display_info =
136
122
      {
137
123
        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),
144
 
        0,              /* n_preallocs    */
145
 
        NULL            /* instance_init  */
 
124
        (GBaseInitFunc) NULL,
 
125
        (GBaseFinalizeFunc) NULL,
 
126
        (GClassInitFunc) cdisplay_contrast_class_init,
 
127
        NULL,           /* class_finalize */
 
128
        NULL,           /* class_data     */
 
129
        sizeof (CdisplayContrast),
 
130
        0,              /* n_preallocs    */
 
131
        NULL            /* instance_init  */
146
132
      };
147
133
 
148
134
      cdisplay_contrast_type =
163
149
 
164
150
  parent_class = g_type_class_peek_parent (klass);
165
151
 
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;
169
 
 
170
 
  g_object_class_install_property (object_class, PROP_CONTRAST,
171
 
                                   g_param_spec_double ("contrast", NULL, NULL,
172
 
                                                        0.01, 10.0,
173
 
                                                        DEFAULT_CONTRAST,
174
 
                                                        G_PARAM_READWRITE |
175
 
                                                        G_PARAM_CONSTRUCT |
176
 
                                                        GIMP_MODULE_PARAM_SERIALIZE));
177
 
 
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;
186
 
}
187
 
 
188
 
static void
189
 
cdisplay_contrast_dispose (GObject *object)
190
 
{
191
 
  CdisplayContrast *contrast = CDISPLAY_CONTRAST (object);
192
 
 
193
 
  if (contrast->hbox)
194
 
    gtk_widget_destroy (contrast->hbox);
195
 
 
196
 
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
152
  object_class->get_property = cdisplay_contrast_get_property;
 
153
  object_class->set_property = cdisplay_contrast_set_property;
 
154
 
 
155
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_CONTRAST,
 
156
                                   "contrast", NULL,
 
157
                                   0.01, 10.0, DEFAULT_CONTRAST,
 
158
                                   0);
 
159
 
 
160
  display_class->name        = _("Contrast");
 
161
  display_class->help_id     = "gimp-colordisplay-contrast";
 
162
  display_class->stock_id    = GIMP_STOCK_DISPLAY_FILTER_CONTRAST;
 
163
 
 
164
  display_class->convert     = cdisplay_contrast_convert;
 
165
  display_class->configure   = cdisplay_contrast_configure;
197
166
}
198
167
 
199
168
static void
234
203
    }
235
204
}
236
205
 
237
 
static GimpColorDisplay *
238
 
cdisplay_contrast_clone (GimpColorDisplay *display)
239
 
{
240
 
  CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
241
 
  CdisplayContrast *copy;
242
 
 
243
 
  copy = CDISPLAY_CONTRAST (gimp_color_display_new (G_TYPE_FROM_INSTANCE (contrast)));
244
 
 
245
 
  copy->contrast = contrast->contrast;
246
 
 
247
 
  memcpy (copy->lookup, contrast->lookup, sizeof (guchar) * 256);
248
 
 
249
 
  return GIMP_COLOR_DISPLAY (copy);
250
 
}
251
 
 
252
206
static void
253
207
cdisplay_contrast_convert (GimpColorDisplay *display,
254
208
                           guchar           *buf,
278
232
    {
279
233
      i = width;
280
234
      while (i--)
281
 
        {
282
 
          *buf = contrast->lookup[*buf];
283
 
          buf++;
284
 
        }
 
235
        {
 
236
          *buf = contrast->lookup[*buf];
 
237
          buf++;
 
238
        }
285
239
      buf += bpl;
286
240
    }
287
241
}
288
242
 
289
 
static void
290
 
cdisplay_contrast_load_state (GimpColorDisplay *display,
291
 
                              GimpParasite     *state)
292
 
{
293
 
  gdouble value;
294
 
 
295
 
#if G_BYTE_ORDER == G_BIG_ENDIAN
296
 
  memcpy (&value, gimp_parasite_data (state), sizeof (gdouble));
297
 
#else
298
 
  {
299
 
    guint32        buf[2];
300
 
    const guint32 *data;
301
 
 
302
 
    data = gimp_parasite_data (state);
303
 
 
304
 
    buf[0] = g_ntohl (data[1]);
305
 
    buf[1] = g_ntohl (data[0]);
306
 
 
307
 
    memcpy (&value, buf, sizeof (gdouble));
308
 
  }
309
 
#endif
310
 
 
311
 
  cdisplay_contrast_set_contrast (CDISPLAY_CONTRAST (display), value);
312
 
}
313
 
 
314
 
static GimpParasite *
315
 
cdisplay_contrast_save_state (GimpColorDisplay *display)
316
 
{
317
 
  CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
318
 
  guint32           buf[2];
319
 
 
320
 
  memcpy (buf, &contrast->contrast, sizeof (double));
321
 
 
322
 
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
323
 
  {
324
 
    guint32 tmp;
325
 
 
326
 
    tmp    = g_htonl (buf[0]);
327
 
    buf[0] = g_htonl (buf[1]);
328
 
    buf[1] = tmp;
329
 
  }
330
 
#endif
331
 
 
332
 
  return gimp_parasite_new ("Display/Contrast", GIMP_PARASITE_PERSISTENT,
333
 
                            sizeof (double), &buf);
334
 
}
335
 
 
336
243
static GtkWidget *
337
244
cdisplay_contrast_configure (GimpColorDisplay *display)
338
245
{
339
246
  CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
 
247
  GtkWidget        *hbox;
340
248
  GtkWidget        *label;
341
249
  GtkWidget        *spinbutton;
342
250
 
343
 
  if (contrast->hbox)
344
 
    gtk_widget_destroy (contrast->hbox);
345
 
 
346
 
  contrast->hbox = gtk_hbox_new (FALSE, 6);
347
 
 
348
 
  g_signal_connect (contrast->hbox, "destroy",
349
 
                    G_CALLBACK (gtk_widget_destroyed),
350
 
                    &contrast->hbox);
351
 
 
352
 
  label = gtk_label_new_with_mnemonic (_("Contrast C_ycles:"));
353
 
  gtk_box_pack_start (GTK_BOX (contrast->hbox), label, FALSE, FALSE, 0);
 
251
  hbox = gtk_hbox_new (FALSE, 6);
 
252
 
 
253
  label = gtk_label_new_with_mnemonic (_("Contrast c_ycles:"));
 
254
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
354
255
  gtk_widget_show (label);
355
256
 
356
 
  spinbutton = gimp_spin_button_new (&contrast->adjustment,
357
 
                                     contrast->contrast,
358
 
                                     0.01, 10.0, 0.01, 0.1, 0.0,
359
 
                                     0.1, 3);
360
 
  gtk_box_pack_start (GTK_BOX (contrast->hbox), spinbutton, FALSE, FALSE, 0);
 
257
  spinbutton = gimp_prop_spin_button_new (G_OBJECT (contrast), "contrast",
 
258
                                          0.1, 1.0, 3);
 
259
  gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
361
260
  gtk_widget_show (spinbutton);
362
261
 
363
262
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
364
263
 
365
 
  g_signal_connect (contrast->adjustment, "value_changed",
366
 
                    G_CALLBACK (cdisplay_contrast_adj_callback),
367
 
                    contrast);
368
 
 
369
 
  return contrast->hbox;
370
 
}
371
 
 
372
 
static void
373
 
cdisplay_contrast_configure_reset (GimpColorDisplay *display)
374
 
{
375
 
  CdisplayContrast *contrast = CDISPLAY_CONTRAST (display);
376
 
 
377
 
  if (contrast->adjustment)
378
 
    gtk_adjustment_set_value (GTK_ADJUSTMENT (contrast->adjustment),
379
 
                              DEFAULT_CONTRAST);
 
264
  return hbox;
380
265
}
381
266
 
382
267
static void
402
287
      gimp_color_display_changed (GIMP_COLOR_DISPLAY (contrast));
403
288
    }
404
289
}
405
 
 
406
 
static void
407
 
cdisplay_contrast_adj_callback (GtkAdjustment    *adj,
408
 
                                CdisplayContrast *contrast)
409
 
{
410
 
  cdisplay_contrast_set_contrast (contrast, adj->value);
411
 
}