2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-01-22 03:53:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-01-22 03:53:56 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-01-22 03:53:56 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-01-22 03:53:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-11-21 05:24:33 +08:00
|
|
|
#include <errno.h>
|
2005-02-07 09:24:22 +08:00
|
|
|
|
2001-01-22 03:53:56 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2005-02-07 09:24:22 +08:00
|
|
|
#include <glib/gstdio.h>
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2003-10-16 20:24:58 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-01-22 03:53:56 +08:00
|
|
|
|
|
|
|
#include "gimppalette.h"
|
2006-10-03 21:22:12 +08:00
|
|
|
#include "gimppalette-save.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-01-22 03:53:56 +08:00
|
|
|
|
|
|
|
|
2006-10-03 21:22:12 +08:00
|
|
|
gboolean
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_palette_save (GimpData *data,
|
|
|
|
GError **error)
|
2001-02-12 00:14:25 +08:00
|
|
|
{
|
2004-01-30 00:19:57 +08:00
|
|
|
GimpPalette *palette = GIMP_PALETTE (data);
|
|
|
|
GList *list;
|
|
|
|
FILE *file;
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2009-10-31 22:24:57 +08:00
|
|
|
file = g_fopen (gimp_data_get_filename (data), "wb");
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
if (! file)
|
2001-01-22 03:53:56 +08:00
|
|
|
{
|
2002-12-02 21:39:09 +08:00
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
|
|
|
|
_("Could not open '%s' for writing: %s"),
|
2009-10-31 22:24:57 +08:00
|
|
|
gimp_filename_to_utf8 (gimp_data_get_filename (data)),
|
2004-06-30 19:09:44 +08:00
|
|
|
g_strerror (errno));
|
2001-01-22 03:53:56 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "GIMP Palette\n");
|
2009-08-29 18:40:40 +08:00
|
|
|
fprintf (file, "Name: %s\n", gimp_object_get_name (palette));
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256));
|
2001-01-22 03:53:56 +08:00
|
|
|
|
|
|
|
for (list = palette->colors; list; list = g_list_next (list))
|
|
|
|
{
|
2004-01-30 00:19:57 +08:00
|
|
|
GimpPaletteEntry *entry = list->data;
|
|
|
|
guchar r, g, b;
|
2001-01-22 03:53:56 +08:00
|
|
|
|
|
|
|
gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
fprintf (file, "%3d %3d %3d\t%s\n", r, g, b, entry->name);
|
2001-01-22 03:53:56 +08:00
|
|
|
}
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
fclose (file);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|