gimpdrawable.c 17.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
18 19
#include <stdlib.h>
#include <math.h>
20
#include <string.h>
21 22 23 24
#include "gimpdrawableP.h"
#include "gimpsignal.h"
#include "gimage.h"
#include "gimage_mask.h"
Manish Singh's avatar
Manish Singh committed
25
#include "gimpparasite.h"
26
#include "parasitelist.h"
27
#include "undo.h"
28

29
#include "libgimp/parasite.h"
30
#include "libgimp/gimpintl.h"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

enum {
  INVALIDATE_PREVIEW,
  LAST_SIGNAL
};

static void gimp_drawable_class_init (GimpDrawableClass *klass);
static void gimp_drawable_init	     (GimpDrawable      *drawable);
static void gimp_drawable_destroy    (GtkObject		*object);

static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };

static GimpDrawableClass *parent_class = NULL;


GtkType
Manish Singh's avatar
Manish Singh committed
47
gimp_drawable_get_type (void)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
{
  static GtkType type;
  GIMP_TYPE_INIT(type,
		 GimpDrawable,
		 GimpDrawableClass,
		 gimp_drawable_init,
		 gimp_drawable_class_init,
		 GIMP_TYPE_OBJECT);
  return type;
}

static void
gimp_drawable_class_init (GimpDrawableClass *class)
{
  GtkObjectClass *object_class;
63 64
  GtkType type = GIMP_TYPE_DRAWABLE;

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  object_class = GTK_OBJECT_CLASS(class);
  parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
  
  gimp_drawable_signals[INVALIDATE_PREVIEW] =
	  gimp_signal_new ("invalidate_pr", GTK_RUN_LAST, type,
			   GTK_SIGNAL_OFFSET(GimpDrawableClass,
					     invalidate_preview),
			   gimp_sigtype_void);

  gtk_object_class_add_signals (object_class, gimp_drawable_signals, LAST_SIGNAL);

  object_class->destroy = gimp_drawable_destroy;
}


/*
 *  Static variables
 */
83
static gint        global_drawable_ID  = 1;
84 85 86 87 88 89
static GHashTable *gimp_drawable_table = NULL;

/**************************/
/*  Function definitions  */

GimpDrawable*
90
gimp_drawable_get_ID (gint drawable_id)
91 92 93 94 95 96 97 98 99
{
  if (gimp_drawable_table == NULL)
    return NULL;

  return (GimpDrawable*) g_hash_table_lookup (gimp_drawable_table, 
					      (gpointer) drawable_id);
}

void
100 101
gimp_drawable_merge_shadow (GimpDrawable *drawable,
			    gint          undo)
102 103 104 105 106 107 108 109 110 111 112
{
  GImage *gimage;
  PixelRegion shadowPR;
  int x1, y1, x2, y2;

  if (! drawable) 
    return;

  if (! (gimage = gimp_drawable_gimage (drawable)))
    return;

113 114 115
  if (! gimage->shadow)
    return;

116 117 118 119 120 121 122 123 124 125 126 127
  /*  A useful optimization here is to limit the update to the
   *  extents of the selection mask, as it cannot extend beyond
   *  them.
   */
  gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
  pixel_region_init (&shadowPR, gimage->shadow, x1, y1,
		     (x2 - x1), (y2 - y1), FALSE);
  gimage_apply_image (gimage, drawable, &shadowPR, undo, OPAQUE_OPACITY,
		      REPLACE_MODE, NULL, x1, y1);
}

void
128 129 130 131 132
gimp_drawable_fill (GimpDrawable *drawable,
		    guchar        r,
		    guchar        g,
		    guchar        b,
		    guchar        a)
