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

« back to all changes in this revision

Viewing changes to app/widgets/gimpcolormapeditor.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) 1995 Spencer Kimball and Peter Mattis
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 <stdio.h>
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
 
25
21
#ifdef __GNUC__
26
22
#warning GTK_DISABLE_DEPRECATED
27
23
#endif
36
32
 
37
33
#include "widgets-types.h"
38
34
 
39
 
#ifdef __GNUC__
40
 
#warning FIXME #include "display/display-types.h"
41
 
#endif
42
 
#include "display/display-types.h"
43
 
 
44
35
#include "core/gimp.h"
45
36
#include "core/gimpcontainer.h"
46
37
#include "core/gimpcontext.h"
48
39
#include "core/gimpimage-colormap.h"
49
40
#include "core/gimpmarshal.h"
50
41
 
51
 
#include "display/gimpdisplayshell-render.h"
52
 
 
53
42
#include "gimpcolormapeditor.h"
54
43
#include "gimpdnd.h"
 
44
#include "gimprender.h"
55
45
#include "gimpmenufactory.h"
56
46
#include "gimpuimanager.h"
57
47
 
73
63
  LAST_SIGNAL
74
64
};
75
65
 
76
 
 
77
 
#define HAVE_COLORMAP(gimage) \
78
 
        (gimage != NULL && \
79
 
         gimp_image_base_type (gimage) == GIMP_INDEXED && \
80
 
         gimp_image_get_colormap (gimage) != NULL)
81
 
 
82
 
 
83
 
static void   gimp_colormap_editor_class_init (GimpColormapEditorClass *klass);
84
 
static void   gimp_colormap_editor_init       (GimpColormapEditor      *colormap_editor);
 
66
#define EPSILON 1e-10
 
67
 
 
68
#define HAVE_COLORMAP(image) \
 
69
        (image != NULL && \
 
70
         gimp_image_base_type (image) == GIMP_INDEXED && \
 
71
         gimp_image_get_colormap (image) != NULL)
 
72
 
85
73
 
86
74
static GObject * gimp_colormap_editor_constructor  (GType               type,
87
75
                                                    guint               n_params,
91
79
static void   gimp_colormap_editor_unmap           (GtkWidget          *widget);
92
80
 
93
81
static void   gimp_colormap_editor_set_image       (GimpImageEditor    *editor,
94
 
                                                    GimpImage          *gimage);
 
82
                                                    GimpImage          *image);
95
83
 
