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;
|
2004-02-16 06:18:17 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bpp;
|
|
|
|
|
|
|
|
width = gimp_drawable_width (drawable_ID);
|
|
|
|
height = gimp_drawable_height (drawable_ID);
|
|
|
|
bpp = gimp_drawable_bpp (drawable_ID);
|
|
|
|
|
|
|
|
g_return_val_if_fail (width > 0 && height > 0 && bpp > 0, NULL);
|
|
|
|
|
|
|
|
drawable = g_new0 (GimpDrawable, 1);
|
2000-05-31 14:15:06 +08:00
|
|
|
|
2001-06-15 04:07:38 +08:00
|
|
|
drawable->drawable_id = drawable_ID;
|
2004-02-16 06:18:17 +08:00
|
|
|
drawable->width = width;
|
|
|
|
drawable->height = height;
|
|
|
|
drawable->bpp = bpp;
|
|
|
|
drawable->ntile_rows = (height + TILE_HEIGHT - 1) / TILE_HEIGHT;
|
|
|
|
drawable->ntile_cols = (width + TILE_WIDTH - 1) / TILE_WIDTH;
|
2000-05-31 14:15:06 +08:00
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_detach (GimpDrawable *drawable)
|
|
|
|
{
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_if_fail (drawable != NULL);
|
2003-12-04 01:47:15 +08:00
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
gimp_drawable_flush (drawable);
|
2003-12-04 01:47:15 +08:00
|
|
|
|
2004-02-17 05:57:01 +08:00
|
|
|
/* nuke all references to this drawable from the cache */
|
|
|
|
_gimp_tile_cache_flush_drawable (drawable);
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
if (drawable->tiles)
|
|
|
|
g_free (drawable->tiles);
|
|
|
|
if (drawable->shadow_tiles)
|
|
|
|
g_free (drawable->shadow_tiles);
|
|
|
|
|
|
|
|
g_free (drawable);
|
2000-05-31 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_flush (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GimpTile *tiles;
|
2003-12-04 01:47:15 +08:00
|
|
|
gint n_tiles;
|
|
|
|
gint i;
|
2000-05-31 14:15:06 +08:00
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_if_fail (drawable != NULL);
|
|
|
|
|
|
|
|
if (drawable->tiles)
|
2000-05-31 14:15:06 +08:00
|
|
|
{
|
2004-02-16 06:18:17 +08:00
|
|
|
tiles = drawable->tiles;
|
|
|
|
n_tiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
|
|
|
|
for (i = 0; i < n_tiles; i++)
|
|
|
|
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
|
|
|
|
gimp_tile_flush (&tiles[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawable->shadow_tiles)
|
|
|
|
{
|
|
|
|
tiles = drawable->shadow_tiles;
|
|
|
|
n_tiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
|
|
|
|
for (i = 0; i < n_tiles; i++)
|
|
|
|
if ((tiles[i].ref_count > 0) && tiles[i].dirty)
|
|
|
|
gimp_tile_flush (&tiles[i]);
|
2000-05-31 14:15:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpTile *
|
|
|
|
gimp_drawable_get_tile (GimpDrawable *drawable,
|
|
|
|
gboolean shadow,
|
|
|
|
gint row,
|
|
|
|
gint col)
|
|
|
|
{
|
|
|
|
GimpTile *tiles;
|
2003-12-04 01:47:15 +08:00
|
|
|
guint right_tile;
|
|
|
|
guint bottom_tile;
|
|
|
|
gint n_tiles;
|
|
|
|
gint tile_num;
|
|
|
|
gint i, j, k;
|
2000-05-31 14:15:06 +08:00
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_val_if_fail (drawable != NULL, NULL);
|
|
|
|
|
|
|
|
if (shadow)
|
|
|
|
tiles = drawable->shadow_tiles;
|
|
|
|
else
|
|
|
|
tiles = drawable->tiles;
|
|
|
|
|
|
|
|
if (! tiles)
|
2000-05-31 14:15:06 +08:00
|
|
|
{
|
2004-02-16 06:18:17 +08:00
|
|
|
n_tiles = drawable->ntile_rows * drawable->ntile_cols;
|
|
|
|
tiles = g_new (GimpTile, n_tiles);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-31 14:15:06 +08:00
|
|
|
if (shadow)
|
2004-02-16 06:18:17 +08:00
|
|
|
drawable->shadow_tiles = tiles;
|
2000-05-31 14:15:06 +08:00
|
|
|
else
|
2004-02-16 06:18:17 +08:00
|
|
|
drawable->tiles = tiles;
|
2000-05-31 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
tile_num = row * drawable->ntile_cols + col;
|
|
|
|
|
|
|
|
return &tiles[tile_num];
|
2000-05-31 14:15:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpTile *
|
|
|
|
gimp_drawable_get_tile2 (GimpDrawable *drawable,
|
|
|
|
gint shadow,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
gint row;
|
|
|
|
gint col;
|
|
|
|
|
2004-02-16 06:18:17 +08:00
|
|
|
g_return_val_if_fail (drawable != NULL, NULL);
|
|
|
|
|
2000-05-31 14:15:06 +08:00
|
|
|
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
|
|
|
|
2004-03-13 06:46:25 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_get_color_uchar (gint32 drawable_ID,
|
|
|
|
const GimpRGB *color,
|
|
|
|
guchar *color_uchar)
|
|
|
|
{
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
g_return_if_fail (color_uchar != NULL);
|
|
|
|
|
|
|
|
switch (gimp_drawable_type (drawable_ID))
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
gimp_rgb_get_uchar (color,
|
|
|
|
&color_uchar[0], &color_uchar[1], &color_uchar[2]);
|
|
|
|
color_uchar[3] = 255;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
gimp_rgba_get_uchar (color,
|
|
|
|
&color_uchar[0], &color_uchar[1], &color_uchar[2],
|
|
|
|
&color_uchar[3]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
color_uchar[0] = gimp_rgb_intensity_uchar (color);
|
|
|
|
color_uchar[1] = 255;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
color_uchar[0] = gimp_rgb_intensity_uchar (color);
|
|
|
|
gimp_rgba_get_uchar (color, NULL, NULL, NULL, &color_uchar[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|