133 134 135 136 137 138
{
  GImage *gimage;
  PixelRegion destPR;
  guchar c[MAX_CHANNELS];
  guchar i;

139 140 141
  g_assert (GIMP_IS_DRAWABLE (drawable));
  gimage = gimp_drawable_gimage (drawable);
  g_assert (gimage);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

  switch (gimp_drawable_type (drawable))
    {
    case RGB_GIMAGE: case RGBA_GIMAGE:
      c[RED_PIX] = r;
      c[GREEN_PIX] = g;
      c[BLUE_PIX] = b;
      if (gimp_drawable_type (drawable) == RGBA_GIMAGE)
	c[ALPHA_PIX] = a;
      break;
    case GRAY_GIMAGE: case GRAYA_GIMAGE:
      c[GRAY_PIX] = r;
      if (gimp_drawable_type (drawable) == GRAYA_GIMAGE)
	c[ALPHA_G_PIX] = a;
      break;
    case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
      c[RED_PIX] = r;
      c[GREEN_PIX] = g;
      c[BLUE_PIX] = b;
      gimage_transform_color (gimage, drawable, c, &i, RGB);
      c[INDEXED_PIX] = i;
      if (gimp_drawable_type (drawable) == INDEXEDA_GIMAGE)
	  c[ALPHA_I_PIX] = a;
      break;
    default:
167
      g_message (_("Can't fill unknown image type."));
168 169 170 171 172 173
      break;
    }

  pixel_region_init (&destPR,
		     gimp_drawable_data (drawable),
		     0, 0,
174
		     gimp_drawable_width  (drawable),
175 176 177 178 179 180
		     gimp_drawable_height (drawable),
		     TRUE);
  color_region (&destPR, c);

}

181
gboolean
182
gimp_drawable_mask_bounds (GimpDrawable *drawable, 
183 184 185 186
			   gint         *x1,
			   gint         *y1,
			   gint         *x2,
			   gint         *y2)
187 188
{
  GImage *gimage;
189
  gint off_x, off_y;
190 191 192 193 194 195 196 197 198 199

  if (! drawable)
    return FALSE;

  if (! (gimage = gimp_drawable_gimage (drawable)))
    return FALSE;

  if (gimage_mask_bounds (gimage, x1, y1, x2, y2))
    {
      gimp_drawable_offsets (drawable, &off_x, &off_y);
200
      *x1 = CLAMP (*x1 - off_x, 0, gimp_drawable_width  (drawable));
201
      *y1 = CLAMP (*y1 - off_y, 0, gimp_drawable_height (drawable));
202
      *x2 = CLAMP (*x2 - off_x, 0, gimp_drawable_width  (drawable));
203 204 205 206 207
      *y2 = CLAMP (*y2 - off_y, 0, gimp_drawable_height (drawable));
      return TRUE;
    }
  else
    {
208
      *x2 = gimp_drawable_width  (drawable);
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
      *y2 = gimp_drawable_height (drawable);
      return FALSE;
    }
}

void
gimp_drawable_invalidate_preview (GimpDrawable *drawable)
{
  GImage *gimage;

  if (! drawable)
    return;

  drawable->preview_valid = FALSE;
#if 0
224 225
  gtk_signal_emit (GTK_OBJECT (drawable),
		   gimp_drawable_signals[INVALIDATE_PREVIEW]);
226 227 228 229 230 231 232 233 234 235 236 237 238 239
#endif
  gimage = gimp_drawable_gimage (drawable);
  if (gimage)
    {
      gimage->comp_preview_valid[0] = FALSE;
      gimage->comp_preview_valid[1] = FALSE;
      gimage->comp_preview_valid[2] = FALSE;
    }
}


GimpImage *
gimp_drawable_gimage (GimpDrawable *drawable)
{
240
  g_assert (GIMP_IS_DRAWABLE (drawable));
241 242 243 244
	
  return drawable->gimage;
}

245
void
246 247
gimp_drawable_set_gimage (GimpDrawable *drawable,
			  GimpImage    *gimage)
248
{
249 250
  g_assert (GIMP_IS_DRAWABLE (drawable));

251 252
  if (gimage == NULL)
    drawable->tattoo = 0;
253
  else if (drawable->tattoo == 0 || drawable->gimage != gimage )
254 255
    drawable->tattoo = gimp_image_get_new_tattoo (gimage);

256
  drawable->gimage = gimage;
257 258
}

