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-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile-manager.h"
|
|
|
|
#include "base/tile.h"
|
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "image_map.h"
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
IMAGE_MAP_WAITING,
|
|
|
|
IMAGE_MAP_WORKING
|
|
|
|
} ImageMapState;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
struct _ImageMap
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
GDisplay *gdisp;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
TileManager *undo_tiles;
|
|
|
|
ImageMapApplyFunc apply_func;
|
|
|
|
gpointer user_data;
|
|
|
|
PixelRegion srcPR;
|
|
|
|
PixelRegion destPR;
|
|
|
|
PixelRegionIterator *PRI;
|
|
|
|
ImageMapState state;
|
|
|
|
guint idle_id;
|
2001-05-25 01:09:57 +08:00
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
/* local function prototypes */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
static gboolean image_map_do (gpointer data);
|
2001-05-25 01:09:57 +08:00
|
|
|
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
/* public functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
ImageMap *
|
2000-12-31 12:07:42 +08:00
|
|
|
image_map_create (GDisplay *gdisp,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
ImageMap *image_map;
|
|
|
|
|
|
|
|
g_return_val_if_fail (gdisp != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map = g_new0 (ImageMap, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map->gdisp = gdisp;
|
|
|
|
image_map->drawable = drawable;
|
|
|
|
image_map->undo_tiles = NULL;
|
2001-08-17 22:27:31 +08:00
|
|
|
image_map->apply_func = NULL;
|
|
|
|
image_map->user_data = NULL;
|
|
|
|
image_map->state = IMAGE_MAP_WAITING;
|
|
|
|
image_map->idle_id = 0;
|
2000-08-17 09:33:44 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
/* Interactive tools based on image_map disable the undo stack
|
|
|
|
* to avert any unintented undo interaction through the UI
|
|
|
|
*/
|
|
|
|
gimp_image_undo_freeze (image_map->gdisp->gimage);
|
|
|
|
gdisplay_set_menu_sensitivity (image_map->gdisp);
|
|
|
|
|
|
|
|
return image_map;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_apply (ImageMap *image_map,
|
1997-11-25 06:05:25 +08:00
|
|
|
ImageMapApplyFunc apply_func,
|
2001-05-25 01:09:57 +08:00
|
|
|
gpointer apply_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
2001-01-23 21:01:48 +08:00
|
|
|
gint offset_x, offset_y;
|
|
|
|
gint width, height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
g_return_if_fail (image_map != NULL);
|
|
|
|
g_return_if_fail (apply_func != NULL);
|
|
|
|
|
|
|
|
image_map->apply_func = apply_func;
|
|
|
|
image_map->user_data = apply_data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* If we're still working, remove the timer */
|
2001-08-17 22:27:31 +08:00
|
|
|
if (image_map->state == IMAGE_MAP_WORKING)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
g_source_remove (image_map->idle_id);
|
|
|
|
image_map->idle_id = 0;
|
2001-05-25 01:09:57 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
pixel_regions_process_stop (image_map->PRI);
|
|
|
|
image_map->PRI = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the drawable is still valid */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (! gimp_drawable_gimage (image_map->drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* The application should occur only within selection bounds */
|
2001-05-25 01:09:57 +08:00
|
|
|
gimp_drawable_mask_bounds (image_map->drawable, &x1, &y1, &x2, &y2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* If undo tiles don't exist, or change size, (re)allocate */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (image_map->undo_tiles)
|
2001-01-23 21:01:48 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
|
|
|
|
width = tile_manager_width (image_map->undo_tiles);
|
|
|
|
height = tile_manager_height (image_map->undo_tiles);
|
2001-01-23 21:01:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset_x = offset_y = width = height = 0;
|
|
|
|
}
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
if (! image_map->undo_tiles ||
|
2001-01-23 21:01:48 +08:00
|
|
|
offset_x != x1 || offset_y != y1 ||
|
|
|
|
width != (x2 - x1) || height != (y2 - y1))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
/* If either the extents changed or the tiles don't exist,
|
|
|
|
* allocate new
|
|
|
|
*/
|
|
|
|
if (! image_map->undo_tiles ||
|
2001-01-23 21:01:48 +08:00
|
|
|
width != (x2 - x1) || height != (y2 - y1))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* Destroy old tiles--If they exist */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (image_map->undo_tiles != NULL)
|
|
|
|
tile_manager_destroy (image_map->undo_tiles);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Allocate new tiles */
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map->undo_tiles =
|
2001-01-15 05:11:52 +08:00
|
|
|
tile_manager_new ((x2 - x1), (y2 - y1),
|
2001-05-25 01:09:57 +08:00
|
|
|
gimp_drawable_bytes (image_map->drawable));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy from the image to the new tiles */
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->srcPR,
|
|
|
|
gimp_drawable_data (image_map->drawable),
|
1997-11-25 06:05:25 +08:00
|
|
|
x1, y1, (x2 - x1), (y2 - y1), FALSE);
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->destPR, image_map->undo_tiles,
|
1997-11-25 06:05:25 +08:00
|
|
|
0, 0, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
copy_region (&image_map->srcPR, &image_map->destPR);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Set the offsets */
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_set_offsets (image_map->undo_tiles, x1, y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-05-25 01:09:57 +08:00
|
|
|
else /* image_map->undo_tiles exist AND drawable dimensions have not changed... */
|
2000-08-24 10:11:37 +08:00
|
|
|
{
|
|
|
|
/* Reset to initial drawable conditions. */
|
|
|
|
/* Copy from the backup undo tiles to the drawable */
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->srcPR, image_map->undo_tiles,
|
2001-01-23 21:01:48 +08:00
|
|
|
0, 0, width, height, FALSE);
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->destPR,
|
|
|
|
gimp_drawable_data (image_map->drawable),
|
2001-01-23 21:01:48 +08:00
|
|
|
offset_x, offset_y, width, height, TRUE);
|
2000-08-24 10:11:37 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
copy_region (&image_map->srcPR, &image_map->destPR);
|
2000-08-24 10:11:37 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Configure the src from the drawable data */
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->srcPR, image_map->undo_tiles,
|
1997-11-25 06:05:25 +08:00
|
|
|
0, 0, (x2 - x1), (y2 - y1), FALSE);
|
|
|
|
|
|
|
|
/* Configure the dest as the shadow buffer */
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&image_map->destPR,
|
|
|
|
gimp_drawable_shadow (image_map->drawable),
|
1997-11-25 06:05:25 +08:00
|
|
|
x1, y1, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
|
|
|
|
/* Apply the image transformation to the pixels */
|
2001-08-17 22:27:31 +08:00
|
|
|
image_map->PRI = pixel_regions_register (2,
|
|
|
|
&image_map->srcPR,
|
|
|
|
&image_map->destPR);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Start the intermittant work procedure */
|
2001-08-17 22:27:31 +08:00
|
|
|
image_map->state = IMAGE_MAP_WORKING;
|
|
|
|
image_map->idle_id = g_idle_add (image_map_do, image_map);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_commit (ImageMap *image_map)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-03-09 19:58:03 +08:00
|
|
|
gint x1, y1, x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
g_return_if_fail (image_map != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
if (image_map->state == IMAGE_MAP_WORKING)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
g_source_remove (image_map->idle_id);
|
|
|
|
image_map->idle_id = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Finish the changes */
|
2001-08-17 22:27:31 +08:00
|
|
|
while (image_map_do (image_map));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the drawable is still valid */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (! gimp_drawable_gimage (image_map->drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
2000-08-17 09:33:44 +08:00
|
|
|
/* Interactive phase ends: we can commit an undo frame now */
|
2001-05-25 01:09:57 +08:00
|
|
|
gimp_image_undo_thaw(image_map->gdisp->gimage);
|
2000-08-17 09:33:44 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Register an undo step */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (image_map->undo_tiles)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_get_offsets (image_map->undo_tiles, &x1, &y1);
|
|
|
|
x2 = x1 + tile_manager_width (image_map->undo_tiles);
|
|
|
|
y2 = y1 + tile_manager_height (image_map->undo_tiles);
|
2001-07-08 06:49:01 +08:00
|
|
|
|
|
|
|
gimp_drawable_apply_image (image_map->drawable,
|
|
|
|
x1, y1, x2, y2, image_map->undo_tiles, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
gdisplay_set_menu_sensitivity (image_map->gdisp);
|
|
|
|
g_free (image_map);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_clear (ImageMap *image_map)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
g_return_if_fail (image_map != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
if (image_map->state == IMAGE_MAP_WORKING)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
g_source_remove (image_map->idle_id);
|
|
|
|
image_map->idle_id = 0;
|
|
|
|
|
|
|
|
pixel_regions_process_stop (image_map->PRI);
|
|
|
|
image_map->PRI = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
image_map->state = IMAGE_MAP_WAITING;
|
2001-05-25 01:09:57 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure the drawable is still valid */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (! gimp_drawable_gimage (image_map->drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* restore the original image */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (image_map->undo_tiles)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-23 21:01:48 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_get_offsets (image_map->undo_tiles, &offset_x, &offset_y);
|
|
|
|
width = tile_manager_width (image_map->undo_tiles);
|
|
|
|
height = tile_manager_height (image_map->undo_tiles),
|
2001-01-23 21:01:48 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Copy from the drawable to the tiles */
|
2001-05-25 01:09:57 +08:00
|
|
|
pixel_region_init (&srcPR, image_map->undo_tiles,
|
2001-01-23 21:01:48 +08:00
|
|
|
0, 0, width, height, FALSE);
|
2001-01-15 05:11:52 +08:00
|
|
|
pixel_region_init (&destPR,
|
2001-05-25 01:09:57 +08:00
|
|
|
gimp_drawable_data (image_map->drawable),
|
2001-01-23 21:01:48 +08:00
|
|
|
offset_x, offset_y, width, height, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if the user has changed the image depth get out quickly */
|
|
|
|
if (destPR.bytes != srcPR.bytes)
|
|
|
|
{
|
1999-12-28 22:09:20 +08:00
|
|
|
g_message ("image depth change, unable to restore original image");
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_destroy (image_map->undo_tiles);
|
|
|
|
gimp_image_undo_thaw (image_map->gdisp->gimage);
|
|
|
|
gdisplay_set_menu_sensitivity (image_map->gdisp);
|
|
|
|
g_free (image_map);
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-05-25 01:09:57 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
copy_region (&srcPR, &destPR);
|
|
|
|
|
|
|
|
/* Update the area */
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_update (image_map->drawable,
|
|
|
|
offset_x, offset_y,
|
|
|
|
width, height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Free the undo_tiles tile manager */
|
2001-05-25 01:09:57 +08:00
|
|
|
tile_manager_destroy (image_map->undo_tiles);
|
|
|
|
image_map->undo_tiles = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-05-09 13:43:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-05-09 13:43:29 +08:00
|
|
|
void
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_abort (ImageMap *image_map)
|
2000-05-09 13:43:29 +08:00
|
|
|
{
|
2001-05-25 01:09:57 +08:00
|
|
|
g_return_if_fail (image_map != NULL);
|
2000-08-17 09:33:44 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_clear (image_map);
|
|
|
|
gimp_image_undo_thaw (image_map->gdisp->gimage);
|
|
|
|
gdisplay_set_menu_sensitivity (image_map->gdisp);
|
2000-05-09 13:43:29 +08:00
|
|
|
g_free (image_map);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
guchar *
|
2001-05-25 01:09:57 +08:00
|
|
|
image_map_get_color_at (ImageMap *image_map,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1999-04-08 06:02:26 +08:00
|
|
|
{
|
2001-01-15 05:11:52 +08:00
|
|
|
Tile *tile;
|
|
|
|
guchar *src;
|
|
|
|
guchar *dest;
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
g_return_val_if_fail (image_map != NULL, NULL);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
if (x >= 0 && x < gimp_drawable_width (image_map->drawable) &&
|
|
|
|
y >= 0 && y < gimp_drawable_height (image_map->drawable))
|
2000-02-28 10:40:44 +08:00
|
|
|
{
|
|
|
|
/* Check if done damage to original image */
|
2001-05-25 01:09:57 +08:00
|
|
|
if (! image_map->undo_tiles)
|
|
|
|
return (gimp_drawable_get_color_at (image_map->drawable, x, y));
|
|
|
|
|
|
|
|
if (! image_map ||
|
|
|
|
(! gimp_drawable_gimage (image_map->drawable) &&
|
|
|
|
gimp_drawable_is_indexed (image_map->drawable)) ||
|
|
|
|
x < 0 || y < 0 ||
|
|
|
|
x >= tile_manager_width (image_map->undo_tiles) ||
|
|
|
|
y >= tile_manager_height (image_map->undo_tiles))
|
2000-02-28 10:40:44 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
dest = g_new (guchar, 5);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
tile = tile_manager_get_tile (image_map->undo_tiles, x, y,
|
2000-02-28 10:40:44 +08:00
|
|
|
TRUE, FALSE);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2000-02-28 10:40:44 +08:00
|
|
|
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
gimp_image_get_color (gimp_drawable_gimage (image_map->drawable),
|
|
|
|
gimp_drawable_type (image_map->drawable),
|
2001-01-15 05:11:52 +08:00
|
|
|
dest, src);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2001-05-25 01:09:57 +08:00
|
|
|
if (GIMP_IMAGE_TYPE_HAS_ALPHA (gimp_drawable_type (image_map->drawable)))
|
|
|
|
dest[3] = src[gimp_drawable_bytes (image_map->drawable) - 1];
|
2000-02-28 10:40:44 +08:00
|
|
|
else
|
|
|
|
dest[3] = 255;
|
2001-05-25 01:09:57 +08:00
|
|
|
|
|
|
|
if (gimp_drawable_is_indexed (image_map->drawable))
|
2000-02-28 10:40:44 +08:00
|
|
|
dest[4] = src[0];
|
|
|
|
else
|
|
|
|
dest[4] = 0;
|
2001-05-25 01:09:57 +08:00
|
|
|
|
2000-02-28 10:40:44 +08:00
|
|
|
tile_release (tile, FALSE);
|
2001-05-25 01:09:57 +08:00
|
|
|
|
2000-02-28 10:40:44 +08:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
else /* out of bounds error */
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
}
|
2001-08-17 22:27:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
image_map_do (gpointer data)
|
|
|
|
{
|
|
|
|
ImageMap *image_map;
|
|
|
|
GimpImage *gimage;
|
|
|
|
PixelRegion shadowPR;
|
|
|
|
gint x, y, w, h;
|
|
|
|
|
|
|
|
image_map = (ImageMap *) data;
|
|
|
|
|
|
|
|
if (! (gimage = gimp_drawable_gimage (image_map->drawable)))
|
|
|
|
{
|
|
|
|
image_map->state = IMAGE_MAP_WAITING;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the pixel regions and apply the image mapping */
|
|
|
|
(* image_map->apply_func) (&image_map->srcPR,
|
|
|
|
&image_map->destPR,
|
|
|
|
image_map->user_data);
|
|
|
|
|
|
|
|
x = image_map->destPR.x;
|
|
|
|
y = image_map->destPR.y;
|
|
|
|
w = image_map->destPR.w;
|
|
|
|
h = image_map->destPR.h;
|
|
|
|
|
|
|
|
/* apply the results */
|
|
|
|
pixel_region_init (&shadowPR, gimage->shadow, x, y, w, h, FALSE);
|
|
|
|
gimp_image_apply_image (gimage, image_map->drawable, &shadowPR,
|
|
|
|
FALSE, OPAQUE_OPACITY, REPLACE_MODE, NULL, x, y);
|
|
|
|
|
|
|
|
/* display the results */
|
|
|
|
if (image_map->gdisp)
|
|
|
|
{
|
|
|
|
gimp_drawable_update (image_map->drawable,
|
|
|
|
x, y,
|
|
|
|
w, h);
|
|
|
|
gdisplay_flush_now (image_map->gdisp);
|
|
|
|
}
|
|
|
|
|
|
|
|
image_map->PRI = pixel_regions_process (image_map->PRI);
|
|
|
|
|
|
|
|
if (image_map->PRI == NULL)
|
|
|
|
{
|
|
|
|
image_map->state = IMAGE_MAP_WAITING;
|
|
|
|
gdisplays_flush ();
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|