made gimp_drawable_fill() use GimpRGB, added some "const", delete unused

2001-01-20  Michael Natterer  <mitch@gimp.org>

	* app/gimpdrawable.[ch]: made gimp_drawable_fill() use GimpRGB,
	added some "const", delete unused function, reordered some
	functions.

	* app/drawable.c
	* app/qmask.c: follow the change.
This commit is contained in:
Michael Natterer 2001-01-20 13:21:49 +00:00 committed by Michael Natterer
parent e0198f9ca2
commit 37932755fa
13 changed files with 570 additions and 526 deletions

View File

@ -1,3 +1,12 @@
2001-01-20 Michael Natterer <mitch@gimp.org>
* app/gimpdrawable.[ch]: made gimp_drawable_fill() use GimpRGB,
added some "const", delete unused function, reordered some
functions.
* app/drawable.c
* app/qmask.c: follow the change.
2001-01-19 Michael Natterer <mitch@gimp.org>
* app/Makefile.am

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -53,16 +53,22 @@ enum
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 void gimp_drawable_name_changed (GimpObject *drawable);
/* private variables */
static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };
static GimpDrawableClass *parent_class = NULL;
static gint global_drawable_ID = 1;
static GHashTable *gimp_drawable_table = NULL;
GtkType
gimp_drawable_get_type (void)
@ -128,6 +134,59 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->invalidate_preview = NULL;
}
static void
gimp_drawable_init (GimpDrawable *drawable)
{
drawable->tiles = NULL;
drawable->visible = FALSE;
drawable->width = 0;
drawable->height = 0;
drawable->offset_x = 0;
drawable->offset_y = 0;
drawable->bytes = 0;
drawable->ID = global_drawable_ID++;
drawable->tattoo = 0;
drawable->gimage = NULL;
drawable->type = -1;
drawable->has_alpha = FALSE;
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
drawable->parasites = parasite_list_new ();
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
if (gimp_drawable_table == NULL)
gimp_drawable_table = g_hash_table_new (g_direct_hash, NULL);
g_hash_table_insert (gimp_drawable_table,
GINT_TO_POINTER (drawable->ID),
(gpointer) drawable);
}
static void
gimp_drawable_destroy (GtkObject *object)
{
GimpDrawable *drawable;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
if (drawable->preview_cache)
gimp_preview_cache_invalidate (&drawable->preview_cache);
if (drawable->parasites)
gtk_object_unref (GTK_OBJECT (drawable->parasites));
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_drawable_name_changed (GimpObject *object)
{
@ -222,15 +281,64 @@ gimp_drawable_name_changed (GimpObject *object)
}
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
gint bpp;
gboolean alpha;
/*
* Static variables
*/
static gint global_drawable_ID = 1;
static GHashTable *gimp_drawable_table = NULL;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
/**************************/
/* Function definitions */
if (!name)
name = _("unnamed");
switch (type)
{
case RGB_GIMAGE:
bpp = 3; alpha = FALSE; break;
case GRAY_GIMAGE:
bpp = 1; alpha = FALSE; break;
case RGBA_GIMAGE:
bpp = 4; alpha = TRUE; break;
case GRAYA_GIMAGE:
bpp = 2; alpha = TRUE; break;
case INDEXED_GIMAGE:
bpp = 1; alpha = FALSE; break;
case INDEXEDA_GIMAGE:
bpp = 2; alpha = TRUE; break;
default:
g_message (_("Layer type %d not supported."), type);
return;
}
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
drawable->type = type;
drawable->has_alpha = alpha;
drawable->offset_x = 0;
drawable->offset_y = 0;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height, bpp);
drawable->visible = TRUE;
if (gimage)
gimp_drawable_set_gimage (drawable, gimage);
gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}
gint
gimp_drawable_get_ID (GimpDrawable *drawable)
@ -251,11 +359,33 @@ gimp_drawable_get_by_ID (gint drawable_id)
(gpointer) drawable_id);
}
GimpImage *
gimp_drawable_gimage (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->gimage;
}
void
gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (gimage == NULL)
drawable->tattoo = 0;
else if (drawable->tattoo == 0 || drawable->gimage != gimage )
drawable->tattoo = gimp_image_get_new_tattoo (gimage);
drawable->gimage = gimage;
}
void
gimp_drawable_merge_shadow (GimpDrawable *drawable,
gint undo)
{
GImage *gimage;
GimpImage *gimage;
PixelRegion shadowPR;
gint x1, y1, x2, y2;
@ -279,13 +409,10 @@ gimp_drawable_merge_shadow (GimpDrawable *drawable,
}
void
gimp_drawable_fill (GimpDrawable *drawable,
guchar r,
guchar g,
guchar b,
guchar a)
gimp_drawable_fill (GimpDrawable *drawable,
const GimpRGB *color)
{
GImage *gimage;
GimpImage *gimage;
PixelRegion destPR;
guchar c[MAX_CHANNELS];
guchar i;
@ -300,27 +427,38 @@ gimp_drawable_fill (GimpDrawable *drawable,
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;
gimp_rgba_get_uchar (color,
&c[RED_PIX],
&c[GREEN_PIX],
&c[BLUE_PIX],
&c[ALPHA_PIX]);
if (gimp_drawable_type (drawable) != RGBA_GIMAGE)
c[ALPHA_PIX] = 255;
break;
case GRAY_GIMAGE: case GRAYA_GIMAGE:
c[GRAY_PIX] = r;
if (gimp_drawable_type (drawable) == GRAYA_GIMAGE)
c[ALPHA_G_PIX] = a;
gimp_rgba_get_uchar (color,
&c[GRAY_PIX],
NULL,
NULL,
&c[ALPHA_G_PIX]);
if (gimp_drawable_type (drawable) != GRAYA_GIMAGE)
c[ALPHA_G_PIX] = 255;
break;
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
c[RED_PIX] = r;
c[GREEN_PIX] = g;
c[BLUE_PIX] = b;
gimp_rgb_get_uchar (color,
&c[RED_PIX],
&c[GREEN_PIX],
&c[BLUE_PIX]);
gimp_image_transform_color (gimage, drawable, c, &i, RGB);
c[INDEXED_PIX] = i;
if (gimp_drawable_type (drawable) == INDEXEDA_GIMAGE)
c[ALPHA_I_PIX] = a;
gimp_rgba_get_uchar (color,
NULL,
NULL,
NULL,
&c[ALPHA_I_PIX]);
break;
default:
@ -345,7 +483,7 @@ gimp_drawable_mask_bounds (GimpDrawable *drawable,
gint *y2)
{
GimpImage *gimage;
gint off_x, off_y;
gint off_x, off_y;
g_return_val_if_fail (drawable != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
@ -399,7 +537,8 @@ gimp_drawable_invalidate_preview (GimpDrawable *drawable,
* associcated with an image. It's needed because layers aren't
* destroyed immediately, but kept around for undo purposes. Connect
* to the removed signal to update bits of UI that are tied to a
* particular layer. */
* particular layer.
*/
void
gimp_drawable_removed (GimpDrawable *drawable)
{
@ -409,28 +548,6 @@ gimp_drawable_removed (GimpDrawable *drawable)
gtk_signal_emit (GTK_OBJECT (drawable), gimp_drawable_signals[REMOVED]);
}
GimpImage *
gimp_drawable_gimage (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->gimage;
}
void
gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (gimage == NULL)
drawable->tattoo = 0;
else if (drawable->tattoo == 0 || drawable->gimage != gimage )
drawable->tattoo = gimp_image_get_new_tattoo (gimage);
drawable->gimage = gimage;
}
gboolean
gimp_drawable_has_alpha (const GimpDrawable *drawable)
{
@ -540,9 +657,9 @@ gimp_drawable_parasite_find (const GimpDrawable *drawable,
}
static void
list_func (gchar *key,
GimpParasite *p,
gchar ***cur)
gimp_drawable_parasite_list_foreach_func (gchar *key,
GimpParasite *p,
gchar ***cur)
{
*(*cur)++ = (gchar *) g_strdup (key);
}
@ -561,7 +678,9 @@ gimp_drawable_parasite_list (const GimpDrawable *drawable,
*count = parasite_list_length (drawable->parasites);
cur = list = g_new (gchar *, *count);
parasite_list_foreach (drawable->parasites, (GHFunc) list_func, &cur);
parasite_list_foreach (drawable->parasites,
(GHFunc) gimp_drawable_parasite_list_foreach_func,
&cur);
return list;
}
@ -693,7 +812,7 @@ gimp_drawable_data (const GimpDrawable *drawable)
TileManager *
gimp_drawable_shadow (GimpDrawable *drawable)
{
GImage *gimage;
GimpImage *gimage;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
@ -705,7 +824,7 @@ gimp_drawable_shadow (GimpDrawable *drawable)
}
int
gimp_drawable_bytes (GimpDrawable *drawable)
gimp_drawable_bytes (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -713,7 +832,7 @@ gimp_drawable_bytes (GimpDrawable *drawable)
}
gint
gimp_drawable_width (GimpDrawable *drawable)
gimp_drawable_width (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -721,7 +840,7 @@ gimp_drawable_width (GimpDrawable *drawable)
}
gint
gimp_drawable_height (GimpDrawable *drawable)
gimp_drawable_height (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -729,9 +848,9 @@ gimp_drawable_height (GimpDrawable *drawable)
}
void
gimp_drawable_offsets (GimpDrawable *drawable,
gint *off_x,
gint *off_y)
gimp_drawable_offsets (const GimpDrawable *drawable,
gint *off_x,
gint *off_y)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@ -746,129 +865,8 @@ gimp_drawable_cmap (const GimpDrawable *drawable)
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
gimage = gimp_drawable_gimage (drawable);
g_return_val_if_fail (gimage != NULL, NULL);
if (! (gimage = gimp_drawable_gimage (drawable)))
return NULL;
return gimage->cmap;
}
void
gimp_drawable_deallocate (GimpDrawable *drawable)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
}
static void
gimp_drawable_init (GimpDrawable *drawable)
{
drawable->tiles = NULL;
drawable->visible = FALSE;
drawable->width = 0;
drawable->height = 0;
drawable->offset_x = 0;
drawable->offset_y = 0;
drawable->bytes = 0;
drawable->ID = global_drawable_ID++;
drawable->tattoo = 0;
drawable->gimage = NULL;
drawable->type = -1;
drawable->has_alpha = FALSE;
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
drawable->parasites = parasite_list_new ();
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
if (gimp_drawable_table == NULL)
gimp_drawable_table = g_hash_table_new (g_direct_hash, NULL);
g_hash_table_insert (gimp_drawable_table,
GINT_TO_POINTER (drawable->ID),
(gpointer) drawable);
}
static void
gimp_drawable_destroy (GtkObject *object)
{
GimpDrawable *drawable;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
if (drawable->preview_cache)
gimp_preview_cache_invalidate (&drawable->preview_cache);
if (drawable->parasites)
gtk_object_unref (GTK_OBJECT (drawable->parasites));
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
gint bpp;
gboolean alpha;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (!name)
name = _("unnamed");
switch (type)
{
case RGB_GIMAGE:
bpp = 3; alpha = FALSE; break;
case GRAY_GIMAGE:
bpp = 1; alpha = FALSE; break;
case RGBA_GIMAGE:
bpp = 4; alpha = TRUE; break;
case GRAYA_GIMAGE:
bpp = 2; alpha = TRUE; break;
case INDEXED_GIMAGE:
bpp = 1; alpha = FALSE; break;
case INDEXEDA_GIMAGE:
bpp = 2; alpha = TRUE; break;
default:
g_message (_("Layer type %d not supported."), type);
return;
}
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
drawable->type = type;
drawable->has_alpha = alpha;
drawable->offset_x = 0;
drawable->offset_y = 0;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height, bpp);
drawable->visible = TRUE;
if (gimage)
gimp_drawable_set_gimage (drawable, gimage);
gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}

View File

@ -68,13 +68,24 @@ struct _GimpDrawableClass
GtkType gimp_drawable_get_type (void);
void gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name);
gint gimp_drawable_get_ID (GimpDrawable *drawable);
GimpDrawable * gimp_drawable_get_by_ID (gint id);
GimpImage * gimp_drawable_gimage (const GimpDrawable *drawable);
void gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage);
void gimp_drawable_merge_shadow (GimpDrawable *drawable,
gint undo);
void gimp_drawable_fill (GimpDrawable *drawable,
guchar r,
guchar g,
guchar b,
guchar a);
const GimpRGB *color);
gboolean gimp_drawable_mask_bounds (GimpDrawable *drawable,
gint *x1,
@ -84,7 +95,7 @@ gboolean gimp_drawable_mask_bounds (GimpDrawable *drawable,
void gimp_drawable_invalidate_preview (GimpDrawable *drawable,
gboolean emit_signal);
void gimp_drawable_removed (GimpDrawable *drawable);
void gimp_drawable_removed (GimpDrawable *drawable);
gboolean gimp_drawable_has_alpha (const GimpDrawable *drawable);
GimpImageType gimp_drawable_type (const GimpDrawable *drawable);
@ -92,13 +103,13 @@ GimpImageType gimp_drawable_type_with_alpha (const GimpDrawable *drawable);
gboolean gimp_drawable_is_rgb (const GimpDrawable *drawable);
gboolean gimp_drawable_is_gray (const GimpDrawable *drawable);
gboolean gimp_drawable_is_indexed (const GimpDrawable *drawable);
TileManager * gimp_drawable_data (const GimpDrawable *drawable);
TileManager * gimp_drawable_shadow (GimpDrawable *);
gint gimp_drawable_bytes (GimpDrawable *);
gint gimp_drawable_width (GimpDrawable *);
gint gimp_drawable_height (GimpDrawable *);
TileManager * gimp_drawable_data (const GimpDrawable *drawable);
TileManager * gimp_drawable_shadow (GimpDrawable *drawable);
gint gimp_drawable_bytes (const GimpDrawable *drawable);
gint gimp_drawable_width (const GimpDrawable *drawable);
gint gimp_drawable_height (const GimpDrawable *drawable);
gboolean gimp_drawable_visible (const GimpDrawable *drawable);
void gimp_drawable_offsets (GimpDrawable *drawable,
void gimp_drawable_offsets (const GimpDrawable *drawable,
gint *offset_x,
gint *offset_y);
@ -120,19 +131,5 @@ Tattoo gimp_drawable_get_tattoo (const GimpDrawable *drawable);
void gimp_drawable_set_tattoo (GimpDrawable *drawable,
Tattoo tattoo);
gint gimp_drawable_get_ID (GimpDrawable *drawable);
GimpDrawable * gimp_drawable_get_by_ID (gint id);
void gimp_drawable_deallocate (GimpDrawable *drawable);
GimpImage * gimp_drawable_gimage (const GimpDrawable *drawable);
void gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage);
void gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name);
#endif /* __GIMP_DRAWABLE_H__ */

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -33,43 +33,39 @@ drawable_fill (GimpDrawable *drawable,
GimpFillType fill_type)
{
GimpRGB color;
guchar r, g, b, a;
g_return_if_fail (drawable != NULL);
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
a = 255;
color.a = 1.0;
switch (fill_type)
{
case FOREGROUND_FILL:
gimp_context_get_foreground (NULL, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
break;
case BACKGROUND_FILL:
gimp_context_get_background (NULL, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
break;
case WHITE_FILL:
r = g = b = 255;
gimp_rgb_set (&color, 1.0, 1.0, 1.0);
break;
case TRANSPARENT_FILL:
a = r = g = b = 0;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
break;
case NO_FILL:
return;
default:
g_warning ("unknown fill type");
a = r = g = b = 0;
break;
g_warning ("drawable_fill(): unknown fill type");
return;
}
gimp_drawable_fill (drawable, r, g, b, a);
gimp_drawable_fill (drawable, &color);
drawable_update (drawable, 0, 0,
gimp_drawable_width (drawable),

View File

@ -53,16 +53,22 @@ enum
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 void gimp_drawable_name_changed (GimpObject *drawable);
/* private variables */
static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };
static GimpDrawableClass *parent_class = NULL;
static gint global_drawable_ID = 1;
static GHashTable *gimp_drawable_table = NULL;
GtkType
gimp_drawable_get_type (void)
@ -128,6 +134,59 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->invalidate_preview = NULL;
}
static void
gimp_drawable_init (GimpDrawable *drawable)
{
drawable->tiles = NULL;
drawable->visible = FALSE;
drawable->width = 0;
drawable->height = 0;
drawable->offset_x = 0;
drawable->offset_y = 0;
drawable->bytes = 0;
drawable->ID = global_drawable_ID++;
drawable->tattoo = 0;
drawable->gimage = NULL;
drawable->type = -1;
drawable->has_alpha = FALSE;
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
drawable->parasites = parasite_list_new ();
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
if (gimp_drawable_table == NULL)
gimp_drawable_table = g_hash_table_new (g_direct_hash, NULL);
g_hash_table_insert (gimp_drawable_table,
GINT_TO_POINTER (drawable->ID),
(gpointer) drawable);
}
static void
gimp_drawable_destroy (GtkObject *object)
{
GimpDrawable *drawable;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
if (drawable->preview_cache)
gimp_preview_cache_invalidate (&drawable->preview_cache);
if (drawable->parasites)
gtk_object_unref (GTK_OBJECT (drawable->parasites));
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_drawable_name_changed (GimpObject *object)
{
@ -222,15 +281,64 @@ gimp_drawable_name_changed (GimpObject *object)
}
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
gint bpp;
gboolean alpha;
/*
* Static variables
*/
static gint global_drawable_ID = 1;
static GHashTable *gimp_drawable_table = NULL;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
/**************************/
/* Function definitions */
if (!name)
name = _("unnamed");
switch (type)
{
case RGB_GIMAGE:
bpp = 3; alpha = FALSE; break;
case GRAY_GIMAGE:
bpp = 1; alpha = FALSE; break;
case RGBA_GIMAGE:
bpp = 4; alpha = TRUE; break;
case GRAYA_GIMAGE:
bpp = 2; alpha = TRUE; break;
case INDEXED_GIMAGE:
bpp = 1; alpha = FALSE; break;
case INDEXEDA_GIMAGE:
bpp = 2; alpha = TRUE; break;
default:
g_message (_("Layer type %d not supported."), type);
return;
}
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
drawable->type = type;
drawable->has_alpha = alpha;
drawable->offset_x = 0;
drawable->offset_y = 0;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height, bpp);
drawable->visible = TRUE;
if (gimage)
gimp_drawable_set_gimage (drawable, gimage);
gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}
gint
gimp_drawable_get_ID (GimpDrawable *drawable)
@ -251,11 +359,33 @@ gimp_drawable_get_by_ID (gint drawable_id)
(gpointer) drawable_id);
}
GimpImage *
gimp_drawable_gimage (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->gimage;
}
void
gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (gimage == NULL)
drawable->tattoo = 0;
else if (drawable->tattoo == 0 || drawable->gimage != gimage )
drawable->tattoo = gimp_image_get_new_tattoo (gimage);
drawable->gimage = gimage;
}
void
gimp_drawable_merge_shadow (GimpDrawable *drawable,
gint undo)
{
GImage *gimage;
GimpImage *gimage;
PixelRegion shadowPR;
gint x1, y1, x2, y2;
@ -279,13 +409,10 @@ gimp_drawable_merge_shadow (GimpDrawable *drawable,
}
void
gimp_drawable_fill (GimpDrawable *drawable,
guchar r,
guchar g,
guchar b,
guchar a)
gimp_drawable_fill (GimpDrawable *drawable,
const GimpRGB *color)
{
GImage *gimage;
GimpImage *gimage;
PixelRegion destPR;
guchar c[MAX_CHANNELS];
guchar i;
@ -300,27 +427,38 @@ gimp_drawable_fill (GimpDrawable *drawable,
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;
gimp_rgba_get_uchar (color,
&c[RED_PIX],
&c[GREEN_PIX],
&c[BLUE_PIX],
&c[ALPHA_PIX]);
if (gimp_drawable_type (drawable) != RGBA_GIMAGE)
c[ALPHA_PIX] = 255;
break;
case GRAY_GIMAGE: case GRAYA_GIMAGE:
c[GRAY_PIX] = r;
if (gimp_drawable_type (drawable) == GRAYA_GIMAGE)
c[ALPHA_G_PIX] = a;
gimp_rgba_get_uchar (color,
&c[GRAY_PIX],
NULL,
NULL,
&c[ALPHA_G_PIX]);
if (gimp_drawable_type (drawable) != GRAYA_GIMAGE)
c[ALPHA_G_PIX] = 255;
break;
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
c[RED_PIX] = r;
c[GREEN_PIX] = g;
c[BLUE_PIX] = b;
gimp_rgb_get_uchar (color,
&c[RED_PIX],
&c[GREEN_PIX],
&c[BLUE_PIX]);
gimp_image_transform_color (gimage, drawable, c, &i, RGB);
c[INDEXED_PIX] = i;
if (gimp_drawable_type (drawable) == INDEXEDA_GIMAGE)
c[ALPHA_I_PIX] = a;
gimp_rgba_get_uchar (color,
NULL,
NULL,
NULL,
&c[ALPHA_I_PIX]);
break;
default:
@ -345,7 +483,7 @@ gimp_drawable_mask_bounds (GimpDrawable *drawable,
gint *y2)
{
GimpImage *gimage;
gint off_x, off_y;
gint off_x, off_y;
g_return_val_if_fail (drawable != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
@ -399,7 +537,8 @@ gimp_drawable_invalidate_preview (GimpDrawable *drawable,
* associcated with an image. It's needed because layers aren't
* destroyed immediately, but kept around for undo purposes. Connect
* to the removed signal to update bits of UI that are tied to a
* particular layer. */
* particular layer.
*/
void
gimp_drawable_removed (GimpDrawable *drawable)
{
@ -409,28 +548,6 @@ gimp_drawable_removed (GimpDrawable *drawable)
gtk_signal_emit (GTK_OBJECT (drawable), gimp_drawable_signals[REMOVED]);
}
GimpImage *
gimp_drawable_gimage (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
return drawable->gimage;
}
void
gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (gimage == NULL)
drawable->tattoo = 0;
else if (drawable->tattoo == 0 || drawable->gimage != gimage )
drawable->tattoo = gimp_image_get_new_tattoo (gimage);
drawable->gimage = gimage;
}
gboolean
gimp_drawable_has_alpha (const GimpDrawable *drawable)
{
@ -540,9 +657,9 @@ gimp_drawable_parasite_find (const GimpDrawable *drawable,
}
static void
list_func (gchar *key,
GimpParasite *p,
gchar ***cur)
gimp_drawable_parasite_list_foreach_func (gchar *key,
GimpParasite *p,
gchar ***cur)
{
*(*cur)++ = (gchar *) g_strdup (key);
}
@ -561,7 +678,9 @@ gimp_drawable_parasite_list (const GimpDrawable *drawable,
*count = parasite_list_length (drawable->parasites);
cur = list = g_new (gchar *, *count);
parasite_list_foreach (drawable->parasites, (GHFunc) list_func, &cur);
parasite_list_foreach (drawable->parasites,
(GHFunc) gimp_drawable_parasite_list_foreach_func,
&cur);
return list;
}
@ -693,7 +812,7 @@ gimp_drawable_data (const GimpDrawable *drawable)
TileManager *
gimp_drawable_shadow (GimpDrawable *drawable)
{
GImage *gimage;
GimpImage *gimage;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
@ -705,7 +824,7 @@ gimp_drawable_shadow (GimpDrawable *drawable)
}
int
gimp_drawable_bytes (GimpDrawable *drawable)
gimp_drawable_bytes (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -713,7 +832,7 @@ gimp_drawable_bytes (GimpDrawable *drawable)
}
gint
gimp_drawable_width (GimpDrawable *drawable)
gimp_drawable_width (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -721,7 +840,7 @@ gimp_drawable_width (GimpDrawable *drawable)
}
gint
gimp_drawable_height (GimpDrawable *drawable)
gimp_drawable_height (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
@ -729,9 +848,9 @@ gimp_drawable_height (GimpDrawable *drawable)
}
void
gimp_drawable_offsets (GimpDrawable *drawable,
gint *off_x,
gint *off_y)
gimp_drawable_offsets (const GimpDrawable *drawable,
gint *off_x,
gint *off_y)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@ -746,129 +865,8 @@ gimp_drawable_cmap (const GimpDrawable *drawable)
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
gimage = gimp_drawable_gimage (drawable);
g_return_val_if_fail (gimage != NULL, NULL);
if (! (gimage = gimp_drawable_gimage (drawable)))
return NULL;
return gimage->cmap;
}
void
gimp_drawable_deallocate (GimpDrawable *drawable)
{
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
}
static void
gimp_drawable_init (GimpDrawable *drawable)
{
drawable->tiles = NULL;
drawable->visible = FALSE;
drawable->width = 0;
drawable->height = 0;
drawable->offset_x = 0;
drawable->offset_y = 0;
drawable->bytes = 0;
drawable->ID = global_drawable_ID++;
drawable->tattoo = 0;
drawable->gimage = NULL;
drawable->type = -1;
drawable->has_alpha = FALSE;
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
drawable->parasites = parasite_list_new ();
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
if (gimp_drawable_table == NULL)
gimp_drawable_table = g_hash_table_new (g_direct_hash, NULL);
g_hash_table_insert (gimp_drawable_table,
GINT_TO_POINTER (drawable->ID),
(gpointer) drawable);
}
static void
gimp_drawable_destroy (GtkObject *object)
{
GimpDrawable *drawable;
g_return_if_fail (GIMP_IS_DRAWABLE (object));
drawable = GIMP_DRAWABLE (object);
g_hash_table_remove (gimp_drawable_table, (gpointer) drawable->ID);
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
if (drawable->preview_cache)
gimp_preview_cache_invalidate (&drawable->preview_cache);
if (drawable->parasites)
gtk_object_unref (GTK_OBJECT (drawable->parasites));
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name)
{
gint bpp;
gboolean alpha;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
if (!name)
name = _("unnamed");
switch (type)
{
case RGB_GIMAGE:
bpp = 3; alpha = FALSE; break;
case GRAY_GIMAGE:
bpp = 1; alpha = FALSE; break;
case RGBA_GIMAGE:
bpp = 4; alpha = TRUE; break;
case GRAYA_GIMAGE:
bpp = 2; alpha = TRUE; break;
case INDEXED_GIMAGE:
bpp = 1; alpha = FALSE; break;
case INDEXEDA_GIMAGE:
bpp = 2; alpha = TRUE; break;
default:
g_message (_("Layer type %d not supported."), type);
return;
}
drawable->width = width;
drawable->height = height;
drawable->bytes = bpp;
drawable->type = type;
drawable->has_alpha = alpha;
drawable->offset_x = 0;
drawable->offset_y = 0;
if (drawable->tiles)
tile_manager_destroy (drawable->tiles);
drawable->tiles = tile_manager_new (width, height, bpp);
drawable->visible = TRUE;
if (gimage)
gimp_drawable_set_gimage (drawable, gimage);
gimp_object_set_name (GIMP_OBJECT (drawable), name);
/* preview variables */
drawable->preview_cache = NULL;
drawable->preview_valid = FALSE;
}

View File

@ -68,13 +68,24 @@ struct _GimpDrawableClass
GtkType gimp_drawable_get_type (void);
void gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name);
gint gimp_drawable_get_ID (GimpDrawable *drawable);
GimpDrawable * gimp_drawable_get_by_ID (gint id);
GimpImage * gimp_drawable_gimage (const GimpDrawable *drawable);
void gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage);
void gimp_drawable_merge_shadow (GimpDrawable *drawable,
gint undo);
void gimp_drawable_fill (GimpDrawable *drawable,
guchar r,
guchar g,
guchar b,
guchar a);
const GimpRGB *color);
gboolean gimp_drawable_mask_bounds (GimpDrawable *drawable,
gint *x1,
@ -84,7 +95,7 @@ gboolean gimp_drawable_mask_bounds (GimpDrawable *drawable,
void gimp_drawable_invalidate_preview (GimpDrawable *drawable,
gboolean emit_signal);
void gimp_drawable_removed (GimpDrawable *drawable);
void gimp_drawable_removed (GimpDrawable *drawable);
gboolean gimp_drawable_has_alpha (const GimpDrawable *drawable);
GimpImageType gimp_drawable_type (const GimpDrawable *drawable);
@ -92,13 +103,13 @@ GimpImageType gimp_drawable_type_with_alpha (const GimpDrawable *drawable);
gboolean gimp_drawable_is_rgb (const GimpDrawable *drawable);
gboolean gimp_drawable_is_gray (const GimpDrawable *drawable);
gboolean gimp_drawable_is_indexed (const GimpDrawable *drawable);
TileManager * gimp_drawable_data (const GimpDrawable *drawable);
TileManager * gimp_drawable_shadow (GimpDrawable *);
gint gimp_drawable_bytes (GimpDrawable *);
gint gimp_drawable_width (GimpDrawable *);
gint gimp_drawable_height (GimpDrawable *);
TileManager * gimp_drawable_data (const GimpDrawable *drawable);
TileManager * gimp_drawable_shadow (GimpDrawable *drawable);
gint gimp_drawable_bytes (const GimpDrawable *drawable);
gint gimp_drawable_width (const GimpDrawable *drawable);
gint gimp_drawable_height (const GimpDrawable *drawable);
gboolean gimp_drawable_visible (const GimpDrawable *drawable);
void gimp_drawable_offsets (GimpDrawable *drawable,
void gimp_drawable_offsets (const GimpDrawable *drawable,
gint *offset_x,
gint *offset_y);
@ -120,19 +131,5 @@ Tattoo gimp_drawable_get_tattoo (const GimpDrawable *drawable);
void gimp_drawable_set_tattoo (GimpDrawable *drawable,
Tattoo tattoo);
gint gimp_drawable_get_ID (GimpDrawable *drawable);
GimpDrawable * gimp_drawable_get_by_ID (gint id);
void gimp_drawable_deallocate (GimpDrawable *drawable);
GimpImage * gimp_drawable_gimage (const GimpDrawable *drawable);
void gimp_drawable_set_gimage (GimpDrawable *drawable,
GimpImage *gimage);
void gimp_drawable_configure (GimpDrawable *drawable,
GimpImage *gimage,
gint width,
gint height,
GimpImageType type,
const gchar *name);
#endif /* __GIMP_DRAWABLE_H__ */

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);

View File

@ -213,7 +213,7 @@ qmask_activate (GtkWidget *widget,
/* Set the defaults */
color = gimg->qmask_color;
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
if ((gmask = gimp_image_get_channel_by_name (gimg, "Qmask")))
{
gimg->qmask_state = TRUE;
/* if the user was clever and created his own */
@ -224,21 +224,25 @@ qmask_activate (GtkWidget *widget,
if (gimage_mask_is_empty (gimg))
{
/* if no selection */
if ((layer = gimp_image_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
}
/* if no selection */
gmask = channel_new (gimg,
gimg->width,
gimg->height,
"Qmask",
&color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE (gmask), 0, 0, 0, 0);
drawable_fill (GIMP_DRAWABLE (gmask), TRANSPARENT_FILL);
}
else
{ /* if selection */
{
/* if selection */
gmask = channel_copy (gimp_image_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color (gmask, &color);
@ -250,10 +254,11 @@ qmask_activate (GtkWidget *widget,
undo_push_group_end (gimg);
gdisp->gimage->qmask_state = TRUE;
gdisplays_flush ();
/* connect to the removed signal, so the buttons get updated */
gtk_signal_connect (GTK_OBJECT (gmask), "removed",
GTK_SIGNAL_FUNC (qmask_removed_callback), gdisp);
GTK_SIGNAL_FUNC (qmask_removed_callback),
gdisp);
}
}
@ -269,10 +274,11 @@ edit_qmask_channel_query (GDisplay * gdisp)
GtkObject *opacity_scale_data;
/* channel = gimp_image_get_channel_by_name (gdisp->gimage, "Qmask"); */
/* the new options structure */
options = g_new (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = gdisp->gimage;
options->color_panel = gimp_color_panel_new (&options->gimage->qmask_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
@ -326,7 +332,7 @@ edit_qmask_channel_query (GDisplay * gdisp)
/* The color panel */
gtk_signal_connect (GTK_OBJECT (options->color_panel), "color_changed",
qmask_color_changed,
GTK_SIGNAL_FUNC (qmask_color_changed),
opacity_scale_data);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
@ -340,13 +346,14 @@ edit_qmask_channel_query (GDisplay * gdisp)
static void
edit_qmask_query_ok_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
Channel *channel;
GimpRGB color;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
channel = gimp_image_get_channel_by_name (options->gimage, "Qmask");
if (options->gimage && channel)
@ -370,11 +377,11 @@ edit_qmask_query_ok_callback (GtkWidget *widget,
static void
edit_qmask_query_cancel_callback (GtkWidget *widget,
gpointer client_data)
gpointer data)
{
EditQmaskOptions *options;
options = (EditQmaskOptions *) client_data;
options = (EditQmaskOptions *) data;
gtk_widget_destroy (options->query_box);
g_free (options);