96
84
static void   gimp_colormap_editor_draw            (GimpColormapEditor *editor);
97
85
static void   gimp_colormap_editor_draw_cell       (GimpColormapEditor *editor,
99
87
static void   gimp_colormap_editor_clear           (GimpColormapEditor *editor,
100
88
                                                    gint                start_row);
101
89
static void   gimp_colormap_editor_update_entries  (GimpColormapEditor *editor);
102
 
static void   gimp_colormap_editor_set_index       (GimpColormapEditor *editor,
103
 
                                                    gint                i);
104
90
 
105
91
static void   gimp_colormap_preview_size_allocate  (GtkWidget          *widget,
106
92
                                                    GtkAllocation      *allocation,
113
99
                                                    GimpRGB            *color,
114
100
                                                    gpointer            data);
115
101
static void   gimp_colormap_preview_drop_color     (GtkWidget          *widget,
 
102
                                                    gint                x,
 
103
                                                    gint                y,
116
104
                                                    const GimpRGB      *color,
117
105
                                                    gpointer            data);
118
106
 
119
107
static void   gimp_colormap_adjustment_changed     (GtkAdjustment      *adjustment,
120
108
                                                    GimpColormapEditor *editor);
121
 
static void   gimp_colormap_hex_entry_activate     (GtkEntry           *entry,
122
 
                                                    GimpColormapEditor *editor);
123
 
static gboolean gimp_colormap_hex_entry_focus_out  (GtkEntry           *entry,
124
 
                                                    GdkEvent           *event,
 
109
static void   gimp_colormap_hex_entry_changed      (GimpColorHexEntry  *entry,
125
110
                                                    GimpColormapEditor *editor);
126
111
 
127
 
static void   gimp_colormap_image_mode_changed     (GimpImage          *gimage,
 
112
static void   gimp_colormap_image_mode_changed     (GimpImage          *image,
128
113
                                                    GimpColormapEditor *editor);
129
 
static void   gimp_colormap_image_colormap_changed (GimpImage          *gimage,
 
114
static void   gimp_colormap_image_colormap_changed (GimpImage          *image,
130
115
                                                    gint                ncol,
131
116
                                                    GimpColormapEditor *editor);
132
117
 
133
118
 
 
119
G_DEFINE_TYPE (GimpColormapEditor, gimp_colormap_editor,
 
120
               GIMP_TYPE_IMAGE_EDITOR)
 
121
 
 
122
#define parent_class gimp_colormap_editor_parent_class
 
123
 
134
124
static guint editor_signals[LAST_SIGNAL] = { 0 };
135
125
 
136
 
static GimpImageEditorClass *parent_class = NULL;
137
 
 
138
 
 
139
 
GType
140
 
gimp_colormap_editor_get_type (void)
141
 
{
142
 
  static GType type = 0;
143
 
 
144
 
  if (! type)
145
 
    {
146
 
      static const GTypeInfo info =
147
 
      {
148
 
        sizeof (GimpColormapEditorClass),
149
 
        (GBaseInitFunc) NULL,
150
 
        (GBaseFinalizeFunc) NULL,
151
 
        (GClassInitFunc) gimp_colormap_editor_class_init,
152
 
        NULL,           /* class_finalize */
153
 
        NULL,           /* class_data     */
154
 
        sizeof (GimpColormapEditor),
155
 
        0,              /* n_preallocs    */
156
 
        (GInstanceInitFunc) gimp_colormap_editor_init,
157
 
      };
158
 
 
159
 
      type = g_type_register_static (GIMP_TYPE_IMAGE_EDITOR,
160
 
                                     "GimpColormapEditor",
161
 
                                     &info, 0);
162
 
    }
163
 
 
164
 
  return type;
165
 
}
166
126
 
167
127
static void
168
128
gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
172
132
  GtkWidgetClass       *widget_class       = GTK_WIDGET_CLASS (klass);
173
133
  GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
174
134
 
175
 
  parent_class = g_type_class_peek_parent (klass);
176
 
 
177
135
  editor_signals[SELECTED] =
178
136
    g_signal_new ("selected",
179
137
                  G_TYPE_FROM_CLASS (klass),
200
158
{
201
159
  GtkWidget *frame;
202
160
  GtkWidget *table;
 
161
  GtkObject *adj;
203
162
 
204
163
  editor->col_index     = 0;
205
164
  editor->dnd_col_index = 0;
213
172
  gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
214
173
  gtk_widget_show (frame);
215
174
 
216
 
  editor->palette = gtk_preview_new (GTK_PREVIEW_COLOR);
217
 
  gtk_widget_set_size_request (editor->palette, -1, 60);
218
 
  gtk_preview_set_expand (GTK_PREVIEW (editor->palette), TRUE);
219
 
  gtk_widget_add_events (editor->palette, GDK_BUTTON_PRESS_MASK);
220
 
  gtk_container_add (GTK_CONTAINER (frame), editor->palette);
221
 
  gtk_widget_show (editor->palette);
 
175
  editor->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
 
176
  gtk_widget_set_size_request (editor->preview, -1, 60);
 
177
  gtk_preview_set_expand (GTK_PREVIEW (editor->preview), TRUE);
 
178
  gtk_widget_add_events (editor->preview, GDK_BUTTON_PRESS_MASK);
 
179
  gtk_container_add (GTK_CONTAINER (frame), editor->preview);
 
180
  gtk_widget_show (editor->preview);
222
181
 
223
 
  g_signal_connect_after (editor->palette, "size_allocate",
 
182
  g_signal_connect_after (editor->preview, "size-allocate",
224
183
                          G_CALLBACK (gimp_colormap_preview_size_allocate),
225
184
                          editor);
226
185
 
227
 
  g_signal_connect (editor->palette, "button_press_event",
 
186
  g_signal_connect (editor->preview, "button-press-event",
228
187
                    G_CALLBACK (gimp_colormap_preview_button_press),
229
188
                    editor);
230
189
 
231
 
  gimp_dnd_color_source_add (editor->palette, gimp_colormap_preview_drag_color,
 
190
  gimp_dnd_color_source_add (editor->preview, gimp_colormap_preview_drag_color,
232
191
                             editor);
233
 
  gimp_dnd_color_dest_add (editor->palette, gimp_colormap_preview_drop_color,
 
192
  gimp_dnd_color_dest_add (editor->preview, gimp_colormap_preview_drop_color,
234
193
                           editor);
235
194
 
236
195
  /*  Some helpful hints  */
240
199
  gtk_box_pack_end (GTK_BOX (editor), table, FALSE, FALSE, 0);
241
200
  gtk_widget_show (table);
242
201
 
243
 
  editor->index_spinbutton =
244
 
    gimp_spin_button_new ((GtkObject **) &editor->index_adjustment,
245
 
                          0, 0, 0, 1, 10, 10, 1.0, 0);
 
202
  editor->index_spinbutton = gimp_spin_button_new (&adj,
 
203
                                                   0, 0, 0, 1, 10, 10, 1.0, 0);
 
204
  editor->index_adjustment = GTK_ADJUSTMENT (adj);
246
205
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
247
206
                             _("Color index:"), 0.0, 0.5,
248
207
                             editor->index_spinbutton, 1, TRUE);
249
208
 
250
 
  g_signal_connect (editor->index_adjustment, "value_changed",
 
209
  g_signal_connect (editor->index_adjustment, "value-changed",
251
210
                    G_CALLBACK (gimp_colormap_adjustment_changed),
252
211
                    editor);
253
212
 
254
 
  editor->color_entry = gtk_entry_new ();
255
 
  gtk_entry_set_width_chars (GTK_ENTRY (editor->color_entry), 8);
256
 
  gtk_entry_set_max_length (GTK_ENTRY (editor->color_entry), 6);
 
213
  editor->color_entry = gimp_color_hex_entry_new ();
 
214
  gtk_entry_set_width_chars (GTK_ENTRY (editor->color_entry), 12);
257
215
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
258
216
                             _("HTML notation:"), 0.0, 0.5,
259
217
                             editor->color_entry, 1, TRUE);
260
218
 
261
 
  g_signal_connect (editor->color_entry, "activate",
262
 
                    G_CALLBACK (gimp_colormap_hex_entry_activate),
263
 
                    editor);
264
 
  g_signal_connect (editor->color_entry, "focus_out_event",
265
 
                    G_CALLBACK (gimp_colormap_hex_entry_focus_out),
 
219
  g_signal_connect (editor->color_entry, "color-changed",
 
220
                    G_CALLBACK (gimp_colormap_hex_entry_changed),
266
221
                    editor);
267
222
}
268
223
 
279
234
  editor = GIMP_COLORMAP_EDITOR (object);
280
235
 
281
236
  editor->edit_button =
282
 
    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap-editor",
283
 
                                   "colormap-editor-edit-color",
 
237
    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
 
238
                                   "colormap-edit-color",
284
239
                                   NULL);
285
240
 
286
241
  editor->add_button =
287
 
    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap-editor",
288
 
                                   "colormap-editor-add-color-from-fg",
289
 
                                   "colormap-editor-add-color-from-bg",
 
242
    gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
 
243
                                   "colormap-add-color-from-fg",
 
244
                                   "colormap-add-color-from-bg",
290
245
                                   GDK_CONTROL_MASK,
291
246
                                   NULL);
292
247
 
320
275
 
321
276
static void
322
277
gimp_colormap_editor_set_image (GimpImageEditor *image_editor,
323
 
                                GimpImage       *gimage)
 
278
                                GimpImage       *image)
324
279
{
325
280
  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (image_editor);
326
281
 
327
 
  if (image_editor->gimage)
 
282
  if (image_editor->image)
328
283
    {
329
 
      g_signal_handlers_disconnect_by_func (image_editor->gimage,
 
284
      g_signal_handlers_disconnect_by_func (image_editor->image,
330
285
                                            gimp_colormap_image_mode_changed,
331
286
                                            editor);
332
 
      g_signal_handlers_disconnect_by_func (image_editor->gimage,
 
287
      g_signal_handlers_disconnect_by_func (image_editor->image,
333
288
                                            gimp_colormap_image_colormap_changed,
334
289
                                            editor);
335
290
 
336
291
      if (editor->color_dialog)
337
292
        gtk_widget_hide (editor->color_dialog);
338
293
 
339
 
      if (! HAVE_COLORMAP (gimage))
 
294
      if (! HAVE_COLORMAP (image))
340
295
        {
341
296
          editor->index_adjustment->upper = 0;
342
297
          gtk_adjustment_changed (editor->index_adjustment);
346
301
        }
347
302
    }
348
303
 
349
 
  GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, gimage);
 
304
  GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
350
305
 
351
306
  editor->col_index     = 0;
352
307
  editor->dnd_col_index = 0;
353
308
 
354
 
  if (gimage)
 
309
  if (image)
355
310
    {
356
 
      g_signal_connect (gimage, "mode_changed",
 
311
      g_signal_connect (image, "mode-changed",
357
312
                        G_CALLBACK (gimp_colormap_image_mode_changed),
358
313
                        editor);
359
 
      g_signal_connect (gimage, "colormap_changed",
 
314
      g_signal_connect (image, "colormap-changed",
360
315
                        G_CALLBACK (gimp_colormap_image_colormap_changed),
361
316
                        editor);
362
317
 
363
 
      if (HAVE_COLORMAP (gimage))
 
318
      if (HAVE_COLORMAP (image))
364
319
        {
365
320
          gimp_colormap_editor_draw (editor);
366
321
 
367
322
          editor->index_adjustment->upper =
368
 
            gimp_image_get_colormap_size (gimage) - 1;
 
323
            gimp_image_get_colormap_size (image) - 1;
369
324
 
370
325
          gtk_adjustment_changed (editor->index_adjustment);
371
326
        }
384
339
 
385
340
  return g_object_new (GIMP_TYPE_COLORMAP_EDITOR,
386
341
                       "menu-factory",    menu_factory,
387
 
                       "menu-identifier", "<ColormapEditor>",
388
 
                       "ui-path",         "/colormap-editor-popup",
 
342
                       "menu-identifier", "<Colormap>",
 
343
                       "ui-path",         "/colormap-popup",
389
344
                       NULL);
390
345
}
391
346
 
392
 
void
393
 
gimp_colormap_editor_selected (GimpColormapEditor *editor,
394
 
                               GdkModifierType     state)
395
 
{
396
 
  g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor));
397
 
 
398
 
  g_signal_emit (editor, editor_signals[SELECTED], 0, state);
399
 
}
400
 
 
401
 
gint
402
 
gimp_colormap_editor_col_index (GimpColormapEditor *editor)
403
 
{
404
 
  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 0);
405
 
 
406
 
  return editor->col_index;
 
347
gint
 
348
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
 
349
                                const GimpRGB      *search)
 
350
{
 
351
  GimpImage *image;
 
352
  gint       index;
 
353
 
 
354
  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 01);
 
355
 
 
356
  image = GIMP_IMAGE_EDITOR (editor)->image;
 
357
 
 
358
  if (! HAVE_COLORMAP (image))
 
359
    return -1;
 
360
 
 
361
  index = editor->col_index;
 
362
 
 
363
  if (search)
 
364
    {
 
365
      GimpRGB temp;
 
366
 
 
367
      gimp_image_get_colormap_entry (image, index, &temp);
 
368
 
 
369
      if (gimp_rgb_distance (&temp, search) > EPSILON)
 
370
        {
 
371
          gint n_colors = gimp_image_get_colormap_size (image);
 
372
          gint i;
 
373
 
 
374
          for (i = 0; i < n_colors; i++)
 
375
            {
 
376
              gimp_image_get_colormap_entry (image, i, &temp);
 
377
 
 
378
              if (gimp_rgb_distance (&temp, search) < EPSILON)
 
379
                {
 
380
                  index = i;
 
381
                  break;
 
382
                }
 
383
            }
 
384
        }
 
385
    }
 
386
 
 
387
  return index;
 
388
}
 
389
 
 
390
gboolean
 
391
gimp_colormap_editor_set_index (GimpColormapEditor *editor,
 
392
                                gint                index,
 
393
                                GimpRGB            *color)
 
394
{
 
395
  GimpImage *image;
 
396
 
 
397
  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
 
398
 
 
399
  image = GIMP_IMAGE_EDITOR (editor)->image;
 
400
 
 
401
  if (! HAVE_COLORMAP (image))
 
402
    return FALSE;
 
403
 
 
404
  index = CLAMP (index, 0, gimp_image_get_colormap_size (image) - 1);
 
405
 
 
406
  if (index != editor->col_index)
 
407
    {
 
408
      gint old = editor->col_index;
 
409
 
 
410
      editor->col_index     = index;
 
411
      editor->dnd_col_index = index;
 
412
 
 
413
      gimp_colormap_editor_draw_cell (editor, old);
 
414
      gimp_colormap_editor_draw_cell (editor, index);
 
415
 
 
416
      gimp_colormap_editor_update_entries (editor);
 
417
    }
 
418
 
 
419
  if (color)
 
420
    gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
 
421
                                   index, color);
 
422
 
 
423
  return TRUE;
 
424
}
 
425
 
 
426
gint
 
427
gimp_colormap_editor_max_index (GimpColormapEditor *editor)
 
428
{
 
429
  GimpImage *image;
 
430
 
 
431
  g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), -1);
 
432
 
 
433
  image = GIMP_IMAGE_EDITOR (editor)->image;
 
434
 
 
435
  if (! HAVE_COLORMAP (image))
 
436
    return -1;
 
437
 
 
438
  return MAX (0, gimp_image_get_colormap_size (image) - 1);
407
439
}
408
440
 
409
441
 
414
446
static void
415
447
gimp_colormap_editor_draw (GimpColormapEditor *editor)
416
448
{
417
 
  GimpImage *gimage;
 
449
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
418
450
  gint       i, j, k, l, b;
419
451
  gint       col;
420
452
  guchar    *row;
421
453
  gint       cellsize, ncol, xn, yn, width, height;
422
 
  GtkWidget *palette;
423
 
 
424
 
  gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
425
 
 
426
 
  palette = editor->palette;
427
 
  width   = palette->allocation.width;
428
 
  height  = palette->allocation.height;
429
 
  ncol    = gimp_image_get_colormap_size (gimage);
 
454
 
 
455
  width  = editor->preview->allocation.width;
 
456
  height = editor->preview->allocation.height;
 
457
  ncol   = gimp_image_get_colormap_size (image);
430
458
 
431
459
  if (! ncol)
432
460
    {
469
497
        {
470
498
          for (k = 0; k < cellsize; k++)
471
499
            for (b = 0; b < 3; b++)
472
 
              row[(j * cellsize + k) * 3 + b] = gimage->cmap[col * 3 + b];
 
500
              row[(j * cellsize + k) * 3 + b] = image->cmap[col * 3 + b];
473
501
        }
474
502
 
475
503
      for (k = 0; k < cellsize; k++)
479
507
              row[l * 3 + b] = (((((i * cellsize + k) & 0x4) ?
480
508
                                  (l) :
481
509
                                  (l + 0x4)) & 0x4) ?
482
 
                                render_blend_light_check[0] :
483
 
                                render_blend_dark_check[0]);
 
510
                                gimp_render_blend_light_check[0] :
 
511
                                gimp_render_blend_dark_check[0]);
484
512
 
485
 
          gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row, 0,
 
513
          gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, 0,
486
514
                                i * cellsize + k,
487
515
                                width);
488
516
        }
493
521
  gimp_colormap_editor_draw_cell (editor, editor->col_index);
494
522
 
495
523
  g_free (row);
496
 
  gtk_widget_queue_draw (palette);
 
524
  gtk_widget_queue_draw (editor->preview);
497
525
}
498
526
 
499
527
static void
500
528
gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
501
529
                                gint                col)
