2000-02-26 11:41:06 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2000-05-27 06:28:40 +08:00
|
|
|
* gimpparasite.c
|
1998-10-08 16:15:21 +08:00
|
|
|
* Copyright (C) 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-10-08 16:15:21 +08:00
|
|
|
* 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.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-10-08 16:15:21 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
#include <stdio.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1998-11-06 08:51:39 +08:00
|
|
|
#include <unistd.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#endif
|
1998-10-08 16:15:21 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-03-07 20:56:03 +08:00
|
|
|
#include <process.h> /* For _getpid() */
|
|
|
|
#endif
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimptypes.h"
|
|
|
|
|
2000-05-27 09:30:21 +08:00
|
|
|
#include "gimpparasite.h"
|
2000-06-01 05:16:11 +08:00
|
|
|
#include "gimpparasite_pdb.h"
|
2000-05-27 09:30:21 +08:00
|
|
|
|
|
|
|
|
1998-12-22 14:03:53 +08:00
|
|
|
#ifdef DEBUG
|
2000-01-11 07:27:25 +08:00
|
|
|
static void
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_print (GimpParasite *parasite)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite == NULL)
|
2000-02-12 10:16:59 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
g_print ("pid %d: attempt to print a null parasite\n", getpid ());
|
2000-02-12 10:16:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
g_print ("pid %d: parasite: %p\n", getpid (), parasite);
|
|
|
|
|
|
|
|
if (parasite->name)
|
|
|
|
g_print ("\tname: %s\n", parasite->name);
|
1998-10-30 18:21:33 +08:00
|
|
|
else
|
2000-05-27 06:28:40 +08:00
|
|
|
g_print ("\tname: NULL\n");
|
|
|
|
|
|
|
|
g_print ("\tflags: %d\n", parasite->flags);
|
|
|
|
g_print ("\tsize: %d\n", parasite->size);
|
|
|
|
if (parasite->size > 0)
|
|
|
|
g_print ("\tdata: %p\n", parasite->data);
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
1998-12-22 14:03:53 +08:00
|
|
|
#endif
|
1998-10-30 18:21:33 +08:00
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *
|
|
|
|
gimp_parasite_new (const gchar *name,
|
|
|
|
guint32 flags,
|
|
|
|
guint32 size,
|
|
|
|
const gpointer data)
|
1998-10-08 16:15:21 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
parasite = g_new (GimpParasite, 1);
|
|
|
|
parasite->name = g_strdup (name);
|
|
|
|
parasite->flags = (flags & 0xFF);
|
|
|
|
parasite->size = size;
|
1998-10-08 16:15:21 +08:00
|
|
|
if (size)
|
2000-05-27 06:28:40 +08:00
|
|
|
parasite->data = g_memdup (data, size);
|
1998-10-08 16:15:21 +08:00
|
|
|
else
|
2000-05-27 06:28:40 +08:00
|
|
|
parasite->data = NULL;
|
|
|
|
|
|
|
|
return parasite;
|
1998-10-08 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_free (GimpParasite *parasite)
|
1998-10-08 16:15:21 +08:00
|
|
|
{
|
1998-11-13 12:00:54 +08:00
|
|
|
if (parasite == NULL)
|
|
|
|
return;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
1998-10-14 10:54:02 +08:00
|
|
|
if (parasite->name)
|
2000-01-11 07:27:25 +08:00
|
|
|
g_free (parasite->name);
|
1998-10-08 16:15:21 +08:00
|
|
|
if (parasite->data)
|
2000-01-11 07:27:25 +08:00
|
|
|
g_free (parasite->data);
|
2000-05-27 06:28:40 +08:00
|
|
|
|
2000-01-11 07:27:25 +08:00
|
|
|
g_free (parasite);
|
1998-10-08 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
gboolean
|
|
|
|
gimp_parasite_is_type (const GimpParasite *parasite,
|
|
|
|
const gchar *name)
|
1998-10-08 16:15:21 +08:00
|
|
|
{
|
1998-10-30 18:21:33 +08:00
|
|
|
if (!parasite || !parasite->name)
|
1998-10-08 16:15:21 +08:00
|
|
|
return FALSE;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return (strcmp (parasite->name, name) == 0);
|
1998-10-08 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *
|
|
|
|
gimp_parasite_copy (const GimpParasite *parasite)
|
1998-10-08 16:15:21 +08:00
|
|
|
{
|
|
|
|
if (parasite == NULL)
|
|
|
|
return NULL;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return gimp_parasite_new (parasite->name, parasite->flags,
|
|
|
|
parasite->size, parasite->data);
|
1998-10-08 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
gboolean
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_compare (const GimpParasite *a,
|
|
|
|
const GimpParasite *b)
|
1999-02-16 16:53:54 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (a && b &&
|
|
|
|
a->name && b->name &&
|
|
|
|
strcmp (a->name, b->name) == 0 &&
|
|
|
|
a->flags == b->flags &&
|
|
|
|
a->size == b->size)
|
1999-03-20 12:41:59 +08:00
|
|
|
{
|
|
|
|
if (a->data == NULL && b->data == NULL)
|
|
|
|
return TRUE;
|
2000-05-27 06:28:40 +08:00
|
|
|
else if (a->data && b->data && memcmp (a->data, b->data, a->size) == 0)
|
1999-03-20 12:41:59 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2000-05-27 06:28:40 +08:00
|
|
|
|
1999-02-16 16:53:54 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-04-12 06:28:51 +08:00
|
|
|
gulong
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_flags (const GimpParasite *parasite)
|
1999-04-12 06:28:51 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite == NULL)
|
1999-04-12 06:28:51 +08:00
|
|
|
return 0;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return parasite->flags;
|
1999-04-12 06:28:51 +08:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
gboolean
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_is_persistent (const GimpParasite *parasite)
|
1998-10-08 16:15:21 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite == NULL)
|
1998-10-08 16:15:21 +08:00
|
|
|
return FALSE;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return (parasite->flags & GIMP_PARASITE_PERSISTENT);
|
1998-12-16 19:23:30 +08:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
gboolean
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_is_undoable (const GimpParasite *parasite)
|
1999-04-23 14:07:09 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite == NULL)
|
1999-04-23 14:07:09 +08:00
|
|
|
return FALSE;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return (parasite->flags & GIMP_PARASITE_UNDOABLE);
|
1999-04-23 14:07:09 +08:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
gboolean
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_has_flag (const GimpParasite *parasite,
|
|
|
|
gulong flag)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite == NULL)
|
1998-12-16 19:23:30 +08:00
|
|
|
return FALSE;
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
return (parasite->flags & flag);
|
1998-12-16 19:23:30 +08:00
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
const gchar *
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_name (const GimpParasite *parasite)
|
1999-02-16 16:53:54 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite)
|
|
|
|
return parasite->name;
|
|
|
|
|
1999-02-16 16:53:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-06-01 05:16:11 +08:00
|
|
|
gpointer
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_data (const GimpParasite *parasite)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite)
|
|
|
|
return parasite->data;
|
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-12 10:16:59 +08:00
|
|
|
glong
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_data_size (const GimpParasite *parasite)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
if (parasite)
|
|
|
|
return parasite->size;
|
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
return 0;
|
1998-10-08 16:15:21 +08:00
|
|
|
}
|
2000-06-01 05:16:11 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_attach_new_parasite (const gchar *name,
|
|
|
|
gint flags,
|
|
|
|
gint size,
|
|
|
|
const gpointer data)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = gimp_parasite_new (name, flags, size, data);
|
|
|
|
|
|
|
|
gimp_parasite_attach (parasite);
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_attach_new_parasite (gint32 drawable,
|
|
|
|
const gchar *name,
|
|
|
|
gint flags,
|
|
|
|
gint size,
|
|
|
|
const gpointer data)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = gimp_parasite_new (name, flags, size, data);
|
|
|
|
|
|
|
|
gimp_drawable_parasite_attach (drawable, parasite);
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_attach_new_parasite (gint32 image_ID,
|
|
|
|
const gchar *name,
|
|
|
|
gint flags,
|
|
|
|
gint size,
|
|
|
|
const gpointer data)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = gimp_parasite_new (name, flags, size, data);
|
|
|
|
|
|
|
|
gimp_image_parasite_attach (image_ID, parasite);
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|