alien-map.c 22.1 KB
Newer Older
1
2
3
4
5
6
/**********************************************************************
 *  AlienMap2 (Co-)sine color transformation plug-in (Version 1.01)
 *  Martin Weber (martweb@gmx.net)
 **********************************************************************
 *  Most code taken from AlienMap by Daniel Cotting
 *  This is not a replacement for AlienMap!
7
 **********************************************************************
8
9
 */

10
/* GIMP - The GNU Image Manipulation Program
11
12
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 3 of the License, or
16
17
18
19
20
21
22
23
 * (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
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26
27
28
29
30
31
32
33
 */

#include "config.h"

#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

#include "libgimp/stdplugins-intl.h"

34
#define PLUG_IN_PROC   "plug-in-alienmap2"
35
#define PLUG_IN_BINARY "alien-map"
36
#define PLUG_IN_ROLE   "gimp-alien-map"
37
38
#define SCALE_WIDTH    200
#define ENTRY_WIDTH      6
39
40
41

/***** Color model *****/

42
43
44
45
46
typedef enum
{
  RGB_MODEL = 0,
  HSL_MODEL = 1
} ColorModel;
47
48
49
50

/***** Types *****/
typedef struct
{
51
52
53
54
55
56
57
58
59
60
  gdouble    redfrequency;
  gdouble    redangle;
  gdouble    greenfrequency;
  gdouble    greenangle;
  gdouble    bluefrequency;
  gdouble    blueangle;
  ColorModel colormodel;
  gboolean   redmode;
  gboolean   greenmode;
  gboolean   bluemode;
61
62
63
64
65
} alienmap2_vals_t;

/* Declare local functions. */

static void      query  (void);
66
static void      run    (const gchar      *name,
67
68
69
70
                         gint              nparams,
                         const GimpParam  *param,
                         gint             *nreturn_vals,
                         GimpParam       **return_vals);
71

72
73
74
75
76
static void      alienmap2                (GimpDrawable  *drawable);
static void      transform                (guchar        *r,
                                           guchar        *g,
                                           guchar        *b);
static gint      alienmap2_dialog         (void);
77
78
static void      dialog_update_preview    (GimpDrawable  *drawable,
                                           GimpPreview   *preview);
79
80
81
82
83
84
85
86
87
88
89
static void      dialog_scale_update      (GtkAdjustment *adjustment,
                                           gdouble       *value);
static void      alienmap2_toggle_update  (GtkWidget     *widget,
                                           gpointer       data);
static void      alienmap2_radio_update   (GtkWidget     *widget,
                                           gpointer       data);

static void      alienmap2_set_labels     (void);
static void      alienmap2_set_sensitive  (void);
static void      alienmap2_get_label_size (void);

90
91
92

/***** Variables *****/

93
static GtkWidget *preview;
94

95
const GimpPlugInInfo PLUG_IN_INFO =
96
97
98
99
{
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
100
  run    /* run_proc   */
101
102
103
104
105
106
107
108
109
110
111
112
113
};

static alienmap2_vals_t wvals =
{
  1.0,
  0.0,
  1.0,
  0.0,
  1.0,
  0.0,
  RGB_MODEL,
  TRUE,
  TRUE,
114
  TRUE
115
116
};

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
static GimpDrawable *drawable         = NULL;

static GtkWidget    *toggle_modify_rh = NULL;
static GtkWidget    *toggle_modify_gs = NULL;
static GtkWidget    *toggle_modify_bl = NULL;

static GtkWidget    *label_freq_rh    = NULL;
static GtkWidget    *label_freq_gs    = NULL;
static GtkWidget    *label_freq_bl    = NULL;
static GtkWidget    *label_phase_rh   = NULL;
static GtkWidget    *label_phase_gs   = NULL;
static GtkWidget    *label_phase_bl   = NULL;

static GtkObject    *entry_freq_rh    = NULL;
static GtkObject    *entry_freq_gs    = NULL;
static GtkObject    *entry_freq_bl    = NULL;
static GtkObject    *entry_phase_rh   = NULL;
static GtkObject    *entry_phase_gs   = NULL;
static GtkObject    *entry_phase_bl   = NULL;