502
530
{
503
 
  GimpImage *gimage;
504
 
  guchar    *row;
505
 
  gint       cellsize, x, y, k;
506
 
 
507
 
  gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
508
 
 
509
 
  cellsize = editor->cellsize;
510
 
  row = g_alloca (cellsize * 3);
 
531
  GimpImage *image    = GIMP_IMAGE_EDITOR (editor)->image;
 
532
  gint       cellsize = editor->cellsize;
 
533
  guchar    *row      = g_alloca (cellsize * 3);
 
534
  gint       x, y, k;
 
535
 
511
536
  x = (col % editor->xn) * cellsize;
512
537
  y = (col / editor->xn) * cellsize;
513
538
 
515
540
    {
516
541
      for(k = 0; k < cellsize; k++)
517
542
        row[k*3] = row[k*3+1] = row[k*3+2] = (k & 1) * 255;
518
 
      gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row, x, y, cellsize);
 
543
      gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, x, y, cellsize);
519
544
 
520
545
      if (!(cellsize & 1))
521
546
        for (k = 0; k < cellsize; k++)
522
547
          row[k*3] = row[k*3+1] = row[k*3+2] = ((x+y+1) & 1) * 255;
523
 
      gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
548
      gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
524
549
                            x, y+cellsize-1, cellsize);
