1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
24
#include <glib-object.h>
26
#include "libgimpcolor/gimpcolor.h"
27
#include "libgimpmath/gimpmath.h"
28
#include "libgimpbase/gimpbase.h"
30
#include "core-types.h"
32
#include "base/temp-buf.h"
33
#include "base/tile-manager.h"
35
#include "config/gimpconfig.h"
36
#include "config/gimpconfig-utils.h"
37
#include "config/gimpcoreconfig.h"
40
#include "gimp-parasites.h"
41
#include "gimp-utils.h"
42
#include "gimpcontext.h"
44
#include "gimpimage.h"
45
#include "gimpimage-colorhash.h"
46
#include "gimpimage-colormap.h"
47
#include "gimpimage-guides.h"
48
#include "gimpimage-preview.h"
49
#include "gimpimage-qmask.h"
50
#include "gimpimage-undo.h"
51
#include "gimpimage-undo-push.h"
52
#include "gimplayer.h"
53
#include "gimplayer-floating-sel.h"
54
#include "gimplayermask.h"
56
#include "gimpmarshal.h"
57
#include "gimpparasitelist.h"
58
#include "gimpprojection.h"
59
#include "gimpselection.h"
60
#include "gimptemplate.h"
61
#include "gimpundostack.h"
63
#include "file/file-utils.h"
65
#include "vectors/gimpvectors.h"
67
#include "gimp-intl.h"
71
#define TRC(x) printf x
81
FLOATING_SELECTION_CHANGED,
83
ACTIVE_CHANNEL_CHANGED,
84
ACTIVE_VECTORS_CHANGED,
85
COMPONENT_VISIBILITY_CHANGED,
86
COMPONENT_ACTIVE_CHANGED,
113
/* local function prototypes */
115
static void gimp_image_class_init (GimpImageClass *klass);
116
static void gimp_image_init (GimpImage *gimage);
118
static GObject *gimp_image_constructor (GType type,
120
GObjectConstructParam *params);
121
static void gimp_image_set_property (GObject *object,
125
static void gimp_image_get_property (GObject *object,
129
static void gimp_image_dispose (GObject *object);
130
static void gimp_image_finalize (GObject *object);
132
static void gimp_image_name_changed (GimpObject *object);
133
static gint64 gimp_image_get_memsize (GimpObject *object,
136
static void gimp_image_invalidate_preview (GimpViewable *viewable);
137
static void gimp_image_size_changed (GimpViewable *viewable);
138
static gchar * gimp_image_get_description (GimpViewable *viewable,
140
static void gimp_image_real_colormap_changed (GimpImage *gimage,
142
static void gimp_image_real_flush (GimpImage *gimage);
144
static void gimp_image_mask_update (GimpDrawable *drawable,
150
static void gimp_image_drawable_update (GimpDrawable *drawable,
156
static void gimp_image_drawable_visibility (GimpItem *item,
158
static void gimp_image_layer_alpha_changed (GimpDrawable *drawable,
160
static void gimp_image_layer_add (GimpContainer *container,
163
static void gimp_image_layer_remove (GimpContainer *container,
166
static void gimp_image_channel_add (GimpContainer *container,
167
GimpChannel *channel,
169
static void gimp_image_channel_remove (GimpContainer *container,
170
GimpChannel *channel,
172
static void gimp_image_channel_name_changed (GimpChannel *channel,
174
static void gimp_image_channel_color_changed (GimpChannel *channel,
178
static gint valid_combinations[][MAX_CHANNELS + 1] =
181
{ -1, -1, -1, COMBINE_INTEN_INTEN, COMBINE_INTEN_INTEN_A },
182
/* GIMP_RGBA_IMAGE */
183
{ -1, -1, -1, COMBINE_INTEN_A_INTEN, COMBINE_INTEN_A_INTEN_A },
184
/* GIMP_GRAY_IMAGE */
185
{ -1, COMBINE_INTEN_INTEN, COMBINE_INTEN_INTEN_A, -1, -1 },
186
/* GIMP_GRAYA_IMAGE */
187
{ -1, COMBINE_INTEN_A_INTEN, COMBINE_INTEN_A_INTEN_A, -1, -1 },
188
/* GIMP_INDEXED_IMAGE */
189
{ -1, COMBINE_INDEXED_INDEXED, COMBINE_INDEXED_INDEXED_A, -1, -1 },
190
/* GIMP_INDEXEDA_IMAGE */
191
{ -1, -1, COMBINE_INDEXED_A_INDEXED_A, -1, -1 },
194
static guint gimp_image_signals[LAST_SIGNAL] = { 0 };
196
static GimpViewableClass *parent_class = NULL;
200
gimp_image_get_type (void)
202
static GType image_type = 0;
206
static const GTypeInfo image_info =
208
sizeof (GimpImageClass),
209
NULL, /* base_init */
210
NULL, /* base_finalize */
211
(GClassInitFunc) gimp_image_class_init,
212
NULL, /* class_finalize */
213
NULL, /* class_data */
216
(GInstanceInitFunc) gimp_image_init,
219
image_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
228
/* private functions */
231
gimp_image_class_init (GimpImageClass *klass)
233
GObjectClass *object_class = G_OBJECT_CLASS (klass);
234
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
235
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
237
parent_class = g_type_class_peek_parent (klass);
239
gimp_image_signals[MODE_CHANGED] =
240
g_signal_new ("mode_changed",
241
G_TYPE_FROM_CLASS (klass),
243
G_STRUCT_OFFSET (GimpImageClass, mode_changed),
245
gimp_marshal_VOID__VOID,
248
gimp_image_signals[ALPHA_CHANGED] =
249
g_signal_new ("alpha_changed",
250
G_TYPE_FROM_CLASS (klass),
252
G_STRUCT_OFFSET (GimpImageClass, alpha_changed),
254
gimp_marshal_VOID__VOID,
257
gimp_image_signals[FLOATING_SELECTION_CHANGED] =
258
g_signal_new ("floating_selection_changed",
259
G_TYPE_FROM_CLASS (klass),
261
G_STRUCT_OFFSET (GimpImageClass, floating_selection_changed),
263
gimp_marshal_VOID__VOID,
266
gimp_image_signals[ACTIVE_LAYER_CHANGED] =
267
g_signal_new ("active_layer_changed",
268
G_TYPE_FROM_CLASS (klass),
270
G_STRUCT_OFFSET (GimpImageClass, active_layer_changed),
272
gimp_marshal_VOID__VOID,
275
gimp_image_signals[ACTIVE_CHANNEL_CHANGED] =
276
g_signal_new ("active_channel_changed",
277
G_TYPE_FROM_CLASS (klass),
279
G_STRUCT_OFFSET (GimpImageClass, active_channel_changed),
281
gimp_marshal_VOID__VOID,
284
gimp_image_signals[ACTIVE_VECTORS_CHANGED] =
285
g_signal_new ("active_vectors_changed",
286
G_TYPE_FROM_CLASS (klass),
288
G_STRUCT_OFFSET (GimpImageClass, active_vectors_changed),
290
gimp_marshal_VOID__VOID,
293
gimp_image_signals[COMPONENT_VISIBILITY_CHANGED] =
294
g_signal_new ("component_visibility_changed",
295
G_TYPE_FROM_CLASS (klass),
297
G_STRUCT_OFFSET (GimpImageClass, component_visibility_changed),
299
gimp_marshal_VOID__ENUM,
301
GIMP_TYPE_CHANNEL_TYPE);
303
gimp_image_signals[COMPONENT_ACTIVE_CHANGED] =
304
g_signal_new ("component_active_changed",
305
G_TYPE_FROM_CLASS (klass),
307
G_STRUCT_OFFSET (GimpImageClass, component_active_changed),
309
gimp_marshal_VOID__ENUM,
311
GIMP_TYPE_CHANNEL_TYPE);
313
gimp_image_signals[MASK_CHANGED] =
314
g_signal_new ("mask_changed",
315
G_TYPE_FROM_CLASS (klass),
317
G_STRUCT_OFFSET (GimpImageClass, mask_changed),
319
gimp_marshal_VOID__VOID,
322
gimp_image_signals[RESOLUTION_CHANGED] =
323
g_signal_new ("resolution_changed",
324
G_TYPE_FROM_CLASS (klass),
326
G_STRUCT_OFFSET (GimpImageClass, resolution_changed),
328
gimp_marshal_VOID__VOID,
331
gimp_image_signals[UNIT_CHANGED] =
332
g_signal_new ("unit_changed",
333
G_TYPE_FROM_CLASS (klass),
335
G_STRUCT_OFFSET (GimpImageClass, unit_changed),
337
gimp_marshal_VOID__VOID,
340
gimp_image_signals[QMASK_CHANGED] =
341
g_signal_new ("qmask_changed",
342
G_TYPE_FROM_CLASS (klass),
344
G_STRUCT_OFFSET (GimpImageClass, qmask_changed),
346
gimp_marshal_VOID__VOID,
349
gimp_image_signals[SELECTION_CONTROL] =
350
g_signal_new ("selection_control",
351
G_TYPE_FROM_CLASS (klass),
353
G_STRUCT_OFFSET (GimpImageClass, selection_control),
355
gimp_marshal_VOID__ENUM,
357
GIMP_TYPE_SELECTION_CONTROL);
359
gimp_image_signals[CLEAN] =
360
g_signal_new ("clean",
361
G_TYPE_FROM_CLASS (klass),
363
G_STRUCT_OFFSET (GimpImageClass, clean),
365
gimp_marshal_VOID__FLAGS,
367
GIMP_TYPE_DIRTY_MASK);
369
gimp_image_signals[DIRTY] =
370
g_signal_new ("dirty",
371
G_TYPE_FROM_CLASS (klass),
373
G_STRUCT_OFFSET (GimpImageClass, dirty),
375
gimp_marshal_VOID__FLAGS,
377
GIMP_TYPE_DIRTY_MASK);
379
gimp_image_signals[UPDATE] =
380
g_signal_new ("update",
381
G_TYPE_FROM_CLASS (klass),
383
G_STRUCT_OFFSET (GimpImageClass, update),
385
gimp_marshal_VOID__INT_INT_INT_INT,
392
gimp_image_signals[UPDATE_GUIDE] =
393
g_signal_new ("update_guide",
394
G_TYPE_FROM_CLASS (klass),
396
G_STRUCT_OFFSET (GimpImageClass, update_guide),
398
gimp_marshal_VOID__POINTER,
402
gimp_image_signals[COLORMAP_CHANGED] =
403
g_signal_new ("colormap_changed",
404
G_TYPE_FROM_CLASS (klass),
406
G_STRUCT_OFFSET (GimpImageClass, colormap_changed),
408
gimp_marshal_VOID__INT,
412
gimp_image_signals[UNDO_EVENT] =
413
g_signal_new ("undo_event",
414
G_TYPE_FROM_CLASS (klass),
416
G_STRUCT_OFFSET (GimpImageClass, undo_event),
418
gimp_marshal_VOID__ENUM_OBJECT,
420
GIMP_TYPE_UNDO_EVENT,
423
gimp_image_signals[FLUSH] =
424
g_signal_new ("flush",
425
G_TYPE_FROM_CLASS (klass),
427
G_STRUCT_OFFSET (GimpImageClass, flush),
429
gimp_marshal_VOID__VOID,
432
object_class->constructor = gimp_image_constructor;
433
object_class->set_property = gimp_image_set_property;
434
object_class->get_property = gimp_image_get_property;
435
object_class->dispose = gimp_image_dispose;
436
object_class->finalize = gimp_image_finalize;
438
gimp_object_class->name_changed = gimp_image_name_changed;
439
gimp_object_class->get_memsize = gimp_image_get_memsize;
441
viewable_class->default_stock_id = "gimp-image";
442
viewable_class->invalidate_preview = gimp_image_invalidate_preview;
443
viewable_class->size_changed = gimp_image_size_changed;
444
viewable_class->get_preview_size = gimp_image_get_preview_size;
445
viewable_class->get_popup_size = gimp_image_get_popup_size;
446
viewable_class->get_preview = gimp_image_get_preview;
447
viewable_class->get_new_preview = gimp_image_get_new_preview;
448
viewable_class->get_description = gimp_image_get_description;
450
klass->mode_changed = NULL;
451
klass->alpha_changed = NULL;
452
klass->floating_selection_changed = NULL;
453
klass->active_layer_changed = NULL;
454
klass->active_channel_changed = NULL;
455
klass->active_vectors_changed = NULL;
456
klass->component_visibility_changed = NULL;
457
klass->component_active_changed = NULL;
458
klass->mask_changed = NULL;
462
klass->update = NULL;
463
klass->update_guide = NULL;
464
klass->colormap_changed = gimp_image_real_colormap_changed;
465
klass->undo_event = NULL;
466
klass->flush = gimp_image_real_flush;
468
g_object_class_install_property (object_class, PROP_GIMP,
469
g_param_spec_object ("gimp", NULL, NULL,
472
G_PARAM_CONSTRUCT_ONLY));
474
g_object_class_install_property (object_class, PROP_ID,
475
g_param_spec_int ("id", NULL, NULL,
479
g_object_class_install_property (object_class, PROP_WIDTH,
480
g_param_spec_int ("width", NULL, NULL,
481
1, GIMP_MAX_IMAGE_SIZE, 1,
485
g_object_class_install_property (object_class, PROP_HEIGHT,
486
g_param_spec_int ("height", NULL, NULL,
487
1, GIMP_MAX_IMAGE_SIZE, 1,
491
g_object_class_install_property (object_class, PROP_BASE_TYPE,
492
g_param_spec_enum ("base-type", NULL, NULL,
493
GIMP_TYPE_IMAGE_BASE_TYPE,
498
gimp_image_color_hash_init ();
502
gimp_image_init (GimpImage *gimage)
508
gimage->save_proc = NULL;
512
gimage->xresolution = 1.0;
513
gimage->yresolution = 1.0;
514
gimage->resolution_unit = GIMP_UNIT_INCH;
515
gimage->base_type = GIMP_RGB;
518
gimage->num_cols = 0;
521
gimage->dirty_time = 0;
522
gimage->undo_freeze_count = 0;
524
gimage->instance_count = 0;
525
gimage->disp_count = 0;
527
gimage->tattoo_state = 0;
529
gimage->shadow = NULL;
531
gimage->projection = gimp_projection_new (gimage);
533
gimage->guides = NULL;
537
gimage->layers = gimp_list_new (GIMP_TYPE_LAYER, TRUE);
538
gimage->channels = gimp_list_new (GIMP_TYPE_CHANNEL, TRUE);
539
gimage->vectors = gimp_list_new (GIMP_TYPE_VECTORS, TRUE);
540
gimage->layer_stack = NULL;
542
gimage->layer_update_handler =
543
gimp_container_add_handler (gimage->layers, "update",
544
G_CALLBACK (gimp_image_drawable_update),
546
gimage->layer_visible_handler =
547
gimp_container_add_handler (gimage->layers, "visibility_changed",
548
G_CALLBACK (gimp_image_drawable_visibility),
550
gimage->layer_alpha_handler =
551
gimp_container_add_handler (gimage->layers, "alpha_changed",
552
G_CALLBACK (gimp_image_layer_alpha_changed),
555
gimage->channel_update_handler =
556
gimp_container_add_handler (gimage->channels, "update",
557
G_CALLBACK (gimp_image_drawable_update),
559
gimage->channel_visible_handler =
560
gimp_container_add_handler (gimage->channels, "visibility_changed",
561
G_CALLBACK (gimp_image_drawable_visibility),
563
gimage->channel_name_changed_handler =
564
gimp_container_add_handler (gimage->channels, "name_changed",
565
G_CALLBACK (gimp_image_channel_name_changed),
567
gimage->channel_color_changed_handler =
568
gimp_container_add_handler (gimage->channels, "color_changed",
569
G_CALLBACK (gimp_image_channel_color_changed),
572
g_signal_connect (gimage->layers, "add",
573
G_CALLBACK (gimp_image_layer_add),
575
g_signal_connect (gimage->layers, "remove",
576
G_CALLBACK (gimp_image_layer_remove),
579
g_signal_connect (gimage->channels, "add",
580
G_CALLBACK (gimp_image_channel_add),
582
g_signal_connect (gimage->channels, "remove",
583
G_CALLBACK (gimp_image_channel_remove),
586
gimage->active_layer = NULL;
587
gimage->active_channel = NULL;
588
gimage->active_vectors = NULL;
590
gimage->floating_sel = NULL;
591
gimage->selection_mask = NULL;
593
gimage->parasites = gimp_parasite_list_new ();
595
for (i = 0; i < MAX_CHANNELS; i++)
597
gimage->visible[i] = TRUE;
598
gimage->active[i] = TRUE;
601
gimage->qmask_state = FALSE;
602
gimage->qmask_inverted = FALSE;
603
gimp_rgba_set (&gimage->qmask_color, 1.0, 0.0, 0.0, 0.5);
605
gimage->undo_stack = gimp_undo_stack_new (gimage);
606
gimage->redo_stack = gimp_undo_stack_new (gimage);
607
gimage->group_count = 0;
608
gimage->pushing_undo_group = GIMP_UNDO_GROUP_NONE;
610
gimage->comp_preview = NULL;
611
gimage->comp_preview_valid = FALSE;
613
gimage->flush_accum.alpha_changed = FALSE;
614
gimage->flush_accum.mask_changed = FALSE;
618
gimp_image_constructor (GType type,
620
GObjectConstructParam *params)
624
GimpCoreConfig *config;
626
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
628
gimage = GIMP_IMAGE (object);
630
g_assert (GIMP_IS_GIMP (gimage->gimp));
632
config = gimage->gimp->config;
634
gimage->ID = gimage->gimp->next_image_ID++;
636
g_hash_table_insert (gimage->gimp->image_table,
637
GINT_TO_POINTER (gimage->ID),
640
gimage->xresolution = config->default_image->xresolution;
641
gimage->yresolution = config->default_image->yresolution;
642
gimage->resolution_unit = config->default_image->resolution_unit;
644
gimage->grid = gimp_config_duplicate (GIMP_CONFIG (config->default_grid));
646
switch (gimage->base_type)
652
/* always allocate 256 colors for the colormap */
653
gimage->num_cols = 0;
654
gimage->cmap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
660
/* create the selection mask */
661
gimage->selection_mask = gimp_selection_new (gimage,
664
g_object_ref (gimage->selection_mask);
665
gimp_item_sink (GIMP_ITEM (gimage->selection_mask));
667
g_signal_connect (gimage->selection_mask, "update",
668
G_CALLBACK (gimp_image_mask_update),
671
g_signal_connect_object (config, "notify::transparency-type",
672
G_CALLBACK (gimp_image_invalidate_layer_previews),
673
gimage, G_CONNECT_SWAPPED);
674
g_signal_connect_object (config, "notify::transparency-size",
675
G_CALLBACK (gimp_image_invalidate_layer_previews),
676
gimage, G_CONNECT_SWAPPED);
677
g_signal_connect_object (config, "notify::layer-previews",
678
G_CALLBACK (gimp_viewable_size_changed),
679
gimage, G_CONNECT_SWAPPED);
685
gimp_image_set_property (GObject *object,
690
GimpImage *gimage = GIMP_IMAGE (object);
695
gimage->gimp = g_value_get_object (value);
698
g_assert_not_reached ();
701
gimage->width = g_value_get_int (value);
704
gimage->height = g_value_get_int (value);
707
gimage->base_type = g_value_get_enum (value);
710
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
716
gimp_image_get_property (GObject *object,
721
GimpImage *gimage = GIMP_IMAGE (object);
726
g_value_set_object (value, gimage->gimp);
729
g_value_set_int (value, gimage->ID);
732
g_value_set_int (value, gimage->width);
735
g_value_set_int (value, gimage->height);
738
g_value_set_enum (value, gimage->base_type);
741
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
747
gimp_image_dispose (GObject *object)
749
GimpImage *gimage = GIMP_IMAGE (object);
751
gimp_image_undo_free (gimage);
753
gimp_container_remove_handler (gimage->layers,
754
gimage->layer_update_handler);
755
gimp_container_remove_handler (gimage->layers,
756
gimage->layer_visible_handler);
757
gimp_container_remove_handler (gimage->layers,
758
gimage->layer_alpha_handler);
760
gimp_container_remove_handler (gimage->channels,
761
gimage->channel_update_handler);
762
gimp_container_remove_handler (gimage->channels,
763
gimage->channel_visible_handler);
764
gimp_container_remove_handler (gimage->channels,
765
gimage->channel_name_changed_handler);
766
gimp_container_remove_handler (gimage->channels,
767
gimage->channel_color_changed_handler);
769
g_signal_handlers_disconnect_by_func (gimage->layers,
770
gimp_image_layer_add,
772
g_signal_handlers_disconnect_by_func (gimage->layers,
773
gimp_image_layer_remove,
776
g_signal_handlers_disconnect_by_func (gimage->channels,
777
gimp_image_channel_add,
779
g_signal_handlers_disconnect_by_func (gimage->channels,
780
gimp_image_channel_remove,
783
gimp_container_foreach (gimage->layers, (GFunc) gimp_item_removed, NULL);
784
gimp_container_foreach (gimage->channels, (GFunc) gimp_item_removed, NULL);
785
gimp_container_foreach (gimage->vectors, (GFunc) gimp_item_removed, NULL);
787
G_OBJECT_CLASS (parent_class)->dispose (object);
791
gimp_image_finalize (GObject *object)
793
GimpImage *gimage = GIMP_IMAGE (object);
795
if (gimage->projection)
797
g_object_unref (gimage->projection);
798
gimage->projection = NULL;
802
gimp_image_free_shadow (gimage);
806
g_free (gimage->cmap);
812
g_object_unref (gimage->layers);
813
gimage->layers = NULL;
815
if (gimage->channels)
817
g_object_unref (gimage->channels);
818
gimage->channels = NULL;
822
g_object_unref (gimage->vectors);
823
gimage->vectors = NULL;
825
if (gimage->layer_stack)
827
g_slist_free (gimage->layer_stack);
828
gimage->layer_stack = NULL;
831
if (gimage->selection_mask)
833
g_object_unref (gimage->selection_mask);
834
gimage->selection_mask = NULL;
837
if (gimage->comp_preview)
839
temp_buf_free (gimage->comp_preview);
840
gimage->comp_preview = NULL;
843
if (gimage->parasites)
845
g_object_unref (gimage->parasites);
846
gimage->parasites = NULL;
851
g_list_foreach (gimage->guides, (GFunc) gimp_image_guide_unref, NULL);
852
g_list_free (gimage->guides);
853
gimage->guides = NULL;
858
g_object_unref (gimage->grid);
862
if (gimage->undo_stack)
864
g_object_unref (gimage->undo_stack);
865
gimage->undo_stack = NULL;
867
if (gimage->redo_stack)
869
g_object_unref (gimage->redo_stack);
870
gimage->redo_stack = NULL;
873
if (gimage->gimp && gimage->gimp->image_table)
875
g_hash_table_remove (gimage->gimp->image_table,
876
GINT_TO_POINTER (gimage->ID));
880
G_OBJECT_CLASS (parent_class)->finalize (object);
884
gimp_image_name_changed (GimpObject *object)
888
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
889
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
891
name = gimp_object_get_name (object);
893
if (! (name && strlen (name)))
895
g_free (object->name);
901
gimp_image_get_memsize (GimpObject *object,
904
GimpImage *gimage = GIMP_IMAGE (object);
908
memsize += GIMP_IMAGE_COLORMAP_SIZE;
911
memsize += tile_manager_get_memsize (gimage->shadow, FALSE);
913
if (gimage->projection)
914
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->projection),
917
memsize += gimp_g_list_get_memsize (gimage->guides, sizeof (GimpGuide));
920
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->grid), gui_size);
922
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->layers),
924
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->channels),
926
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->vectors),
929
memsize += gimp_g_slist_get_memsize (gimage->layer_stack, 0);
931
if (gimage->selection_mask)
932
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->selection_mask),
935
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->parasites),
938
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->undo_stack),
940
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimage->redo_stack),
943
if (gimage->comp_preview)
944
*gui_size += temp_buf_get_memsize (gimage->comp_preview);
946
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
951
gimp_image_invalidate_preview (GimpViewable *viewable)
953
GimpImage *gimage = GIMP_IMAGE (viewable);
955
if (GIMP_VIEWABLE_CLASS (parent_class)->invalidate_preview)
956
GIMP_VIEWABLE_CLASS (parent_class)->invalidate_preview (viewable);
958
gimage->comp_preview_valid = FALSE;
960
if (gimage->comp_preview)
962
temp_buf_free (gimage->comp_preview);
963
gimage->comp_preview = NULL;
968
gimp_image_size_changed (GimpViewable *viewable)
970
GimpImage *gimage = GIMP_IMAGE (viewable);
973
if (GIMP_VIEWABLE_CLASS (parent_class)->size_changed)
974
GIMP_VIEWABLE_CLASS (parent_class)->size_changed (viewable);
976
gimp_container_foreach (gimage->layers,
977
(GFunc) gimp_viewable_size_changed,
979
gimp_container_foreach (gimage->channels,
980
(GFunc) gimp_viewable_size_changed,
982
gimp_container_foreach (gimage->vectors,
983
(GFunc) gimp_viewable_size_changed,
986
for (list = GIMP_LIST (gimage->layers)->list; list; list = g_list_next (list))
988
GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (list->data));
991
gimp_viewable_size_changed (GIMP_VIEWABLE (mask));
994
gimp_viewable_size_changed (GIMP_VIEWABLE (gimp_image_get_mask (gimage)));
998
gimp_image_get_description (GimpViewable *viewable,
1001
GimpImage *gimage = GIMP_IMAGE (viewable);
1006
uri = gimp_image_get_uri (GIMP_IMAGE (gimage));
1008
basename = file_utils_uri_to_utf8_basename (uri);
1011
*tooltip = file_utils_uri_to_utf8_filename (uri);
1013
retval = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
1021
gimp_image_real_colormap_changed (GimpImage *gimage,
1024
if (gimp_image_base_type (gimage) == GIMP_INDEXED)
1026
gimp_image_color_hash_invalidate (gimage, color_index);
1028
/* A colormap alteration affects the whole image */
1029
gimp_image_update (gimage, 0, 0, gimage->width, gimage->height);
1031
gimp_image_invalidate_layer_previews (gimage);
1032
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
1037
gimp_image_real_flush (GimpImage *gimage)
1039
if (gimage->flush_accum.alpha_changed)
1041
gimp_image_alpha_changed (gimage);
1042
gimage->flush_accum.alpha_changed = FALSE;
1045
if (gimage->flush_accum.mask_changed)
1047
gimp_image_mask_changed (gimage);
1048
gimage->flush_accum.mask_changed = FALSE;
1053
gimp_image_mask_update (GimpDrawable *drawable,
1060
gimage->flush_accum.mask_changed = TRUE;
1064
gimp_image_drawable_update (GimpDrawable *drawable,
1071
GimpItem *item = GIMP_ITEM (drawable);
1073
if (gimp_item_get_visible (item))
1078
gimp_item_offsets (item, &offset_x, &offset_y);
1082
gimp_image_update (gimage, x, y, width, height);
1083
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
1088
gimp_image_drawable_visibility (GimpItem *item,
1094
gimp_item_offsets (item, &offset_x, &offset_y);
1096
gimp_image_update (gimage,
1098
gimp_item_width (item),
1099
gimp_item_height (item));
1100
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
1104
gimp_image_layer_alpha_changed (GimpDrawable *drawable,
1107
if (gimp_container_num_children (gimage->layers) == 1)
1108
gimage->flush_accum.alpha_changed = TRUE;
1112
gimp_image_layer_add (GimpContainer *container,
1116
GimpItem *item = GIMP_ITEM (layer);
1118
if (gimp_item_get_visible (item))
1119
gimp_image_drawable_visibility (item, gimage);
1123
gimp_image_layer_remove (GimpContainer *container,
1127
GimpItem *item = GIMP_ITEM (layer);
1129
if (gimp_item_get_visible (item))
1130
gimp_image_drawable_visibility (item, gimage);
1134
gimp_image_channel_add (GimpContainer *container,
1135
GimpChannel *channel,
1138
GimpItem *item = GIMP_ITEM (channel);
1140
if (gimp_item_get_visible (item))
1141
gimp_image_drawable_visibility (item, gimage);
1143
if (! strcmp (GIMP_IMAGE_QMASK_NAME,
1144
gimp_object_get_name (GIMP_OBJECT (channel))))
1146
gimp_image_set_qmask_state (gimage, TRUE);
1151
gimp_image_channel_remove (GimpContainer *container,
1152
GimpChannel *channel,
1155
GimpItem *item = GIMP_ITEM (channel);
1157
if (gimp_item_get_visible (item))
1158
gimp_image_drawable_visibility (item, gimage);
1160
if (! strcmp (GIMP_IMAGE_QMASK_NAME,
1161
gimp_object_get_name (GIMP_OBJECT (channel))))
1163
gimp_image_set_qmask_state (gimage, FALSE);
1168
gimp_image_channel_name_changed (GimpChannel *channel,
1171
if (! strcmp (GIMP_IMAGE_QMASK_NAME,
1172
gimp_object_get_name (GIMP_OBJECT (channel))))
1174
gimp_image_set_qmask_state (gimage, TRUE);
1176
else if (gimp_image_get_qmask_state (gimage) &&
1177
! gimp_image_get_qmask (gimage))
1179
gimp_image_set_qmask_state (gimage, FALSE);
1184
gimp_image_channel_color_changed (GimpChannel *channel,
1187
if (! strcmp (GIMP_IMAGE_QMASK_NAME,
1188
gimp_object_get_name (GIMP_OBJECT (channel))))
1190
gimage->qmask_color = channel->color;
1195
/* public functions */
1198
gimp_image_new (Gimp *gimp,
1201
GimpImageBaseType base_type)
1203
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1205
return g_object_new (GIMP_TYPE_IMAGE,
1209
"base-type", base_type,
1214
gimp_image_base_type (const GimpImage *gimage)
1216
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
1218
return gimage->base_type;
1222
gimp_image_base_type_with_alpha (const GimpImage *gimage)
1224
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
1226
switch (gimage->base_type)
1229
return GIMP_RGBA_IMAGE;
1231
return GIMP_GRAYA_IMAGE;
1233
return GIMP_INDEXEDA_IMAGE;
1236
return GIMP_RGB_IMAGE;
1240
gimp_image_get_combination_mode (GimpImageType dest_type,
1243
return valid_combinations[dest_type][src_bytes];
1247
gimp_image_get_ID (const GimpImage *gimage)
1249
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
1255
gimp_image_get_by_ID (Gimp *gimp,
1258
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1260
if (gimp->image_table == NULL)
1263
return (GimpImage *) g_hash_table_lookup (gimp->image_table,
1264
GINT_TO_POINTER (image_id));
1268
gimp_image_set_uri (GimpImage *gimage,
1271
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1273
gimp_object_set_name (GIMP_OBJECT (gimage), uri);
1277
gimp_image_get_uri (const GimpImage *gimage)
1281
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
1283
uri = gimp_object_get_name (GIMP_OBJECT (gimage));
1285
return uri ? uri : _("Untitled");
1289
gimp_image_set_filename (GimpImage *gimage,
1290
const gchar *filename)
1292
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1294
if (filename && strlen (filename))
1298
uri = file_utils_filename_to_uri (gimage->gimp->load_procs, filename,
1301
gimp_image_set_uri (gimage, uri);
1307
gimp_image_set_uri (gimage, NULL);
1312
gimp_image_get_filename (const GimpImage *gimage)
1316
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
1318
uri = gimp_object_get_name (GIMP_OBJECT (gimage));
1323
return g_filename_from_uri (uri, NULL, NULL);
1327
gimp_image_set_save_proc (GimpImage *gimage,
1328
PlugInProcDef *proc)
1330
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1332
gimage->save_proc = proc;
1336
gimp_image_get_save_proc (const GimpImage *gimage)
1338
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
1340
return gimage->save_proc;
1344
gimp_image_set_resolution (GimpImage *gimage,
1345
gdouble xresolution,
1346
gdouble yresolution)
1348
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1350
/* don't allow to set the resolution out of bounds */
1351
if (xresolution < GIMP_MIN_RESOLUTION || xresolution > GIMP_MAX_RESOLUTION ||
1352
yresolution < GIMP_MIN_RESOLUTION || yresolution > GIMP_MAX_RESOLUTION)
1355
if ((ABS (gimage->xresolution - xresolution) >= 1e-5) ||
1356
(ABS (gimage->yresolution - yresolution) >= 1e-5))
1358
gimp_image_undo_push_image_resolution (gimage,
1359
_("Change Image Resolution"));
1361
gimage->xresolution = xresolution;
1362
gimage->yresolution = yresolution;
1364
gimp_image_resolution_changed (gimage);
1365
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
1370
gimp_image_get_resolution (const GimpImage *gimage,
1371
gdouble *xresolution,
1372
gdouble *yresolution)
1374
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1375
g_return_if_fail (xresolution && yresolution);
1377
*xresolution = gimage->xresolution;
1378
*yresolution = gimage->yresolution;
1382
gimp_image_resolution_changed (GimpImage *gimage)
1384
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1386
g_signal_emit (gimage, gimp_image_signals[RESOLUTION_CHANGED], 0);
1390
gimp_image_set_unit (GimpImage *gimage,
1393
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1394
g_return_if_fail (unit > GIMP_UNIT_PIXEL);
1396
if (gimage->resolution_unit != unit)
1398
gimp_image_undo_push_image_resolution (gimage,
1399
_("Change Image Unit"));
1401
gimage->resolution_unit = unit;
1402
gimp_image_unit_changed (gimage);
1407
gimp_image_get_unit (const GimpImage *gimage)
1409
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_UNIT_INCH);
1411
return gimage->resolution_unit;
1415
gimp_image_unit_changed (GimpImage *gimage)
1417
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1419
g_signal_emit (gimage, gimp_image_signals[UNIT_CHANGED], 0);
1423
gimp_image_get_width (const GimpImage *gimage)
1425
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 0);
1427
return gimage->width;
1431
gimp_image_get_height (const GimpImage *gimage)
1433
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 0);
1435
return gimage->height;
1439
gimp_image_has_alpha (const GimpImage *gimage)
1443
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), TRUE);
1445
layer = (GimpLayer *) gimp_container_get_child_by_index (gimage->layers, 0);
1447
return ((gimp_container_num_children (gimage->layers) > 1) ||
1448
(layer && gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))));
1452
gimp_image_is_empty (const GimpImage *gimage)
1454
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), TRUE);
1456
return (gimp_container_num_children (gimage->layers) == 0);
1460
gimp_image_floating_sel (const GimpImage *gimage)
1462
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
1464
return gimage->floating_sel;
1468
gimp_image_floating_selection_changed (GimpImage *gimage)
1470
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1472
g_signal_emit (gimage, gimp_image_signals[FLOATING_SELECTION_CHANGED], 0);
1476
gimp_image_get_mask (const GimpImage *gimage)
1478
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
1480
return gimage->selection_mask;
1484
gimp_image_mask_changed (GimpImage *gimage)
1486
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1488
g_signal_emit (gimage, gimp_image_signals[MASK_CHANGED], 0);
1492
gimp_image_get_component_index (const GimpImage *gimage,
1493
GimpChannelType channel)
1495
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
1499
case GIMP_RED_CHANNEL: return RED_PIX;
1500
case GIMP_GREEN_CHANNEL: return GREEN_PIX;
1501
case GIMP_BLUE_CHANNEL: return BLUE_PIX;
1502
case GIMP_GRAY_CHANNEL: return GRAY_PIX;
1503
case GIMP_INDEXED_CHANNEL: return INDEXED_PIX;
1504
case GIMP_ALPHA_CHANNEL:
1505
switch (gimp_image_base_type (gimage))
1507
case GIMP_RGB: return ALPHA_PIX;
1508
case GIMP_GRAY: return ALPHA_G_PIX;
1509
case GIMP_INDEXED: return ALPHA_I_PIX;
1517
gimp_image_set_component_active (GimpImage *gimage,
1518
GimpChannelType channel,
1523
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1525
index = gimp_image_get_component_index (gimage, channel);
1527
if (index != -1 && active != gimage->active[index])
1529
gimage->active[index] = active ? TRUE : FALSE;
1531
/* If there is an active channel and we mess with the components,
1532
* the active channel gets unset...
1534
gimp_image_unset_active_channel (gimage);
1536
g_signal_emit (gimage,
1537
gimp_image_signals[COMPONENT_ACTIVE_CHANGED], 0,
1543
gimp_image_get_component_active (const GimpImage *gimage,
1544
GimpChannelType channel)
1548
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1550
index = gimp_image_get_component_index (gimage, channel);
1553
return gimage->active[index];
1559
gimp_image_set_component_visible (GimpImage *gimage,
1560
GimpChannelType channel,
1565
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1567
index = gimp_image_get_component_index (gimage, channel);
1569
if (index != -1 && visible != gimage->visible[index])
1571
gimage->visible[index] = visible ? TRUE : FALSE;
1573
g_signal_emit (gimage,
1574
gimp_image_signals[COMPONENT_VISIBILITY_CHANGED], 0,
1577
gimp_image_update (gimage, 0, 0, gimage->width, gimage->height);
1578
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
1583
gimp_image_get_component_visible (const GimpImage *gimage,
1584
GimpChannelType channel)
1588
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1590
index = gimp_image_get_component_index (gimage, channel);
1593
return gimage->visible[index];
1599
gimp_image_mode_changed (GimpImage *gimage)
1601
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1603
g_signal_emit (gimage, gimp_image_signals[MODE_CHANGED], 0);
1607
gimp_image_alpha_changed (GimpImage *gimage)
1609
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1611
g_signal_emit (gimage, gimp_image_signals[ALPHA_CHANGED], 0);
1615
gimp_image_update (GimpImage *gimage,
1621
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1623
g_signal_emit (gimage, gimp_image_signals[UPDATE], 0,
1624
x, y, width, height);
1628
gimp_image_update_guide (GimpImage *gimage,
1631
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1632
g_return_if_fail (guide != NULL);
1634
g_signal_emit (gimage, gimp_image_signals[UPDATE_GUIDE], 0, guide);
1638
gimp_image_colormap_changed (GimpImage *gimage,
1641
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1642
g_return_if_fail (color_index >= -1 && color_index < gimage->num_cols);
1644
g_signal_emit (gimage, gimp_image_signals[COLORMAP_CHANGED], 0,
1649
gimp_image_selection_control (GimpImage *gimage,
1650
GimpSelectionControl control)
1652
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1654
g_signal_emit (gimage, gimp_image_signals[SELECTION_CONTROL], 0, control);
1658
gimp_image_qmask_changed (GimpImage *gimage)
1660
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1662
g_signal_emit (gimage, gimp_image_signals[QMASK_CHANGED], 0);
1669
gimp_image_undo_is_enabled (const GimpImage *gimage)
1671
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1673
return (gimage->undo_freeze_count == 0);
1677
gimp_image_undo_enable (GimpImage *gimage)
1679
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1681
/* Free all undo steps as they are now invalidated */
1682
gimp_image_undo_free (gimage);
1684
return gimp_image_undo_thaw (gimage);
1688
gimp_image_undo_disable (GimpImage *gimage)
1690
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1692
return gimp_image_undo_freeze (gimage);
1696
gimp_image_undo_freeze (GimpImage *gimage)
1698
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1700
gimage->undo_freeze_count++;
1702
if (gimage->undo_freeze_count == 1)
1703
gimp_image_undo_event (gimage, GIMP_UNDO_EVENT_UNDO_FREEZE, NULL);
1709
gimp_image_undo_thaw (GimpImage *gimage)
1711
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1712
g_return_val_if_fail (gimage->undo_freeze_count > 0, FALSE);
1714
gimage->undo_freeze_count--;
1716
if (gimage->undo_freeze_count == 0)
1717
gimp_image_undo_event (gimage, GIMP_UNDO_EVENT_UNDO_THAW, NULL);
1723
gimp_image_undo_event (GimpImage *gimage,
1724
GimpUndoEvent event,
1727
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1728
g_return_if_fail (((event == GIMP_UNDO_EVENT_UNDO_FREE ||
1729
event == GIMP_UNDO_EVENT_UNDO_FREEZE ||
1730
event == GIMP_UNDO_EVENT_UNDO_THAW) && undo == NULL) ||
1731
GIMP_IS_UNDO (undo));
1733
g_signal_emit (gimage, gimp_image_signals[UNDO_EVENT], 0, event, undo);
1737
/* NOTE about the gimage->dirty counter:
1738
* If 0, then the image is clean (ie, copy on disk is the same as the one
1740
* If positive, then that's the number of dirtying operations done
1741
* on the image since the last save.
1742
* If negative, then user has hit undo and gone back in time prior
1743
* to the saved copy. Hitting redo will eventually come back to
1746
* The image is dirty (ie, needs saving) if counter is non-zero.
1748
* If the counter is around 10000, this is due to undo-ing back
1749
* before a saved version, then mutating the image (thus destroying
1750
* the redo stack). Once this has happened, it's impossible to get
1751
* the image back to the state on disk, since the redo info has been
1752
* freed. See undo.c for the gorey details.
1757
* NEVER CALL gimp_image_dirty() directly!
1759
* If your code has just dirtied the image, push an undo instead.
1760
* Failing that, push the trivial undo which tells the user the
1761
* command is not undoable: undo_push_cantundo() (But really, it would
1762
* be best to push a proper undo). If you just dirty the image
1763
* without pushing an undo then the dirty count is increased, but
1764
* popping that many undo actions won't lead to a clean image.
1768
gimp_image_dirty (GimpImage *gimage,
1769
GimpDirtyMask dirty_mask)
1771
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1775
if (! gimage->dirty_time)
1776
gimage->dirty_time = time (NULL);
1778
g_signal_emit (gimage, gimp_image_signals[DIRTY], 0, dirty_mask);
1780
TRC (("dirty %d -> %d\n", gimage->dirty - 1, gimage->dirty));
1782
return gimage->dirty;
1786
gimp_image_clean (GimpImage *gimage,
1787
GimpDirtyMask dirty_mask)
1789
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
1793
g_signal_emit (gimage, gimp_image_signals[CLEAN], 0, dirty_mask);
1795
TRC (("clean %d -> %d\n", gimage->dirty + 1, gimage->dirty));
1797
return gimage->dirty;
1801
gimp_image_clean_all (GimpImage *gimage)
1803
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1806
gimage->dirty_time = 0;
1808
g_signal_emit (gimage, gimp_image_signals[CLEAN], 0);
1812
/* flush this image's displays */
1815
gimp_image_flush (GimpImage *gimage)
1817
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1819
g_signal_emit (gimage, gimp_image_signals[FLUSH], 0);
1823
/* color transforms / utilities */
1826
gimp_image_get_foreground (const GimpImage *gimage,
1827
const GimpDrawable *drawable,
1828
GimpContext *context,
1834
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1835
g_return_if_fail (! drawable || GIMP_IS_DRAWABLE (drawable));
1836
g_return_if_fail (GIMP_IS_CONTEXT (context));
1837
g_return_if_fail (fg != NULL);
1839
gimp_context_get_foreground (context, &color);
1841
gimp_rgb_get_uchar (&color, &pfg[0], &pfg[1], &pfg[2]);
1843
gimp_image_transform_color (gimage, drawable, fg, GIMP_RGB, pfg);
1847
gimp_image_get_background (const GimpImage *gimage,
1848
const GimpDrawable *drawable,
1849
GimpContext *context,
1855
g_return_if_fail (GIMP_IS_IMAGE (gimage));
1856
g_return_if_fail (! drawable || GIMP_IS_DRAWABLE (drawable));
1857
g_return_if_fail (GIMP_IS_CONTEXT (context));
1858
g_return_if_fail (bg != NULL);
1860
gimp_context_get_background (context, &color);
1862
gimp_rgb_get_uchar (&color, &pbg[0], &pbg[1], &pbg[2]);
1864
gimp_image_transform_color (gimage, drawable, bg, GIMP_RGB, pbg);
1868
gimp_image_get_color (const GimpImage *src_gimage,
1869
GimpImageType src_type,
1873
gboolean has_alpha = FALSE;
1875
g_return_if_fail (GIMP_IS_IMAGE (src_gimage));
1879
case GIMP_RGBA_IMAGE:
1882
case GIMP_RGB_IMAGE:
1889
case GIMP_GRAYA_IMAGE:
1892
case GIMP_GRAY_IMAGE:
1899
case GIMP_INDEXEDA_IMAGE:
1902
case GIMP_INDEXED_IMAGE:
1903
/* Indexed palette lookup */
1905
gint index = *src++ * 3;
1907
*rgba++ = src_gimage->cmap[index++];
1908
*rgba++ = src_gimage->cmap[index++];
1909
*rgba++ = src_gimage->cmap[index++];
1917
*rgba = OPAQUE_OPACITY;
1921
gimp_image_transform_rgb (const GimpImage *dest_gimage,
1922
const GimpDrawable *dest_drawable,
1928
g_return_if_fail (GIMP_IS_IMAGE (dest_gimage));
1929
g_return_if_fail (! dest_drawable || GIMP_IS_DRAWABLE (dest_drawable));
1930
g_return_if_fail (rgb != NULL);
1931
g_return_if_fail (color != NULL);
1933
gimp_rgb_get_uchar (rgb, &col[0], &col[1], &col[2]);
1935
gimp_image_transform_color (dest_gimage, dest_drawable, color, GIMP_RGB, col);
1939
gimp_image_transform_color (const GimpImage *dest_gimage,
1940
const GimpDrawable *dest_drawable,
1942
GimpImageBaseType src_type,
1945
GimpImageType dest_type;
1947
g_return_if_fail (GIMP_IS_IMAGE (dest_gimage));
1948
g_return_if_fail (src_type != GIMP_INDEXED);
1950
dest_type = (dest_drawable ?
1951
gimp_drawable_type (dest_drawable) :
1952
gimp_image_base_type_with_alpha (dest_gimage));
1959
case GIMP_RGB_IMAGE:
1960
case GIMP_RGBA_IMAGE:
1967
case GIMP_GRAY_IMAGE:
1968
case GIMP_GRAYA_IMAGE:
1969
/* NTSC conversion */
1970
*dest = GIMP_RGB_INTENSITY (src[RED_PIX],
1972
src[BLUE_PIX]) + 0.5;
1975
case GIMP_INDEXED_IMAGE:
1976
case GIMP_INDEXEDA_IMAGE:
1977
/* Least squares method */
1978
*dest = gimp_image_color_hash_rgb_to_indexed (dest_gimage,
1989
case GIMP_RGB_IMAGE:
1990
case GIMP_RGBA_IMAGE:
1997
case GIMP_GRAY_IMAGE:
1998
case GIMP_GRAYA_IMAGE:
2003
case GIMP_INDEXED_IMAGE:
2004
case GIMP_INDEXEDA_IMAGE:
2005
/* Least squares method */
2006
*dest = gimp_image_color_hash_rgb_to_indexed (dest_gimage,
2020
gimp_image_transform_temp_buf (const GimpImage *dest_image,
2021
const GimpDrawable *dest_drawable,
2026
GimpImageType ret_buf_type;
2032
g_return_val_if_fail (GIMP_IMAGE (dest_image), NULL);
2033
g_return_val_if_fail (GIMP_DRAWABLE (dest_drawable), NULL);
2034
g_return_val_if_fail (temp_buf != NULL, NULL);
2035
g_return_val_if_fail (new_buf != NULL, NULL);
2037
in_bytes = temp_buf->bytes;
2039
has_alpha = (in_bytes == 2 || in_bytes == 4);
2040
is_rgb = (in_bytes == 3 || in_bytes == 4);
2043
ret_buf_type = gimp_drawable_type_with_alpha (dest_drawable);
2045
ret_buf_type = gimp_drawable_type_without_alpha (dest_drawable);
2047
out_bytes = GIMP_IMAGE_TYPE_BYTES (ret_buf_type);
2049
/* If the pattern doesn't match the image in terms of color type,
2050
* transform it. (ie pattern is RGB, image is indexed)
2052
if (in_bytes != out_bytes || gimp_drawable_is_indexed (dest_drawable))
2058
ret_buf = temp_buf_new (temp_buf->width, temp_buf->height,
2059
out_bytes, 0, 0, NULL);
2061
src = temp_buf_data (temp_buf);
2062
dest = temp_buf_data (ret_buf);
2064
size = temp_buf->width * temp_buf->height;
2068
gimp_image_transform_color (dest_image, dest_drawable, dest,
2069
is_rgb ? GIMP_RGB : GIMP_GRAY, src);
2073
dest[out_bytes - 1] = src[in_bytes - 1];
2094
gimp_image_shadow (GimpImage *gimage,
2099
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2103
if ((width != tile_manager_width (gimage->shadow)) ||
2104
(height != tile_manager_height (gimage->shadow)) ||
2105
(bpp != tile_manager_bpp (gimage->shadow)))
2107
gimp_image_free_shadow (gimage);
2111
return gimage->shadow;
2115
gimage->shadow = tile_manager_new (width, height, bpp);
2117
return gimage->shadow;
2121
gimp_image_free_shadow (GimpImage *gimage)
2123
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2127
tile_manager_unref (gimage->shadow);
2128
gimage->shadow = NULL;
2136
gimp_image_parasite_find (const GimpImage *gimage,
2139
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2141
return gimp_parasite_list_find (gimage->parasites, name);
2145
list_func (gchar *key,
2149
*(*cur)++ = (gchar *) g_strdup (key);
2153
gimp_image_parasite_list (const GimpImage *gimage,
2159
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2161
*count = gimp_parasite_list_length (gimage->parasites);
2162
cur = list = g_new (gchar*, *count);
2164
gimp_parasite_list_foreach (gimage->parasites, (GHFunc) list_func, &cur);
2170
gimp_image_parasite_attach (GimpImage *gimage,
2171
GimpParasite *parasite)
2173
g_return_if_fail (GIMP_IS_IMAGE (gimage) && parasite != NULL);
2175
/* only set the dirty bit manually if we can be saved and the new
2176
parasite differs from the current one and we aren't undoable */
2177
if (gimp_parasite_is_undoable (parasite))
2178
gimp_image_undo_push_image_parasite (gimage,
2179
_("Attach Parasite to Image"),
2182
/* We used to push an cantundo on te stack here. This made the undo stack
2183
unusable (NULL on the stack) and prevented people from undoing after a
2184
save (since most save plug-ins attach an undoable comment parasite).
2185
Now we simply attach the parasite without pushing an undo. That way it's
2186
undoable but does not block the undo system. --Sven
2189
gimp_parasite_list_add (gimage->parasites, parasite);
2191
if (gimp_parasite_has_flag (parasite, GIMP_PARASITE_ATTACH_PARENT))
2193
gimp_parasite_shift_parent (parasite);
2194
gimp_parasite_attach (gimage->gimp, parasite);
2199
gimp_image_parasite_detach (GimpImage *gimage,
2200
const gchar *parasite)
2204
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2205
g_return_if_fail (parasite != NULL);
2207
if (!(p = gimp_parasite_list_find (gimage->parasites, parasite)))
2210
if (gimp_parasite_is_undoable (p))
2211
gimp_image_undo_push_image_parasite_remove (gimage,
2212
_("Remove Parasite from Image"),
2213
gimp_parasite_name (p));
2215
gimp_parasite_list_remove (gimage->parasites, parasite);
2222
gimp_image_get_new_tattoo (GimpImage *gimage)
2224
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 0);
2226
gimage->tattoo_state++;
2228
if (gimage->tattoo_state <= 0)
2229
g_warning ("%s: Tattoo state corrupted (integer overflow).", G_STRFUNC);
2231
return gimage->tattoo_state;
2235
gimp_image_get_tattoo_state (GimpImage *gimage)
2237
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 0);
2239
return gimage->tattoo_state;
2243
gimp_image_set_tattoo_state (GimpImage *gimage,
2247
gboolean retval = TRUE;
2248
GimpTattoo maxval = 0;
2250
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2252
/* Check that the layer tatoos don't overlap with channel or vector ones */
2253
for (list = GIMP_LIST (gimage->layers)->list;
2255
list = g_list_next (list))
2259
ltattoo = gimp_item_get_tattoo (GIMP_ITEM (list->data));
2260
if (ltattoo > maxval)
2263
if (gimp_image_get_channel_by_tattoo (gimage, ltattoo))
2264
retval = FALSE; /* Oopps duplicated tattoo in channel */
2266
if (gimp_image_get_vectors_by_tattoo (gimage, ltattoo))
2267
retval = FALSE; /* Oopps duplicated tattoo in vectors */
2270
/* Now check that the channel and vectors tattoos don't overlap */
2271
for (list = GIMP_LIST (gimage->channels)->list;
2273
list = g_list_next (list))
2277
ctattoo = gimp_item_get_tattoo (GIMP_ITEM (list->data));
2278
if (ctattoo > maxval)
2281
if (gimp_image_get_vectors_by_tattoo (gimage, ctattoo))
2282
retval = FALSE; /* Oopps duplicated tattoo in vectors */
2285
/* Find the max tattoo value in the vectors */
2286
for (list = GIMP_LIST (gimage->vectors)->list;
2288
list = g_list_next (list))
2292
vtattoo = gimp_item_get_tattoo (GIMP_ITEM (list->data));
2293
if (vtattoo > maxval)
2300
/* Must check if the state is valid */
2302
gimage->tattoo_state = val;
2308
/* layers / channels / vectors */
2311
gimp_image_get_layers (const GimpImage *gimage)
2313
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2315
return gimage->layers;
2319
gimp_image_get_channels (const GimpImage *gimage)
2321
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2323
return gimage->channels;
2327
gimp_image_get_vectors (const GimpImage *gimage)
2329
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2331
return gimage->vectors;
2335
gimp_image_active_drawable (const GimpImage *gimage)
2337
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2339
/* If there is an active channel (a saved selection, etc.),
2340
* we ignore the active layer
2342
if (gimage->active_channel)
2344
return GIMP_DRAWABLE (gimage->active_channel);
2346
else if (gimage->active_layer)
2348
GimpLayer *layer = gimage->active_layer;
2350
if (layer->mask && layer->mask->edit_mask)
2351
return GIMP_DRAWABLE (layer->mask);
2353
return GIMP_DRAWABLE (layer);
2360
gimp_image_get_active_layer (const GimpImage *gimage)
2362
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2364
return gimage->active_layer;
2368
gimp_image_get_active_channel (const GimpImage *gimage)
2370
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2372
return gimage->active_channel;
2376
gimp_image_get_active_vectors (const GimpImage *gimage)
2378
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2380
return gimage->active_vectors;
2384
gimp_image_set_active_layer (GimpImage *gimage,
2387
GimpLayer *floating_sel;
2389
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2390
g_return_val_if_fail (layer == NULL || GIMP_IS_LAYER (layer), NULL);
2391
g_return_val_if_fail (layer == NULL ||
2392
gimp_container_have (gimage->layers,
2393
GIMP_OBJECT (layer)), NULL);
2395
floating_sel = gimp_image_floating_sel (gimage);
2397
/* Make sure the floating_sel always is the active layer */
2398
if (floating_sel && layer != floating_sel)
2399
return floating_sel;
2401
if (layer != gimage->active_layer)
2405
/* Configure the layer stack to reflect this change */
2406
gimage->layer_stack = g_slist_remove (gimage->layer_stack, layer);
2407
gimage->layer_stack = g_slist_prepend (gimage->layer_stack, layer);
2410
/* Don't cache selection info for the previous active layer */
2411
if (gimage->active_layer)
2412
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (gimage->active_layer));
2414
gimage->active_layer = layer;
2416
g_signal_emit (gimage, gimp_image_signals[ACTIVE_LAYER_CHANGED], 0);
2418
if (layer && gimage->active_channel)
2419
gimp_image_set_active_channel (gimage, NULL);
2422
return gimage->active_layer;
2426
gimp_image_set_active_channel (GimpImage *gimage,
2427
GimpChannel *channel)
2429
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2430
g_return_val_if_fail (channel == NULL || GIMP_IS_CHANNEL (channel), NULL);
2431
g_return_val_if_fail (channel == NULL ||
2432
gimp_container_have (gimage->channels,
2433
GIMP_OBJECT (channel)), NULL);
2435
/* Not if there is a floating selection */
2436
if (channel && gimp_image_floating_sel (gimage))
2439
if (channel != gimage->active_channel)
2441
gimage->active_channel = channel;
2443
g_signal_emit (gimage, gimp_image_signals[ACTIVE_CHANNEL_CHANGED], 0);
2445
if (channel && gimage->active_layer)
2446
gimp_image_set_active_layer (gimage, NULL);
2449
return gimage->active_channel;
2453
gimp_image_unset_active_channel (GimpImage *gimage)
2455
GimpChannel *channel;
2457
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2459
channel = gimp_image_get_active_channel (gimage);
2463
gimp_image_set_active_channel (gimage, NULL);
2465
if (gimage->layer_stack)
2466
gimp_image_set_active_layer (gimage, gimage->layer_stack->data);
2473
gimp_image_set_active_vectors (GimpImage *gimage,
2474
GimpVectors *vectors)
2476
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2477
g_return_val_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors), NULL);
2478
g_return_val_if_fail (vectors == NULL ||
2479
gimp_container_have (gimage->vectors,
2480
GIMP_OBJECT (vectors)), NULL);
2482
if (vectors != gimage->active_vectors)
2484
gimage->active_vectors = vectors;
2486
g_signal_emit (gimage, gimp_image_signals[ACTIVE_VECTORS_CHANGED], 0);
2489
return gimage->active_vectors;
2493
gimp_image_active_layer_changed (GimpImage *gimage)
2495
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2497
g_signal_emit (gimage, gimp_image_signals[ACTIVE_LAYER_CHANGED], 0);
2501
gimp_image_active_channel_changed (GimpImage *gimage)
2503
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2505
g_signal_emit (gimage, gimp_image_signals[ACTIVE_CHANNEL_CHANGED], 0);
2509
gimp_image_active_vectors_changed (GimpImage *gimage)
2511
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2513
g_signal_emit (gimage, gimp_image_signals[ACTIVE_VECTORS_CHANGED], 0);
2517
gimp_image_get_layer_index (const GimpImage *gimage,
2518
const GimpLayer *layer)
2520
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
2521
g_return_val_if_fail (GIMP_IS_LAYER (layer), -1);
2523
return gimp_container_get_child_index (gimage->layers,
2524
GIMP_OBJECT (layer));
2528
gimp_image_get_channel_index (const GimpImage *gimage,
2529
const GimpChannel *channel)
2531
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
2532
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), -1);
2534
return gimp_container_get_child_index (gimage->channels,
2535
GIMP_OBJECT (channel));
2539
gimp_image_get_vectors_index (const GimpImage *gimage,
2540
const GimpVectors *vectors)
2542
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), -1);
2543
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), -1);
2545
return gimp_container_get_child_index (gimage->vectors,
2546
GIMP_OBJECT (vectors));
2550
gimp_image_get_layer_by_tattoo (const GimpImage *gimage,
2555
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2557
for (list = GIMP_LIST (gimage->layers)->list;
2559
list = g_list_next (list))
2561
GimpLayer *layer = list->data;
2563
if (gimp_item_get_tattoo (GIMP_ITEM (layer)) == tattoo)
2571
gimp_image_get_channel_by_tattoo (const GimpImage *gimage,
2576
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2578
for (list = GIMP_LIST (gimage->channels)->list;
2580
list = g_list_next (list))
2582
GimpChannel *channel = list->data;
2584
if (gimp_item_get_tattoo (GIMP_ITEM (channel)) == tattoo)
2592
gimp_image_get_vectors_by_tattoo (const GimpImage *gimage,
2597
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2599
for (list = GIMP_LIST (gimage->vectors)->list;
2601
list = g_list_next (list))
2603
GimpVectors *vectors = list->data;
2605
if (gimp_item_get_tattoo (GIMP_ITEM (vectors)) == tattoo)
2613
gimp_image_get_layer_by_name (const GimpImage *gimage,
2616
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2618
return (GimpLayer *) gimp_container_get_child_by_name (gimage->layers,
2623
gimp_image_get_channel_by_name (const GimpImage *gimage,
2626
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2628
return (GimpChannel *) gimp_container_get_child_by_name (gimage->channels,
2633
gimp_image_get_vectors_by_name (const GimpImage *gimage,
2636
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
2638
return (GimpVectors *) gimp_container_get_child_by_name (gimage->vectors,
2643
gimp_image_add_layer (GimpImage *gimage,
2647
GimpLayer *active_layer;
2648
GimpLayer *floating_sel;
2649
gboolean old_has_alpha;
2651
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2652
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2654
if (GIMP_ITEM (layer)->gimage != NULL &&
2655
GIMP_ITEM (layer)->gimage != gimage)
2657
g_warning ("%s: attempting to add layer to wrong image.", G_STRFUNC);
2661
if (gimp_container_have (gimage->layers, GIMP_OBJECT (layer)))
2663
g_warning ("%s: trying to add layer to image twice.", G_STRFUNC);
2667
floating_sel = gimp_image_floating_sel (gimage);
2669
if (floating_sel && gimp_layer_is_floating_sel (layer))
2671
g_warning ("%s: trying to add floating layer to image which alyready "
2672
"has a floating selection.", G_STRFUNC);
2676
active_layer = gimp_image_get_active_layer (gimage);
2678
old_has_alpha = gimp_image_has_alpha (gimage);
2680
gimp_image_undo_push_layer_add (gimage, _("Add Layer"),
2681
layer, 0, active_layer);
2683
gimp_item_set_image (GIMP_ITEM (layer), gimage);
2686
gimp_item_set_image (GIMP_ITEM (layer->mask), gimage);
2688
/* If the layer is a floating selection, set the ID */
2689
if (gimp_layer_is_floating_sel (layer))
2690
gimage->floating_sel = layer;
2692
/* add the layer to the list at the specified position */
2696
position = gimp_container_get_child_index (gimage->layers,
2697
GIMP_OBJECT (active_layer));
2702
/* If there is a floating selection (and this isn't it!),
2703
* make sure the insert position is greater than 0
2705
if (position == 0 && floating_sel)
2708
/* Don't add at a non-existing index */
2709
if (position > gimp_container_num_children (gimage->layers))
2710
position = gimp_container_num_children (gimage->layers);
2712
gimp_container_insert (gimage->layers, GIMP_OBJECT (layer), position);
2713
gimp_item_sink (GIMP_ITEM (layer));
2715
/* notify the layers dialog of the currently active layer */
2716
gimp_image_set_active_layer (gimage, layer);
2718
if (old_has_alpha != gimp_image_has_alpha (gimage))
2719
gimp_image_alpha_changed (gimage);
2721
if (gimp_layer_is_floating_sel (layer))
2722
gimp_image_floating_selection_changed (gimage);
2728
gimp_image_remove_layer (GimpImage *gimage,
2731
GimpLayer *active_layer;
2733
gboolean old_has_alpha;
2734
gboolean undo_group = FALSE;
2736
g_return_if_fail (GIMP_IS_IMAGE (gimage));
2737
g_return_if_fail (GIMP_IS_LAYER (layer));
2738
g_return_if_fail (gimp_container_have (gimage->layers,
2739
GIMP_OBJECT (layer)));
2741
if (gimp_drawable_has_floating_sel (GIMP_DRAWABLE (layer)))
2743
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_ITEM_REMOVE,
2747
floating_sel_remove (gimp_image_floating_sel (gimage));
2750
active_layer = gimp_image_get_active_layer (gimage);
2752
index = gimp_container_get_child_index (gimage->layers,
2753
GIMP_OBJECT (layer));
2755
old_has_alpha = gimp_image_has_alpha (gimage);
2757
gimp_image_undo_push_layer_remove (gimage, _("Remove Layer"),
2758
layer, index, active_layer);
2760
g_object_ref (layer);
2762
/* Make sure we're not caching any old selection info */
2763
if (layer == active_layer)
2764
gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer));
2766
gimp_container_remove (gimage->layers, GIMP_OBJECT (layer));
2767
gimage->layer_stack = g_slist_remove (gimage->layer_stack, layer);
2769
if (gimage->floating_sel == layer)
2771
/* If this was the floating selection, reset the fs pointer
2772
* and activate the underlying drawable
2774
gimage->floating_sel = NULL;
2776
floating_sel_activate_drawable (layer);
2778
gimp_image_floating_selection_changed (gimage);
2780
else if (layer == active_layer)
2782
if (gimage->layer_stack)
2784
active_layer = gimage->layer_stack->data;
2788
gint n_children = gimp_container_num_children (gimage->layers);
2792
index = CLAMP (index, 0, n_children - 1);
2794
active_layer = (GimpLayer *)
2795
gimp_container_get_child_by_index (gimage->layers, index);
2799
active_layer = NULL;
2803
gimp_image_set_active_layer (gimage, active_layer);
2806
gimp_item_removed (GIMP_ITEM (layer));
2808
g_object_unref (layer);
2810
if (old_has_alpha != gimp_image_has_alpha (gimage))
2811
gimp_image_alpha_changed (gimage);
2814
gimp_image_undo_group_end (gimage);
2818
gimp_image_raise_layer (GimpImage *gimage,
2823
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2824
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2826
index = gimp_container_get_child_index (gimage->layers,
2827
GIMP_OBJECT (layer));
2831
g_message (_("Layer cannot be raised higher."));
2835
if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
2837
g_message (_("Cannot raise a layer without alpha."));
2841
return gimp_image_position_layer (gimage, layer, index - 1,
2842
TRUE, _("Raise Layer"));
2846
gimp_image_lower_layer (GimpImage *gimage,
2851
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2852
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2854
index = gimp_container_get_child_index (gimage->layers,
2855
GIMP_OBJECT (layer));
2857
if (index == gimp_container_num_children (gimage->layers) - 1)
2859
g_message (_("Layer cannot be lowered more."));
2863
return gimp_image_position_layer (gimage, layer, index + 1,
2864
TRUE, _("Lower Layer"));
2868
gimp_image_raise_layer_to_top (GimpImage *gimage,
2873
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2874
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2876
index = gimp_container_get_child_index (gimage->layers,
2877
GIMP_OBJECT (layer));
2881
g_message (_("Layer is already on top."));
2885
if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
2887
g_message (_("Cannot raise a layer without alpha."));
2891
return gimp_image_position_layer (gimage, layer, 0,
2892
TRUE, _("Raise Layer to Top"));
2896
gimp_image_lower_layer_to_bottom (GimpImage *gimage,
2902
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2903
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2905
index = gimp_container_get_child_index (gimage->layers,
2906
GIMP_OBJECT (layer));
2908
length = gimp_container_num_children (gimage->layers);
2910
if (index == length - 1)
2912
g_message (_("Layer is already on the bottom."));
2916
return gimp_image_position_layer (gimage, layer, length - 1,
2917
TRUE, _("Lower Layer to Bottom"));
2921
gimp_image_position_layer (GimpImage *gimage,
2925
const gchar *undo_desc)
2930
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2931
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
2933
index = gimp_container_get_child_index (gimage->layers,
2934
GIMP_OBJECT (layer));
2938
num_layers = gimp_container_num_children (gimage->layers);
2940
new_index = CLAMP (new_index, 0, num_layers - 1);
2942
if (new_index == index)
2945
/* check if we want to move it below a bottom layer without alpha */
2946
if (new_index == num_layers - 1)
2950
tmp = (GimpLayer *) gimp_container_get_child_by_index (gimage->layers,
2953
if (new_index == num_layers - 1 &&
2954
! gimp_drawable_has_alpha (GIMP_DRAWABLE (tmp)))
2956
g_message (_("Layer '%s' has no alpha. Layer was placed above it."),
2957
GIMP_OBJECT (tmp)->name);
2963
gimp_image_undo_push_layer_reposition (gimage, undo_desc, layer);
2965
gimp_container_reorder (gimage->layers, GIMP_OBJECT (layer), new_index);
2967
if (gimp_item_get_visible (GIMP_ITEM (layer)))
2971
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
2973
gimp_image_update (gimage,
2975
gimp_item_width (GIMP_ITEM (layer)),
2976
gimp_item_height (GIMP_ITEM (layer)));
2977
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
2984
gimp_image_add_channel (GimpImage *gimage,
2985
GimpChannel *channel,
2988
GimpChannel *active_channel;
2990
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
2991
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
2993
if (GIMP_ITEM (channel)->gimage != NULL &&
2994
GIMP_ITEM (channel)->gimage != gimage)
2996
g_warning ("%s: attempting to add channel to wrong image.", G_STRFUNC);
3000
if (gimp_container_have (gimage->channels, GIMP_OBJECT (channel)))
3002
g_warning ("%s: trying to add channel to image twice.", G_STRFUNC);
3006
active_channel = gimp_image_get_active_channel (gimage);
3008
gimp_image_undo_push_channel_add (gimage, _("Add Channel"),
3009
channel, 0, active_channel);
3011
gimp_item_set_image (GIMP_ITEM (channel), gimage);
3013
/* add the layer to the list at the specified position */
3017
position = gimp_container_get_child_index (gimage->channels,
3018
GIMP_OBJECT (active_channel));
3023
/* Don't add at a non-existing index */
3024
if (position > gimp_container_num_children (gimage->channels))
3025
position = gimp_container_num_children (gimage->channels);
3027
gimp_container_insert (gimage->channels, GIMP_OBJECT (channel), position);
3028
gimp_item_sink (GIMP_ITEM (channel));
3030
/* notify this gimage of the currently active channel */
3031
gimp_image_set_active_channel (gimage, channel);
3037
gimp_image_remove_channel (GimpImage *gimage,
3038
GimpChannel *channel)
3040
GimpChannel *active_channel;
3042
gboolean undo_group = FALSE;
3044
g_return_if_fail (GIMP_IS_IMAGE (gimage));
3045
g_return_if_fail (GIMP_IS_CHANNEL (channel));
3046
g_return_if_fail (gimp_container_have (gimage->channels,
3047
GIMP_OBJECT (channel)));
3049
if (gimp_drawable_has_floating_sel (GIMP_DRAWABLE (channel)))
3051
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_IMAGE_ITEM_REMOVE,
3052
_("Remove Channel"));
3055
floating_sel_remove (gimp_image_floating_sel (gimage));
3058
active_channel = gimp_image_get_active_channel (gimage);
3060
index = gimp_container_get_child_index (gimage->channels,
3061
GIMP_OBJECT (channel));
3063
gimp_image_undo_push_channel_remove (gimage, _("Remove Channel"),
3064
channel, index, active_channel);
3066
g_object_ref (channel);
3068
gimp_container_remove (gimage->channels, GIMP_OBJECT (channel));
3069
gimp_item_removed (GIMP_ITEM (channel));
3071
if (channel == active_channel)
3073
gint n_children = gimp_container_num_children (gimage->channels);
3077
index = CLAMP (index, 0, n_children - 1);
3079
active_channel = (GimpChannel *)
3080
gimp_container_get_child_by_index (gimage->channels, index);
3082
gimp_image_set_active_channel (gimage, active_channel);
3086
gimp_image_unset_active_channel (gimage);
3090
g_object_unref (channel);
3093
gimp_image_undo_group_end (gimage);
3097
gimp_image_raise_channel (GimpImage *gimage,
3098
GimpChannel *channel)
3102
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3103
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
3105
index = gimp_container_get_child_index (gimage->channels,
3106
GIMP_OBJECT (channel));
3110
g_message (_("Channel cannot be raised higher."));
3114
return gimp_image_position_channel (gimage, channel, index - 1,
3115
TRUE, _("Raise Channel"));
3119
gimp_image_raise_channel_to_top (GimpImage *gimage,
3120
GimpChannel *channel)
3124
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3125
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
3127
index = gimp_container_get_child_index (gimage->channels,
3128
GIMP_OBJECT (channel));
3132
g_message (_("Channel is already on top."));
3136
return gimp_image_position_channel (gimage, channel, 0,
3137
TRUE, _("Raise Channel to Top"));
3141
gimp_image_lower_channel (GimpImage *gimage,
3142
GimpChannel *channel)
3146
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3147
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
3149
index = gimp_container_get_child_index (gimage->channels,
3150
GIMP_OBJECT (channel));
3152
if (index == gimp_container_num_children (gimage->channels) - 1)
3154
g_message (_("Channel cannot be lowered more."));
3158
return gimp_image_position_channel (gimage, channel, index + 1,
3159
TRUE, _("Lower Channel"));
3163
gimp_image_lower_channel_to_bottom (GimpImage *gimage,
3164
GimpChannel *channel)
3169
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3170
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
3172
index = gimp_container_get_child_index (gimage->channels,
3173
GIMP_OBJECT (channel));
3175
length = gimp_container_num_children (gimage->channels);
3177
if (index == length - 1)
3179
g_message (_("Channel is already on the bottom."));
3183
return gimp_image_position_channel (gimage, channel, length - 1,
3184
TRUE, _("Lower Channel to Bottom"));
3188
gimp_image_position_channel (GimpImage *gimage,
3189
GimpChannel *channel,
3192
const gchar *undo_desc)
3197
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3198
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
3200
index = gimp_container_get_child_index (gimage->channels,
3201
GIMP_OBJECT (channel));
3205
num_channels = gimp_container_num_children (gimage->channels);
3207
new_index = CLAMP (new_index, 0, num_channels - 1);
3209
if (new_index == index)
3213
gimp_image_undo_push_channel_reposition (gimage, undo_desc, channel);
3215
gimp_container_reorder (gimage->channels,
3216
GIMP_OBJECT (channel), new_index);
3218
if (gimp_item_get_visible (GIMP_ITEM (channel)))
3222
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
3224
gimp_image_update (gimage,
3226
gimp_item_width (GIMP_ITEM (channel)),
3227
gimp_item_height (GIMP_ITEM (channel)));
3228
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
3235
gimp_image_add_vectors (GimpImage *gimage,
3236
GimpVectors *vectors,
3239
GimpVectors *active_vectors;
3241
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3242
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3244
if (GIMP_ITEM (vectors)->gimage != NULL &&
3245
GIMP_ITEM (vectors)->gimage != gimage)
3247
g_warning ("%s: attempting to add vectors to wrong image.", G_STRFUNC);
3251
if (gimp_container_have (gimage->vectors, GIMP_OBJECT (vectors)))
3253
g_warning ("%s: trying to add vectors to image twice.", G_STRFUNC);
3257
active_vectors = gimp_image_get_active_vectors (gimage);
3259
gimp_image_undo_push_vectors_add (gimage, _("Add Path"),
3260
vectors, 0, active_vectors);
3262
gimp_item_set_image (GIMP_ITEM (vectors), gimage);
3264
/* add the layer to the list at the specified position */
3268
position = gimp_container_get_child_index (gimage->vectors,
3269
GIMP_OBJECT (active_vectors));
3274
/* Don't add at a non-existing index */
3275
if (position > gimp_container_num_children (gimage->vectors))
3276
position = gimp_container_num_children (gimage->vectors);
3278
gimp_container_insert (gimage->vectors, GIMP_OBJECT (vectors), position);
3279
gimp_item_sink (GIMP_ITEM (vectors));
3281
/* notify this gimage of the currently active vectors */
3282
gimp_image_set_active_vectors (gimage, vectors);
3288
gimp_image_remove_vectors (GimpImage *gimage,
3289
GimpVectors *vectors)
3291
GimpVectors *active_vectors;
3294
g_return_if_fail (GIMP_IS_IMAGE (gimage));
3295
g_return_if_fail (GIMP_IS_VECTORS (vectors));
3296
g_return_if_fail (gimp_container_have (gimage->vectors,
3297
GIMP_OBJECT (vectors)));
3299
active_vectors = gimp_image_get_active_vectors (gimage);
3301
index = gimp_container_get_child_index (gimage->vectors,
3302
GIMP_OBJECT (vectors));
3304
gimp_image_undo_push_vectors_remove (gimage, _("Remove Path"),
3305
vectors, index, active_vectors);
3307
g_object_ref (vectors);
3309
gimp_container_remove (gimage->vectors, GIMP_OBJECT (vectors));
3310
gimp_item_removed (GIMP_ITEM (vectors));
3312
if (vectors == active_vectors)
3314
gint n_children = gimp_container_num_children (gimage->vectors);
3318
index = CLAMP (index, 0, n_children - 1);
3320
active_vectors = (GimpVectors *)
3321
gimp_container_get_child_by_index (gimage->vectors, index);
3325
active_vectors = NULL;
3328
gimp_image_set_active_vectors (gimage, active_vectors);
3331
g_object_unref (vectors);
3335
gimp_image_raise_vectors (GimpImage *gimage,
3336
GimpVectors *vectors)
3340
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3341
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3343
index = gimp_container_get_child_index (gimage->vectors,
3344
GIMP_OBJECT (vectors));
3348
g_message (_("Path cannot be raised higher."));
3352
return gimp_image_position_vectors (gimage, vectors, index - 1,
3353
TRUE, _("Raise Path"));
3357
gimp_image_raise_vectors_to_top (GimpImage *gimage,
3358
GimpVectors *vectors)
3362
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3363
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3365
index = gimp_container_get_child_index (gimage->vectors,
3366
GIMP_OBJECT (vectors));
3370
g_message (_("Path is already on top."));
3374
return gimp_image_position_vectors (gimage, vectors, 0,
3375
TRUE, _("Raise Path to Top"));
3379
gimp_image_lower_vectors (GimpImage *gimage,
3380
GimpVectors *vectors)
3384
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3385
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3387
index = gimp_container_get_child_index (gimage->vectors,
3388
GIMP_OBJECT (vectors));
3390
if (index == gimp_container_num_children (gimage->vectors) - 1)
3392
g_message (_("Path cannot be lowered more."));
3396
return gimp_image_position_vectors (gimage, vectors, index + 1,
3397
TRUE, _("Lower Path"));
3401
gimp_image_lower_vectors_to_bottom (GimpImage *gimage,
3402
GimpVectors *vectors)
3407
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3408
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3410
index = gimp_container_get_child_index (gimage->vectors,
3411
GIMP_OBJECT (vectors));
3413
length = gimp_container_num_children (gimage->vectors);
3415
if (index == length - 1)
3417
g_message (_("Path is already on the bottom."));
3421
return gimp_image_position_vectors (gimage, vectors, length - 1,
3422
TRUE, _("Lower Path to Bottom"));
3426
gimp_image_position_vectors (GimpImage *gimage,
3427
GimpVectors *vectors,
3430
const gchar *undo_desc)
3435
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3436
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
3438
index = gimp_container_get_child_index (gimage->vectors,
3439
GIMP_OBJECT (vectors));
3443
num_vectors = gimp_container_num_children (gimage->vectors);
3445
new_index = CLAMP (new_index, 0, num_vectors - 1);
3447
if (new_index == index)
3451
gimp_image_undo_push_vectors_reposition (gimage, undo_desc, vectors);
3453
gimp_container_reorder (gimage->vectors,
3454
GIMP_OBJECT (vectors), new_index);
3460
gimp_image_layer_boundary (const GimpImage *gimage,
3466
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3467
g_return_val_if_fail (segs != NULL, FALSE);
3468
g_return_val_if_fail (n_segs != NULL, FALSE);
3470
/* The second boundary corresponds to the active layer's
3473
layer = gimp_image_get_active_layer (gimage);
3477
*segs = gimp_layer_boundary (layer, n_segs);
3489
gimp_image_pick_correlate_layer (const GimpImage *gimage,
3495
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
3497
for (list = GIMP_LIST (gimage->layers)->list;
3499
list = g_list_next (list))
3501
GimpLayer *layer = list->data;
3503
if (gimp_layer_pick_correlate (layer, x, y))
3511
gimp_image_coords_in_active_drawable (GimpImage *gimage,
3512
const GimpCoords *coords)
3514
GimpDrawable *drawable;
3516
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
3518
drawable = gimp_image_active_drawable (gimage);
3522
GimpItem *item = GIMP_ITEM (drawable);
3525
gimp_item_offsets (item, &x, &y);
3527
x = ROUND (coords->x) - x;
3528
y = ROUND (coords->y) - y;
3530
if (x < 0 || x > gimp_item_width (item))
3533
if (y < 0 || y > gimp_item_height (item))
3543
gimp_image_invalidate_layer_previews (GimpImage *gimage)
3545
g_return_if_fail (GIMP_IS_IMAGE (gimage));
3547
gimp_container_foreach (gimage->layers,
3548
(GFunc) gimp_viewable_invalidate_preview,
3553
gimp_image_invalidate_channel_previews (GimpImage *gimage)
3555
g_return_if_fail (GIMP_IS_IMAGE (gimage));
3557
gimp_container_foreach (gimage->channels,
3558
(GFunc) gimp_viewable_invalidate_preview,