static const gchar *ctext[][2] =
{
140
141
142
  { N_("_Modify red channel"),   N_("_Modify hue channel")        },
  { N_("Mo_dify green channel"), N_("Mo_dify saturation channel") },
  { N_("Mod_ify blue channel"),  N_("Mod_ify luminosity channel") }
143
144
145
146
};

static const gchar *etext[][2] =
{
147
  { N_("Red _frequency:"),       N_("Hue _frequency:")            },
148
149
  { N_("Green fr_equency:"),     N_("Saturation fr_equency:")     },
  { N_("Blue freq_uency:"),      N_("Luminosity freq_uency:")     },
150

151
  { N_("Red _phaseshift:"),      N_("Hue _phaseshift:")           },
152
153
  { N_("Green ph_aseshift:"),    N_("Saturation ph_aseshift:")    },
  { N_("Blue pha_seshift:"),     N_("Luminosity pha_seshift:")    },
154
155
156
};
static gint elabel_maxwidth = 0;

157
158
159
160
161
162
163
164

/***** Functions *****/

MAIN ()

static void
query (void)
{
165
  static const GimpParamDef args[] =
166
  {
167
    { GIMP_PDB_INT32,    "run-mode",       "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
168
169
170
171
172
173
174
175
    { GIMP_PDB_IMAGE,    "image",          "Input image" },
    { GIMP_PDB_DRAWABLE, "drawable",       "Input drawable" },
    { GIMP_PDB_FLOAT,    "redfrequency",   "Red/hue component frequency factor" },
    { GIMP_PDB_FLOAT,    "redangle",       "Red/hue component angle factor (0-360)" },
    { GIMP_PDB_FLOAT,    "greenfrequency", "Green/saturation component frequency factor" },
    { GIMP_PDB_FLOAT,    "greenangle",     "Green/saturation component angle factor (0-360)" },
    { GIMP_PDB_FLOAT,    "bluefrequency",  "Blue/luminance component frequency factor" },
    { GIMP_PDB_FLOAT,    "blueangle",      "Blue/luminance component angle factor (0-360)" },
176
177
178
179
    { GIMP_PDB_INT8,     "colormodel",     "Color model { RGB-MODEL (0), HSL-MODEL (1) }" },
    { GIMP_PDB_INT8,     "redmode",        "Red/hue application mode { TRUE, FALSE }" },
    { GIMP_PDB_INT8,     "greenmode",      "Green/saturation application mode { TRUE, FALSE }" },
    { GIMP_PDB_INT8,     "bluemode",       "Blue/luminance application mode { TRUE, FALSE }" },
180
181
  };

182
  gimp_install_procedure (PLUG_IN_PROC,
183
                          N_("Alter colors in various psychedelic ways"),
184
185
186
187
                          "No help yet. Just try it and you'll see!",
                          "Martin Weber (martweb@gmx.net)",
                          "Martin Weber (martweb@gmx.net",
                          "24th April 1998",
Sven Neumann's avatar
Sven Neumann committed
188
                          N_("_Alien Map..."),
189
190
                          "RGB*",
                          GIMP_PLUGIN,
191
192
                          G_N_ELEMENTS (args), 0,
                          args, NULL);
193

194
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Map");
195
196
}

197
198
static void
transform (guchar *r,
199
200
           guchar *g,
           guchar *b)
201
{
202
  switch (wvals.colormodel)
203
    {
204
205
206
207
    case HSL_MODEL:
      {
        GimpHSL hsl;
        GimpRGB rgb;
208

209
210
        gimp_rgb_set_uchar (&rgb, *r, *g, *b);
        gimp_rgb_to_hsl (&rgb, &hsl);
211

212
213
214
        if (wvals.redmode)
          hsl.h = 0.5 * (1.0 + sin (((2 * hsl.h - 1.0) * wvals.redfrequency +
                                     wvals.redangle / 180.0) * G_PI));
Michael Natterer's avatar
Michael Natterer committed
215

216
217
218
        if (wvals.greenmode)
          hsl.s = 0.5 * (1.0 + sin (((2 * hsl.s - 1.0) * wvals.greenfrequency +
                                     wvals.greenangle / 180.0) * G_PI));
Michael Natterer's avatar
Michael Natterer committed
219

220
221
222
        if (wvals.bluemode)
          hsl.l = 0.5 * (1.0 + sin (((2 * hsl.l - 1.0) * wvals.bluefrequency +
                                     wvals.blueangle / 180.0) * G_PI));
223

224
225
226
227
228
229
        gimp_hsl_to_rgb (&hsl, &rgb);
        gimp_rgb_get_uchar (&rgb, r, g, b);
      }
      break;

    case RGB_MODEL:
230
      if (wvals.redmode)
231
        *r = ROUND (127.5 * (1.0 +
Michael Natterer's avatar
Michael Natterer committed
232
233
234
                             sin (((*r / 127.5 - 1.0) * wvals.redfrequency +
                                   wvals.redangle / 180.0) * G_PI)));

235
      if (wvals.greenmode)
236
        *g = ROUND (127.5 * (1.0 +
Michael Natterer's avatar
Michael Natterer committed
237
238
239
                             sin (((*g / 127.5 - 1.0) * wvals.greenfrequency +
                                   wvals.greenangle / 180.0) * G_PI)));

240
      if (wvals.bluemode)
Michael Natterer's avatar
Michael Natterer committed
241
242
243
        *b = ROUND (127.5 * (1.0 +
                             sin (((*b / 127.5 - 1.0) * wvals.bluefrequency +
                                   wvals.blueangle / 180.0) * G_PI)));
244
      break;
245
246
247
248
    }
}

static void
249
250
251
252
253
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
254
{
255
  static GimpParam  values[1];
256
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
257
  GimpRunMode       run_mode;
258

259
  INIT_I18N ();
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

  run_mode = param[0].data.d_int32;

  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  *nreturn_vals = 1;
  *return_vals = values;

  /*  Get the specified drawable  */
  drawable = gimp_drawable_get (param[2].data.d_drawable);

  /* See how we will run */
  switch (run_mode)
    {
    case GIMP_RUN_INTERACTIVE:
      /* Possibly retrieve data */
277
      gimp_get_data (PLUG_IN_PROC, &wvals);
278
279

      /* Get information from the dialog */
280
      if (!alienmap2_dialog ())
281
        return;
282
283
284
285
286
287

      break;

    case GIMP_RUN_NONINTERACTIVE:
      /* Make sure all the arguments are present */
      if (nparams != 13)
288
        status = GIMP_PDB_CALLING_ERROR;
289
290

      if (status == GIMP_PDB_SUCCESS)
291
292
293
294
295
296
297
298
299
300
301
302
        {
          wvals.redfrequency   = param[3].data.d_float;
          wvals.redangle       = param[4].data.d_float;
          wvals.greenfrequency = param[5].data.d_float;
          wvals.greenangle     = param[6].data.d_float;
          wvals.bluefrequency  = param[7].data.d_float;
          wvals.blueangle      = param[8].data.d_float;
          wvals.colormodel     = param[9].data.d_int8;
          wvals.redmode        = param[10].data.d_int8 ? TRUE : FALSE;
          wvals.greenmode      = param[11].data.d_int8 ? TRUE : FALSE;
          wvals.bluemode       = param[12].data.d_int8 ? TRUE : FALSE;
        }
303
304
305
306
307

      break;

    case GIMP_RUN_WITH_LAST_VALS:
      /* Possibly retrieve data */
308
      gimp_get_data (PLUG_IN_PROC, &wvals);
309
310
311
312
313
314
315
316
      break;

    default:
      break;
    }

  if (status == GIMP_PDB_SUCCESS)
    {
317
      /*  Make sure that the drawable is RGB or RGBA  */
318
      if (gimp_drawable_is_rgb (drawable->drawable_id))
319
        {
Sven Neumann's avatar
Sven Neumann committed
320
          gimp_progress_init (_("Alien Map: Transforming"));
321

322
          /* Set the tile cache size */
323
          gimp_tile_cache_ntiles (2 * (drawable->width /
324
                                       gimp_tile_width () + 1));
325

326
          /* Run! */
327
328

          alienmap2 (drawable);
329
          if (run_mode != GIMP_RUN_NONINTERACTIVE)
330
            gimp_displays_flush ();
331

332
333
          /* Store data */
          if (run_mode == GIMP_RUN_INTERACTIVE)
334
335
            gimp_set_data (PLUG_IN_PROC,
                           &wvals, sizeof (alienmap2_vals_t));
336
337
338
        }
      else
        {
339
          /* gimp_message("This filter only applies on RGB_MODEL-images"); */
340
341
342
343
344
345
346
347
348
          status = GIMP_PDB_EXECUTION_ERROR;
        }
    }

  values[0].data.d_status = status;

  gimp_drawable_detach (drawable);
}

349
static void
350
351
352
353
alienmap2_func (const guchar *src,
                guchar       *dest,
                gint          bpp,
                gpointer      data)
354
{
355
  guchar v1, v2, v3;
356

357
358
359
  v1 = src[0];
  v2 = src[1];
  v3 = src[2];
360

361
  transform (&v1, &v2, &v3);
362

363
364
365
  dest[0] = v1;
  dest[1] = v2;
  dest[2] = v3;
366

367
368
  if (bpp == 4)
    dest[3] = src[3];
369
370
371
372
373
}

static void
alienmap2 (GimpDrawable *drawable)
{
374
  gimp_rgn_iterate2 (drawable, 0 /* unused */, alienmap2_func, NULL);
375
376
377
378
379
380
}

static gint
alienmap2_dialog (void)
{
  GtkWidget *dialog;
381
  GtkWidget *main_vbox;
382
383
384
  GtkWidget *top_table;
  GtkWidget *frame;
  GtkWidget *toggle;
385
  GtkWidget *hbox;
Sven Neumann's avatar
Sven Neumann committed
386
  GtkWidget *vbox;
387
388
  GtkWidget *table;
  GtkObject *adj;
389
  gboolean   run;
390

391
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
392

393
  dialog = gimp_dialog_new (_("Alien Map"), PLUG_IN_ROLE,
394
                            NULL, 0,
395
                            gimp_standard_help_func, PLUG_IN_PROC,
396

397
398
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
Sven Neumann's avatar
Sven Neumann committed
399

400
                            NULL);
401

402
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
403
404
405
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);
406

407
  gimp_window_set_transient (GTK_WINDOW (dialog));
408

Michael Natterer's avatar
Michael Natterer committed
409
  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
410
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
411
412
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      main_vbox, TRUE, TRUE, 0);
413
414
  gtk_widget_show (main_vbox);

