1998-01-22 15:02:57 +08:00
|
|
|
/* TODO: make sure has_alpha gets set */
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-14 21:52:16 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-09-24 09:19:57 +08:00
|
|
|
#include <stdlib.h>
|
2000-12-14 21:52:16 +08:00
|
|
|
#include <string.h>
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "apptypes.h"
|
|
|
|
|
|
|
|
#include "boundary.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "drawable.h"
|
|
|
|
#include "floating_sel.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "gimage_mask.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimpimage.h"
|
2001-01-29 00:44:22 +08:00
|
|
|
#include "gimplayermask.h"
|
2001-01-23 04:46:50 +08:00
|
|
|
#include "gimppreviewcache.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "layer.h"
|
2001-01-23 04:46:50 +08:00
|
|
|
#include "parasitelist.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paint_funcs.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "pixel_region.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "undo.h"
|
2001-01-23 04:46:50 +08:00
|
|
|
#include "temp_buf.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tile_manager.h"
|
|
|
|
#include "tile.h"
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2000-05-27 09:30:21 +08:00
|
|
|
#include "libgimp/gimpparasite.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
static void gimp_layer_class_init (GimpLayerClass *klass);
|
|
|
|
static void gimp_layer_init (GimpLayer *layer);
|
|
|
|
static void gimp_layer_destroy (GtkObject *object);
|
|
|
|
static void gimp_layer_invalidate_preview (GimpDrawable *object);
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
static void gimp_layer_transform_color (GimpImage *gimage,
|
|
|
|
PixelRegion *layerPR,
|
|
|
|
PixelRegion *bufPR,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpImageBaseType type);
|
|
|
|
static void gimp_layer_preview_scale (GimpImageBaseType type,
|
|
|
|
guchar *cmap,
|
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR,
|
|
|
|
gint subsample);
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
static TempBuf * gimp_layer_preview_private (GimpLayer *layer,
|
2001-01-29 00:44:22 +08:00
|
|
|
gint width,
|
|
|
|
gint height);
|
2001-01-29 07:25:25 +08:00
|
|
|
static TempBuf * gimp_layer_mask_preview_private (GimpLayer *layer,
|
2001-01-29 00:44:22 +08:00
|
|
|
gint width,
|
|
|
|
gint height);
|
2000-12-17 06:02:10 +08:00
|
|
|
|
|
|
|
|
2001-01-29 08:46:04 +08:00
|
|
|
static GimpDrawableClass *parent_class = NULL;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-10 08:36:54 +08:00
|
|
|
|
1998-06-28 16:01:38 +08:00
|
|
|
GtkType
|
2000-02-17 19:44:27 +08:00
|
|
|
gimp_layer_get_type (void)
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
1998-06-28 16:01:38 +08:00
|
|
|
static GtkType layer_type = 0;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-10 08:36:54 +08:00
|
|
|
if (! layer_type)
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
|
|
|
GtkTypeInfo layer_info =
|
|
|
|
{
|
|
|
|
"GimpLayer",
|
|
|
|
sizeof (GimpLayer),
|
|
|
|
sizeof (GimpLayerClass),
|
|
|
|
(GtkClassInitFunc) gimp_layer_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_layer_init,
|
1998-07-05 08:03:06 +08:00
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
1998-06-28 16:01:38 +08:00
|
|
|
(GtkClassInitFunc) NULL,
|
1998-01-22 15:02:57 +08:00
|
|
|
};
|
|
|
|
|
2000-12-29 00:19:55 +08:00
|
|
|
layer_type = gtk_type_unique (GIMP_TYPE_DRAWABLE, &layer_info);
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return layer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-12-29 00:19:55 +08:00
|
|
|
gimp_layer_class_init (GimpLayerClass *klass)
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
2000-12-04 02:15:08 +08:00
|
|
|
GtkObjectClass *object_class;
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawableClass *drawable_class;
|
|
|
|
|
2001-01-10 08:36:54 +08:00
|
|
|
object_class = (GtkObjectClass *) klass;
|
2000-12-29 00:19:55 +08:00
|
|
|
drawable_class = (GimpDrawableClass *) klass;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_DRAWABLE);
|
1998-01-22 15:02:57 +08:00
|
|
|
|
|
|
|
object_class->destroy = gimp_layer_destroy;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
drawable_class->invalidate_preview = gimp_layer_invalidate_preview;
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_layer_init (GimpLayer *layer)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
layer->linked = FALSE;
|
|
|
|
layer->preserve_trans = FALSE;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
layer->mask = NULL;
|
|
|
|
layer->apply_mask = FALSE;
|
|
|
|
layer->edit_mask = FALSE;
|
|
|
|
layer->show_mask = FALSE;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
layer->opacity = 100;
|
|
|
|
layer->mode = NORMAL_MODE;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
/* floating selection */
|
|
|
|
layer->fs.backing_store = NULL;
|
|
|
|
layer->fs.drawable = NULL;
|
|
|
|
layer->fs.initial = TRUE;
|
|
|
|
layer->fs.boundary_known = FALSE;
|
|
|
|
layer->fs.segs = NULL;
|
|
|
|
layer->fs.num_segs = 0;
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_invalidate_preview (GimpDrawable *drawable)
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
|
|
|
GimpLayer *layer;
|
|
|
|
|
2000-12-29 00:19:55 +08:00
|
|
|
g_return_if_fail (drawable != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_LAYER (drawable));
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2000-12-29 00:19:55 +08:00
|
|
|
layer = GIMP_LAYER (drawable);
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1998-01-22 15:02:57 +08:00
|
|
|
floating_sel_invalidate (layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_transform_color (GimpImage *gimage,
|
|
|
|
PixelRegion *layerPR,
|
|
|
|
PixelRegion *bufPR,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpImageBaseType type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-04 02:15:08 +08:00
|
|
|
gint i;
|
|
|
|
gint h;
|
|
|
|
guchar *s;
|
|
|
|
guchar *d;
|
|
|
|
gpointer pr;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
for (pr = pixel_regions_register (2, layerPR, bufPR);
|
|
|
|
pr != NULL;
|
|
|
|
pr = pixel_regions_process (pr))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
h = layerPR->h;
|
|
|
|
s = bufPR->data;
|
|
|
|
d = layerPR->data;
|
|
|
|
|
|
|
|
while (h--)
|
|
|
|
{
|
|
|
|
for (i = 0; i < layerPR->w; i++)
|
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_transform_color (gimage, drawable,
|
|
|
|
s + (i * bufPR->bytes),
|
|
|
|
d + (i * layerPR->bytes), type);
|
1997-11-25 06:05:25 +08:00
|
|
|
/* copy alpha channel */
|
|
|
|
d[(i + 1) * layerPR->bytes - 1] = s[(i + 1) * bufPR->bytes - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
s += bufPR->rowstride;
|
|
|
|
d += layerPR->rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/* Function definitions */
|
1999-08-22 19:45:31 +08:00
|
|
|
/**************************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *
|
|
|
|
gimp_layer_new (GimpImage *gimage,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpImageType type,
|
|
|
|
const gchar *name,
|
|
|
|
gint opacity,
|
|
|
|
LayerModeEffects mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (width < 1 || height < 1)
|
1999-08-22 19:45:31 +08:00
|
|
|
{
|
|
|
|
g_message (_("Zero width or height layers not allowed."));
|
|
|
|
return NULL;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-14 11:55:56 +08:00
|
|
|
layer = gtk_type_new (GIMP_TYPE_LAYER);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gimp_drawable_configure (GIMP_DRAWABLE (layer),
|
1998-06-29 08:24:44 +08:00
|
|
|
gimage, width, height, type, name);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* mode and opacity */
|
1999-08-22 19:45:31 +08:00
|
|
|
layer->mode = mode;
|
1997-11-25 06:05:25 +08:00
|
|
|
layer->opacity = opacity;
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *
|
|
|
|
gimp_layer_copy (GimpLayer *layer,
|
|
|
|
gboolean add_alpha)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-04 02:15:08 +08:00
|
|
|
gchar *layer_name;
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *new_layer;
|
2000-12-04 02:15:08 +08:00
|
|
|
GimpImageType new_type;
|
|
|
|
gchar *ext;
|
|
|
|
gint number;
|
2000-12-29 00:19:55 +08:00
|
|
|
const gchar *name;
|
2000-12-04 02:15:08 +08:00
|
|
|
gint len;
|
|
|
|
PixelRegion srcPR;
|
|
|
|
PixelRegion destPR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* formulate the new layer name */
|
2001-01-10 11:13:03 +08:00
|
|
|
name = gimp_object_get_name (GIMP_OBJECT (layer));
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
ext = strrchr (name, '#');
|
1998-12-26 02:22:01 +08:00
|
|
|
len = strlen (_("copy"));
|
2000-12-04 02:15:08 +08:00
|
|
|
|
1998-12-26 02:22:01 +08:00
|
|
|
if ((strlen(name) >= len &&
|
1999-08-22 19:45:31 +08:00
|
|
|
strcmp (&name[strlen (name) - len], _("copy")) == 0) ||
|
|
|
|
(ext && (number = atoi (ext + 1)) > 0 &&
|
2000-12-04 02:15:08 +08:00
|
|
|
((gint) (log10 (number) + 1)) == strlen (ext + 1)))
|
1998-12-26 02:22:01 +08:00
|
|
|
/* don't have redundant "copy"s */
|
|
|
|
layer_name = g_strdup (name);
|
1998-09-24 09:19:57 +08:00
|
|
|
else
|
1998-12-26 02:22:01 +08:00
|
|
|
layer_name = g_strdup_printf (_("%s copy"), name);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* when copying a layer, the copy ALWAYS has an alpha channel */
|
|
|
|
if (add_alpha)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
switch (GIMP_DRAWABLE (layer)->type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
case RGB_GIMAGE:
|
|
|
|
new_type = RGBA_GIMAGE;
|
|
|
|
break;
|
|
|
|
case GRAY_GIMAGE:
|
|
|
|
new_type = GRAYA_GIMAGE;
|
|
|
|
break;
|
|
|
|
case INDEXED_GIMAGE:
|
|
|
|
new_type = INDEXEDA_GIMAGE;
|
|
|
|
break;
|
|
|
|
default:
|
1999-08-22 19:45:31 +08:00
|
|
|
new_type = GIMP_DRAWABLE (layer)->type;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-01-29 00:44:22 +08:00
|
|
|
{
|
|
|
|
new_type = GIMP_DRAWABLE (layer)->type;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate a new layer object */
|
2001-01-29 00:44:22 +08:00
|
|
|
new_layer = gimp_layer_new (GIMP_DRAWABLE (layer)->gimage,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
|
|
|
new_type,
|
|
|
|
layer_name,
|
|
|
|
layer->opacity,
|
|
|
|
layer->mode);
|
|
|
|
if (! new_layer)
|
1999-08-22 19:45:31 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
g_message ("gimp_layer_copy: could not allocate new layer");
|
1999-08-22 19:45:31 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_DRAWABLE (new_layer)->offset_x = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
GIMP_DRAWABLE (new_layer)->offset_y = GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
GIMP_DRAWABLE (new_layer)->visible = GIMP_DRAWABLE (layer)->visible;
|
|
|
|
new_layer->linked = layer->linked;
|
1997-11-25 06:05:25 +08:00
|
|
|
new_layer->preserve_trans = layer->preserve_trans;
|
|
|
|
|
|
|
|
/* copy the contents across layers */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (new_type == GIMP_DRAWABLE (layer)->type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
|
|
|
pixel_region_init (&destPR, GIMP_DRAWABLE(new_layer)->tiles,
|
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&destPR, GIMP_DRAWABLE (new_layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE(layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
add_alpha_region (&srcPR, &destPR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* duplicate the layer mask if necessary */
|
|
|
|
if (layer->mask)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
new_layer->mask = gimp_layer_mask_copy (layer->mask);
|
|
|
|
|
|
|
|
gtk_object_ref (GTK_OBJECT (new_layer->mask));
|
|
|
|
gtk_object_sink (GTK_OBJECT (new_layer->mask));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
new_layer->apply_mask = layer->apply_mask;
|
1999-08-22 19:45:31 +08:00
|
|
|
new_layer->edit_mask = layer->edit_mask;
|
|
|
|
new_layer->show_mask = layer->show_mask;
|
2000-05-13 01:07:54 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_mask_set_layer (new_layer->mask, new_layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-10-08 16:15:21 +08:00
|
|
|
/* copy the parasites */
|
1999-11-07 02:19:41 +08:00
|
|
|
gtk_object_unref (GTK_OBJECT (GIMP_DRAWABLE (new_layer)->parasites));
|
1999-08-22 19:45:31 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->parasites
|
|
|
|
= parasite_list_copy (GIMP_DRAWABLE (layer)->parasites);
|
1998-10-08 16:15:21 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
cleanup:
|
|
|
|
/* free up the layer_name memory */
|
|
|
|
g_free (layer_name);
|
|
|
|
|
|
|
|
return new_layer;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *
|
|
|
|
gimp_layer_new_from_tiles (GimpImage *gimage,
|
|
|
|
GimpImageType layer_type,
|
|
|
|
TileManager *tiles,
|
|
|
|
gchar *name,
|
|
|
|
gint opacity,
|
|
|
|
LayerModeEffects mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayer *new_layer;
|
2000-12-04 02:15:08 +08:00
|
|
|
PixelRegion layerPR;
|
|
|
|
PixelRegion bufPR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Function copies buffer to a layer
|
|
|
|
* taking into consideration the possibility of transforming
|
|
|
|
* the contents to meet the requirements of the target image type
|
|
|
|
*/
|
|
|
|
|
2000-01-02 02:33:40 +08:00
|
|
|
/* If no image or no tile manager, return NULL */
|
|
|
|
if (!gimage || !tiles )
|
1997-11-25 06:05:25 +08:00
|
|
|
return NULL;
|
2000-01-12 05:23:38 +08:00
|
|
|
|
|
|
|
/* the layer_type needs to have alpha */
|
2000-12-14 02:53:35 +08:00
|
|
|
g_return_val_if_fail (GIMP_IMAGE_TYPE_HAS_ALPHA (layer_type), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-12 04:08:45 +08:00
|
|
|
/* Create the new layer */
|
2001-01-29 00:44:22 +08:00
|
|
|
new_layer = gimp_layer_new (0,
|
|
|
|
tile_manager_width (tiles),
|
|
|
|
tile_manager_height (tiles),
|
|
|
|
layer_type,
|
|
|
|
name,
|
|
|
|
opacity,
|
|
|
|
mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (!new_layer)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
g_message ("gimp_layer_new_from_tiles: could not allocate new layer");
|
1999-08-22 19:45:31 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the pixel regions */
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&layerPR, GIMP_DRAWABLE (new_layer)->tiles,
|
|
|
|
0, 0,
|
2000-12-04 02:15:08 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->width,
|
|
|
|
GIMP_DRAWABLE (new_layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
TRUE);
|
|
|
|
pixel_region_init (&bufPR, tiles,
|
|
|
|
0, 0,
|
2000-12-04 02:15:08 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->width,
|
2000-12-29 23:22:01 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-23 21:01:48 +08:00
|
|
|
if ((tile_manager_bpp (tiles) == 4 &&
|
2000-12-29 23:22:01 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->type == RGBA_GIMAGE) ||
|
2001-01-23 21:01:48 +08:00
|
|
|
(tile_manager_bpp (tiles) == 2 &&
|
2000-12-29 23:22:01 +08:00
|
|
|
GIMP_DRAWABLE (new_layer)->type == GRAYA_GIMAGE))
|
1997-11-25 06:05:25 +08:00
|
|
|
/* If we want a layer the same type as the buffer */
|
|
|
|
copy_region (&bufPR, &layerPR);
|
|
|
|
else
|
|
|
|
/* Transform the contents of the buf to the new_layer */
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_transform_color (gimage, &layerPR, &bufPR,
|
|
|
|
GIMP_DRAWABLE (new_layer),
|
|
|
|
(tile_manager_bpp (tiles) == 4) ? RGB : GRAY);
|
2000-12-04 02:15:08 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return new_layer;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayerMask *
|
|
|
|
gimp_layer_add_mask (GimpLayer *layer,
|
|
|
|
GimpLayerMask *mask)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (layer->mask)
|
|
|
|
return NULL;
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
layer->mask = mask;
|
|
|
|
|
|
|
|
gtk_object_ref (GTK_OBJECT (layer->mask));
|
|
|
|
gtk_object_sink (GTK_OBJECT (layer->mask));
|
|
|
|
|
|
|
|
gimp_layer_mask_set_layer (mask, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Set the application mode in the layer to "apply" */
|
1999-08-22 19:45:31 +08:00
|
|
|
layer->apply_mask = TRUE;
|
|
|
|
layer->edit_mask = TRUE;
|
|
|
|
layer->show_mask = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-14 21:52:16 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
1999-08-22 19:45:31 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return layer->mask;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayerMask *
|
|
|
|
gimp_layer_create_mask (GimpLayer *layer,
|
|
|
|
AddMaskType add_mask_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
PixelRegion maskPR;
|
|
|
|
PixelRegion layerPR;
|
|
|
|
GimpLayerMask *mask;
|
|
|
|
gchar *mask_name;
|
|
|
|
GimpRGB black = { 0.0, 0.0, 0.0, 1.0 };
|
|
|
|
guchar white_mask = OPAQUE_OPACITY;
|
|
|
|
guchar black_mask = TRANSPARENT_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-10 11:13:03 +08:00
|
|
|
mask_name = g_strdup_printf (_("%s mask"),
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (layer)));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Create the layer mask */
|
2001-01-29 00:44:22 +08:00
|
|
|
mask = gimp_layer_mask_new (GIMP_DRAWABLE (layer)->gimage,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
|
|
|
mask_name, &black);
|
1999-08-22 19:45:31 +08:00
|
|
|
GIMP_DRAWABLE (mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
GIMP_DRAWABLE (mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&maskPR, GIMP_DRAWABLE (mask)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (mask)->width, GIMP_DRAWABLE (mask)->height,
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
switch (add_mask_type)
|
|
|
|
{
|
1999-04-25 04:33:31 +08:00
|
|
|
case ADD_WHITE_MASK:
|
1997-11-25 06:05:25 +08:00
|
|
|
color_region (&maskPR, &white_mask);
|
|
|
|
break;
|
1999-04-25 04:33:31 +08:00
|
|
|
case ADD_BLACK_MASK:
|
1997-11-25 06:05:25 +08:00
|
|
|
color_region (&maskPR, &black_mask);
|
|
|
|
break;
|
1999-04-25 04:33:31 +08:00
|
|
|
case ADD_ALPHA_MASK:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Extract the layer's alpha channel */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_has_alpha (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&layerPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
extract_alpha_region (&layerPR, NULL, &maskPR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (mask_name);
|
2001-01-29 00:44:22 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
static void
|
|
|
|
gimp_layer_destroy (GtkObject *object)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_LAYER (object));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
layer = GIMP_LAYER (object);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if a layer mask exists, free it */
|
|
|
|
if (layer->mask)
|
2001-01-29 00:44:22 +08:00
|
|
|
gtk_object_unref (GTK_OBJECT (layer->mask));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* free the layer boundary if it exists */
|
|
|
|
if (layer->fs.segs)
|
|
|
|
g_free (layer->fs.segs);
|
|
|
|
|
|
|
|
/* free the floating selection if it exists */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
tile_manager_destroy (layer->fs.backing_store);
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_apply_mask (GimpLayer *layer,
|
|
|
|
MaskApplyMode mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegion srcPR, maskPR;
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (! layer->mask)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* this operation can only be done to layers with an alpha channel */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (! gimp_layer_has_alpha (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Need to save the mask here for undo */
|
|
|
|
|
|
|
|
if (mode == APPLY)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
/* Put this apply mask operation on the undo stack */
|
|
|
|
drawable_apply_image (GIMP_DRAWABLE (layer),
|
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
1999-08-22 19:45:31 +08:00
|
|
|
NULL, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Combine the current layer's alpha channel and the mask */
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE(layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
TRUE);
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&maskPR, GIMP_DRAWABLE (layer->mask)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
2000-05-13 01:07:54 +08:00
|
|
|
GIMP_DRAWABLE(layer)->height,
|
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-25 09:24:46 +08:00
|
|
|
apply_mask_to_region (&srcPR, &maskPR, OPAQUE_OPACITY);
|
1999-08-22 19:45:31 +08:00
|
|
|
GIMP_DRAWABLE (layer)->preview_valid = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
layer->mask = NULL;
|
|
|
|
layer->apply_mask = FALSE;
|
|
|
|
layer->edit_mask = FALSE;
|
|
|
|
layer->show_mask = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else if (mode == DISCARD)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
layer->mask = NULL;
|
|
|
|
layer->apply_mask = FALSE;
|
|
|
|
layer->edit_mask = FALSE;
|
|
|
|
layer->show_mask = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_translate (GimpLayer *layer,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
/* the undo call goes here */
|
2000-12-14 21:52:16 +08:00
|
|
|
undo_push_layer_displace (GIMP_DRAWABLE (layer)->gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the affected region */
|
2000-12-14 21:52:16 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer), 0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
/* invalidate the selection boundary because of a layer modification */
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_invalidate_boundary (layer);
|
2000-10-23 17:05:45 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* update the layer offsets */
|
2000-10-23 17:05:45 +08:00
|
|
|
GIMP_DRAWABLE (layer)->offset_x += off_x;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y += off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the affected region */
|
2000-10-23 17:05:45 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (layer->mask)
|
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_x += off_x;
|
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_y += off_y;
|
1999-02-07 23:16:45 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
/* invalidate the mask preview */
|
|
|
|
gimp_drawable_invalidate_preview (GIMP_DRAWABLE (layer->mask),
|
|
|
|
FALSE);
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_add_alpha (GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
TileManager *new_tiles;
|
|
|
|
GimpImageType type;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Don't bother if the layer already has alpha */
|
2000-12-14 21:52:16 +08:00
|
|
|
switch (GIMP_DRAWABLE (layer)->type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
case RGB_GIMAGE:
|
|
|
|
type = RGBA_GIMAGE;
|
|
|
|
break;
|
|
|
|
case GRAY_GIMAGE:
|
|
|
|
type = GRAYA_GIMAGE;
|
|
|
|
break;
|
|
|
|
case INDEXED_GIMAGE:
|
|
|
|
type = INDEXEDA_GIMAGE;
|
|
|
|
break;
|
|
|
|
case RGBA_GIMAGE:
|
|
|
|
case GRAYA_GIMAGE:
|
|
|
|
case INDEXEDA_GIMAGE:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the pixel regions */
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Allocate the new layer, configure dest region */
|
2000-12-14 21:52:16 +08:00
|
|
|
new_tiles = tile_manager_new (GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
|
|
|
GIMP_DRAWABLE (layer)->bytes + 1);
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Add an alpha channel */
|
|
|
|
add_alpha_region (&srcPR, &destPR);
|
|
|
|
|
|
|
|
/* Push the layer on the undo stack */
|
2000-12-14 21:52:16 +08:00
|
|
|
undo_push_layer_mod (GIMP_DRAWABLE (layer)->gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the new layer */
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->tiles = new_tiles;
|
|
|
|
GIMP_DRAWABLE (layer)->type = type;
|
|
|
|
GIMP_DRAWABLE (layer)->bytes = GIMP_DRAWABLE(layer)->bytes + 1;
|
|
|
|
GIMP_DRAWABLE (layer)->has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (type);
|
|
|
|
GIMP_DRAWABLE (layer)->preview_valid = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
gtk_signal_emit_by_name
|
|
|
|
(GTK_OBJECT (gimp_drawable_gimage (GIMP_DRAWABLE (layer))), "restructure");
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-02-27 02:46:08 +08:00
|
|
|
static void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_scale_lowlevel (GimpLayer *layer,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
PixelRegion srcPR, destPR;
|
1997-11-25 06:05:25 +08:00
|
|
|
TileManager *new_tiles;
|
|
|
|
|
|
|
|
/* Update the old layer position */
|
2000-12-14 21:52:16 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
1999-08-22 19:45:31 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the pixel regions */
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE(layer)->tiles,
|
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Allocate the new layer, configure dest region */
|
2000-10-23 17:05:45 +08:00
|
|
|
new_tiles = tile_manager_new (new_width, new_height,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->bytes);
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
0, 0,
|
|
|
|
new_width, new_height,
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Scale the layer -
|
|
|
|
* If the layer is of type INDEXED, then we don't use pixel-value
|
|
|
|
* resampling because that doesn't necessarily make sense for INDEXED
|
|
|
|
* images.
|
|
|
|
*/
|
2000-12-14 21:52:16 +08:00
|
|
|
if ((GIMP_DRAWABLE (layer)->type == INDEXED_GIMAGE) ||
|
|
|
|
(GIMP_DRAWABLE (layer)->type == INDEXEDA_GIMAGE))
|
1997-11-25 06:05:25 +08:00
|
|
|
scale_region_no_resample (&srcPR, &destPR);
|
|
|
|
else
|
|
|
|
scale_region (&srcPR, &destPR);
|
|
|
|
|
|
|
|
/* Push the layer on the undo stack */
|
2000-12-14 21:52:16 +08:00
|
|
|
undo_push_layer_mod (GIMP_DRAWABLE (layer)->gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the new layer */
|
|
|
|
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->offset_x = new_offset_x;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y = new_offset_y;
|
|
|
|
GIMP_DRAWABLE (layer)->tiles = new_tiles;
|
|
|
|
GIMP_DRAWABLE (layer)->width = new_width;
|
|
|
|
GIMP_DRAWABLE (layer)->height = new_height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
/* If there is a layer mask, make sure it gets scaled also */
|
|
|
|
if (layer->mask)
|
|
|
|
{
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
channel_scale (GIMP_CHANNEL (layer->mask), new_width, new_height);
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
2000-07-19 06:48:14 +08:00
|
|
|
|
|
|
|
/* Make sure we're not caching any old selection info */
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_invalidate_boundary (layer);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Update the new layer position */
|
2000-02-27 02:46:08 +08:00
|
|
|
|
2000-12-14 21:52:16 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
1999-08-22 19:45:31 +08:00
|
|
|
0, 0,
|
2000-12-14 21:52:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-02-27 02:46:08 +08:00
|
|
|
/**
|
2001-01-29 00:44:22 +08:00
|
|
|
* gimp_layer_check_scaling:
|
2000-02-27 02:46:08 +08:00
|
|
|
* @layer: Layer to check
|
|
|
|
* @new_width: proposed width of layer, in pixels
|
|
|
|
* @new_height: proposed height of layer, in pixels
|
2000-02-27 20:09:29 +08:00
|
|
|
*
|
2000-02-27 02:46:08 +08:00
|
|
|
* Scales layer dimensions, then snaps them to pixel centers
|
2000-02-27 20:09:29 +08:00
|
|
|
*
|
2000-02-27 02:46:08 +08:00
|
|
|
* Returns FALSE if any dimension reduces to zero as a result
|
2000-02-27 20:09:29 +08:00
|
|
|
* of this; otherwise, returns TRUE.
|
2000-02-27 02:46:08 +08:00
|
|
|
*/
|
2001-01-29 00:44:22 +08:00
|
|
|
gboolean
|
|
|
|
gimp_layer_check_scaling (GimpLayer *layer,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height)
|
2000-02-27 02:46:08 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
gdouble img_scale_w;
|
|
|
|
gdouble img_scale_h;
|
|
|
|
gint new_layer_width;
|
|
|
|
gint new_layer_height;
|
|
|
|
|
|
|
|
gimage = GIMP_DRAWABLE (layer)->gimage;
|
|
|
|
img_scale_w = (gdouble) new_width / (gdouble) gimage->width;
|
|
|
|
img_scale_h = (gdouble) new_height / (gdouble) gimage->height;
|
|
|
|
new_layer_width = ROUND (img_scale_w *
|
|
|
|
(gdouble) GIMP_DRAWABLE (layer)->width);
|
|
|
|
new_layer_height = ROUND (img_scale_h *
|
|
|
|
(gdouble) GIMP_DRAWABLE (layer)->height);
|
|
|
|
|
|
|
|
return (new_layer_width != 0 && new_layer_height != 0);
|
2000-02-27 02:46:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-01-29 00:44:22 +08:00
|
|
|
* gimp_layer_scale_by_factors:
|
2000-02-27 02:46:08 +08:00
|
|
|
* @layer: Layer to be transformed by explicit width and height factors.
|
|
|
|
* @w_factor: scale factor to apply to width and horizontal offset
|
|
|
|
* @h_factor: scale factor to apply to height and vertical offset
|
|
|
|
*
|
|
|
|
* Scales layer dimensions and offsets by uniform width and
|
|
|
|
* height factors.
|
|
|
|
*
|
2001-01-29 00:44:22 +08:00
|
|
|
* Use gimp_layer_scale_by_factors() in circumstances when the
|
2000-02-27 02:46:08 +08:00
|
|
|
* same width and height scaling factors are to be uniformly
|
|
|
|
* applied to a set of layers. In this context, the layer's
|
|
|
|
* dimensions and offsets from the sides of the containing
|
|
|
|
* image all change by these predetermined factors. By fiat,
|
|
|
|
* the fixed point of the transform is the upper left hand
|
|
|
|
* corner of the image. Returns gboolean FALSE if a requested
|
|
|
|
* scale factor is zero or if a scaling zero's out a layer
|
|
|
|
* dimension; returns TRUE otherwise.
|
|
|
|
*
|
2001-01-29 00:44:22 +08:00
|
|
|
* Use gimp_layer_scale() in circumstances where new layer width
|
2000-02-27 02:46:08 +08:00
|
|
|
* and height dimensions are predetermined instead.
|
|
|
|
*
|
2000-02-27 20:09:29 +08:00
|
|
|
* Side effects: Undo set created for layer. Old layer imagery
|
|
|
|
* scaled & painted to new layer tiles.
|
2000-02-27 02:46:08 +08:00
|
|
|
*
|
2000-02-27 20:09:29 +08:00
|
|
|
* Returns: TRUE, if the scaled layer has positive dimensions
|
|
|
|
* FALSE if the scaled layer has at least one zero dimension
|
2000-02-27 02:46:08 +08:00
|
|
|
*/
|
|
|
|
gboolean
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_scale_by_factors (GimpLayer *layer,
|
|
|
|
gdouble w_factor,
|
|
|
|
gdouble h_factor)
|
2000-02-27 02:46:08 +08:00
|
|
|
{
|
2000-02-27 20:09:29 +08:00
|
|
|
gint new_width, new_height;
|
|
|
|
gint new_offset_x, new_offset_y;
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2000-02-27 02:46:08 +08:00
|
|
|
if (w_factor == 0.0 || h_factor == 0.0)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
g_message ("gimp_layer_scale_by_factors: Error. Requested width or height scale equals zero.");
|
2000-02-27 02:46:08 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
new_offset_x = ROUND (w_factor * (gdouble) GIMP_DRAWABLE (layer)->offset_x);
|
|
|
|
new_offset_y = ROUND (h_factor * (gdouble) GIMP_DRAWABLE (layer)->offset_y);
|
|
|
|
new_width = ROUND (w_factor * (gdouble) GIMP_DRAWABLE (layer)->width);
|
|
|
|
new_height = ROUND (h_factor * (gdouble) GIMP_DRAWABLE (layer)->height);
|
2000-02-27 02:46:08 +08:00
|
|
|
|
2000-02-27 20:09:29 +08:00
|
|
|
if (new_width != 0 && new_height != 0)
|
2000-02-27 02:46:08 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_scale_lowlevel (layer,
|
|
|
|
new_width, new_height,
|
|
|
|
new_offset_x, new_offset_y);
|
2000-02-27 02:46:08 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
return FALSE;
|
2000-02-27 02:46:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-01-29 00:44:22 +08:00
|
|
|
* gimp_layer_scale:
|
2000-05-13 01:07:54 +08:00
|
|
|
* @layer: The layer to be transformed by width & height scale factors
|
2000-02-27 02:46:08 +08:00
|
|
|
* @new_width: The width that layer will acquire
|
|
|
|
* @new_height: The height that the layer will acquire
|
|
|
|
* @local_origin: sets fixed point of the scaling transform. See below.
|
|
|
|
*
|
|
|
|
* Sets layer dimensions to new_width and
|
|
|
|
* new_height. Derives vertical and horizontal scaling
|
|
|
|
* transforms from new width and height. If local_origin is
|
|
|
|
* TRUE, the fixed point of the scaling transform coincides
|
|
|
|
* with the layer's center point. Otherwise, the fixed
|
|
|
|
* point is taken to be [-GIMP_DRAWABLE(layer)->offset_x,
|
|
|
|
* -GIMP_DRAWABLE(layer)->offset_y].
|
|
|
|
*
|
|
|
|
* Since this function derives scale factors from new and
|
|
|
|
* current layer dimensions, these factors will vary from
|
|
|
|
* layer to layer because of aliasing artifacts; factor
|
|
|
|
* variations among layers can be quite large where layer
|
|
|
|
* dimensions approach pixel dimensions. Use
|
2001-01-29 00:44:22 +08:00
|
|
|
* gimp_layer_scale_by_factors() where constant scales are to
|
2000-02-27 02:46:08 +08:00
|
|
|
* be uniformly applied to a number of layers.
|
|
|
|
*
|
|
|
|
* Side effects: undo set created for layer.
|
|
|
|
* Old layer imagery scaled
|
|
|
|
* & painted to new layer tiles
|
|
|
|
*/
|
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_scale (GimpLayer *layer,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gboolean local_origin)
|
2000-02-27 02:46:08 +08:00
|
|
|
{
|
|
|
|
gint new_offset_x, new_offset_y;
|
|
|
|
|
|
|
|
if (new_width == 0 || new_height == 0)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
g_message ("gimp_layer_scale: Error. Requested width or height equals zero.");
|
2000-02-27 02:46:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2000-02-27 02:46:08 +08:00
|
|
|
if (local_origin)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
new_offset_x = GIMP_DRAWABLE (layer)->offset_x +
|
|
|
|
((GIMP_DRAWABLE (layer)->width - new_width) / 2.0);
|
|
|
|
|
|
|
|
new_offset_y = GIMP_DRAWABLE (layer)->offset_y +
|
|
|
|
((GIMP_DRAWABLE (layer)->height - new_height) / 2.0);
|
2000-02-27 02:46:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
new_offset_x = (gint) (((gdouble) new_width *
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x /
|
|
|
|
(gdouble) GIMP_DRAWABLE (layer)->width));
|
|
|
|
|
|
|
|
new_offset_y = (gint) (((gdouble) new_height *
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y /
|
|
|
|
(gdouble) GIMP_DRAWABLE (layer)->height));
|
2000-02-27 02:46:08 +08:00
|
|
|
}
|
2001-01-29 00:44:22 +08:00
|
|
|
|
|
|
|
gimp_layer_scale_lowlevel (layer,
|
|
|
|
new_width, new_height,
|
|
|
|
new_offset_x, new_offset_y);
|
2000-02-27 02:46:08 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_resize (GimpLayer *layer,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offx,
|
|
|
|
gint offy)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
PixelRegion srcPR, destPR;
|
1997-11-25 06:05:25 +08:00
|
|
|
TileManager *new_tiles;
|
2001-01-29 00:44:22 +08:00
|
|
|
gint w, h;
|
|
|
|
gint x1, y1, x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (new_width < 1 || new_height < 1)
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1998-06-29 08:24:44 +08:00
|
|
|
x1 = CLAMP (offx, 0, new_width);
|
|
|
|
y1 = CLAMP (offy, 0, new_height);
|
2000-12-04 02:15:08 +08:00
|
|
|
x2 = CLAMP ((offx + GIMP_DRAWABLE(layer)->width), 0, new_width);
|
1998-06-29 08:24:44 +08:00
|
|
|
y2 = CLAMP ((offy + GIMP_DRAWABLE(layer)->height), 0, new_height);
|
1997-11-25 06:05:25 +08:00
|
|
|
w = x2 - x1;
|
|
|
|
h = y2 - y1;
|
|
|
|
|
|
|
|
if (offx > 0)
|
|
|
|
{
|
|
|
|
x1 = 0;
|
|
|
|
x2 = offx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = -offx;
|
|
|
|
x2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offy > 0)
|
|
|
|
{
|
|
|
|
y1 = 0;
|
|
|
|
y2 = offy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y1 = -offy;
|
|
|
|
y2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the old layer position */
|
2001-01-29 00:44:22 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE( layer),
|
1999-08-22 19:45:31 +08:00
|
|
|
0, 0,
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the pixel regions */
|
2001-01-29 00:44:22 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
x1, y1,
|
|
|
|
w, h,
|
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Allocate the new layer, configure dest region */
|
2000-12-04 02:15:08 +08:00
|
|
|
new_tiles = tile_manager_new (new_width, new_height,
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (layer)->bytes);
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
0, 0,
|
|
|
|
new_width, new_height,
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* fill with the fill color */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_has_alpha (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* Set to transparent and black */
|
2001-01-29 00:44:22 +08:00
|
|
|
guchar bg[4] = {0, 0, 0, 0};
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
color_region (&destPR, bg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
guchar bg[3];
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_get_background (GIMP_DRAWABLE (layer)->gimage,
|
|
|
|
GIMP_DRAWABLE (layer), bg);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_region (&destPR, bg);
|
|
|
|
}
|
2001-01-29 00:44:22 +08:00
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
pixel_region_init (&destPR, new_tiles,
|
|
|
|
x2, y2,
|
|
|
|
w, h,
|
|
|
|
TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* copy from the old to the new */
|
|
|
|
if (w && h)
|
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
|
|
|
|
/* Push the layer on the undo stack */
|
1998-06-29 08:24:44 +08:00
|
|
|
undo_push_layer_mod (GIMP_DRAWABLE(layer)->gimage, layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the new layer */
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (layer)->tiles = new_tiles;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_x = x1 + GIMP_DRAWABLE (layer)->offset_x - x2;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y = y1 + GIMP_DRAWABLE (layer)->offset_y - y2;
|
|
|
|
GIMP_DRAWABLE (layer)->width = new_width;
|
|
|
|
GIMP_DRAWABLE (layer)->height = new_height;
|
1998-01-22 15:02:57 +08:00
|
|
|
|
|
|
|
/* If there is a layer mask, make sure it gets resized also */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (layer->mask)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_x = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
GIMP_DRAWABLE (layer->mask)->offset_y = GIMP_DRAWABLE (layer)->offset_y;
|
1999-08-22 19:45:31 +08:00
|
|
|
channel_resize (GIMP_CHANNEL (layer->mask),
|
|
|
|
new_width, new_height, offx, offy);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-07-19 06:48:14 +08:00
|
|
|
/* Make sure we're not caching any old selection info */
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_invalidate_boundary (layer);
|
2000-07-19 06:48:14 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* update the new layer area */
|
2001-01-29 00:44:22 +08:00
|
|
|
drawable_update (GIMP_DRAWABLE (layer),
|
1999-08-22 19:45:31 +08:00
|
|
|
0, 0,
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (layer)->width, GIMP_DRAWABLE (layer)->height);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-11-27 22:00:26 +08:00
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_resize_to_image (GimpLayer *layer)
|
1999-11-27 22:00:26 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
1999-11-27 22:00:26 +08:00
|
|
|
|
|
|
|
if (!(gimage = GIMP_DRAWABLE (layer)->gimage))
|
|
|
|
return;
|
|
|
|
|
|
|
|
undo_push_group_start (gimage, LAYER_RESIZE_UNDO);
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1999-11-27 22:00:26 +08:00
|
|
|
floating_sel_relax (layer, TRUE);
|
|
|
|
|
|
|
|
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &offset_x, &offset_y);
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_resize (layer, gimage->width, gimage->height, offset_x, offset_y);
|
1999-11-27 22:00:26 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1999-11-27 22:00:26 +08:00
|
|
|
floating_sel_rigor (layer, TRUE);
|
|
|
|
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
BoundSeg *
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_boundary (GimpLayer *layer,
|
|
|
|
gint *num_segs)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
BoundSeg *new_segs;
|
|
|
|
|
|
|
|
/* Create the four boundary segments that encompass this
|
|
|
|
* layer's boundary.
|
|
|
|
*/
|
2001-01-29 00:44:22 +08:00
|
|
|
new_segs = g_new (BoundSeg, 4);
|
1997-11-25 06:05:25 +08:00
|
|
|
*num_segs = 4;
|
|
|
|
|
|
|
|
/* if the layer is a floating selection */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (GIMP_IS_CHANNEL (layer->fs.drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
/* if the owner drawable is a channel, just return nothing */
|
|
|
|
|
|
|
|
g_free (new_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
*num_segs = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
2001-01-29 00:44:22 +08:00
|
|
|
{
|
|
|
|
/* otherwise, set the layer to the owner drawable */
|
|
|
|
|
|
|
|
layer = GIMP_LAYER (layer->fs.drawable);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
new_segs[0].x1 = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
new_segs[0].y1 = GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
new_segs[0].x2 = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
new_segs[0].y2 = GIMP_DRAWABLE (layer)->offset_y + GIMP_DRAWABLE (layer)->height;
|
1997-11-25 06:05:25 +08:00
|
|
|
new_segs[0].open = 1;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
new_segs[1].x1 = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
new_segs[1].y1 = GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
new_segs[1].x2 = GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width;
|
|
|
|
new_segs[1].y2 = GIMP_DRAWABLE (layer)->offset_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
new_segs[1].open = 1;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
new_segs[2].x1 = GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width;
|
|
|
|
new_segs[2].y1 = GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
new_segs[2].x2 = GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width;
|
|
|
|
new_segs[2].y2 = GIMP_DRAWABLE (layer)->offset_y + GIMP_DRAWABLE (layer)->height;
|
1997-11-25 06:05:25 +08:00
|
|
|
new_segs[2].open = 0;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
new_segs[3].x1 = GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
new_segs[3].y1 = GIMP_DRAWABLE (layer)->offset_y + GIMP_DRAWABLE (layer)->height;
|
|
|
|
new_segs[3].x2 = GIMP_DRAWABLE (layer)->offset_x + GIMP_DRAWABLE (layer)->width;
|
|
|
|
new_segs[3].y2 = GIMP_DRAWABLE (layer)->offset_y + GIMP_DRAWABLE (layer)->height;
|
1997-11-25 06:05:25 +08:00
|
|
|
new_segs[3].open = 0;
|
|
|
|
|
|
|
|
return new_segs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_invalidate_boundary (GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
Channel *mask;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* first get the selection mask channel */
|
2001-01-15 05:11:52 +08:00
|
|
|
if (! (gimage = gimp_drawable_gimage (GIMP_DRAWABLE (layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Turn the current selection off */
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_selection_visibility (gimage, SelectionOff);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-02-09 03:22:46 +08:00
|
|
|
/* clear the affected region surrounding the layer */
|
|
|
|
gdisplays_selection_visibility (gimage, SelectionLayerOff);
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
mask = gimp_image_get_mask (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Only bother with the bounds if there is a selection */
|
|
|
|
if (! channel_is_empty (mask))
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
mask->bounds_known = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
mask->boundary_known = FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
|
|
|
floating_sel_invalidate (layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gint
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_pick_correlate (GimpLayer *layer,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
Tile *tile;
|
|
|
|
Tile *mask_tile;
|
2001-01-29 00:44:22 +08:00
|
|
|
gint val;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Is the point inside the layer?
|
|
|
|
* First transform the point to layer coordinates...
|
|
|
|
*/
|
2001-01-29 00:44:22 +08:00
|
|
|
x -= GIMP_DRAWABLE (layer)->offset_x;
|
|
|
|
y -= GIMP_DRAWABLE (layer)->offset_y;
|
|
|
|
|
|
|
|
if (x >= 0 && x < GIMP_DRAWABLE (layer)->width &&
|
|
|
|
y >= 0 && y < GIMP_DRAWABLE (layer)->height &&
|
|
|
|
GIMP_DRAWABLE (layer)->visible)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* If the point is inside, and the layer has no
|
|
|
|
* alpha channel, success!
|
|
|
|
*/
|
2001-01-29 00:44:22 +08:00
|
|
|
if (! gimp_layer_has_alpha (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Otherwise, determine if the alpha value at
|
|
|
|
* the given point is non-zero
|
|
|
|
*/
|
2000-12-04 02:15:08 +08:00
|
|
|
tile = tile_manager_get_tile (GIMP_DRAWABLE(layer)->tiles,
|
|
|
|
x, y, TRUE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
val = * ((guchar *) tile_data_pointer (tile,
|
|
|
|
x % TILE_WIDTH,
|
|
|
|
y % TILE_HEIGHT) +
|
|
|
|
tile_bpp (tile) - 1);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (layer->mask)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
guchar *ptr;
|
|
|
|
|
2000-12-04 02:15:08 +08:00
|
|
|
mask_tile = tile_manager_get_tile (GIMP_DRAWABLE(layer->mask)->tiles,
|
|
|
|
x, y, TRUE, FALSE);
|
1998-08-12 01:35:34 +08:00
|
|
|
ptr = tile_data_pointer (mask_tile, x % TILE_WIDTH, y % TILE_HEIGHT);
|
|
|
|
val = val * (*ptr) / 255;
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (mask_tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_release (tile, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (val > 63)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
/**********************/
|
|
|
|
/* access functions */
|
|
|
|
/**********************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpLayerMask *
|
|
|
|
gimp_layer_get_mask (GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
return layer->mask;
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gboolean
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_has_alpha (GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-14 21:52:16 +08:00
|
|
|
g_return_val_if_fail (layer != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
2000-12-14 02:53:35 +08:00
|
|
|
|
|
|
|
return GIMP_IMAGE_TYPE_HAS_ALPHA (GIMP_DRAWABLE (layer)->type);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gboolean
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_is_floating_sel (GimpLayer *layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
g_return_val_if_fail (layer != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
|
|
|
|
|
|
|
return (layer->fs.drawable != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gboolean
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_linked (GimpLayer *layer)
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
|
|
|
return layer->linked;
|
|
|
|
}
|
|
|
|
|
2000-12-15 23:54:17 +08:00
|
|
|
TempBuf *
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_preview (GimpLayer *layer,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2000-12-17 06:02:10 +08:00
|
|
|
{
|
|
|
|
/* Ok prime the cache with a large preview if the cache is invalid */
|
|
|
|
if (! GIMP_DRAWABLE (layer)->preview_valid &&
|
|
|
|
width <= PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
height <= PREVIEW_CACHE_PRIME_HEIGHT &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage->width > PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage->height > PREVIEW_CACHE_PRIME_HEIGHT)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
TempBuf * tb = gimp_layer_preview_private (layer,
|
|
|
|
PREVIEW_CACHE_PRIME_WIDTH,
|
|
|
|
PREVIEW_CACHE_PRIME_HEIGHT);
|
2000-12-17 06:02:10 +08:00
|
|
|
|
|
|
|
/* Save the 2nd call */
|
|
|
|
if (width == PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
height == PREVIEW_CACHE_PRIME_HEIGHT)
|
|
|
|
return tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second call - should NOT visit the tile cache...*/
|
2001-01-29 00:44:22 +08:00
|
|
|
return gimp_layer_preview_private (layer, width, height);
|
2000-12-17 06:02:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static TempBuf *
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_preview_private (GimpLayer *layer,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
GimpImage *gimage;
|
2000-12-04 02:15:08 +08:00
|
|
|
TempBuf *preview_buf;
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
GimpImageBaseType type;
|
|
|
|
gint bytes;
|
|
|
|
gint subsample;
|
|
|
|
TempBuf *ret_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-15 23:54:17 +08:00
|
|
|
g_return_val_if_fail (layer != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
|
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
type = RGB;
|
1997-11-25 06:05:25 +08:00
|
|
|
bytes = 0;
|
|
|
|
|
|
|
|
/* The easy way */
|
2000-12-04 02:15:08 +08:00
|
|
|
if (GIMP_DRAWABLE (layer)->preview_valid &&
|
|
|
|
(ret_buf =
|
2000-12-15 23:54:17 +08:00
|
|
|
gimp_preview_cache_get (&(GIMP_DRAWABLE (layer)->preview_cache),
|
|
|
|
width, height)))
|
1999-06-24 07:01:14 +08:00
|
|
|
return ret_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
/* The hard way */
|
|
|
|
else
|
|
|
|
{
|
2000-12-04 02:15:08 +08:00
|
|
|
gimage = GIMP_DRAWABLE (layer)->gimage;
|
|
|
|
switch (GIMP_DRAWABLE (layer)->type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
case RGB_GIMAGE: case RGBA_GIMAGE:
|
2000-05-13 01:07:54 +08:00
|
|
|
type = RGB;
|
2000-12-15 23:54:17 +08:00
|
|
|
bytes = GIMP_DRAWABLE (layer)->bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
case GRAY_GIMAGE: case GRAYA_GIMAGE:
|
2000-05-13 01:07:54 +08:00
|
|
|
type = GRAY;
|
2000-12-15 23:54:17 +08:00
|
|
|
bytes = GIMP_DRAWABLE (layer)->bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
|
2000-05-13 01:07:54 +08:00
|
|
|
type = INDEXED;
|
2000-12-15 23:54:17 +08:00
|
|
|
bytes = (GIMP_DRAWABLE (layer)->type == INDEXED_GIMAGE) ? 3 : 4;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate 'acceptable' subsample */
|
|
|
|
subsample = 1;
|
1997-12-07 05:53:02 +08:00
|
|
|
/* handle some truncation errors */
|
2000-12-15 23:54:17 +08:00
|
|
|
if (width < 1) width = 1;
|
|
|
|
if (height < 1) height = 1;
|
|
|
|
|
|
|
|
while ((width * (subsample + 1) * 2 < GIMP_DRAWABLE (layer)->width) &&
|
|
|
|
(height * (subsample + 1) * 2 < GIMP_DRAWABLE (layer)->height))
|
1997-11-25 06:05:25 +08:00
|
|
|
subsample = subsample + 1;
|
|
|
|
|
2000-12-14 21:52:16 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-15 23:54:17 +08:00
|
|
|
preview_buf = temp_buf_new (width, height, bytes, 0, 0, NULL);
|
2000-05-13 01:07:54 +08:00
|
|
|
|
|
|
|
destPR.bytes = preview_buf->bytes;
|
2000-12-15 23:54:17 +08:00
|
|
|
destPR.w = width;
|
|
|
|
destPR.h = height;
|
|
|
|
destPR.rowstride = width * destPR.bytes;
|
2000-05-13 01:07:54 +08:00
|
|
|
destPR.data = temp_buf_data (preview_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_preview_scale (type, gimage->cmap, &srcPR, &destPR, subsample);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
if (!GIMP_DRAWABLE (layer)->preview_valid)
|
2000-12-14 21:52:16 +08:00
|
|
|
gimp_preview_cache_invalidate (&(GIMP_DRAWABLE(layer)->preview_cache));
|
2000-05-13 01:07:54 +08:00
|
|
|
|
|
|
|
GIMP_DRAWABLE (layer)->preview_valid = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-04 02:15:08 +08:00
|
|
|
gimp_preview_cache_add (&(GIMP_DRAWABLE (layer)->preview_cache),
|
|
|
|
preview_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-24 07:01:14 +08:00
|
|
|
return preview_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TempBuf *
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_mask_preview (GimpLayer *layer,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2000-12-17 06:02:10 +08:00
|
|
|
{
|
|
|
|
/* Ok prime the cache with a large preview if the cache is invalid */
|
|
|
|
if (! GIMP_DRAWABLE (layer)->preview_valid &&
|
|
|
|
width <= PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
height <= PREVIEW_CACHE_PRIME_HEIGHT &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage->width > PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
GIMP_DRAWABLE (layer)->gimage->height > PREVIEW_CACHE_PRIME_HEIGHT)
|
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
TempBuf * tb = gimp_layer_preview_private (layer,
|
|
|
|
PREVIEW_CACHE_PRIME_WIDTH,
|
|
|
|
PREVIEW_CACHE_PRIME_HEIGHT);
|
2000-12-17 06:02:10 +08:00
|
|
|
|
|
|
|
/* Save the 2nd call */
|
|
|
|
if (width == PREVIEW_CACHE_PRIME_WIDTH &&
|
|
|
|
height == PREVIEW_CACHE_PRIME_HEIGHT)
|
|
|
|
return tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second call - should NOT visit the tile cache...*/
|
2001-01-29 00:44:22 +08:00
|
|
|
return gimp_layer_mask_preview_private (layer, width, height);
|
2000-12-17 06:02:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static TempBuf *
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_mask_preview_private (GimpLayer *layer,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 00:44:22 +08:00
|
|
|
TempBuf *preview_buf;
|
|
|
|
GimpLayerMask *mask;
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
gint subsample;
|
|
|
|
TempBuf *ret_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-15 23:54:17 +08:00
|
|
|
g_return_val_if_fail (layer != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
mask = layer->mask;
|
|
|
|
if (!mask)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The easy way */
|
2001-01-29 00:44:22 +08:00
|
|
|
if (GIMP_DRAWABLE (mask)->preview_valid &&
|
|
|
|
(ret_buf = gimp_preview_cache_get (&(GIMP_DRAWABLE (mask)->preview_cache),
|
2000-12-15 23:54:17 +08:00
|
|
|
width, height)))
|
1999-06-24 07:01:14 +08:00
|
|
|
return ret_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
/* The hard way */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* calculate 'acceptable' subsample */
|
|
|
|
subsample = 1;
|
2000-12-15 23:54:17 +08:00
|
|
|
if (width < 1) width = 1;
|
|
|
|
if (height < 1) height = 1;
|
2001-01-29 00:44:22 +08:00
|
|
|
while ((width * (subsample + 1) * 2 < GIMP_DRAWABLE (layer)->width) &&
|
|
|
|
(height * (subsample + 1) * 2 < GIMP_DRAWABLE (layer)->height))
|
1997-11-25 06:05:25 +08:00
|
|
|
subsample = subsample + 1;
|
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
pixel_region_init (&srcPR, GIMP_DRAWABLE (mask)->tiles,
|
2000-05-13 01:07:54 +08:00
|
|
|
0, 0,
|
2001-01-29 00:44:22 +08:00
|
|
|
GIMP_DRAWABLE (mask)->width,
|
|
|
|
GIMP_DRAWABLE (mask)->height,
|
2000-05-13 01:07:54 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-15 23:54:17 +08:00
|
|
|
preview_buf = temp_buf_new (width, height, 1, 0, 0, NULL);
|
2000-05-13 01:07:54 +08:00
|
|
|
|
|
|
|
destPR.bytes = preview_buf->bytes;
|
2000-12-15 23:54:17 +08:00
|
|
|
destPR.w = width;
|
|
|
|
destPR.h = height;
|
|
|
|
destPR.rowstride = width * destPR.bytes;
|
2000-05-13 01:07:54 +08:00
|
|
|
destPR.data = temp_buf_data (preview_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_preview_scale (GRAY, NULL, &srcPR, &destPR, subsample);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-13 01:07:54 +08:00
|
|
|
if (!GIMP_DRAWABLE (mask)->preview_valid)
|
1999-08-22 19:45:31 +08:00
|
|
|
gimp_preview_cache_invalidate (&(GIMP_DRAWABLE (mask)->preview_cache));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
GIMP_DRAWABLE (mask)->preview_valid = TRUE;
|
|
|
|
gimp_preview_cache_add (&(GIMP_DRAWABLE (mask)->preview_cache),
|
|
|
|
preview_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-24 07:01:14 +08:00
|
|
|
return preview_buf;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-29 00:44:22 +08:00
|
|
|
gimp_layer_preview_scale (GimpImageBaseType type,
|
|
|
|
guchar *cmap,
|
|
|
|
PixelRegion *srcPR,
|
|
|
|
PixelRegion *destPR,
|
|
|
|
gint subsample)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
#define EPSILON 0.000001
|
2000-12-04 02:15:08 +08:00
|
|
|
guchar *src, *s;
|
|
|
|
guchar *dest, *d;
|
2000-05-13 01:07:54 +08:00
|
|
|
gdouble *row, *r;
|
2000-12-04 02:15:08 +08:00
|
|
|
gint destwidth;
|
|
|
|
gint src_row, src_col;
|
|
|
|
gint bytes, b;
|
|
|
|
gint width, height;
|
|
|
|
gint orig_width, orig_height;
|
|
|
|
gdouble x_rat, y_rat;
|
|
|
|
gdouble x_cum, y_cum;
|
|
|
|
gdouble x_last, y_last;
|
|
|
|
gdouble *x_frac, y_frac, tot_frac;
|
|
|
|
gint i, j;
|
|
|
|
gint frac;
|
2000-05-13 01:07:54 +08:00
|
|
|
gboolean advance_dest;
|
2000-12-04 02:15:08 +08:00
|
|
|
guchar rgb[MAX_CHANNELS];
|
2000-05-13 01:07:54 +08:00
|
|
|
|
|
|
|
orig_width = srcPR->w / subsample;
|
1997-11-25 06:05:25 +08:00
|
|
|
orig_height = srcPR->h / subsample;
|
2000-12-04 02:15:08 +08:00
|
|
|
width = destPR->w;
|
|
|
|
height = destPR->h;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Some calculations... */
|
2000-05-13 01:07:54 +08:00
|
|
|
bytes = destPR->bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
destwidth = destPR->rowstride;
|
|
|
|
|
|
|
|
/* the data pointers... */
|
2000-05-13 01:07:54 +08:00
|
|
|
src = g_new (guchar, orig_width * bytes);
|
1997-11-25 06:05:25 +08:00
|
|
|
dest = destPR->data;
|
|
|
|
|
|
|
|
/* find the ratios of old x to new x and old y to new y */
|
2000-05-13 01:07:54 +08:00
|
|
|
x_rat = (gdouble) orig_width / (gdouble) width;
|
|
|
|
y_rat = (gdouble) orig_height / (gdouble) height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate an array to help with the calculations */
|
2000-05-13 01:07:54 +08:00
|
|
|
row = g_new (gdouble, width * bytes);
|
|
|
|
x_frac = g_new (gdouble, width + orig_width);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* initialize the pre-calculated pixel fraction array */
|
|
|
|
src_col = 0;
|
2000-05-13 01:07:54 +08:00
|
|
|
x_cum = (gdouble) src_col;
|
1997-11-25 06:05:25 +08:00
|
|
|
x_last = x_cum;
|
|
|
|
|
|
|
|
for (i = 0; i < width + orig_width; i++)
|
|
|
|
{
|
|
|
|
if (x_cum + x_rat <= (src_col + 1 + EPSILON))
|
|
|
|
{
|
|
|
|
x_cum += x_rat;
|
|
|
|
x_frac[i] = x_cum - x_last;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_col ++;
|
|
|
|
x_frac[i] = src_col - x_last;
|
|
|
|
}
|
|
|
|
x_last += x_frac[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the "row" array */
|
2000-05-13 01:07:54 +08:00
|
|
|
memset (row, 0, sizeof (gdouble) * width * bytes);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* counters... */
|
|
|
|
src_row = 0;
|
|
|
|
y_cum = (double) src_row;
|
|
|
|
y_last = y_cum;
|
|
|
|
|
2000-12-04 02:15:08 +08:00
|
|
|
pixel_region_get_row (srcPR,
|
|
|
|
0,
|
|
|
|
src_row * subsample,
|
|
|
|
orig_width * subsample,
|
|
|
|
src,
|
|
|
|
subsample);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Scale the selected region */
|
|
|
|
for (i = 0; i < height; )
|
|
|
|
{
|
|
|
|
src_col = 0;
|
2000-05-13 01:07:54 +08:00
|
|
|
x_cum = (gdouble) src_col;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* determine the fraction of the src pixel we are using for y */
|
|
|
|
if (y_cum + y_rat <= (src_row + 1 + EPSILON))
|
|
|
|
{
|
|
|
|
y_cum += y_rat;
|
|
|
|
y_frac = y_cum - y_last;
|
|
|
|
advance_dest = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_row ++;
|
|
|
|
y_frac = src_row - y_last;
|
|
|
|
advance_dest = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
y_last += y_frac;
|
|
|
|
|
|
|
|
s = src;
|
|
|
|
r = row;
|
|
|
|
|
|
|
|
frac = 0;
|
|
|
|
j = width;
|
|
|
|
|
|
|
|
while (j)
|
|
|
|
{
|
|
|
|
tot_frac = x_frac[frac++] * y_frac;
|
|
|
|
|
|
|
|
/* If indexed, transform the color to RGB */
|
2000-05-13 01:07:54 +08:00
|
|
|
if (type == INDEXED)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
map_to_color (2, cmap, s, rgb);
|
|
|
|
|
|
|
|
r[RED_PIX] += rgb[RED_PIX] * tot_frac;
|
|
|
|
r[GREEN_PIX] += rgb[GREEN_PIX] * tot_frac;
|
|
|
|
r[BLUE_PIX] += rgb[BLUE_PIX] * tot_frac;
|
|
|
|
if (bytes == 4)
|
|
|
|
r[ALPHA_PIX] += s[ALPHA_I_PIX] * tot_frac;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (b = 0; b < bytes; b++)
|
|
|
|
r[b] += s[b] * tot_frac;
|
|
|
|
|
|
|
|
/* increment the destination */
|
|
|
|
if (x_cum + x_rat <= (src_col + 1 + EPSILON))
|
|
|
|
{
|
|
|
|
r += bytes;
|
|
|
|
x_cum += x_rat;
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* increment the source */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s += srcPR->bytes;
|
|
|
|
src_col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (advance_dest)
|
|
|
|
{
|
|
|
|
tot_frac = 1.0 / (x_rat * y_rat);
|
|
|
|
|
|
|
|
/* copy "row" to "dest" */
|
|
|
|
d = dest;
|
|
|
|
r = row;
|
|
|
|
|
|
|
|
j = width;
|
|
|
|
while (j--)
|
|
|
|
{
|
|
|
|
b = bytes;
|
|
|
|
while (b--)
|
2000-05-13 01:07:54 +08:00
|
|
|
*d++ = (guchar) ((*r++ * tot_frac)+0.5);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dest += destwidth;
|
|
|
|
|
|
|
|
/* clear the "row" array */
|
2000-05-13 01:07:54 +08:00
|
|
|
memset (row, 0, sizeof (gdouble) * destwidth);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
2000-12-04 02:15:08 +08:00
|
|
|
pixel_region_get_row (srcPR,
|
|
|
|
0,
|
|
|
|
src_row * subsample,
|
|
|
|
orig_width * subsample,
|
|
|
|
src,
|
|
|
|
subsample);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free up temporary arrays */
|
|
|
|
g_free (row);
|
|
|
|
g_free (x_frac);
|
|
|
|
g_free (src);
|
|
|
|
}
|