gimp/app/core/gimpimage-duplicate.c
Michael Natterer 2fd2a4e6b5 app/channel_ops.c app/channels_dialog.c app/commands.c app/floating_sel.c
2001-02-25  Michael Natterer  <mitch@gimp.org>

	* app/channel_ops.c
	* app/channels_dialog.c
	* app/commands.c
	* app/floating_sel.c
	* app/gdisplay.c
	* app/gimpimage.[ch]
	* app/layer_select.c
	* app/layers_dialog.c
	* app/undo.c
	* app/xcf.c
	* app/tools/move.c: remove direct access of gimage->active_layer and
	gimage->active_channel. Reading access is of course harmless, but
	gimp_image_set_active_blah() will trigger a signal emission soon.

	It will probably be neccessary to change the functions to accept
	NULL layers and channels to acheive exactly what weird places like
	floating_sel.c did before by setting it directly.

	* gimptool-1.4.in
	* libgimp/Makefile.am
	* libgimpcolor/Makefile.am
	* libgimpmath/Makefile.am
	* libgimpwidgets/Makefile.am
	* plug-ins/libgck/gck/Makefile.am: made linking against stable
	GIMP installed in the same prefix work again by renaming all our
	libraries explicitly to libgimp<foo>-1.3.* (not as part of the
	libtool revision but as part of the library name). Removed the
	libtool revision to avoid double versioning. This has to be
	hardcoded in the libraries' Makefile.am ...

	* app/Makefile.am
	* plug-ins/FractalExplorer/Makefile.am
	* plug-ins/Lighting/Makefile.am
	* plug-ins/MapObject/Makefile.am
	* plug-ins/bmp/Makefile.am
	* plug-ins/common/Makefile.am
	* plug-ins/common/mkgen.pl
	* plug-ins/dbbrowser/Makefile.am
	* plug-ins/faxg3/Makefile.am
	* plug-ins/fits/Makefile.am
	* plug-ins/flame/Makefile.am
	* plug-ins/fp/Makefile.am
	* plug-ins/gap/Makefile.am
	* plug-ins/gdyntext/Makefile.am
	* plug-ins/gfig/Makefile.am
	* plug-ins/gflare/Makefile.am
	* plug-ins/gfli/Makefile.am
	* plug-ins/gimpressionist/Makefile.am
	* plug-ins/helpbrowser/Makefile.am
	* plug-ins/ifscompose/Makefile.am
	* plug-ins/imagemap/Makefile.am
	* plug-ins/maze/Makefile.am
	* plug-ins/mosaic/Makefile.am
	* plug-ins/pagecurl/Makefile.am
	* plug-ins/plugin-helper/Makefile.am
	* plug-ins/print/Makefile.am
	* plug-ins/rcm/Makefile.am
	* plug-ins/script-fu/Makefile.am
	* plug-ins/sel2path/Makefile.am
	* plug-ins/sgi/Makefile.am
	* plug-ins/webbrowser/Makefile.am
	* plug-ins/xjt/Makefile.am: ... while all other Makefiles can simply
	link against "libgimp<foo>-$(LT_REVISION).la"
2001-02-25 14:37:12 +00:00