415
  preview = gimp_zoom_preview_new (drawable);
416
  gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
417
  gtk_widget_show (preview);
418

419
420
421
  g_signal_connect_swapped (preview, "invalidated",
                            G_CALLBACK (dialog_update_preview),
                            drawable);
422
423

  top_table = gtk_table_new (2, 2, FALSE);
Sven Neumann's avatar
Sven Neumann committed
424
425
  gtk_table_set_col_spacings (GTK_TABLE (top_table), 12);
  gtk_table_set_row_spacings (GTK_TABLE (top_table), 12);
426
  gtk_box_pack_start (GTK_BOX (main_vbox), top_table, FALSE, FALSE, 0);
427
428
429
430
  gtk_widget_show (top_table);

  /* Controls */
  table = gtk_table_new (6, 3, FALSE);
Sven Neumann's avatar
Sven Neumann committed
431
432
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
433
  gtk_table_attach (GTK_TABLE (top_table), table, 0, 2, 1, 2,
434
                    GTK_EXPAND | GTK_FILL, 0, 0, 0);
435
436
  gtk_widget_show (table);

437
438
  entry_freq_rh = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
439
440
441
442
443
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.redfrequency, 0, 20.0, 0.1, 1, 2,
                          TRUE, 0, 0,
                          _("Number of cycles covering full value range"),
                          NULL);
