2000-05-31 14:15:06 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpdrawable.c
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
2000-05-31 14:15:06 +08:00
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2000-05-31 21:24:14 +08:00
|
|
|
|
Changed the semantics of GIMP_EXTENSION and (to some extent) of
2003-06-19 Michael Natterer <mitch@gimp.org>
Changed the semantics of GIMP_EXTENSION and (to some extent)
of GIMP_PLUGIN:
The old meaning of EXTENSION was "I live in the toolbox" and
PLUGIN meant "I take RUN-MODE,IMAGE,DRAWABLE args (but only if I
am invoked interactively)". This is completely useless, since
living in the toolbox means having "<Toolbox>" in the menu_path
and taking RUN-MODE,IMAGE,DRAWABLE means just that, regardless of
what type of procedure we are.
The new meaning of GIMP_PLUGIN is just "I am an ordinary procedure,
I am invoked, do my job and finish", while GIMP_EXTENSION means
"I will install temporary procedures and I will keep running to
keep them available".
(A GIMP_EXTENSION *must* call gimp_extension_ack() now to tell the
core that it's ready to run, or the core will block waiting for
the message !!!).
* configure.in: bumped version number to 1.3.16.
* libgimpbase/gimpprotocol.h: increased protocol version number so
old extensions will refuse to load.
* app/gui/plug-in-commands.c (plug_in_run_cmd_callback): don't
blindly pass RUN-MODE,IMAGE,DRAWABLE to GIMP_PLUGIN procedures but
look at their parameters and pass them either RUN-MODE, or
RUN-MODE,IMAGE, or RUN-MODE,IMAGE,DRAWABLE.
* app/pdb/procedural_db.c: cleaned up, better error reporting,
replaced an impossible error message by g_return_if_fail()
* app/plug-in/plug-in-message.c (plug_in_handle_proc_install):
better error messages.
* app/plug-in/plug-in-params.c: allocate parameter arrays using
g_new0() so we don't have to worry about uninitialized stuff
later.
* app/plug-in/plug-in-run.c (plug_in_run): wait for
gimp_extension_ack() installation confirmation for ALL extensions,
not just for automatically started ones.
* app/plug-in/plug-ins.c: cleanup.
* libgimp/gimp.[ch]: cleaned up and API-documented massively. Made
all magic values given in the GPConfig message static and added
accessor functions for them. Added gimp_tile_width()/height().
Added new function gimp_extension_enable() which turns on
asynchronous processing of temp_proc run requests without having
to enter an endless gimp_extension_process() loop. Moved all
private functions to the end of the file. Added tons of
g_return_if_fail() all over the place. Call gimp_run_procedure2()
from gimp_run_procedure() instead of duplicating the
code. Indentation, spacing, stuff...
* libgimp/gimptile.[ch]: removed gimp_tile_width()/height().
* libgimp/gimpdrawable.c
* libgimp/gimppixelrgn.c
* libgimp/gimptile.c: use the gimp_tile_width()/height() accessor
functions.
* libgimp/gimp.def: added gimp_extension_enable.
* libgimp/gimpmenu.c: removed evil code which connected to
_readchannel manually and use gimp_extension_enable() for watching
temp_procs.
* plug-ins/helpbrowser/helpbrowser.c: removed the same evil code
here and call gimp_extension_enable(). Call gimp_extension_ack()
to let the core know that the temp_proc is installed.
* plug-ins/script-fu/script-fu.c: made all procedures except the
permanently running "extension_script_fu" ordinary GIMP_PLUGIN
procedures.
* plug-ins/common/curve_bend.c
* plug-ins/common/plugindetails.c
* plug-ins/common/screenshot.c
* plug-ins/common/uniteditor.c
* plug-ins/common/winclipboard.c
* plug-ins/dbbrowser/dbbrowser.c
* plug-ins/gfli/gfli.c
* plug-ins/twain/twain.c
* plug-ins/webbrowser/webbrowser.c
* plug-ins/winsnap/winsnap.c: made them all ordinary GIMP_PLUGIN
procedures and renamed them from "extension_*" to "plug_in_*".
Random cleanups.
* app/widgets/gimphelp.c
* plug-ins/maze/maze_face.c: call "plug_in_web_browser" now.
2003-06-20 01:12:00 +08:00
|
|
|
#define TILE_WIDTH gimp_tile_width()
|
|
|
|
#define TILE_HEIGHT gimp_tile_height()
|
2000-05-31 14:15:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
GimpDrawable *
|
|
|
|
gimp_drawable_get (gint32 drawable_ID)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
drawable = g_new (GimpDrawable, 1);
|
2001-06-15 04:07:38 +08:00
|
|
|
drawable->drawable_id = drawable_ID;
|
2000-05-31 14:15:06 +08:00
|
|
|
drawable->width = gimp_drawable_width (drawable_ID);
|
|
|
|
drawable->height = gimp_drawable_height (drawable_ID);
|
|
|
|
drawable->bpp = gimp_drawable_bpp (drawable_ID);
|
|
|
|
drawable->ntile_rows = (drawable->height + TILE_HEIGHT - 1) / TILE_HEIGHT;
|
|
|
|
drawable->ntile_cols = (drawable->width + TILE_WIDTH - 1) / TILE_WIDTH;
|
|
|
|
drawable->tiles = NULL;
|
|
|
|
drawable->shadow_tiles = NULL;
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_detach (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
if (drawable)
|
|
|
|
{
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
if (drawable->tiles)
|
|
|
|
g_free (drawable->tiles);
|
|
|
|
if (drawable->shadow_tiles)
|
|
|
|
g_free (drawable->shadow_tiles);
|
|
|
|
g_free (drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_flush (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GimpTile *tiles;
|
|
|
|
gint ntiles;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (drawable)
|
|
|
|
{
|
|
|
|
if (drawable->tiles)
|
|
|
|
{
|
|
|
|
tiles = drawable->tiles;
|
|
|
|
ntiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
|
|
|
|
for (i = 0; i < ntiles; i++)
|
|
|
|
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
|
|
|
|
gimp_tile_flush (&tiles[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawable->shadow_tiles)
|
|
|
|
{
|
|
|
|
tiles = drawable->shadow_tiles;
|
|
|
|
ntiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
|
|
|
|
for (i = 0; i < ntiles; i++)
|
|
|
|
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
|
|
|
|
gimp_tile_flush (&tiles[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_delete (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
if (drawable)
|
|
|
|
{
|
2001-06-15 04:07:38 +08:00
|
|
|
if (gimp_drawable_is_layer (drawable->drawable_id))
|
|
|
|
gimp_layer_delete (drawable->drawable_id);
|
2000-05-31 14:15:06 +08:00
|
|
|
else
|
2001-06-15 04:07:38 +08:00
|
|
|
gimp_channel_delete (drawable->drawable_id);
|
2000-05-31 14:15:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpTile *
|
|
|
|
gimp_drawable_get_tile (GimpDrawable *drawable,
|
|
|
|
gboolean shadow,
|
|
|
|
gint row,
|
|
|
|
gint col)
|
|
|
|
{
|
|
|
|
GimpTile *tiles;
|
|
|
|
guint right_tile;
|
|
|
|
guint bottom_tile;
|
|
|
|
gint ntiles;
|
|
|
|
gint tile_num;
|
|
|
|
gint i, j, k;
|
|
|
|
|
|
|
|
if (drawable)
|
|
|
|
{
|
|
|
|
if (shadow)
|
|
|
|
tiles = drawable->shadow_tiles;
|
|
|
|
else
|
|
|
|
tiles = drawable->tiles;
|
|
|
|
|
|
|
|
if (!tiles)
|
|
|
|
{
|
|
|
|
ntiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
tiles = g_new (GimpTile, ntiles);
|
|
|
|
|
|
|
|
right_tile = drawable->width - ((drawable->ntile_cols - 1) * TILE_WIDTH);
|
|
|
|
bottom_tile = drawable->height - ((drawable->ntile_rows - 1) * TILE_HEIGHT);
|
|
|
|
|
|
|
|
for (i = 0, k = 0; i < drawable->ntile_rows; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < drawable->ntile_cols; j++, k++)
|
|
|
|
{
|
|
|
|
tiles[k].bpp = drawable->bpp;
|
|
|
|
tiles[k].tile_num = k;
|
|
|
|
tiles[k].ref_count = 0;
|
|
|
|
tiles[k].dirty = FALSE;
|
|
|
|
tiles[k].shadow = shadow;
|
|
|
|
tiles[k].data = NULL;
|
|
|
|
tiles[k].drawable = drawable;
|
|
|
|
|
|
|
|
if (j == (drawable->ntile_cols - 1))
|
|
|
|
tiles[k].ewidth = right_tile;
|
|
|
|
else
|
|
|
|
tiles[k].ewidth = TILE_WIDTH;
|
|
|
|
|
|
|
|
if (i == (drawable->ntile_rows - 1))
|
|
|
|
tiles[k].eheight = bottom_tile;
|
|
|
|
else
|
|
|
|
tiles[k].eheight = TILE_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow)
|
|
|
|
drawable->shadow_tiles = tiles;
|
|
|
|
else
|
|
|
|
drawable->tiles = tiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
tile_num = row * drawable->ntile_cols + col;
|
|
|
|
return &tiles[tile_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpTile *
|
|
|
|
gimp_drawable_get_tile2 (GimpDrawable *drawable,
|
|
|
|
gint shadow,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
|
|
|
|
col = x / TILE_WIDTH;
|
|
|
|
row = y / TILE_HEIGHT;
|
|
|
|
|
|
|
|
return gimp_drawable_get_tile (drawable, shadow, row, col);
|
|
|
|
}
|
2000-06-01 22:59:22 +08:00
|
|
|
|
|
|
|
guchar *
|
|
|
|
gimp_drawable_get_thumbnail_data (gint32 drawable_ID,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *bpp)
|
|
|
|
{
|
|
|
|
gint ret_width;
|
|
|
|
gint ret_height;
|
|
|
|
guchar *image_data;
|
|
|
|
gint data_size;
|
|
|
|
|
|
|
|
_gimp_drawable_thumbnail (drawable_ID,
|
|
|
|
*width,
|
|
|
|
*height,
|
|
|
|
&ret_width,
|
|
|
|
&ret_height,
|
|
|
|
bpp,
|
|
|
|
&data_size,
|
|
|
|
&image_data);
|
|
|
|
|
|
|
|
*width = ret_width;
|
|
|
|
*height = ret_height;
|
|
|
|
|
|
|
|
return image_data;
|
|
|
|
}
|
2001-05-21 21:58:46 +08:00
|
|
|
|
2002-12-18 01:30:34 +08:00
|
|
|
/**
|
|
|
|
* gimp_drawable_attach_new_parasite:
|
|
|
|
* @drawable_ID: the ID of the #GimpDrawable to attach the #GimpParasite to.
|
|
|
|
* @name: the name of the #GimpParasite to create and attach.
|
|
|
|
* @flags: the flags set on the #GimpParasite.
|
|
|
|
* @size: the size of the parasite data in bytes.
|
|
|
|
* @data: a pointer to the data attached with the #GimpParasite.
|
|
|
|
*
|
|
|
|
* Convenience function that creates a parasite and attaches it
|
|
|
|
* to the GIMP.
|
|
|
|
*
|
|
|
|
* See Also: gimp_drawable_parasite_attach()
|
|
|
|
*/
|
2001-05-21 21:58:46 +08:00
|
|
|
void
|
2002-12-19 20:01:52 +08:00
|
|
|
gimp_drawable_attach_new_parasite (gint32 drawable_ID,
|
2003-12-04 00:39:32 +08:00
|
|
|
const gchar *name,
|
2001-05-21 21:58:46 +08:00
|
|
|
gint flags,
|
2003-12-04 00:39:32 +08:00
|
|
|
gint size,
|
2003-07-02 02:11:18 +08:00
|
|
|
gconstpointer data)
|
2001-05-21 21:58:46 +08:00
|
|
|
{
|
|
|
|
GimpParasite *parasite = gimp_parasite_new (name, flags, size, data);
|
|
|
|
|
2002-12-19 20:01:52 +08:00
|
|
|
gimp_drawable_parasite_attach (drawable_ID, parasite);
|
2001-05-21 21:58:46 +08:00
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|