259 260 261 262 263 264 265 266
gboolean
gimp_drawable_has_alpha (GimpDrawable *drawable)
{
  if (drawable)
    return drawable->has_alpha;
  else
    return FALSE;
}
267

268
GimpImageType
269 270 271 272 273 274 275 276
gimp_drawable_type (GimpDrawable *drawable)
{
  if (drawable)
    return drawable->type;
  else
    return -1;
}

277 278
GimpImageType
gimp_drawable_type_with_alpha (GimpDrawable *drawable)
279
{
280 281 282 283 284 285
  GimpImageType type = gimp_drawable_type (drawable);

  gboolean has_alpha = gimp_drawable_has_alpha (drawable);

  if (has_alpha)
    return type;
286
  else
287 288 289 290 291 292 293 294
    switch (type)
      {
      case RGB_GIMAGE:
	return RGBA_GIMAGE; break;
      case GRAY_GIMAGE:
	return GRAYA_GIMAGE; break;
      case INDEXED_GIMAGE:
	return INDEXEDA_GIMAGE; break;
295 296 297
      default:
	  g_assert_not_reached ();
	  break;
298 299
      }
  return 0;
300 301
}

302
gboolean
303 304 305 306 307
gimp_drawable_visible (GimpDrawable *drawable)
{
  return drawable->visible;
}

308
gchar *
309
gimp_drawable_get_name (GimpDrawable *drawable)
310 311 312 313
{
  return drawable->name;
}

314
void
315 316
gimp_drawable_set_name (GimpDrawable *drawable,
			gchar        *name)
317 318 319
{
  GSList *list, *listb, *base_list;
  GimpDrawable *drawableb;
320 321 322 323 324 325
  gint number = 1;
  gchar *newname;
  gchar *ext;
  gchar numberbuf[20];

  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
326
  g_return_if_fail (name != NULL);
327 328

  if (drawable->name)
329 330 331 332 333
    {
      g_free (drawable->name);
      drawable->name = NULL;
    }

334
  if (drawable->gimage == 0 || drawable->gimage->layers == 0)
335 336 337 338 339 340 341
    {
      /* no other layers to check name against */
      drawable->name = g_strdup (name);
      return;
    }

  if (GIMP_IS_LAYER (drawable))
342
    base_list = drawable->gimage->layers;
343
  else if (GIMP_IS_CHANNEL (drawable))
344 345 346 347 348 349
    base_list = drawable->gimage->channels;
  else
    base_list = NULL;

  list = base_list;
  while (list)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
    {
      drawableb = GIMP_DRAWABLE (list->data);
      if (drawable != drawableb &&
	  strcmp (name, gimp_drawable_get_name (drawableb)) == 0)
	{ /* names conflict */
	  newname = g_malloc (strlen (name) + 10); /* if this aint enough 
						      yer screwed */
	  strcpy (newname, name);
	  if ((ext = strrchr (newname, '#')))
	    {
	      number = atoi(ext+1);
	      /* Check if there really was the number we think after the # */
	      sprintf (numberbuf, "#%d", number);
	      if (strcmp (ext, numberbuf) != 0)
		{
		  /* No, so just ignore the # */
		  number = 1;
		  ext = &newname[strlen (newname)];
		}
	    }
	  else
	    {
	      number = 1;
	      ext = &newname[strlen (newname)];
	    }
	  sprintf (ext, "#%d", number+1);
376
	  listb = base_list;
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
	  while (listb) /* make sure the new name is unique */
	    {
	      drawableb = GIMP_DRAWABLE (listb->data);
	      if (drawable !=
		  drawableb && strcmp (newname,
				       gimp_drawable_get_name(drawableb)) == 0)
		{
		  number++;
		  sprintf (ext, "#%d", number+1);
		  /* Rescan from beginning */
		  listb = base_list;
		  continue;
		}
	      listb = listb->next;
	    }
	  drawable->name = g_strdup (newname);
	  g_free (newname);
	  return;
395
	}
396
      list = list->next;
397
    }
398
  drawable->name = g_strdup (name);
399 400
}

401 402 403 404
guchar *
gimp_drawable_get_color_at (GimpDrawable *drawable,
			    gint          x,
			    gint          y)
