2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* 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
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "core-types.h"
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "base/tile.h"
|
|
|
|
#include "base/tile-manager.h"
|
2001-05-14 05:51:20 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimparea.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpmarshal.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "gimppickable.h"
|
2004-07-14 00:36:29 +08:00
|
|
|
#include "gimpprojection.h"
|
|
|
|
#include "gimpprojection-construct.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
enum
|
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
2002-05-10 21:09:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
/* local function prototypes */
|
2001-07-31 19:33:13 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static void gimp_projection_pickable_iface_init (GimpPickableInterface *iface);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
static void gimp_projection_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gint64 gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
static void gimp_projection_pickable_flush (GimpPickable *pickable);
|
2004-07-14 07:04:05 +08:00
|
|
|
static guchar * gimp_projection_get_color_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
2005-07-12 03:21:52 +08:00
|
|
|
static gint gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
2004-07-14 07:04:05 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static void gimp_projection_alloc_tiles (GimpProjection *proj);
|
2004-07-14 18:31:59 +08:00
|
|
|
static void gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2004-07-14 00:36:29 +08:00
|
|
|
static void gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now);
|
2004-07-14 18:31:59 +08:00
|
|
|
static void gimp_projection_idle_render_init (GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_idle_render_callback (gpointer data);
|
2004-07-14 00:36:29 +08:00
|
|
|
static gboolean gimp_projection_idle_render_next_area (GimpProjection *proj);
|
|
|
|
static void gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
|
|
|
static void gimp_projection_invalidate (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
|
|
|
static void gimp_projection_validate_tile (TileManager *tm,
|
|
|
|
Tile *tile);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_projection_image_update (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_projection_image_size_changed (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_projection_image_mode_changed (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_projection_image_flush (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj);
|
|
|
|
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProjection, gimp_projection, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_projection_pickable_iface_init))
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_projection_parent_class
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint projection_signals[LAST_SIGNAL] = { 0 };
|
2001-02-02 02:44:22 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_class_init (GimpProjectionClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
projection_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpProjectionClass, update),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__BOOLEAN_INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 5,
|
2004-07-14 00:36:29 +08:00
|
|
|
G_TYPE_BOOLEAN,
|
2006-04-12 20:49:29 +08:00
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
object_class->finalize = gimp_projection_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_projection_get_memsize;
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_init (GimpProjection *proj)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
proj->image = NULL;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->type = -1;
|
|
|
|
proj->bytes = 0;
|
|
|
|
proj->tiles = NULL;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->update_areas = NULL;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.idle_id = 0;
|
|
|
|
proj->idle_render.update_areas = NULL;
|
1998-06-15 10:25:27 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->construct_flag = FALSE;
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 06:41:03 +08:00
|
|
|
/* sorry for the evil casts */
|
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
static void
|
2005-12-11 03:24:36 +08:00
|
|
|
gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
|
2004-07-14 07:04:05 +08:00
|
|
|
{
|
2006-03-03 03:30:59 +08:00
|
|
|
iface->flush = gimp_projection_pickable_flush;
|
2006-11-25 06:41:03 +08:00
|
|
|
iface->get_image = (GimpImage * (*) (GimpPickable *pickable)) gimp_projection_get_image;
|
|
|
|
iface->get_image_type = (GimpImageType (*) (GimpPickable *pickable)) gimp_projection_get_image_type;
|
|
|
|
iface->get_bytes = (gint (*) (GimpPickable *pickable)) gimp_projection_get_bytes;
|
|
|
|
iface->get_tiles = (TileManager * (*) (GimpPickable *pickable)) gimp_projection_get_tiles;
|
2005-12-11 03:24:36 +08:00
|
|
|
iface->get_color_at = gimp_projection_get_color_at;
|
|
|
|
iface->get_opacity_at = gimp_projection_get_opacity_at;
|
2004-07-14 07:04:05 +08:00
|
|
|
}
|
|
|
|
|
2002-05-10 21:09:19 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_finalize (GObject *object)
|
2002-05-10 21:09:19 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj = GIMP_PROJECTION (object);
|
2004-07-12 19:43:00 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->idle_render.idle_id)
|
2002-05-10 21:09:19 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_source_remove (proj->idle_render.idle_id);
|
|
|
|
proj->idle_render.idle_id = 0;
|
2002-05-10 21:09:19 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_area_list_free (proj->update_areas);
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->update_areas = NULL;
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_area_list_free (proj->idle_render.update_areas);
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.update_areas = NULL;
|
2002-05-10 21:09:19 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->tiles)
|
2002-05-10 21:09:19 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
tile_manager_unref (proj->tiles);
|
|
|
|
proj->tiles = NULL;
|
2002-05-10 21:09:19 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2002-05-10 21:09:19 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static gint64
|
|
|
|
gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
|
|
|
gint64 memsize = 0;
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (projection->tiles)
|
2004-09-20 03:47:26 +08:00
|
|
|
memsize += tile_manager_get_memsize (projection->tiles, FALSE);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2006-03-03 03:30:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_pickable_flush (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
|
|
|
gimp_projection_finish_draw (proj);
|
|
|
|
gimp_projection_flush_now (proj);
|
|
|
|
}
|
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
static guchar *
|
|
|
|
gimp_projection_get_color_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
Tile *tile;
|
|
|
|
guchar *src;
|
|
|
|
guchar *dest;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (x < 0 || y < 0 || x >= proj->image->width || y >= proj->image->height)
|
2004-07-14 07:04:05 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dest = g_new (guchar, 5);
|
|
|
|
tile = tile_manager_get_tile (gimp_projection_get_tiles (proj),
|
|
|
|
x, y, TRUE, FALSE);
|
|
|
|
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_color (proj->image, gimp_projection_get_image_type (proj),
|
2004-07-14 07:04:05 +08:00
|
|
|
src, dest);
|
|
|
|
|
|
|
|
dest[4] = 0;
|
|
|
|
tile_release (tile, FALSE);
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2005-07-12 03:21:52 +08:00
|
|
|
static gint
|
|
|
|
gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
return OPAQUE_OPACITY;
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_new (GimpImage *image)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
GimpProjection *proj;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj = g_object_new (GIMP_TYPE_PROJECTION, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
proj->image = image;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect_object (image, "update",
|
2004-07-14 00:36:29 +08:00
|
|
|
G_CALLBACK (gimp_projection_image_update),
|
|
|
|
proj, 0);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect_object (image, "size-changed",
|
2004-07-14 00:36:29 +08:00
|
|
|
G_CALLBACK (gimp_projection_image_size_changed),
|
|
|
|
proj, 0);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect_object (image, "mode-changed",
|
2004-07-14 00:36:29 +08:00
|
|
|
G_CALLBACK (gimp_projection_image_mode_changed),
|
|
|
|
proj, 0);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect_object (image, "flush",
|
2004-07-14 00:36:29 +08:00
|
|
|
G_CALLBACK (gimp_projection_image_flush),
|
|
|
|
proj, 0);
|
2001-11-10 00:54:56 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
TileManager *
|
|
|
|
gimp_projection_get_tiles (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->tiles == NULL ||
|
2006-03-29 01:08:36 +08:00
|
|
|
tile_manager_width (proj->tiles) != proj->image->width ||
|
|
|
|
tile_manager_height (proj->tiles) != proj->image->height)
|
2001-09-26 01:44:03 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_alloc_tiles (proj);
|
2001-09-26 01:44:03 +08:00
|
|
|
}
|
1998-02-14 23:30:31 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj->tiles;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-09-25 21:16:13 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_projection_get_image (const GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return proj->image;
|
2004-09-25 21:16:13 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpImageType
|
|
|
|
gimp_projection_get_image_type (const GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), -1);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj->type;
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gint
|
|
|
|
gimp_projection_get_bytes (const GimpProjection *proj)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return proj->bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gdouble
|
|
|
|
gimp_projection_get_opacity (const GimpProjection *proj)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), GIMP_OPACITY_OPAQUE);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
return GIMP_OPACITY_OPAQUE;
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-10-02 00:22:28 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush (GimpProjection *proj)
|
1998-10-02 00:22:28 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-09-26 01:44:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Construct on idle time */
|
|
|
|
gimp_projection_flush_whenever (proj, FALSE);
|
1998-10-02 00:22:28 +08:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:15:30 +08:00
|
|
|
void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_now (GimpProjection *proj)
|
2001-02-20 23:15:30 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Construct NOW */
|
|
|
|
gimp_projection_flush_whenever (proj, TRUE);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
void
|
|
|
|
gimp_projection_finish_draw (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
if (proj->idle_render.idle_id)
|
|
|
|
{
|
2006-03-03 03:30:59 +08:00
|
|
|
#if 0
|
|
|
|
g_printerr ("%s: flushing idle render queue\n", G_STRFUNC);
|
|
|
|
#endif
|
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
g_source_remove (proj->idle_render.idle_id);
|
|
|
|
proj->idle_render.idle_id = 0;
|
|
|
|
|
|
|
|
while (gimp_projection_idle_render_callback (proj));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* private functions */
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_alloc_tiles (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
GimpImageType proj_type = 0;
|
|
|
|
gint proj_bytes = 0;
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Find the number of bytes required for the projection.
|
|
|
|
* This includes the intensity channels and an alpha channel
|
|
|
|
* if one doesn't exist.
|
|
|
|
*/
|
2006-03-29 01:08:36 +08:00
|
|
|
switch (gimp_image_base_type (proj->image))
|
2003-05-08 22:06:03 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
case GIMP_RGB:
|
|
|
|
case GIMP_INDEXED:
|
|
|
|
proj_bytes = 4;
|
|
|
|
proj_type = GIMP_RGBA_IMAGE;
|
|
|
|
break;
|
2003-05-08 22:06:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
case GIMP_GRAY:
|
|
|
|
proj_bytes = 2;
|
|
|
|
proj_type = GIMP_GRAYA_IMAGE;
|
|
|
|
break;
|
2003-05-08 22:06:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2003-05-08 22:06:03 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->tiles)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
if (proj_type != proj->type ||
|
|
|
|
proj_bytes != proj->bytes ||
|
|
|
|
proj->image->width != tile_manager_width (proj->tiles) ||
|
|
|
|
proj->image->height != tile_manager_height (proj->tiles))
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
tile_manager_unref (proj->tiles);
|
|
|
|
proj->tiles = NULL;
|
|
|
|
}
|
2003-05-08 22:06:03 +08:00
|
|
|
}
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (! proj->tiles)
|
|
|
|
{
|
|
|
|
proj->type = proj_type;
|
|
|
|
proj->bytes = proj_bytes;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
proj->tiles = tile_manager_new (proj->image->width,
|
|
|
|
proj->image->height,
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->bytes);
|
|
|
|
tile_manager_set_user_data (proj->tiles, proj);
|
|
|
|
tile_manager_set_validate_proc (proj->tiles,
|
|
|
|
gimp_projection_validate_tile);
|
|
|
|
}
|
2002-10-14 21:39:35 +08:00
|
|
|
}
|
2001-02-20 23:15:30 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
|
|
|
GimpArea *area;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
area = gimp_area_new (CLAMP (x, 0, proj->image->width),
|
|
|
|
CLAMP (y, 0, proj->image->height),
|
|
|
|
CLAMP (x + w, 0, proj->image->width),
|
|
|
|
CLAMP (y + h, 0, proj->image->height));
|
2004-07-14 18:31:59 +08:00
|
|
|
|
|
|
|
proj->update_areas = gimp_area_list_process (proj->update_areas, area);
|
|
|
|
}
|
|
|
|
|
2001-11-11 07:03:22 +08:00
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2001-11-11 07:03:22 +08:00
|
|
|
/* First the updates... */
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->update_areas)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-07-12 19:43:00 +08:00
|
|
|
if (now) /* Synchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2004-07-12 19:43:00 +08:00
|
|
|
GSList *list;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
for (list = proj->update_areas; list; list = g_slist_next (list))
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2004-07-12 19:43:00 +08:00
|
|
|
GimpArea *area = list->data;
|
2003-07-30 00:36:56 +08:00
|
|
|
|
|
|
|
if ((area->x1 != area->x2) && (area->y1 != area->y2))
|
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_paint_area (proj,
|
|
|
|
FALSE, /* sic! */
|
|
|
|
area->x1,
|
|
|
|
area->y1,
|
|
|
|
(area->x2 - area->x1),
|
|
|
|
(area->y2 - area->y1));
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-12 19:43:00 +08:00
|
|
|
else /* Asynchronous */
|
2003-07-30 00:36:56 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_idle_render_init (proj);
|
2003-07-30 00:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the update lists */
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->update_areas = gimp_area_list_free (proj->update_areas);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
static void
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_idle_render_init (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GSList *list;
|
|
|
|
GimpArea *area;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* We need to merge the IdleRender's and the GimpProjection's update_areas list
|
2001-11-11 07:03:22 +08:00
|
|
|
* to keep track of which of the updates have been flushed and hence need
|
2003-10-08 22:50:26 +08:00
|
|
|
* to be drawn.
|
2001-11-11 07:03:22 +08:00
|
|
|
*/
|
2004-07-14 00:36:29 +08:00
|
|
|
for (list = proj->update_areas; list; list = g_slist_next (list))
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
area = g_memdup (list->data, sizeof (GimpArea));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.update_areas =
|
|
|
|
gimp_area_list_process (proj->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If an idlerender was already running, merge the remainder of its
|
|
|
|
* unrendered area with the update_areas list, and make it start work
|
|
|
|
* on the next unrendered area in the list.
|
|
|
|
*/
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->idle_render.idle_id)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
area =
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_area_new (proj->idle_render.base_x,
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.y,
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.base_x + proj->idle_render.width,
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.y + (proj->idle_render.height -
|
|
|
|
(proj->idle_render.y -
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.base_y)));
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.update_areas =
|
|
|
|
gimp_area_list_process (proj->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_idle_render_next_area (proj);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->idle_render.update_areas == NULL)
|
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
g_warning ("%s: wanted to start idle render with no update_areas",
|
|
|
|
G_STRFUNC);
|
2004-07-14 00:36:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_projection_idle_render_next_area (proj);
|
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.idle_id =
|
|
|
|
g_idle_add_full (G_PRIORITY_LOW,
|
|
|
|
gimp_projection_idle_render_callback,
|
|
|
|
proj, NULL);
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
/* Unless specified otherwise, projection re-rendering is organised by
|
2001-11-11 07:03:22 +08:00
|
|
|
* IdleRender, which amalgamates areas to be re-rendered and breaks
|
|
|
|
* them into bite-sized chunks which are chewed on in a low- priority
|
|
|
|
* idle thread. This greatly improves responsiveness for many GIMP
|
|
|
|
* operations. -- Adam
|
|
|
|
*/
|
|
|
|
static gboolean
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_idle_render_callback (gpointer data)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj = data;
|
2004-07-14 18:31:59 +08:00
|
|
|
gint workx, worky;
|
|
|
|
gint workw, workh;
|
|
|
|
|
|
|
|
#define CHUNK_WIDTH 256
|
|
|
|
#define CHUNK_HEIGHT 128
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
workw = CHUNK_WIDTH;
|
|
|
|
workh = CHUNK_HEIGHT;
|
2004-07-14 00:36:29 +08:00
|
|
|
workx = proj->idle_render.x;
|
|
|
|
worky = proj->idle_render.y;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
if (workx + workw > proj->idle_render.base_x + proj->idle_render.width)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
workw = proj->idle_render.base_x + proj->idle_render.width - workx;
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
if (worky + workh > proj->idle_render.base_y + proj->idle_render.height)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
workh = proj->idle_render.base_y + proj->idle_render.height - worky;
|
2003-10-08 22:50:26 +08:00
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
gimp_projection_paint_area (proj, TRUE /* sic! */,
|
2004-07-14 00:36:29 +08:00
|
|
|
workx, worky, workw, workh);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.x += CHUNK_WIDTH;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (proj->idle_render.x >=
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.base_x + proj->idle_render.width)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.x = proj->idle_render.base_x;
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.y += CHUNK_HEIGHT;
|
|
|
|
|
|
|
|
if (proj->idle_render.y >=
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.base_y + proj->idle_render.height)
|
2004-07-14 00:36:29 +08:00
|
|
|
{
|
|
|
|
if (! gimp_projection_idle_render_next_area (proj))
|
|
|
|
{
|
|
|
|
/* FINISHED */
|
|
|
|
proj->idle_render.idle_id = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Still work to do. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_idle_render_next_area (GimpProjection *proj)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2001-11-16 23:08:59 +08:00
|
|
|
GimpArea *area;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
if (! proj->idle_render.update_areas)
|
2001-11-16 23:08:59 +08:00
|
|
|
return FALSE;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
area = (GimpArea *) proj->idle_render.update_areas->data;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.update_areas =
|
|
|
|
g_slist_remove (proj->idle_render.update_areas, area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 18:31:59 +08:00
|
|
|
proj->idle_render.x = proj->idle_render.base_x = area->x1;
|
|
|
|
proj->idle_render.y = proj->idle_render.base_y = area->y1;
|
2004-07-14 00:36:29 +08:00
|
|
|
proj->idle_render.width = area->x2 - area->x1;
|
|
|
|
proj->idle_render.height = area->y2 - area->y1;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2001-11-16 23:08:59 +08:00
|
|
|
g_free (area);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-11 07:03:22 +08:00
|
|
|
{
|
2004-07-14 00:36:29 +08:00
|
|
|
gint x1, y1, x2, y2;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
|
|
|
/* Bounds check */
|
2006-03-29 01:08:36 +08:00
|
|
|
x1 = CLAMP (x, 0, proj->image->width);
|
|
|
|
y1 = CLAMP (y, 0, proj->image->height);
|
|
|
|
x2 = CLAMP (x + w, 0, proj->image->width);
|
|
|
|
y2 = CLAMP (y + h, 0, proj->image->height);
|
2001-11-11 07:03:22 +08:00
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
w = (x2 - x1);
|
|
|
|
h = (y2 - y1);
|
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
gimp_projection_invalidate (proj, x, y, w, h);
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
g_signal_emit (proj, projection_signals[UPDATE], 0,
|
|
|
|
now, x, y, w, h);
|
|
|
|
}
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
static void
|
|
|
|
gimp_projection_invalidate (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
|
|
|
Tile *tile;
|
|
|
|
TileManager *tm;
|
|
|
|
gint i, j;
|
2001-11-11 07:03:22 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
tm = gimp_projection_get_tiles (proj);
|
|
|
|
|
|
|
|
for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT)))
|
|
|
|
for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH)))
|
|
|
|
{
|
2006-04-12 20:49:29 +08:00
|
|
|
tile = tile_manager_get_tile (tm, j, i, FALSE, FALSE);
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
tile_invalidate_tile (&tile, tm, j, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_validate_tile (TileManager *tm,
|
|
|
|
Tile *tile)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = tile_manager_get_user_data (tm);
|
|
|
|
gint x, y;
|
|
|
|
gint w, h;
|
|
|
|
|
|
|
|
/* Find the coordinates of this tile */
|
|
|
|
tile_manager_get_tile_coordinates (tm, tile, &x, &y);
|
|
|
|
w = tile_ewidth (tile);
|
|
|
|
h = tile_eheight (tile);
|
|
|
|
|
|
|
|
gimp_projection_construct (proj, x, y, w, h);
|
|
|
|
}
|
2003-11-21 02:08:01 +08:00
|
|
|
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
/* image callbacks */
|
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_image_update (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_add_update_area (proj, x, y, w, h);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2004-07-14 00:36:29 +08:00
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_image_size_changed (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_alloc_tiles (proj);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_image_mode_changed (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_alloc_tiles (proj);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
|
2004-07-14 00:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_projection_image_flush (GimpImage *image,
|
2004-07-14 00:36:29 +08:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_flush (proj);
|
|
|
|
}
|
|
|
|
|