869 lines
24 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "apptypes.h"
#include "apptypes.h"
#include "channel_ops.h"
#include "cursorutil.h"
#include "drawable.h"
#include "floating_sel.h"
#include "gdisplay.h"
#include "gimage.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimplayer.h"
#include "gimplist.h"
#include "paint_funcs.h"
#include "parasitelist.h"
#include "path.h"
#include "pixel_region.h"
#include "tile_manager.h"
#include "libgimp/gimpintl.h"
#define ENTRY_WIDTH 60
typedef struct _OffsetDialog OffsetDialog;
struct _OffsetDialog
{
GtkWidget *dlg;
GtkWidget *off_se;
gboolean wrap_around;
ChannelOffsetType fill_type;
GimpImage *gimage;
};
/* Forward declarations */
static void offset_ok_callback (GtkWidget *widget,
gpointer data);
static void offset_cancel_callback (GtkWidget *widget,
gpointer data);
static void offset_halfheight_callback (GtkWidget *widget,
gpointer data);
void
channel_ops_offset (GimpImage* gimage)
{
OffsetDialog *off_d;
GtkWidget *label;
GtkWidget *check;
GtkWidget *push;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *adjustment;
GtkWidget *spinbutton;
GtkWidget *frame;
GtkWidget *radio_button;
GimpDrawable *drawable;
drawable = gimp_image_active_drawable (gimage);
off_d = g_new (OffsetDialog, 1);
off_d->wrap_around = TRUE;
off_d->fill_type = gimp_drawable_has_alpha (drawable);
off_d->gimage = gimage;
off_d->dlg = gimp_dialog_new (_("Offset"), "offset",
gimp_standard_help_func,
"dialogs/offset.html",
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
_("OK"), offset_ok_callback,
off_d, NULL, NULL, TRUE, FALSE,
_("Cancel"), offset_cancel_callback,
off_d, NULL, NULL, FALSE, TRUE,
NULL);
/* The vbox for first column of options */
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (off_d->dlg)->vbox), vbox);
/* The table for the offsets */
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
/* The offset labels */
label = gtk_label_new (_("Offset X:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
gtk_widget_show (label);
label = gtk_label_new (_("Y:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
gtk_widget_show (label);
/* The offset sizeentry */
adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 1);
spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 2);
gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinbutton),
GTK_SHADOW_NONE);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0);
off_d->off_se = gimp_size_entry_new (1, gimage->unit, "%a",
TRUE, TRUE, FALSE, 75,
GIMP_SIZE_ENTRY_UPDATE_SIZE);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (off_d->off_se),
GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_table_attach_defaults (GTK_TABLE (off_d->off_se), spinbutton,
1, 2, 0, 1);
gtk_widget_show (spinbutton);
gtk_table_attach (GTK_TABLE (table), off_d->off_se, 1, 2, 0, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (off_d->off_se);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (off_d->off_se), GIMP_UNIT_PIXEL);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (off_d->off_se), 0,
gimage->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (off_d->off_se), 1,
gimage->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (off_d->off_se), 0,
-gimage->width, gimage->width);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (off_d->off_se), 1,
-gimage->height, gimage->height);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (off_d->off_se), 0,
0, gimage->width);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (off_d->off_se), 1,
0, gimage->height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (off_d->off_se), 0, 0);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (off_d->off_se), 1, 0);
gtk_widget_show (table);
/* The wrap around option */
check = gtk_check_button_new_with_label (_("Wrap Around"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);
/* The fill options */
frame =
gimp_radio_group_new2 (TRUE, _("Fill Type"),
gimp_radio_button_update,
&off_d->fill_type, (gpointer) off_d->fill_type,
_("Background"), (gpointer) OFFSET_BACKGROUND, NULL,
_("Transparent"), (gpointer) OFFSET_TRANSPARENT,
&radio_button,
NULL);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
if (! gimp_drawable_has_alpha (drawable))
gtk_widget_set_sensitive (radio_button, FALSE);
/* The by half height and half width option */
push = gtk_button_new_with_label (_("Offset by (x/2),(y/2)"));
gtk_container_set_border_width (GTK_CONTAINER (push), 2);
gtk_box_pack_start (GTK_BOX (vbox), push, FALSE, FALSE, 0);
gtk_widget_show (push);
/* Hook up the wrap around */
gtk_signal_connect (GTK_OBJECT (check), "toggled",
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
&off_d->wrap_around);
gtk_object_set_data (GTK_OBJECT (check), "inverse_sensitive", frame);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), off_d->wrap_around);
/* Hook up the by half */
gtk_signal_connect (GTK_OBJECT (push), "clicked",
(GtkSignalFunc) offset_halfheight_callback,
off_d);
gtk_widget_show (vbox);
gtk_widget_show (off_d->dlg);
}
void
offset (GimpImage *gimage,
GimpDrawable *drawable,
gboolean wrap_around,
ChannelOffsetType fill_type,
gint offset_x,
gint offset_y)
{
PixelRegion srcPR, destPR;
TileManager *new_tiles;
gint width, height;
gint src_x, src_y;
gint dest_x, dest_y;
guchar fill[MAX_CHANNELS] = { 0 };
if (! drawable)
return;
width = gimp_drawable_width (drawable);
height = gimp_drawable_height (drawable);
if (wrap_around)
{
/* avoid modulo operation on negative values */
while (offset_x < 0)
offset_x += width;
while (offset_y < 0)
offset_y += height;
offset_x %= width;
offset_y %= height;
}
else
{
offset_x = CLAMP (offset_x, -width, width);
offset_y = CLAMP (offset_y, -height, height);
}
if (offset_x == 0 && offset_y == 0)
return;
new_tiles = tile_manager_new (width, height, gimp_drawable_bytes (drawable));
if (offset_x >= 0)
{
src_x = 0;
dest_x = offset_x;
width = CLAMP ((width - offset_x), 0, width);
}
else
{
src_x = -offset_x;
dest_x = 0;
width = CLAMP ((width + offset_x), 0, width);
}
if (offset_y >= 0)
{
src_y = 0;
dest_y = offset_y;
height = CLAMP ((height - offset_y), 0, height);
}
else
{
src_y = -offset_y;
dest_y = 0;
height = CLAMP ((height + offset_y), 0, height);
}
/* Copy the center region */
if (width && height)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
src_x, src_y, width, height, FALSE);
pixel_region_init (&destPR, new_tiles,
dest_x, dest_y, width, height, TRUE);
copy_region (&srcPR, &destPR);
}
/* Copy appropriately for wrap around */
if (wrap_around == TRUE)
{
if (offset_x >= 0 && offset_y >= 0)
{
src_x = gimp_drawable_width (drawable) - offset_x;
src_y = gimp_drawable_height (drawable) - offset_y;
}
else if (offset_x >= 0 && offset_y < 0)
{
src_x = gimp_drawable_width (drawable) - offset_x;
src_y = 0;
}
else if (offset_x < 0 && offset_y >= 0)
{
src_x = 0;
src_y = gimp_drawable_height (drawable) - offset_y;
}
else if (offset_x < 0 && offset_y < 0)
{
src_x = 0;
src_y = 0;
}
dest_x = (src_x + offset_x) % gimp_drawable_width (drawable);
if (dest_x < 0)
dest_x = gimp_drawable_width (drawable) + dest_x;
dest_y = (src_y + offset_y) % gimp_drawable_height (drawable);
if (dest_y < 0)
dest_y = gimp_drawable_height (drawable) + dest_y;
/* intersecting region */
if (offset_x != 0 && offset_y != 0)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
src_x, src_y, ABS (offset_x), ABS (offset_y)
, FALSE);
pixel_region_init (&destPR, new_tiles,
dest_x, dest_y, ABS (offset_x), ABS (offset_y),
TRUE);
copy_region (&srcPR, &destPR);
}
/* X offset */
if (offset_x != 0)
{
if (offset_y >= 0)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
src_x, 0, ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
FALSE);
pixel_region_init (&destPR, new_tiles,
dest_x, dest_y + offset_y,
ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
TRUE);
}
else if (offset_y < 0)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
src_x, src_y - offset_y,
ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
FALSE);
pixel_region_init (&destPR, new_tiles,
dest_x, 0,
ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
TRUE);
}
copy_region (&srcPR, &destPR);
}
/* X offset */
if (offset_y != 0)
{
if (offset_x >= 0)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
0, src_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y), FALSE);
pixel_region_init (&destPR, new_tiles, dest_x + offset_x, dest_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y), TRUE);
}
else if (offset_x < 0)
{
pixel_region_init (&srcPR, gimp_drawable_data (drawable),
src_x - offset_x, src_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y), FALSE);
pixel_region_init (&destPR, new_tiles, 0, dest_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y), TRUE);
}
copy_region (&srcPR, &destPR);
}
}
/* Otherwise, fill the vacated regions */
else
{
if (fill_type == OFFSET_BACKGROUND)
{
GimpRGB color;
gimp_context_get_background (NULL, &color);
gimp_rgb_get_uchar (&color, &fill[0], &fill[1], &fill[2]);
if (gimp_drawable_has_alpha (drawable))
fill[gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
}
if (offset_x >= 0 && offset_y >= 0)
{
dest_x = 0;
dest_y = 0;
}
else if (offset_x >= 0 && offset_y < 0)
{
dest_x = 0;
dest_y = gimp_drawable_height (drawable) + offset_y;
}
else if (offset_x < 0 && offset_y >= 0)
{
dest_x = gimp_drawable_width (drawable) + offset_x;
dest_y = 0;
}
else if (offset_x < 0 && offset_y < 0)
{
dest_x = gimp_drawable_width (drawable) + offset_x;
dest_y = gimp_drawable_height (drawable) + offset_y;
}
/* intersecting region */
if (offset_x != 0 && offset_y != 0)
{
pixel_region_init (&destPR, new_tiles, dest_x, dest_y,
ABS (offset_x), ABS (offset_y), TRUE);
color_region (&destPR, fill);
}
/* X offset */
if (offset_x != 0)
{
if (offset_y >= 0)
pixel_region_init (&destPR, new_tiles,
dest_x, dest_y + offset_y,
ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
TRUE);
else if (offset_y < 0)
pixel_region_init (&destPR, new_tiles,
dest_x, 0,
ABS (offset_x),
gimp_drawable_height (drawable) - ABS (offset_y),
TRUE);
color_region (&destPR, fill);
}
/* X offset */
if (offset_y != 0)
{
if (offset_x >= 0)
pixel_region_init (&destPR, new_tiles,
dest_x + offset_x,
dest_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y),
TRUE);
else if (offset_x < 0)
pixel_region_init (&destPR, new_tiles,
0, dest_y,
gimp_drawable_width (drawable) - ABS (offset_x),
ABS (offset_y),
TRUE);
color_region (&destPR, fill);
}
}
/* push an undo */
drawable_apply_image (drawable,
0, 0,
gimp_drawable_width (drawable),
gimp_drawable_height (drawable),
gimp_drawable_data (drawable),
FALSE);
/* swap the tiles */
drawable->tiles = new_tiles;
/* update the drawable */
drawable_update (drawable,
0, 0,
gimp_drawable_width (drawable),
gimp_drawable_height (drawable));
}
/*
* Interface callbacks
*/
static void
offset_ok_callback (GtkWidget *widget,
gpointer data)
{
OffsetDialog *off_d;
GImage *gimage;
GimpDrawable *drawable;
gint offset_x;
gint offset_y;
off_d = (OffsetDialog *) data;
if ((gimage = off_d->gimage) != NULL)
{
drawable = gimp_image_active_drawable (gimage);
offset_x = (gint)
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (off_d->off_se), 0));
offset_y = (gint)
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (off_d->off_se), 1));
offset (gimage, drawable, off_d->wrap_around, off_d->fill_type,
offset_x, offset_y);
gdisplays_flush ();
}
gtk_widget_destroy (off_d->dlg);
g_free (off_d);
}
static void
offset_cancel_callback (GtkWidget *widget,
gpointer data)
{
OffsetDialog *off_d;
off_d = (OffsetDialog *) data;
gtk_widget_destroy (off_d->dlg);
g_free (off_d);
}
static void
offset_halfheight_callback (GtkWidget *widget,
gpointer data)
{
OffsetDialog *off_d;
GImage *gimage;
off_d = (OffsetDialog *) data;
gimage = off_d->gimage;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (off_d->off_se),
0, gimage->width / 2);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (off_d->off_se),
1, gimage->height / 2);
}
GimpImage *
duplicate (GimpImage *gimage)
{
PixelRegion srcPR, destPR;
GimpImage *new_gimage;
GimpLayer *layer, *new_layer;
GimpLayer *floating_layer;
GimpChannel *channel, *new_channel;
GList *list;
Guide *guide = NULL;
GimpLayer *active_layer = NULL;
GimpChannel *active_channel = NULL;
GimpDrawable *new_floating_sel_drawable = NULL;
GimpDrawable *floating_sel_drawable = NULL;
ParasiteList *parasites;
PathList *paths;
gint count;
gimp_add_busy_cursors_until_idle ();
/* Create a new image */
new_gimage = gimage_new (gimage->width, gimage->height, gimage->base_type);
gimp_image_undo_disable (new_gimage);
/* Copy resolution and unit information */
new_gimage->xresolution = gimage->xresolution;
new_gimage->yresolution = gimage->yresolution;
new_gimage->unit = gimage->unit;
/* Copy floating layer */
floating_layer = gimp_image_floating_sel (gimage);
if (floating_layer)
{
floating_sel_relax (floating_layer, FALSE);
floating_sel_drawable = floating_layer->fs.drawable;
floating_layer = NULL;
}
/* Copy the layers */
for (list = GIMP_LIST (gimage->layers)->list, count = 0;
list;
list = g_list_next (list), count++)
{
layer = (GimpLayer *) list->data;
new_layer = gimp_layer_copy (layer, FALSE);
gimp_drawable_set_gimage (GIMP_DRAWABLE (new_layer), new_gimage);
/* Make sure the copied layer doesn't say: "<old layer> copy" */
gimp_object_set_name (GIMP_OBJECT (new_layer),
gimp_object_get_name (GIMP_OBJECT (layer)));
/* Make sure if the layer has a layer mask, it's name isn't screwed up */
if (new_layer->mask)
{
gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
gimp_object_get_name (GIMP_OBJECT (layer->mask)));
}
if (gimp_image_get_active_layer (gimage) == layer)
active_layer = new_layer;
if (gimage->floating_sel == layer)
floating_layer = new_layer;
if (floating_sel_drawable == GIMP_DRAWABLE (layer))
new_floating_sel_drawable = GIMP_DRAWABLE (new_layer);
/* Add the layer */
if (floating_layer != new_layer)
gimp_image_add_layer (new_gimage, new_layer, count);
}
/* Copy the channels */
for (list = GIMP_LIST (gimage->channels)->list, count = 0;
list;
list = g_list_next (list), count++)
{
channel = (GimpChannel *) list->data;
new_channel = gimp_channel_copy (channel);
gimp_drawable_set_gimage (GIMP_DRAWABLE (new_channel), new_gimage);
/* Make sure the copied channel doesn't say: "<old channel> copy" */
gimp_object_set_name (GIMP_OBJECT (new_channel),
gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimp_image_get_active_channel (gimage) == channel)
active_channel = (new_channel);
if (floating_sel_drawable == GIMP_DRAWABLE (channel))
new_floating_sel_drawable = GIMP_DRAWABLE (new_channel);
/* Add the channel */
gimp_image_add_channel (new_gimage, new_channel, count);
}
/* Copy the selection mask */
pixel_region_init (&srcPR,
gimp_drawable_data (GIMP_DRAWABLE (gimage->selection_mask)),
0, 0, gimage->width, gimage->height, FALSE);
pixel_region_init (&destPR,
gimp_drawable_data (GIMP_DRAWABLE (new_gimage->selection_mask)),
0, 0, gimage->width, gimage->height, TRUE);
copy_region (&srcPR, &destPR);
new_gimage->selection_mask->bounds_known = FALSE;
new_gimage->selection_mask->boundary_known = FALSE;
/* Set active layer, active channel */
if (active_layer)
gimp_image_set_active_layer (new_gimage, active_layer);
if (active_channel)
gimp_image_set_active_channel (new_gimage, active_channel);
if (floating_layer)
floating_sel_attach (floating_layer, new_floating_sel_drawable);
/* Copy the colormap if necessary */
if (new_gimage->base_type == INDEXED)
memcpy (new_gimage->cmap, gimage->cmap, gimage->num_cols * 3);
new_gimage->num_cols = gimage->num_cols;
/* copy state of all color channels */
for (count = 0; count < MAX_CHANNELS; count++)
{
new_gimage->visible[count] = gimage->visible[count];
new_gimage->active[count] = gimage->active[count];
}
/* Copy any Guides */
for (list = gimage->guides; list; list = g_list_next (list))
{
Guide* new_guide;
guide = (Guide*) list->data;
switch (guide->orientation)
{
case ORIENTATION_HORIZONTAL:
new_guide = gimp_image_add_hguide (new_gimage);
new_guide->position = guide->position;
break;
case ORIENTATION_VERTICAL:
new_guide = gimp_image_add_vguide (new_gimage);
new_guide->position = guide->position;
break;
default:
g_error ("Unknown guide orientation.\n");
}
}
/* Copy the qmask info */
new_gimage->qmask_state = gimage->qmask_state;
new_gimage->qmask_color = gimage->qmask_color;
/* Copy parasites */
parasites = gimage->parasites;
if (parasites)
new_gimage->parasites = parasite_list_copy (parasites);
/* Copy paths */
paths = gimp_image_get_paths (gimage);
if (paths)
{
GSList *plist = NULL;
GSList *new_plist = NULL;
Path *path;
PathList *new_paths;
for (plist = paths->bz_paths; plist; plist = plist->next)
{
path = plist->data;
new_plist = g_slist_append (new_plist, path_copy (new_gimage, path));
}
new_paths = path_list_new (new_gimage, paths->last_selected_row, new_plist);
gimp_image_set_paths (new_gimage, new_paths);
}
gimp_image_undo_enable (new_gimage);
return new_gimage;
}
#ifdef I_LIKE_BOGUS_CRAP
static void
duplicate_projection (GimpImage *oldgimage,
GimpImage *newgimage,
GDisplay *newgdisplay)
{
PixelRegion srcPR, destPR;
/* Copy-on-write the projection tilemanager so we don't have
* to reproject the new gimage - since if we do the duplicate
* operation correctly, the projection for the new gimage is
* identical to that of the source. (Is this true? View-only
* attributes vs. image meta-attributes? -- View-only attributes
* *should* strictly be applied post-projection.)
*/
#if 0
newgimage->construct_flag = oldgimage->construct_flag;
g_warning("CONSTR:%d %dx%dx%d",newgimage->construct_flag,
tile_manager_level_width(gimp_image_projection (newgimage)),
tile_manager_level_height(gimp_image_projection (newgimage)),
tile_manager_level_bpp(gimp_image_projection (newgimage))
);
gdisplay_expose_area(newgdisplay,
newgdisplay->disp_xoffset, newgdisplay->disp_yoffset,
newgdisplay->disp_width, newgdisplay->disp_height);
if (newgimage->construct_flag)
#endif
{
tile_manager_set_user_data(gimp_image_projection (newgimage),
(void *) newgimage);
/*
newgimage->proj_type = oldgimage->proj_type;
newgimage->proj_bytes = oldgimage->proj_bytes;
newgimage->proj_level = oldgimage->proj_level;
gimage_projection_realloc (new_gimage);*/
pixel_region_init (&srcPR, gimp_image_projection (oldgimage), 0, 0,
oldgimage->width, oldgimage->height, FALSE);
pixel_region_init (&destPR, gimp_image_projection (newgimage), 0, 0,
newgimage->width, newgimage->height, TRUE);
copy_region(&srcPR, &destPR);
/*
pixel_region_init (&srcPR, gimp_image_projection (oldgimage),
newgdisplay->disp_xoffset, newgdisplay->disp_yoffset,
newgdisplay->disp_width, newgdisplay->disp_height,
FALSE);
pixel_region_init (&destPR, gimp_image_projection (newgimage),
newgdisplay->disp_xoffset, newgdisplay->disp_yoffset,
newgdisplay->disp_width, newgdisplay->disp_height,
TRUE);
copy_region(&srcPR, &destPR);
*/
if (1)
{
GDisplay* gdisp;
int x,y,w,h;
int x1, y1, x2, y2;
gdisp = newgdisplay;
fprintf (stderr, " [pointers: %p, %p ] ", oldgimage, gdisp->gimage);
gdisplay_untransform_coords (gdisp, 0, 0, &x1, &y1, FALSE, FALSE);
gdisplay_untransform_coords (gdisp, gdisp->disp_width, gdisp->disp_height,
&x2, &y2, FALSE, FALSE);
fprintf(stderr," <%dx%d %dx%d %d,%d->%d,%d> ",
oldgimage->width, oldgimage->height,
newgimage->width, newgimage->height,
x1,y1, x2,y2);
gimage_invalidate_without_render (gdisp->gimage, 0,0,
gdisp->gimage->width,
gdisp->gimage->height,
64,64,128,128);
/* newgdisplay->disp_width,newgdisplay->disp_height,
newgdisplay->disp_width+newgdisplay->disp_xoffset,newgdisplay->disp_height+newgdisplay->disp_yoffset */
x1, y1, x2, y2
);
}
}
}
#endif
void
channel_ops_duplicate (GimpImage *gimage)
{
GDisplay *new_gdisp;
GImage *new_gimage;
new_gimage = duplicate (gimage);
/* We don't want to copy a half-redrawn projection, so force a flush. */
/* gdisplays_finish_draw();
gdisplays_flush_now(); */
new_gdisp = gdisplay_new (new_gimage, 0x0101);
/* duplicate_projection(gimage, new_gimage, new_gdisp);*/
}