444
  label_freq_rh = GIMP_SCALE_ENTRY_LABEL (adj);
445
  g_signal_connect (adj, "value-changed",
446
447
                    G_CALLBACK (dialog_scale_update),
                    &wvals.redfrequency);
448

449
450
  entry_phase_rh = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
451
452
453
454
455
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.redangle, 0, 360.0, 1, 15, 2,
                          TRUE, 0, 0,
                          _("Phase angle, range 0-360"),
                          NULL);
456
  label_phase_rh = GIMP_SCALE_ENTRY_LABEL (adj);
457
  g_signal_connect (adj, "value-changed",
458
459
                    G_CALLBACK (dialog_scale_update),
                    &wvals.redangle);
460

461
462
  entry_freq_gs = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
463
464
465
466
467
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.greenfrequency, 0, 20.0, 0.1, 1, 2,
                          TRUE, 0, 0,
                          _("Number of cycles covering full value range"),
                          NULL);
468
  label_freq_gs = GIMP_SCALE_ENTRY_LABEL (adj);
469
  g_signal_connect (adj, "value-changed",
470
471
                    G_CALLBACK (dialog_scale_update),
                    &wvals.greenfrequency);
472

473
474
  entry_phase_gs = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
475
476
477
478
479
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.redangle, 0, 360.0, 1, 15, 2,
                          TRUE, 0, 0,
                          _("Phase angle, range 0-360"),
                          NULL);
