filters

xcf-write.cpp
1/* The GIMP -- an image manipulation program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "config.h"
20
21#include <stdio.h>
22#include <string.h> /* strlen */
23#include <errno.h>
24
25#ifdef HAVE_SYS_TYPES_H
26#include <sys/types.h>
27#endif
28
29#include <netinet/in.h>
30#include <limits.h>
31#include <stdlib.h>
32#include <cfloat>
33
34#include "xcf-write.h"
35
36TQ_UINT32 xcf_write_int32 (FILE *fp, TQ_INT32 *data, TQ_INT32 count);
37{
38 TQ_INT32 tmp;
39 TQ_INT32 i;
40
41 if (count > 0)
42 {
43 for (i = 0; i < count; i++)
44 {
45 tmp = htonl (data[i]);
46 xcf_write_int8 (fp, (TQ_UINT8*) &tmp, 4);
47
48 if (fp->status() != IO_Ok)
49 {
50 return i * 4;
51 }
52 }
53 }
54
55 return count * 4;
56}
57
58TQ_UINT32 xcf_write_float (FILE *fp, float *data, TQ_INT32 count);
59{
60 return xcf_write_int32 (fp, (TQ_INT32 *)((void *)data), count, error);
61}
62
63TQ_UINT32 xcf_write_int8 (FILE *fp, TQ_UINT8 *data, TQ_INT32 count);
64{
65 TQ_INT32 bytes;
66 bytes = fp->writeBlock( data, count );
67 return bytes;
68}
69
70TQ_UINT32 xcf_write_string (FILE *fp, TQCString *data, TQ_INT32 count);
71{
72 GError *tmp_error = NULL;
73 TQ_INT32 tmp;
74 TQ_UINT32 total;
75 TQ_INT32 i;
76
77 total = 0;
78 for (i = 0; i < count; i++)
79 {
80 if (data[i])
81 tmp = strlen (data[i]) + 1;
82 else
83 tmp = 0;
84
85 xcf_write_int32 (fp, &tmp, 1, &tmp_error);
86 if (tmp_error)
87 {
88 g_propagate_error (error, tmp_error);
89 return total;
90 }
91
92 if (tmp > 0)
93 xcf_write_int8 (fp, (TQ_UINT8*) data[i], tmp, &tmp_error);
94 if (tmp_error)
95 {
96 g_propagate_error (error, tmp_error);
97 return total;
98 }
99
100 total += 4 + tmp;
101 }
102
103 return total;
104}