525
550
 
526
551
      row[0]=row[1]=row[2]=255;
528
553
        = 255 * (cellsize & 1);
529
554
      for (k = 1; k < cellsize - 1; k++)
530
555
        {
531
 
          row[k*3]   = gimage->cmap[col * 3];
532
 
          row[k*3+1] = gimage->cmap[col * 3 + 1];
533
 
          row[k*3+2] = gimage->cmap[col * 3 + 2];
 
556
          row[k*3]   = image->cmap[col * 3];
 
557
          row[k*3+1] = image->cmap[col * 3 + 1];
 
558
          row[k*3+2] = image->cmap[col * 3 + 2];
534
559
        }
535
560
      for (k = 1; k < cellsize - 1; k+=2)
536
 
        gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
561
        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
537
562
                              x, y+k, cellsize);
538
563
 
539
564
      row[0] = row[1] = row[2] = 0;
540
565
      row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1]
541
566
        = 255 * ((cellsize+1) & 1);
542
567
      for (k = 2; k < cellsize - 1; k += 2)
543
 
        gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
568
        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
544
569
                              x, y+k, cellsize);
545
570
    }
546
571
  else
547
572
    {
548
573
      for (k = 0; k < cellsize; k++)
549
574
        {
550
 
          row[k*3]   = gimage->cmap[col * 3];
551
 
          row[k*3+1] = gimage->cmap[col * 3 + 1];
552
 
          row[k*3+2] = gimage->cmap[col * 3 + 2];
 
575
          row[k*3]   = image->cmap[col * 3];
 
576
          row[k*3+1] = image->cmap[col * 3 + 1];
 
577
          row[k*3+2] = image->cmap[col * 3 + 2];
553
578
        }
554
579
      for (k = 0; k < cellsize; k++)
555
 
        gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
580
        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
556
581
                              x, y+k, cellsize);