480
  label_phase_gs = GIMP_SCALE_ENTRY_LABEL (adj);
481
  g_signal_connect (adj, "value-changed",
482
483
                    G_CALLBACK (dialog_scale_update),
                    &wvals.greenangle);
484

485
486
  entry_freq_bl = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 4,
487
488
489
490
491
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.bluefrequency, 0, 20.0, 0.1, 1, 2,
                          TRUE, 0, 0,
                          _("Number of cycles covering full value range"),
                          NULL);
492
  label_freq_bl = GIMP_SCALE_ENTRY_LABEL (adj);
493
  g_signal_connect (adj, "value-changed",
494
495
                    G_CALLBACK (dialog_scale_update),
                    &wvals.bluefrequency);
496

497
498
  entry_phase_bl = adj =
    gimp_scale_entry_new (GTK_TABLE (table), 0, 5,
499
500
501
502
503
                          NULL, SCALE_WIDTH, ENTRY_WIDTH,
                          wvals.blueangle, 0, 360.0, 1, 15, 2,
                          TRUE, 0, 0,
                          _("Phase angle, range 0-360"),
                          NULL);
504
  label_phase_bl = GIMP_SCALE_ENTRY_LABEL (adj);
505
  g_signal_connect (adj, "value-changed",
506
507
                    G_CALLBACK (dialog_scale_update),
                    &wvals.blueangle);
508
509

  /*  Mode toggle box  */
Michael Natterer's avatar
Michael Natterer committed
510
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
511
  gtk_table_attach (GTK_TABLE (top_table), hbox, 1, 2, 0, 1,
Sven Neumann's avatar
Sven Neumann committed
512
                    GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
513
  gtk_widget_show (hbox);
Sven Neumann's avatar
Sven Neumann committed
514

515
  frame =
516
    gimp_int_radio_group_new (TRUE, _("Mode"),
517
518
                              G_CALLBACK (alienmap2_radio_update),
                              &wvals.colormodel, wvals.colormodel,
519

520
521
                              _("_RGB color model"), RGB_MODEL, NULL,
                              _("_HSL color model"), HSL_MODEL, NULL,
522

523
                              NULL);
524

525
526
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);

Michael Natterer's avatar
Michael Natterer committed
527
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
528
529
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);
530

531
  toggle_modify_rh = toggle = gtk_check_button_new_with_mnemonic (NULL);
Sven Neumann's avatar
Sven Neumann committed
532
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
533
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.redmode);
534
  gtk_widget_show (toggle);
535

536
  g_signal_connect (toggle, "toggled",
537
538
539
                    G_CALLBACK (alienmap2_toggle_update),
                    &wvals.redmode);

540
  toggle_modify_gs = toggle = gtk_check_button_new_with_mnemonic (NULL);
Sven Neumann's avatar
Sven Neumann committed
541
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
542
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.greenmode);
543
  gtk_widget_show (toggle);
544

545
  g_signal_connect (toggle, "toggled",
546
547
548
                    G_CALLBACK (alienmap2_toggle_update),
                    &wvals.greenmode);

549
  toggle_modify_bl = toggle = gtk_check_button_new_with_mnemonic (NULL);
Sven Neumann's avatar
Sven Neumann committed
550
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
551
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), wvals.bluemode);
552
  gtk_widget_show (toggle);
553

554
  g_signal_connect (toggle, "toggled",
555
556
557
                    G_CALLBACK (alienmap2_toggle_update),
                    &wvals.bluemode);

558
559
  gtk_widget_show (frame);
  gtk_widget_show (dialog);
