1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include <glib-object.h>
27
#include "libgimpbase/gimpbase.h"
29
#include "core-types.h"
31
#include "gimpgradient.h"
32
#include "gimpgradient-save.h"
34
#include "gimp-intl.h"
38
gimp_gradient_save (GimpData *data,
41
GimpGradient *gradient = GIMP_GRADIENT (data);
42
GimpGradientSegment *seg;
46
file = fopen (data->filename, "wb");
50
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
51
_("Could not open '%s' for writing: %s"),
52
gimp_filename_to_utf8 (data->filename),
62
* left middle right r0 g0 b0 a0 r1 g1 b1 a1 type coloring
63
* left middle right r0 g0 b0 a0 r1 g1 b1 a1 type coloring
67
fprintf (file, "GIMP Gradient\n");
69
fprintf (file, "Name: %s\n", GIMP_OBJECT (gradient)->name);
71
/* Count number of segments */
73
seg = gradient->segments;
81
/* Write rest of file */
82
fprintf (file, "%d\n", num_segments);
84
for (seg = gradient->segments; seg; seg = seg->next)
86
gchar buf[11][G_ASCII_DTOSTR_BUF_SIZE];
88
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE,
90
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE,
92
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE,
94
g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE,
95
"%f", seg->left_color.r);
96
g_ascii_formatd (buf[4], G_ASCII_DTOSTR_BUF_SIZE,
97
"%f", seg->left_color.g);
98
g_ascii_formatd (buf[5], G_ASCII_DTOSTR_BUF_SIZE,
99
"%f", seg->left_color.b);
100
g_ascii_formatd (buf[6], G_ASCII_DTOSTR_BUF_SIZE,
101
"%f", seg->left_color.a);
102
g_ascii_formatd (buf[7], G_ASCII_DTOSTR_BUF_SIZE,
103
"%f", seg->right_color.r);
104
g_ascii_formatd (buf[8], G_ASCII_DTOSTR_BUF_SIZE,
105
"%f", seg->right_color.g);
106
g_ascii_formatd (buf[9], G_ASCII_DTOSTR_BUF_SIZE,
107
"%f", seg->right_color.b);
108
g_ascii_formatd (buf[10], G_ASCII_DTOSTR_BUF_SIZE,
109
"%f", seg->right_color.a);
111
fprintf (file, "%s %s %s %s %s %s %s %s %s %s %s %d %d\n",
112
buf[0], buf[1], buf[2], buf[3], buf[4],
113
buf[5], buf[6], buf[7], buf[8], buf[9], buf[10],
124
gimp_gradient_save_as_pov (GimpGradient *gradient,
125
const gchar *filename,
129
GimpGradientSegment *seg;
130
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
131
gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE];
133
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
134
g_return_val_if_fail (filename != NULL, FALSE);
135
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
137
file = fopen (filename, "wb");
141
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
142
_("Could not open '%s' for writing: %s"),
143
gimp_filename_to_utf8 (filename), g_strerror (errno));
148
fprintf (file, "/* color_map file created by the GIMP */\n");
149
fprintf (file, "/* http://www.gimp.org/ */\n");
151
fprintf (file, "color_map {\n");
153
for (seg = gradient->segments; seg; seg = seg->next)
156
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
158
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
160
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
162
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
164
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
165
1.0 - seg->left_color.a);
167
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
169
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
172
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
174
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
175
(seg->left_color.r + seg->right_color.r) / 2.0);
176
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
177
(seg->left_color.g + seg->right_color.g) / 2.0);
178
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
179
(seg->left_color.b + seg->right_color.b) / 2.0);
180
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
181
1.0 - (seg->left_color.a + seg->right_color.a) / 2.0);
183
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
185
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
188
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
190
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
192
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
194
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
196
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
197
1.0 - seg->right_color.a);
199
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
201
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
204
fprintf (file, "} /* color_map */\n");