557
582
    }
558
583
 
559
 
  gtk_widget_queue_draw_area (editor->palette,
 
584
  gtk_widget_queue_draw_area (editor->preview,
560
585
                              x, y,
561
586
                              cellsize, cellsize);
562
587
}
565
590
gimp_colormap_editor_clear (GimpColormapEditor *editor,
566
591
                            gint                start_row)
567
592
{
568
 
  gint       i, j;
569
 
  gint       offset;
570
 
  gint       width, height;
571
 
  guchar    *row = NULL;
572
 
  GtkWidget *palette;
573
 
 
574
 
  palette = editor->palette;
575
 
 
576
 
  width  = palette->allocation.width;
577
 
  height = palette->allocation.height;
 
593
  gint    i, j;
 
594
  gint    offset;
 
595
  gint    width, height;
 
596
  guchar *row;
 
597
 
 
598
  width  = editor->preview->allocation.width;
 
599
  height = editor->preview->allocation.height;
578
600
 
579
601
  if (start_row < 0)
580
602
    start_row = 0;
582
604
  if (start_row >= height)
583
605
    return;
584
606
 
585
 
  if (width > 0)
586
 
    row = g_new (guchar, width * 3);
 
607
  row = g_alloca (width * 3);
587
608
 
588
609
  if (start_row & 0x3)
589
610
    {
593
614
        {
594
615
          row[j * 3 + 0] = row[j * 3 + 1] = row[j * 3 + 2] =
595
616
            ((j + offset) & 0x4) ?
596
 
            render_blend_dark_check[0] : render_blend_light_check[0];
 
617
            gimp_render_blend_dark_check[0] : gimp_render_blend_light_check[0];
597
618
        }
598
619
 
599
620
      for (j = 0; j < (4 - (start_row & 0x3)) && start_row + j < height; j++)
600
 
        gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
621
        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
601
622
                              0, start_row + j, width);
602
623
 
603
624
      start_row += (4 - (start_row & 0x3));
611
632
        {
612
633
          row[j * 3 + 0] = row[j * 3 + 1] = row[j * 3 + 2] =
613
634
            ((j + offset) & 0x4) ?
614
 
            render_blend_dark_check[0] : render_blend_light_check[0];
 
635
            gimp_render_blend_dark_check[0] : gimp_render_blend_light_check[0];
615
636
        }
616
637
 
617
638
      for (j = 0; j < 4 && i + j < height; j++)
618
 
        gtk_preview_draw_row (GTK_PREVIEW (editor->palette), row,
 
639
        gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
619
640
                              0, i + j, width);
620
641
    }
