2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-04 02:38:56 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-07-28 00:39:00 +08:00
|
|
|
#include <glib-object.h>
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-10-16 20:24:58 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "xcf-read.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-05-30 22:37:35 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
guint
|
2003-09-10 18:40:57 +08:00
|
|
|
xcf_read_int32 (FILE *fp,
|
2006-04-12 20:49:29 +08:00
|
|
|
guint32 *data,
|
|
|
|
gint count)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
guint total = 0;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
total += xcf_read_int8 (fp, (guint8 *) data, count * 4);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
*data = g_ntohl (*data);
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 23:12:43 +08:00
|
|
|
return total;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2003-09-10 18:40:57 +08:00
|
|
|
xcf_read_float (FILE *fp,
|
2006-04-12 20:49:29 +08:00
|
|
|
gfloat *data,
|
|
|
|
gint count)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2003-09-10 18:40:57 +08:00
|
|
|
return xcf_read_int32 (fp, (guint32 *) ((void *) data), count);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2003-09-10 18:40:57 +08:00
|
|
|
xcf_read_int8 (FILE *fp,
|
2006-04-12 20:49:29 +08:00
|
|
|
guint8 *data,
|
|
|
|
gint count)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
guint total = 0;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
gint bytes = fread ((char *) data, sizeof (char), count, fp);
|
2006-07-11 00:40:26 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
if (bytes <= 0) /* something bad happened */
|
|
|
|
break;
|
2006-07-11 00:40:26 +08:00
|
|
|
|
2007-07-05 23:12:43 +08:00
|
|
|
total += bytes;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
count -= bytes;
|
|
|
|
data += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2003-09-10 18:40:57 +08:00
|
|
|
xcf_read_string (FILE *fp,
|
2006-04-12 20:49:29 +08:00
|
|
|
gchar **data,
|
|
|
|
gint count)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2006-07-11 00:40:26 +08:00
|
|
|
guint total = 0;
|
|
|
|
gint i;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2006-07-11 00:40:26 +08:00
|
|
|
guint32 tmp;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
total += xcf_read_int32 (fp, &tmp, 1);
|
2006-07-11 00:40:26 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
if (tmp > 0)
|
|
|
|
{
|
2002-05-30 22:37:35 +08:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = g_new (gchar, tmp);
|
|
|
|
total += xcf_read_int8 (fp, (guint8*) str, tmp);
|
|
|
|
|
|
|
|
if (str[tmp - 1] != '\0')
|
|
|
|
str[tmp - 1] = '\0';
|
|
|
|
|
2003-10-16 20:24:58 +08:00
|
|
|
data[i] = gimp_any_to_utf8 (str, -1,
|
|
|
|
_("Invalid UTF-8 string in XCF file"));
|
2002-05-30 22:37:35 +08:00
|
|
|
|
2003-10-16 20:24:58 +08:00
|
|
|
g_free (str);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|