2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00: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 05:44:11 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00: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-01 20:30:56 +00:00
|
|
|
#include "config.h"
|
2001-10-29 11:47:11 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
#include <glib-object.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
#include "core-types.h"
|
2002-05-03 12:45:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
#include "base/tile.h"
|
|
|
|
#include "base/tile-manager.h"
|
2001-05-13 21:51:20 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimparea.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpmarshal.h"
|
2004-07-13 23:04:05 +00:00
|
|
|
#include "gimppickable.h"
|
2004-07-13 16:36:29 +00:00
|
|
|
#include "gimpprojection.h"
|
|
|
|
#include "gimpprojection-construct.h"
|
2000-04-27 17:27:28 +00:00
|
|
|
|
2001-07-31 11:33:13 +00:00
|
|
|
|
2002-05-10 13:09:19 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
UPDATE,
|
|
|
|
LAST_SIGNAL
|
2002-05-10 13:09:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-10-31 21:20:09 +00:00
|
|
|
/* local function prototypes */
|
2001-07-31 11:33:13 +00:00
|
|
|
|
2005-12-10 19:24:36 +00:00
|
|
|
static void gimp_projection_pickable_iface_init (GimpPickableInterface *iface);
|
2004-07-13 16:36:29 +00:00
|
|
|
|
|
|
|
static void gimp_projection_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gint64 gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
2006-03-02 19:30:59 +00:00
|
|
|
static void gimp_projection_pickable_flush (GimpPickable *pickable);
|
2007-04-27 16:07:49 +00:00
|
|
|
static gboolean gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guchar *pixel);
|
2005-07-11 19:21:52 +00:00
|
|
|
static gint gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
2004-07-13 23:04:05 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
static void gimp_projection_alloc_levels (GimpProjection *proj);
|
2004-07-14 10:31:59 +00:00
|
|
|
static void gimp_projection_add_update_area (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2004-07-13 16:36:29 +00:00
|
|
|
static void gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now);
|
2004-07-14 10:31:59 +00:00
|
|
|
static void gimp_projection_idle_render_init (GimpProjection *proj);
|
|
|
|
static gboolean gimp_projection_idle_render_callback (gpointer data);
|
2004-07-13 16:36:29 +00: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);
|
2007-06-06 13:45:44 +00:00
|
|
|
static void gimp_projection_write_quarter (Tile *dest,
|
|
|
|
Tile *source,
|
|
|
|
gint i,
|
|
|
|
gint j);
|
|
|
|
static void gimp_projection_validate_pyramid_tile (TileManager *tm,
|
|
|
|
Tile *tile);
|
2004-07-13 16:36:29 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
static void gimp_projection_image_update (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj);
|
2006-03-28 17:08:36 +00:00
|
|
|
static void gimp_projection_image_size_changed (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj);
|
2006-03-28 17:08:36 +00:00
|
|
|
static void gimp_projection_image_mode_changed (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj);
|
2006-03-28 17:08:36 +00:00
|
|
|
static void gimp_projection_image_flush (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj);
|
|
|
|
|
|
|
|
|
2005-12-10 19:24:36 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpProjection, gimp_projection, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
|
2006-05-15 09:46:31 +00:00
|
|
|
gimp_projection_pickable_iface_init))
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2005-12-10 19:24:36 +00:00
|
|
|
#define parent_class gimp_projection_parent_class
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2005-12-10 19:24:36 +00:00
|
|
|
static guint projection_signals[LAST_SIGNAL] = { 0 };
|
2001-02-01 18:44:22 +00:00
|
|
|
|
2001-09-25 17:44:03 +00:00
|
|
|
|
|
|
|
static void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_class_init (GimpProjectionClass *klass)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
projection_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
2006-04-12 12:49:29 +00: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-13 16:36:29 +00:00
|
|
|
G_TYPE_BOOLEAN,
|
2006-04-12 12:49:29 +00:00
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2004-07-13 16:36:29 +00:00
|
|
|
|
|
|
|
object_class->finalize = gimp_projection_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_projection_get_memsize;
|
2001-09-25 17:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_init (GimpProjection *proj)
|
2001-09-25 17:44:03 +00:00
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
proj->image = NULL;
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->type = -1;
|
|
|
|
proj->bytes = 0;
|
2007-06-06 13:45:44 +00:00
|
|
|
|
|
|
|
for (level = 0; level < PYRAMID_MAX_LEVELS; level++)
|
|
|
|
proj->pyramid[level] = NULL;
|
|
|
|
|
|
|
|
proj->top_level = PYRAMID_BASE_LEVEL;
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->update_areas = NULL;
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.idle_id = 0;
|
|
|
|
proj->idle_render.update_areas = NULL;
|
1998-06-15 02:25:27 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->construct_flag = FALSE;
|
2001-09-25 17:44:03 +00:00
|
|
|
}
|
|
|
|
|
2006-11-24 22:41:03 +00:00
|
|
|
/* sorry for the evil casts */
|
|
|
|
|
2004-07-13 23:04:05 +00:00
|
|
|
static void
|
2005-12-10 19:24:36 +00:00
|
|
|
gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
|
2004-07-13 23:04:05 +00:00
|
|
|
{
|
2006-03-02 19:30:59 +00:00
|
|
|
iface->flush = gimp_projection_pickable_flush;
|
2006-11-24 22:41:03 +00: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;
|
2007-04-27 16:07:49 +00:00
|
|
|
iface->get_pixel_at = gimp_projection_get_pixel_at;
|
2005-12-10 19:24:36 +00:00
|
|
|
iface->get_opacity_at = gimp_projection_get_opacity_at;
|
2004-07-13 23:04:05 +00:00
|
|
|
}
|
|
|
|
|
2002-05-10 13:09:19 +00:00
|
|
|
static void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_finalize (GObject *object)
|
2002-05-10 13:09:19 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj = GIMP_PROJECTION (object);
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
2004-07-12 11:43:00 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
if (proj->idle_render.idle_id)
|
2002-05-10 13:09:19 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_source_remove (proj->idle_render.idle_id);
|
|
|
|
proj->idle_render.idle_id = 0;
|
2002-05-10 13:09:19 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_area_list_free (proj->update_areas);
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->update_areas = NULL;
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_area_list_free (proj->idle_render.update_areas);
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.update_areas = NULL;
|
2002-05-10 13:09:19 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
for (level = 0; level <= proj->top_level; level++)
|
|
|
|
if (proj->pyramid[level])
|
|
|
|
{
|
|
|
|
tile_manager_unref (proj->pyramid[level]);
|
|
|
|
proj->pyramid[level] = NULL;
|
|
|
|
}
|
2007-06-06 13:59:41 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
proj->top_level = PYRAMID_BASE_LEVEL;
|
2004-07-13 16:36:29 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2002-05-10 13:09:19 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
static gint64
|
|
|
|
gimp_projection_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size)
|
2001-09-25 17:44:03 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *projection = GIMP_PROJECTION (object);
|
|
|
|
gint64 memsize = 0;
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
for (level = 0; level <= projection->top_level; level++)
|
|
|
|
if (projection->pyramid[level])
|
|
|
|
memsize += tile_manager_get_memsize (projection->pyramid[level], FALSE);
|
2001-10-29 11:47:11 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
|
|
|
}
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2007-06-06 10:03:17 +00:00
|
|
|
/**
|
|
|
|
* gimp_projection_estimate_memsize:
|
|
|
|
* @type: the image base type
|
|
|
|
* @width: image width
|
|
|
|
* @height: image height
|
|
|
|
*
|
|
|
|
* Calculates a rough estimate of the memory that is required for the
|
|
|
|
* projection of an image with the given @width and @height.
|
|
|
|
*
|
|
|
|
* Return value: a rough estimate of the memory requirements.
|
|
|
|
**/
|
|
|
|
gint64
|
|
|
|
gimp_projection_estimate_memsize (GimpImageBaseType type,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2007-06-06 10:48:00 +00:00
|
|
|
gint64 bytes = 0;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB:
|
|
|
|
case GIMP_INDEXED:
|
|
|
|
bytes = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY:
|
|
|
|
bytes = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
/* The levels constitute a geometric sum with a ratio of 1/4. */
|
|
|
|
return bytes * (gint64) width * (gint64) height * 1.33;
|
2007-06-06 10:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-02 19:30:59 +00:00
|
|
|
static void
|
|
|
|
gimp_projection_pickable_flush (GimpPickable *pickable)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
|
|
|
gimp_projection_finish_draw (proj);
|
|
|
|
gimp_projection_flush_now (proj);
|
|
|
|
}
|
|
|
|
|
2007-04-27 16:07:49 +00:00
|
|
|
static gboolean
|
|
|
|
gimp_projection_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guchar *pixel)
|
|
|
|
{
|
|
|
|
GimpProjection *proj = GIMP_PROJECTION (pickable);
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x >= proj->image->width || y >= proj->image->height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
read_pixel_data_1 (gimp_projection_get_tiles (proj), x, y, pixel);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-11 19:21:52 +00:00
|
|
|
static gint
|
|
|
|
gimp_projection_get_opacity_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
return OPAQUE_OPACITY;
|
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_new (GimpImage *image)
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
|
|
|
GimpProjection *proj;
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj = g_object_new (GIMP_TYPE_PROJECTION, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
proj->image = image;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_signal_connect_object (image, "update",
|
2004-07-13 16:36:29 +00:00
|
|
|
G_CALLBACK (gimp_projection_image_update),
|
|
|
|
proj, 0);
|
2006-03-28 17:08:36 +00:00
|
|
|
g_signal_connect_object (image, "size-changed",
|
2004-07-13 16:36:29 +00:00
|
|
|
G_CALLBACK (gimp_projection_image_size_changed),
|
|
|
|
proj, 0);
|
2006-03-28 17:08:36 +00:00
|
|
|
g_signal_connect_object (image, "mode-changed",
|
2004-07-13 16:36:29 +00:00
|
|
|
G_CALLBACK (gimp_projection_image_mode_changed),
|
|
|
|
proj, 0);
|
2006-03-28 17:08:36 +00:00
|
|
|
g_signal_connect_object (image, "flush",
|
2004-07-13 16:36:29 +00:00
|
|
|
G_CALLBACK (gimp_projection_image_flush),
|
|
|
|
proj, 0);
|
2001-11-09 16:54:56 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
return proj;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
TileManager *
|
|
|
|
gimp_projection_get_tiles (GimpProjection *proj)
|
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
return gimp_projection_get_tiles_at_level (proj, PYRAMID_BASE_LEVEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
TileManager *
|
|
|
|
gimp_projection_get_tiles_at_level (GimpProjection *proj,
|
|
|
|
gint level)
|
|
|
|
{
|
|
|
|
TileManager *base_level;
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
|
2001-02-20 15:15:30 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
base_level = proj->pyramid[PYRAMID_BASE_LEVEL];
|
|
|
|
|
|
|
|
if (base_level == NULL ||
|
|
|
|
proj->image->width != tile_manager_width (base_level) ||
|
|
|
|
proj->image->height != tile_manager_height (base_level))
|
2007-06-06 13:59:41 +00:00
|
|
|
{
|
|
|
|
gimp_projection_alloc_levels (proj);
|
|
|
|
}
|
2007-06-06 13:45:44 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (level >= PYRAMID_BASE_LEVEL &&
|
|
|
|
level <= proj->top_level,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return proj->pyramid[level];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-06 21:40:31 +00:00
|
|
|
* gimp_projection_get_level:
|
|
|
|
* @proj: pointer to a GimpProjection
|
|
|
|
* @scale_x: horizontal scale factor
|
|
|
|
* @scale_y: vertical scale factor
|
2007-06-06 13:45:44 +00:00
|
|
|
*
|
2007-06-06 21:40:31 +00:00
|
|
|
* Return value: the pyramid level to use for a given display scale factor.
|
2007-06-06 13:45:44 +00:00
|
|
|
**/
|
|
|
|
gint
|
2007-06-06 21:40:31 +00:00
|
|
|
gimp_projection_get_level (GimpProjection *proj,
|
|
|
|
gdouble scale_x,
|
|
|
|
gdouble scale_y)
|
2007-06-06 13:45:44 +00:00
|
|
|
{
|
2007-06-06 21:40:31 +00:00
|
|
|
gdouble scale;
|
|
|
|
gint level;
|
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), PYRAMID_BASE_LEVEL);
|
|
|
|
|
2007-06-06 21:40:31 +00:00
|
|
|
scale = MAX (scale_x, scale_y);
|
|
|
|
level = -(log (scale) / G_LN2);
|
|
|
|
|
|
|
|
return CLAMP (level, PYRAMID_BASE_LEVEL, proj->top_level);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2004-09-25 13:16:13 +00:00
|
|
|
GimpImage *
|
|
|
|
gimp_projection_get_image (const GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
return proj->image;
|
2004-09-25 13:16:13 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpImageType
|
|
|
|
gimp_projection_get_image_type (const GimpProjection *proj)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), -1);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
return proj->type;
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gint
|
|
|
|
gimp_projection_get_bytes (const GimpProjection *proj)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), 0);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
return proj->bytes;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gdouble
|
|
|
|
gimp_projection_get_opacity (const GimpProjection *proj)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_PROJECTION (proj), GIMP_OPACITY_OPAQUE);
|
2001-10-31 21:20:09 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
return GIMP_OPACITY_OPAQUE;
|
2001-10-31 21:20:09 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1998-10-01 16:22:28 +00:00
|
|
|
void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_flush (GimpProjection *proj)
|
1998-10-01 16:22:28 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-09-25 17:44:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
/* Construct on idle time */
|
|
|
|
gimp_projection_flush_whenever (proj, FALSE);
|
1998-10-01 16:22:28 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 15:15:30 +00:00
|
|
|
void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_flush_now (GimpProjection *proj)
|
2001-02-20 15:15:30 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2001-02-20 15:15:30 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
/* Construct NOW */
|
|
|
|
gimp_projection_flush_whenever (proj, TRUE);
|
2001-10-31 21:20:09 +00:00
|
|
|
}
|
2001-02-20 15:15:30 +00:00
|
|
|
|
2004-07-14 10:31:59 +00:00
|
|
|
void
|
|
|
|
gimp_projection_finish_draw (GimpProjection *proj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
|
|
|
|
|
|
|
if (proj->idle_render.idle_id)
|
|
|
|
{
|
2006-03-02 19:30:59 +00:00
|
|
|
#if 0
|
|
|
|
g_printerr ("%s: flushing idle render queue\n", G_STRFUNC);
|
|
|
|
#endif
|
|
|
|
|
2004-07-14 10:31:59 +00: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 13:39:35 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
/* private functions */
|
2002-10-14 13:39:35 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
static void
|
2007-06-06 13:45:44 +00:00
|
|
|
gimp_projection_alloc_levels (GimpProjection *proj)
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
|
|
|
GimpImageType proj_type = 0;
|
|
|
|
gint proj_bytes = 0;
|
2002-10-14 13:39:35 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
g_return_if_fail (GIMP_IS_PROJECTION (proj));
|
2002-10-14 13:39:35 +00:00
|
|
|
|
2004-07-13 16:36:29 +00: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-28 17:08:36 +00:00
|
|
|
switch (gimp_image_base_type (proj->image))
|
2003-05-08 14:06:03 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
case GIMP_RGB:
|
|
|
|
case GIMP_INDEXED:
|
|
|
|
proj_bytes = 4;
|
|
|
|
proj_type = GIMP_RGBA_IMAGE;
|
|
|
|
break;
|
2003-05-08 14:06:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
case GIMP_GRAY:
|
|
|
|
proj_bytes = 2;
|
|
|
|
proj_type = GIMP_GRAYA_IMAGE;
|
|
|
|
break;
|
2003-05-08 14:06:03 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2003-05-08 14:06:03 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
if (proj->pyramid[PYRAMID_BASE_LEVEL])
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
2007-06-06 13:59:41 +00:00
|
|
|
gint width = tile_manager_width (proj->pyramid[PYRAMID_BASE_LEVEL]);
|
|
|
|
gint height = tile_manager_height (proj->pyramid[PYRAMID_BASE_LEVEL]);
|
2007-06-06 13:45:44 +00:00
|
|
|
|
2007-06-06 13:59:41 +00:00
|
|
|
if (proj_type != proj->type ||
|
|
|
|
proj_bytes != proj->bytes ||
|
|
|
|
proj->image->width != width ||
|
|
|
|
proj->image->height != height)
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
|
|
|
|
|
|
|
for (level = 0; level <= proj->top_level; level++)
|
|
|
|
{
|
|
|
|
tile_manager_unref (proj->pyramid[level]);
|
|
|
|
proj->pyramid[level] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
proj->top_level = 0;
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
2003-05-08 14:06:03 +00:00
|
|
|
}
|
2002-10-14 13:39:35 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
if (! proj->pyramid[PYRAMID_BASE_LEVEL])
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->type = proj_type;
|
|
|
|
proj->bytes = proj_bytes;
|
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
for (level = 0; level < PYRAMID_MAX_LEVELS; level++)
|
|
|
|
{
|
|
|
|
gint level_width = proj->image->width / (1 << level);
|
|
|
|
gint level_height = proj->image->height / (1 << level);
|
|
|
|
|
2007-06-06 13:59:41 +00:00
|
|
|
if (level_width == 0 || level_height == 0)
|
|
|
|
break;
|
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
/* There is no use having levels that have the same number of
|
|
|
|
* tiles as the parent level.
|
|
|
|
*/
|
|
|
|
if (level != PYRAMID_BASE_LEVEL &&
|
|
|
|
level_width <= TILE_WIDTH / 2 &&
|
2007-06-06 13:59:41 +00:00
|
|
|
level_height <= TILE_HEIGHT / 2)
|
2007-06-06 13:45:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
proj->top_level = level;
|
|
|
|
proj->pyramid[level] = tile_manager_new (level_width,
|
|
|
|
level_height,
|
|
|
|
proj->bytes);
|
|
|
|
|
|
|
|
tile_manager_set_user_data (proj->pyramid[level], proj);
|
|
|
|
|
|
|
|
if (level == PYRAMID_BASE_LEVEL)
|
|
|
|
{
|
|
|
|
/* Validate tiles by building from the layers of the image. */
|
|
|
|
tile_manager_set_validate_proc (proj->pyramid[level],
|
|
|
|
gimp_projection_validate_tile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use the level below to validate tiles. */
|
|
|
|
tile_manager_set_validate_proc (proj->pyramid[level],
|
|
|
|
gimp_projection_validate_pyramid_tile);
|
|
|
|
|
|
|
|
tile_manager_set_level_below (proj->pyramid[level],
|
|
|
|
proj->pyramid[level - 1]);
|
|
|
|
}
|
|
|
|
}
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
2002-10-14 13:39:35 +00:00
|
|
|
}
|
2001-02-20 15:15:30 +00:00
|
|
|
|
2004-07-14 10:31:59 +00: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-28 17:08:36 +00: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 10:31:59 +00:00
|
|
|
|
|
|
|
proj->update_areas = gimp_area_list_process (proj->update_areas, area);
|
|
|
|
}
|
|
|
|
|
2001-11-10 23:03:22 +00:00
|
|
|
static void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_flush_whenever (GimpProjection *proj,
|
|
|
|
gboolean now)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2001-11-10 23:03:22 +00:00
|
|
|
/* First the updates... */
|
2004-07-13 16:36:29 +00:00
|
|
|
if (proj->update_areas)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2004-07-12 11:43:00 +00:00
|
|
|
if (now) /* Synchronous */
|
2003-07-29 16:36:56 +00:00
|
|
|
{
|
2004-07-12 11:43:00 +00:00
|
|
|
GSList *list;
|
2003-07-29 16:36:56 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
for (list = proj->update_areas; list; list = g_slist_next (list))
|
2003-07-29 16:36:56 +00:00
|
|
|
{
|
2004-07-12 11:43:00 +00:00
|
|
|
GimpArea *area = list->data;
|
2003-07-29 16:36:56 +00:00
|
|
|
|
|
|
|
if ((area->x1 != area->x2) && (area->y1 != area->y2))
|
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_paint_area (proj,
|
|
|
|
FALSE, /* sic! */
|
|
|
|
area->x1,
|
|
|
|
area->y1,
|
|
|
|
(area->x2 - area->x1),
|
|
|
|
(area->y2 - area->y1));
|
2003-07-29 16:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-12 11:43:00 +00:00
|
|
|
else /* Asynchronous */
|
2003-07-29 16:36:56 +00:00
|
|
|
{
|
2004-07-14 10:31:59 +00:00
|
|
|
gimp_projection_idle_render_init (proj);
|
2003-07-29 16:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the update lists */
|
2007-05-22 18:52:11 +00:00
|
|
|
gimp_area_list_free (proj->update_areas);
|
|
|
|
proj->update_areas = NULL;
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
2001-11-10 23:03:22 +00:00
|
|
|
|
|
|
|
static void
|
2004-07-14 10:31:59 +00:00
|
|
|
gimp_projection_idle_render_init (GimpProjection *proj)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2007-05-22 18:52:11 +00:00
|
|
|
GSList *list;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2007-05-22 18:52:11 +00:00
|
|
|
/* We need to merge the IdleRender's and the GimpProjection's update_areas
|
|
|
|
* list to keep track of which of the updates have been flushed and hence
|
|
|
|
* need to be drawn.
|
2001-11-10 23:03:22 +00:00
|
|
|
*/
|
2004-07-13 16:36:29 +00:00
|
|
|
for (list = proj->update_areas; list; list = g_slist_next (list))
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2007-05-22 18:52:11 +00:00
|
|
|
GimpArea *area = list->data;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.update_areas =
|
2007-05-22 18:52:11 +00:00
|
|
|
gimp_area_list_process (proj->idle_render.update_areas,
|
|
|
|
gimp_area_new (area->x1, area->y1,
|
|
|
|
area->x2, area->y2));
|
2001-11-10 23:03:22 +00: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-13 16:36:29 +00:00
|
|
|
if (proj->idle_render.idle_id)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2007-05-22 18:52:11 +00:00
|
|
|
GimpArea *area =
|
2004-07-14 10:31:59 +00:00
|
|
|
gimp_area_new (proj->idle_render.base_x,
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.y,
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.base_x + proj->idle_render.width,
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.y + (proj->idle_render.height -
|
|
|
|
(proj->idle_render.y -
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.base_y)));
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.update_areas =
|
|
|
|
gimp_area_list_process (proj->idle_render.update_areas, area);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_idle_render_next_area (proj);
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
if (proj->idle_render.update_areas == NULL)
|
|
|
|
{
|
2004-07-14 10:31:59 +00:00
|
|
|
g_warning ("%s: wanted to start idle render with no update_areas",
|
|
|
|
G_STRFUNC);
|
2004-07-13 16:36:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_projection_idle_render_next_area (proj);
|
|
|
|
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.idle_id =
|
|
|
|
g_idle_add_full (G_PRIORITY_LOW,
|
|
|
|
gimp_projection_idle_render_callback,
|
|
|
|
proj, NULL);
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
/* Unless specified otherwise, projection re-rendering is organised by
|
2001-11-10 23:03:22 +00: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 10:31:59 +00:00
|
|
|
gimp_projection_idle_render_callback (gpointer data)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj = data;
|
2004-07-14 10:31:59 +00:00
|
|
|
gint workx, worky;
|
|
|
|
gint workw, workh;
|
|
|
|
|
|
|
|
#define CHUNK_WIDTH 256
|
|
|
|
#define CHUNK_HEIGHT 128
|
2001-11-10 23:03:22 +00:00
|
|
|
|
|
|
|
workw = CHUNK_WIDTH;
|
|
|
|
workh = CHUNK_HEIGHT;
|
2004-07-13 16:36:29 +00:00
|
|
|
workx = proj->idle_render.x;
|
|
|
|
worky = proj->idle_render.y;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-14 10:31:59 +00:00
|
|
|
if (workx + workw > proj->idle_render.base_x + proj->idle_render.width)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-14 10:31:59 +00:00
|
|
|
workw = proj->idle_render.base_x + proj->idle_render.width - workx;
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
|
2004-07-14 10:31:59 +00:00
|
|
|
if (worky + workh > proj->idle_render.base_y + proj->idle_render.height)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-14 10:31:59 +00:00
|
|
|
workh = proj->idle_render.base_y + proj->idle_render.height - worky;
|
2003-10-08 14:50:26 +00:00
|
|
|
}
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-14 10:31:59 +00:00
|
|
|
gimp_projection_paint_area (proj, TRUE /* sic! */,
|
2004-07-13 16:36:29 +00:00
|
|
|
workx, worky, workw, workh);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.x += CHUNK_WIDTH;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
if (proj->idle_render.x >=
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.base_x + proj->idle_render.width)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.x = proj->idle_render.base_x;
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.y += CHUNK_HEIGHT;
|
|
|
|
|
|
|
|
if (proj->idle_render.y >=
|
2004-07-14 10:31:59 +00:00
|
|
|
proj->idle_render.base_y + proj->idle_render.height)
|
2004-07-13 16:36:29 +00:00
|
|
|
{
|
|
|
|
if (! gimp_projection_idle_render_next_area (proj))
|
|
|
|
{
|
|
|
|
/* FINISHED */
|
|
|
|
proj->idle_render.idle_id = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-10 23:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Still work to do. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_idle_render_next_area (GimpProjection *proj)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2001-11-16 15:08:59 +00:00
|
|
|
GimpArea *area;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
if (! proj->idle_render.update_areas)
|
2001-11-16 15:08:59 +00:00
|
|
|
return FALSE;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2007-05-22 18:52:11 +00:00
|
|
|
area = proj->idle_render.update_areas->data;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
proj->idle_render.update_areas =
|
|
|
|
g_slist_remove (proj->idle_render.update_areas, area);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-14 10:31:59 +00: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-13 16:36:29 +00:00
|
|
|
proj->idle_render.width = area->x2 - area->x1;
|
|
|
|
proj->idle_render.height = area->y2 - area->y1;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2007-05-22 18:52:11 +00:00
|
|
|
gimp_area_free (area);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_paint_area (GimpProjection *proj,
|
|
|
|
gboolean now,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-10 23:03:22 +00:00
|
|
|
{
|
2004-07-13 16:36:29 +00:00
|
|
|
gint x1, y1, x2, y2;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
|
|
|
/* Bounds check */
|
2006-03-28 17:08:36 +00: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-10 23:03:22 +00:00
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
w = (x2 - x1);
|
|
|
|
h = (y2 - y1);
|
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
gimp_projection_invalidate (proj, x, y, w, h);
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
g_signal_emit (proj, projection_signals[UPDATE], 0,
|
|
|
|
now, x, y, w, h);
|
|
|
|
}
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
static void
|
|
|
|
gimp_projection_invalidate (GimpProjection *proj,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
|
|
|
TileManager *tm;
|
2007-06-06 13:45:44 +00:00
|
|
|
gint level;
|
2001-11-10 23:03:22 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
for (level = 0; level <= proj->top_level; level++)
|
|
|
|
{
|
|
|
|
gint c = (1 << level);
|
2004-07-13 16:36:29 +00:00
|
|
|
|
2007-06-06 13:59:41 +00:00
|
|
|
/* Tile invalidation must propagate all the way up in the pyramid,
|
|
|
|
* so keep width and height > 0.
|
2007-06-06 13:45:44 +00:00
|
|
|
*/
|
|
|
|
gint invalidation_width = MAX (w / c, 1);
|
|
|
|
gint invalidation_height = MAX (h / c, 1);
|
2004-07-13 16:36:29 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
tm = gimp_projection_get_tiles_at_level (proj, level);
|
|
|
|
|
|
|
|
tile_manager_invalidate_area (tm,
|
|
|
|
x / c,
|
|
|
|
y / c,
|
|
|
|
invalidation_width,
|
|
|
|
invalidation_height);
|
|
|
|
}
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2007-06-06 13:59:41 +00:00
|
|
|
|
2004-07-13 16:36:29 +00:00
|
|
|
w = tile_ewidth (tile);
|
|
|
|
h = tile_eheight (tile);
|
|
|
|
|
|
|
|
gimp_projection_construct (proj, x, y, w, h);
|
|
|
|
}
|
2003-11-20 18:08:01 +00:00
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
static void
|
|
|
|
gimp_projection_write_quarter (Tile *dest,
|
|
|
|
Tile *source,
|
|
|
|
gint i,
|
|
|
|
gint j)
|
|
|
|
{
|
|
|
|
const guchar *source_data = tile_data_pointer (source, 0, 0);
|
|
|
|
guchar *dest_data = tile_data_pointer (dest, 0, 0);
|
|
|
|
|
|
|
|
gint source_ewidth = tile_ewidth (source);
|
|
|
|
gint source_eheight = tile_eheight (source);
|
|
|
|
gint dest_ewidth = tile_ewidth (dest);
|
|
|
|
gint bpp = tile_bpp (dest);
|
|
|
|
gint y;
|
|
|
|
|
|
|
|
/* Adjust dest pointer to the right quadrant. */
|
|
|
|
dest_data += i * bpp * (TILE_WIDTH / 2) +
|
|
|
|
j * bpp * dest_ewidth * (TILE_HEIGHT / 2);
|
|
|
|
|
|
|
|
for (y = 0; y < source_eheight / 2; y++)
|
|
|
|
{
|
|
|
|
gint x;
|
|
|
|
guchar *dst = dest_data + y * dest_ewidth * bpp;
|
|
|
|
const guchar *src = source_data + y * 2 * source_ewidth * bpp;
|
|
|
|
|
|
|
|
for (x = 0; x < source_ewidth / 2; x++)
|
|
|
|
{
|
2007-06-06 13:59:41 +00:00
|
|
|
gint i;
|
|
|
|
|
2007-06-06 13:45:44 +00:00
|
|
|
for (i = 0; i < bpp; i++)
|
|
|
|
dst[i] = (src[i] +
|
|
|
|
src[i + bpp] +
|
|
|
|
src[i + source_ewidth * bpp] +
|
|
|
|
src[i + source_ewidth * bpp + bpp]) / 4;
|
|
|
|
|
|
|
|
dst += bpp;
|
|
|
|
src += bpp * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_projection_validate_pyramid_tile (TileManager *tm,
|
|
|
|
Tile *tile)
|
|
|
|
{
|
|
|
|
gint tile_col;
|
|
|
|
gint tile_row;
|
|
|
|
gint i;
|
|
|
|
gint j;
|
|
|
|
TileManager *level_below = tile_manager_get_level_below (tm);
|
|
|
|
Tile *source[2][2] = { { NULL, NULL },
|
|
|
|
{ NULL, NULL } };
|
|
|
|
|
|
|
|
tile_manager_get_tile_col_row (tm, tile, &tile_col, &tile_row);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
for (j = 0; j < 2; j++)
|
|
|
|
source[i][j] = tile_manager_get_at (level_below,
|
|
|
|
tile_col * 2 + i,
|
|
|
|
tile_row * 2 + j,
|
|
|
|
TRUE,
|
|
|
|
FALSE);
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
for (j = 0; j < 2; j++)
|
|
|
|
if (source[i][j])
|
|
|
|
{
|
|
|
|
gimp_projection_write_quarter (tile, source[i][j], i, j);
|
|
|
|
|
|
|
|
tile_release (source[i][j], FALSE);
|
|
|
|
}
|
|
|
|
}
|
2004-07-13 16:36:29 +00:00
|
|
|
|
|
|
|
/* image callbacks */
|
|
|
|
|
|
|
|
static void
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_image_update (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_add_update_area (proj, x, y, w, h);
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
2004-07-13 16:36:29 +00:00
|
|
|
|
|
|
|
static void
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_image_size_changed (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
gimp_projection_alloc_levels (proj);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_image_mode_changed (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
2007-06-06 13:45:44 +00:00
|
|
|
gimp_projection_alloc_levels (proj);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
|
2004-07-13 16:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_projection_image_flush (GimpImage *image,
|
2004-07-13 16:36:29 +00:00
|
|
|
GimpProjection *proj)
|
|
|
|
{
|
|
|
|
gimp_projection_flush (proj);
|
|
|
|
}
|