405 406
{
  Tile *tile;
407 408
  guchar *src;
  guchar *dest;
409 410

  if (!drawable ||
Marc Lehmann's avatar
Marc Lehmann committed
411
      (!gimp_drawable_gimage (drawable) && gimp_drawable_is_indexed (drawable)) 
412 413
      || x < 0 || y < 0 ||
      x >= drawable->width || y >= drawable->height)
414 415 416 417
    {
      return NULL;
    }
  dest = g_new (guchar, 5);
418 419 420
  tile = tile_manager_get_tile (gimp_drawable_data (drawable), x, y,
				TRUE, FALSE);
  src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
421
  gimp_image_get_color (gimp_drawable_gimage (drawable),
422 423 424 425 426
			gimp_drawable_type (drawable), dest, src);
  if(TYPE_HAS_ALPHA(gimp_drawable_type (drawable)))
    dest[3] = src[gimp_drawable_bytes (drawable) - 1];
  else
    dest[3] = 255;
Marc Lehmann's avatar
Marc Lehmann committed
427
  if (gimp_drawable_is_indexed (drawable))
428 429 430 431 432 433 434
    dest[4] = src[0];
  else
    dest[4] = 0;
  tile_release (tile, FALSE);
  return dest;
}

435
Parasite *
Marc Lehmann's avatar
Marc Lehmann committed
436
gimp_drawable_parasite_find (const GimpDrawable *drawable,
437
			     const gchar        *name)
438
{
439
  return parasite_list_find (drawable->parasites, name);
440 441
}

442 443 444 445
static void
list_func (gchar      *key,
	   Parasite   *p,
	   gchar    ***cur)
Marc Lehmann's avatar
Marc Lehmann committed
446
{
447
  *(*cur)++ = (gchar *) g_strdup (key);
Marc Lehmann's avatar
Marc Lehmann committed
448 449
}

450 451 452
gchar **
gimp_drawable_parasite_list (GimpDrawable *drawable,
			     gint         *count)
Marc Lehmann's avatar
Marc Lehmann committed
453
{
454
  gchar **list, **cur;
Marc Lehmann's avatar
Marc Lehmann committed
455 456

  *count = parasite_list_length (drawable->parasites);
457
  cur = list = (gchar **) g_malloc (sizeof (gchar *) * *count);
Marc Lehmann's avatar
Marc Lehmann committed
458

459
  parasite_list_foreach (drawable->parasites, (GHFunc) list_func, &cur);
Marc Lehmann's avatar
Marc Lehmann committed
460 461 462 463
  
  return list;
}

464
void
Marc Lehmann's avatar
Marc Lehmann committed
465
gimp_drawable_parasite_attach (GimpDrawable *drawable,
466
			       Parasite     *parasite)
467
{
jaycox's avatar
jaycox committed
468 469
  /* only set the dirty bit manually if we can be saved and the new
     parasite differs from the current one and we arn't undoable */
470 471
  if (parasite_is_undoable (parasite))
    {
472 473 474
      /* do a group in case we have attach_parent set */
      undo_push_group_start (drawable->gimage, PARASITE_ATTACH_UNDO);

475 476
      undo_push_drawable_parasite (drawable->gimage, drawable, parasite);
    }
jaycox's avatar
jaycox committed
477
  else if (parasite_is_persistent(parasite) &&
478
	   !parasite_compare( parasite,
Marc Lehmann's avatar
Marc Lehmann committed
479
			      gimp_drawable_parasite_find
480
			      (drawable, parasite_name (parasite))))
481
    undo_push_cantundo (drawable->gimage, _("parasite attach to drawable"));
482 483 484 485 486

  parasite_list_add (drawable->parasites, parasite);
  if (parasite_has_flag (parasite, PARASITE_ATTACH_PARENT))
    {
      parasite_shift_parent (parasite);
Marc Lehmann's avatar
Marc Lehmann committed
487
      gimp_image_parasite_attach (drawable->gimage, parasite);
488 489 490 491 492
    }
  else if (parasite_has_flag (parasite, PARASITE_ATTACH_GRANDPARENT))
    {
      parasite_shift_parent (parasite);
      parasite_shift_parent (parasite);
Marc Lehmann's avatar
Marc Lehmann committed
493
      gimp_parasite_attach (parasite);
494 495 496 497 498
    }
  if (parasite_is_undoable (parasite))
    {
      undo_push_group_end (drawable->gimage);
    }
499 500 501
}