560
561
562
563
564

  alienmap2_get_label_size ();
  alienmap2_set_labels ();
  alienmap2_set_sensitive ();

565
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
566

567
  gtk_widget_destroy (dialog);
568

569
  return run;
570
571
572
}

static void
573
574
dialog_update_preview (GimpDrawable *drawable,
                       GimpPreview  *preview)
575
{
576
577
  guchar *dest, *src;
  gint    width, height, bpp;
578
579
  gint    i;

580
581
  src = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
                                      &width, &height, &bpp);
582
583
584
585
586
587
588
589
  dest = g_new (guchar, width * height * bpp);

  for (i = 0 ; i < width * height ; i++)
    alienmap2_func (src + i * bpp, dest + i * bpp, bpp, NULL);

  gimp_preview_draw_buffer (preview, dest, width * bpp);

  g_free (src);
590
  g_free (dest);
591
592
593
594
}

static void
dialog_scale_update (GtkAdjustment *adjustment,
595
                     gdouble       *value)
596
597
598
{
  gimp_double_adjustment_update (adjustment, value);

599
  gimp_preview_invalidate (GIMP_PREVIEW (preview));
600
601
602
603
}

static void
alienmap2_toggle_update (GtkWidget *widget,
604
                         gpointer   data)
605
606
607
{
  gimp_toggle_button_update (widget, data);

608
609
  alienmap2_set_sensitive ();

610
  gimp_preview_invalidate (GIMP_PREVIEW (preview));
611
612
613
614
}

static void
alienmap2_radio_update (GtkWidget *widget,
615
                        gpointer   data)
616
617
618
{
  gimp_radio_button_update (widget, data);

619
  alienmap2_set_labels ();
620

621
  gimp_preview_invalidate (GIMP_PREVIEW (preview));
622
}
623

624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

static void
alienmap2_set_sensitive (void)
{
  gimp_scale_entry_set_sensitive (entry_freq_rh,  wvals.redmode);
  gimp_scale_entry_set_sensitive (entry_phase_rh, wvals.redmode);
  gimp_scale_entry_set_sensitive (entry_freq_gs,  wvals.greenmode);
  gimp_scale_entry_set_sensitive (entry_phase_gs, wvals.greenmode);
  gimp_scale_entry_set_sensitive (entry_freq_bl,  wvals.bluemode);
  gimp_scale_entry_set_sensitive (entry_phase_bl, wvals.bluemode);
}


static void
alienmap2_set_labels (void)
{
640
641
642
643
644
645
  gtk_button_set_label (GTK_BUTTON (toggle_modify_rh),
                        gettext (ctext[0][wvals.colormodel]));
  gtk_button_set_label (GTK_BUTTON (toggle_modify_gs),
                        gettext (ctext[1][wvals.colormodel]));
  gtk_button_set_label (GTK_BUTTON (toggle_modify_bl),
                        gettext (ctext[2][wvals.colormodel]));
646
647

  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_freq_rh),
648
                                    gettext (etext[0][wvals.colormodel]));
649
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_freq_gs),
650
                                    gettext (etext[1][wvals.colormodel]));
651
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_freq_bl),
652
                                    gettext (etext[2][wvals.colormodel]));
653
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_phase_rh),
654
                                    gettext (etext[3][wvals.colormodel]));
655
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_phase_gs),
656
                                    gettext (etext[4][wvals.colormodel]));
657
  gtk_label_set_text_with_mnemonic (GTK_LABEL (label_phase_bl),
658
                                    gettext (etext[5][wvals.colormodel]));
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684

  gtk_widget_set_size_request (label_freq_rh, elabel_maxwidth, -1);
}


static void
alienmap2_get_label_size (void)
{
  PangoLayout *layout;
  gint         width;
  gint         i, j;

  elabel_maxwidth = 0;

  for (i = 0; i < 6; i++)
    for (j = 0; j < 2; j++)
      {
        gtk_label_set_text_with_mnemonic (GTK_LABEL (label_freq_rh),
                                          gettext (etext[i][j]));
        layout = gtk_label_get_layout (GTK_LABEL (label_freq_rh));
        pango_layout_get_pixel_size (layout, &width, NULL);

        if (width > elabel_maxwidth)
          elabel_maxwidth = width;
      }
}