621
642
 
622
 
  if (width > 0)
623
 
    g_free (row);
624
 
 
625
 
  gtk_widget_queue_draw (palette);
 
643
  gtk_widget_queue_draw (editor->preview);
626
644
}
627
645
 
628
646
static void
629
647
gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
630
648
{
631
 
  GimpImage *gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
 
649
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
632
650
 
633
 
  if (! HAVE_COLORMAP (gimage))
 
651
  if (! HAVE_COLORMAP (image))
634
652
    {
635
653
      gtk_widget_set_sensitive (editor->index_spinbutton, FALSE);
636
654
      gtk_widget_set_sensitive (editor->color_entry, FALSE);
645
663
 
646
664
      gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
647
665
 
648
 
      col = &gimage->cmap[editor->col_index * 3];
 
666
      col = image->cmap + editor->col_index * 3;
649
667
 
650
668
      string = g_strdup_printf ("%02x%02x%02x", col[0], col[1], col[2]);
651
669
      gtk_entry_set_text (GTK_ENTRY (editor->color_entry), string);
657
675
}
658
676
 
659
677
static void
660
 
gimp_colormap_editor_set_index (GimpColormapEditor *editor,
661
 
                                gint                i)
662
 
{
663
 
  if (i != editor->col_index)
664
 
    {
665
 
      gint old = editor->col_index;
666
 
 
667
 
      editor->col_index     = i;
668
 
      editor->dnd_col_index = i;
669
 
 
670
 
      gimp_colormap_editor_draw_cell (editor, old);
671
 
      gimp_colormap_editor_draw_cell (editor, i);
672
 
 
673
 
      gimp_colormap_editor_update_entries (editor);
674
 
    }
675
 
}
676
 
 
677
 
static void
678
678
gimp_colormap_preview_size_allocate (GtkWidget          *widget,
679
679
                                     GtkAllocation      *alloc,
680
680
                                     GimpColormapEditor *editor)
681
681
{
682
 
  GimpImage *gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
 
682
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
683
683
 
684
 
  if (HAVE_COLORMAP (gimage))
 
684
  if (HAVE_COLORMAP (image))
685
685
    gimp_colormap_editor_draw (editor);
686
686
  else
687
687
    gimp_colormap_editor_clear (editor, -1);
693
693
                                    GdkEventButton     *bevent,
694
694
                                    GimpColormapEditor *editor)
695
695
{
696
 
  GimpImage *gimage;
 
696
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
697
697
  guint      col;
698
698
 
699
 
  gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
700
 
 
701
 
  if (! HAVE_COLORMAP (gimage))
 
699
  if (! HAVE_COLORMAP (image))
702
700
    return TRUE;
703
701
 
704
702
  if (!(bevent->y < editor->cellsize * editor->yn
708
706
  col = (editor->xn * ((gint) bevent->y / editor->cellsize) +
709
707
         ((gint) bevent->x / editor->cellsize));
710
708
 
711
 
  if (col >= gimp_image_get_colormap_size (gimage))
 
709
  if (col >= gimp_image_get_colormap_size (image))
712
710
    return TRUE;
713
711
 
714
712
  switch (bevent->button)
715
713
    {
716
714
    case 1:
717
 
      gimp_colormap_editor_set_index (editor, col);
718
 
      gimp_colormap_editor_selected (editor, bevent->state);
 
715
      gimp_colormap_editor_set_index (editor, col, NULL);
 
716
      g_signal_emit (editor, editor_signals[SELECTED], 0, bevent->state);
719
717
 
720
718
      if (bevent->type == GDK_2BUTTON_PRESS)
721
 
        {
722
 
          GtkAction *action;
723
 
 
724
 
          action = gimp_ui_manager_find_action (GIMP_EDITOR (editor)->ui_manager,
725
 
                                                "colormap-editor",
726
 
                                                "colormap-editor-edit-color");
727
 
 
728
 
          if (action)
729
 
            gtk_action_activate (action);
730
 
        }
 
719
        gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
 
720
                                         "colormap",
 
721
                                         "colormap-edit-color");
731
722
      return TRUE;
732
723
 
733
724
    case 2:
735
726
      break;
736
727
 
737
728
    case 3:
738
 
      gimp_colormap_editor_set_index (editor, col);
 
729
      gimp_colormap_editor_set_index (editor, col, NULL);
739
730
      gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
740
731
      return TRUE;
741
732
 
751
742
                                  GimpRGB   *color,
752
743
                                  gpointer   data)
753
744
{
754
 
  GimpColormapEditor *editor;
755
 
  GimpImage          *gimage;
756
 
 
757
 
  editor = GIMP_COLORMAP_EDITOR (data);
758
 
  gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
759
 
 
760
 
  if (HAVE_COLORMAP (gimage))
761
 
    gimp_image_get_colormap_entry (gimage, editor->dnd_col_index, color);
 
745
  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
 
746
  GimpImage          *image = GIMP_IMAGE_EDITOR (editor)->image;
 
747
 
 
748
  if (HAVE_COLORMAP (image))
 
749
    gimp_image_get_colormap_entry (image, editor->dnd_col_index, color);
762
750
}
763
751
 
764
752
static void
765
753
gimp_colormap_preview_drop_color (GtkWidget     *widget,
 
754
                                  gint           x,
 
755
                                  gint           y,
766
756
                                  const GimpRGB *color,
767
757
                                  gpointer       data)
768
758
{
769
 
  GimpColormapEditor *editor;
770
 
  GimpImage          *gimage;
771
 
 
772
 
  editor = GIMP_COLORMAP_EDITOR (data);
773
 
  gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
774
 
 
775
 
  if (HAVE_COLORMAP (gimage) && gimp_image_get_colormap_size (gimage) < 256)
 
759
  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
 
760
  GimpImage          *image = GIMP_IMAGE_EDITOR (editor)->image;
 
761
 
 
762
  if (HAVE_COLORMAP (image) && gimp_image_get_colormap_size (image) < 256)
776
763
    {
777
 
      gimp_image_add_colormap_entry (gimage, color);
 
764
      gimp_image_add_colormap_entry (image, color);
778
765
    }
779
766
}
780
767
 
782
769
gimp_colormap_adjustment_changed (GtkAdjustment      *adjustment,
783
770
                                  GimpColormapEditor *editor)
784
771
{
785
 
  GimpImage *gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
 
772
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
786
773
 
787
 
  if (HAVE_COLORMAP (gimage))
 
774
  if (HAVE_COLORMAP (image))
788
775
    {
789
 
      gimp_colormap_editor_set_index (editor, adjustment->value + 0.5);
 
776
      gimp_colormap_editor_set_index (editor, adjustment->value + 0.5, NULL);
790
777
 
791
778
      gimp_colormap_editor_update_entries (editor);
792
779
    }
793
780
}
794
781
 
795
782
static void
796
 
gimp_colormap_hex_entry_activate (GtkEntry           *entry,
797
 
                                  GimpColormapEditor *editor)
 
783
gimp_colormap_hex_entry_changed (GimpColorHexEntry  *entry,
 
784
                                 GimpColormapEditor *editor)
798
785
{
799
 
  GimpImage *gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
 
786
  GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
800
787
 
801
 
  if (gimage)
 
788
  if (image)
802
789
    {
803
 
      const gchar *s;
804
 
      gulong       i;
805
 
 
806
 
      s = gtk_entry_get_text (entry);
807
 
 
808
 
      if (sscanf (s, "%lx", &i))
809
 
        {
810
 
          GimpRGB color;
811
 
          guchar  r, g, b;
812
 
 
813
 
          r = (i & 0xFF0000) >> 16;
814
 
          g = (i & 0x00FF00) >> 8;
815
 
          b = (i & 0x0000FF);
816
 
 
817
 
          gimp_rgb_set_uchar (&color, r, g, b);
818
 
 
819
 
          gimp_image_set_colormap_entry (gimage, editor->col_index, &color,
820
 
                                         TRUE);
821
 
          gimp_image_flush (gimage);
822
 
        }
 
790
      GimpRGB color;
 
791
 
 
792
      gimp_color_hex_entry_get_color (entry, &color);
 
793
 
 
794
      gimp_image_set_colormap_entry (image, editor->col_index, &color, TRUE);
 
795
      gimp_image_flush (image);
823
796
    }
824
797
}
825
798
 
826
 
static gboolean
827
 
gimp_colormap_hex_entry_focus_out (GtkEntry           *entry,
828
 
                                   GdkEvent           *event,
829
 
                                   GimpColormapEditor *editor)
830
 
{
831
 
  gimp_colormap_hex_entry_activate (entry, editor);
832
 
 
833
 
  return FALSE;
834
 
}
835
 
 
836
799
static void
837
 
gimp_colormap_image_mode_changed (GimpImage          *gimage,
 
800
gimp_colormap_image_mode_changed (GimpImage          *image,
838
801
                                  GimpColormapEditor *editor)
839
802
{
840
803
  if (editor->color_dialog)
841
804
    gtk_widget_hide (editor->color_dialog);
842
805
 
843
 
  gimp_colormap_image_colormap_changed (gimage, -1, editor);
 
806
  gimp_colormap_image_colormap_changed (image, -1, editor);
844
807
}
845
808
 
846
809
static void
847
 
gimp_colormap_image_colormap_changed (GimpImage          *gimage,
 
810
gimp_colormap_image_colormap_changed (GimpImage          *image,
848
811
                                      gint                ncol,
849
812
                                      GimpColormapEditor *editor)
850
813
{
851
 
  if (HAVE_COLORMAP (gimage))
 
814
  if (HAVE_COLORMAP (image))
852
815
    {
853
816
      if (ncol < 0)
854
817
        {
860
823
        }
861
824
 
862
825
      if (editor->index_adjustment->upper !=
863
 
          (gimp_image_get_colormap_size (gimage) - 1))
 
826
          (gimp_image_get_colormap_size (image) - 1))
864
827
        {
865
828
          editor->index_adjustment->upper =
866
 
            gimp_image_get_colormap_size (gimage) - 1;
 
829
            gimp_image_get_colormap_size (image) - 1;
867
830
 
868
831
          gtk_adjustment_changed (editor->index_adjustment);
869
832
        }