void
Marc Lehmann's avatar
Marc Lehmann committed
502
gimp_drawable_parasite_detach (GimpDrawable *drawable,
503
			       const gchar  *parasite)
504
{
505
  Parasite *p;
506 507

  if (!(p = parasite_list_find (drawable->parasites, parasite)))
508
    return;
509 510

  if (parasite_is_undoable (p))
jaycox's avatar
jaycox committed
511
    undo_push_drawable_parasite_remove (drawable->gimage, drawable,
512 513
					parasite_name (p));
  else if (parasite_is_persistent (p))
514
    undo_push_cantundo (drawable->gimage, _("detach parasite from drawable"));
515 516

  parasite_list_remove (drawable->parasites, parasite);
517 518
}

519
Tattoo
520
gimp_drawable_get_tattoo (const GimpDrawable *drawable)
521 522 523
{
  return drawable->tattoo;
}
524

525
gboolean
Marc Lehmann's avatar
Marc Lehmann committed
526
gimp_drawable_is_rgb (GimpDrawable *drawable)
527 528 529
{
  if (gimp_drawable_type (drawable) == RGBA_GIMAGE ||
      gimp_drawable_type (drawable) == RGB_GIMAGE)
530
    return TRUE;
531
  else
532
    return FALSE;
533 534
}

535
gboolean
Marc Lehmann's avatar
Marc Lehmann committed
536
gimp_drawable_is_gray (GimpDrawable *drawable)
537 538 539
{
  if (gimp_drawable_type (drawable) == GRAYA_GIMAGE ||
      gimp_drawable_type (drawable) == GRAY_GIMAGE)
540
    return TRUE;
541
  else
542
    return FALSE;
543 544
}

545
gboolean
Marc Lehmann's avatar
Marc Lehmann committed
546
gimp_drawable_is_indexed (GimpDrawable *drawable)
547 548 549
{
  if (gimp_drawable_type (drawable) == INDEXEDA_GIMAGE ||
      gimp_drawable_type (drawable) == INDEXED_GIMAGE)
550
    return TRUE;
551
  else
552
    return FALSE;
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
}

TileManager *
gimp_drawable_data (GimpDrawable *drawable)
{
  if (drawable) 
    return drawable->tiles;
  else
    return NULL;
}

TileManager *
gimp_drawable_shadow (GimpDrawable *drawable)
{
  GImage *gimage;

  if (! (gimage = gimp_drawable_gimage (drawable)))
    return NULL;

  if (drawable) 
    return gimage_shadow (gimage, drawable->width, drawable->height, 
			  drawable->bytes);
  else
    return NULL;
}

int
gimp_drawable_bytes (GimpDrawable *drawable)
{
  if (drawable) 
    return drawable->bytes;
  else
    return -1;
}

588
gint
589 590 591 592 593 594 595 596
gimp_drawable_width (GimpDrawable *drawable)
{
  if (drawable) 
    return drawable->width;
  else
    return -1;
}

597
gint
598 599 600 601 602 603 604 605 606
gimp_drawable_height (GimpDrawable *drawable)
{
  if (drawable) 
    return drawable->height;
  else
    return -1;
}

void
607 608 609
gimp_drawable_offsets (GimpDrawable *drawable,
		       gint         *off_x,
		       gint         *off_y)
610 611 612 613 614 615 616 617 618 619
{
  if (drawable) 
    {
      *off_x = drawable->offset_x;
      *off_y = drawable->offset_y;
    }
  else
    *off_x = *off_y = 0;
}

620
guchar *
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
gimp_drawable_cmap (GimpDrawable *drawable)
{
  GImage *gimage;

  if ((gimage = gimp_drawable_gimage (drawable)))
    return gimage->cmap;
  else
    return NULL;
}

void
gimp_drawable_deallocate (GimpDrawable *drawable)
{
  if (drawable->tiles)
    tile_manager_destroy (drawable->tiles);
}

static void
gimp_drawable_init (GimpDrawable *drawable)
{
641 642 643 644 645 646 647 648 649 650 651
  drawable->name          = NULL;
  drawable->tiles         = NULL;
  drawable->visible       = FALSE;
  drawable->width         = 0;
  drawable->height        = 0;
  drawable->offset_x      = 0;
  drawable->offset_y      = 0;
  drawable->bytes         = 0;
  drawable->gimage        = NULL;
  drawable->type          = -1;
  drawable->has_alpha     = FALSE;
652
  drawable->preview_cache = NULL;
653
  drawable->preview_valid = FALSE;
654 655
  drawable->parasites     = parasite_list_new ();
  drawable->tattoo        = 0;
656 657

  drawable->ID = global_drawable_ID++;
658

659 660
  if (gimp_drawable_table == NULL)
    gimp_drawable_table = g_hash_table_new (g_direct_hash, NULL);
661

662 663 664 665 666 667 668 669
  g_hash_table_insert (gimp_drawable_table, (gpointer) drawable->ID,
		       (gpointer) drawable);
}

static void
gimp_drawable_destroy (GtkObject *object)
{
  GimpDrawable *drawable;
670

671 672 673 674 675 676 677 678 679 680 681 682 683
  g_return_if_fail (object != NULL);
  g_return_if_fail (GIMP_IS_DRAWABLE (object));

  drawable = GIMP_DRAWABLE (object);

  g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
  
  if (drawable->name)
    g_free (drawable->name);

  if (drawable->tiles)
    tile_manager_destroy (drawable->tiles);

684
  if (drawable->preview_cache)
685
    gimp_preview_cache_invalidate (&drawable->preview_cache);
686

687
  if (drawable->parasites)
688
    gtk_object_unref (GTK_OBJECT (drawable->parasites));
689

690
  if (GTK_OBJECT_CLASS (parent_class)->destroy)
691
    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
692 693 694
}

void
695 696 697 698 699 700
gimp_drawable_configure (GimpDrawable  *drawable,
			 GimpImage     *gimage,
			 gint           width,
			 gint           height, 
			 GimpImageType  type,
			 gchar         *name)
701
{
702 703
  gint bpp;
  gboolean alpha;
704 705

  if (!name)
706
    name = _("unnamed");
707 708 709 710

  switch (type)
    {
    case RGB_GIMAGE:
711
      bpp = 3; alpha = FALSE; break;
712
    case GRAY_GIMAGE:
713
      bpp = 1; alpha = FALSE; break;
714
    case RGBA_GIMAGE:
715
      bpp = 4; alpha = TRUE; break;
716
    case GRAYA_GIMAGE:
717
      bpp = 2; alpha = TRUE; break;
718
    case INDEXED_GIMAGE:
719
      bpp = 1; alpha = FALSE; break;
720
    case INDEXEDA_GIMAGE:
721
      bpp = 2; alpha = TRUE; break;
722
    default:
723
      g_message (_("Layer type %d not supported."), type);
724 725 726
      return;
    }

727 728 729 730 731
  drawable->name      = NULL;
  drawable->width     = width;
  drawable->height    = height;
  drawable->bytes     = bpp;
  drawable->type      = type;
732
  drawable->has_alpha = alpha;
733 734
  drawable->offset_x  = 0;
  drawable->offset_y  = 0;
735 736 737 738 739 740

  if (drawable->tiles)
    tile_manager_destroy (drawable->tiles);
  drawable->tiles = tile_manager_new (width, height, bpp);
  drawable->visible = TRUE;

741
  if (gimage)
742
    gimp_drawable_set_gimage (drawable, gimage);
743

744
  gimp_drawable_set_name (drawable, name);
745

746
  /*  preview variables  */
747
  drawable->preview_cache = NULL;
748 749
  drawable->preview_valid = FALSE;
}