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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-01-22 03:53:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2012-03-30 21:08:54 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2006-10-03 22:31:31 +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
|
|
|
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
#include "gimp-utils.h"
|
2001-01-22 03:53:56 +08:00
|
|
|
#include "gimppalette.h"
|
2006-10-03 21:22:12 +08:00
|
|
|
#include "gimppalette-load.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
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
|
2013-09-15 14:46:28 +08:00
|
|
|
GList *
|
2014-07-04 09:31:03 +08:00
|
|
|
gimp_palette_load (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2001-01-22 03:53:56 +08:00
|
|
|
{
|
2014-07-03 21:49:58 +08:00
|
|
|
GimpPalette *palette = NULL;
|
2004-06-13 06:28:13 +08:00
|
|
|
GimpPaletteEntry *entry;
|
2014-07-03 21:49:58 +08:00
|
|
|
GDataInputStream *data_input;
|
|
|
|
gchar *str;
|
|
|
|
gsize str_len;
|
2004-06-13 06:28:13 +08:00
|
|
|
gchar *tok;
|
|
|
|
gint r, g, b;
|
|
|
|
gint linenum;
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2014-07-03 22:11:26 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2002-12-02 21:39:09 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2014-07-03 22:11:26 +08:00
|
|
|
data_input = g_data_input_stream_new (input);
|
2014-07-03 21:49:58 +08:00
|
|
|
|
|
|
|
r = g = b = 0;
|
|
|
|
|
|
|
|
linenum = 1;
|
|
|
|
str_len = 1024;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
str = gimp_data_input_stream_read_line_always (data_input, &str_len,
|
|
|
|
NULL, error);
|
2014-07-03 21:49:58 +08:00
|
|
|
if (! str)
|
|
|
|
goto failed;
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (! g_str_has_prefix (str, "GIMP Palette"))
|
2006-10-05 01:50:35 +08:00
|
|
|
{
|
2014-07-05 00:46:02 +08:00
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2014-07-03 21:49:58 +08:00
|
|
|
_("Missing magic header."));
|
|
|
|
g_free (str);
|
|
|
|
goto failed;
|
2001-01-22 03:53:56 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 03:40:57 +08:00
|
|
|
g_free (str);
|
|
|
|
|
2005-05-26 07:25:45 +08:00
|
|
|
palette = g_object_new (GIMP_TYPE_PALETTE,
|
|
|
|
"mime-type", "application/x-gimp-palette",
|
|
|
|
NULL);
|
2001-02-12 00:14:25 +08:00
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 21:49:58 +08:00
|
|
|
str_len = 1024;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
str = gimp_data_input_stream_read_line_always (data_input, &str_len,
|
|
|
|
NULL, error);
|
2014-07-03 21:49:58 +08:00
|
|
|
if (! str)
|
|
|
|
goto failed;
|
2001-02-12 00:14:25 +08:00
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (g_str_has_prefix (str, "Name: "))
|
2001-02-12 00:14:25 +08:00
|
|
|
{
|
2003-10-16 20:24:58 +08:00
|
|
|
gchar *utf8;
|
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1,
|
2003-10-16 20:24:58 +08:00
|
|
|
_("Invalid UTF-8 string in palette file '%s'"),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2006-10-05 01:50:35 +08:00
|
|
|
gimp_object_take_name (GIMP_OBJECT (palette), utf8);
|
2014-07-03 21:49:58 +08:00
|
|
|
g_free (str);
|
2003-10-16 20:24:58 +08:00
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 21:49:58 +08:00
|
|
|
str_len = 1024;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
str = gimp_data_input_stream_read_line_always (data_input, &str_len,
|
|
|
|
NULL, error);
|
2014-07-03 21:49:58 +08:00
|
|
|
if (! str)
|
|
|
|
goto failed;
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (g_str_has_prefix (str, "Columns: "))
|
2004-06-30 19:09:44 +08:00
|
|
|
{
|
|
|
|
gint columns;
|
2001-02-13 02:05:12 +08:00
|
|
|
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtoi (g_strstrip (str + strlen ("Columns: ")),
|
|
|
|
NULL, 10, &columns))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid column count."));
|
|
|
|
g_free (str);
|
|
|
|
goto failed;
|
|
|
|
}
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
if (columns < 0 || columns > 256)
|
|
|
|
{
|
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"Invalid number of columns in line %d. "
|
2003-11-14 23:33:40 +08:00
|
|
|
"Using default value."),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file), linenum);
|
2004-06-30 19:09:44 +08:00
|
|
|
columns = 0;
|
|
|
|
}
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2010-10-27 20:36:44 +08:00
|
|
|
gimp_palette_set_columns (palette, columns);
|
2014-07-03 21:49:58 +08:00
|
|
|
g_free (str);
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 21:49:58 +08:00
|
|
|
str_len = 1024;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
str = gimp_data_input_stream_read_line_always (data_input, &str_len,
|
|
|
|
NULL, error);
|
2014-07-03 21:49:58 +08:00
|
|
|
if (! str)
|
|
|
|
goto failed;
|
2004-06-30 19:09:44 +08:00
|
|
|
}
|
2001-02-12 00:14:25 +08:00
|
|
|
}
|
|
|
|
else /* old palette format */
|
|
|
|
{
|
2006-04-07 18:51:22 +08:00
|
|
|
gimp_object_take_name (GIMP_OBJECT (palette),
|
2014-07-01 20:25:37 +08:00
|
|
|
g_path_get_basename (gimp_file_get_utf8_name (file)));
|
2001-02-12 00:14:25 +08:00
|
|
|
}
|
|
|
|
|
2014-07-03 21:49:58 +08:00
|
|
|
while (str)
|
2001-02-12 00:14:25 +08:00
|
|
|
{
|
2014-07-05 00:46:02 +08:00
|
|
|
GError *my_error = NULL;
|
|
|
|
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (str[0] != '#' && str[0] != '\0')
|
2004-06-30 19:09:44 +08:00
|
|
|
{
|
|
|
|
tok = strtok (str, " \t");
|
|
|
|
if (tok)
|
|
|
|
r = atoi (tok);
|
|
|
|
else
|
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"Missing RED component in line %d."),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file), linenum);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
tok = strtok (NULL, " \t");
|
|
|
|
if (tok)
|
|
|
|
g = atoi (tok);
|
|
|
|
else
|
2008-09-17 04:25:15 +08:00
|
|
|
g_message (_("Reading palette file '%s': "
|
2004-06-30 19:09:44 +08:00
|
|
|
"Missing GREEN component in line %d."),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file), linenum);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
tok = strtok (NULL, " \t");
|
|
|
|
if (tok)
|
|
|
|
b = atoi (tok);
|
|
|
|
else
|
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"Missing BLUE component in line %d."),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file), linenum);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
/* optional name */
|
|
|
|
tok = strtok (NULL, "\n");
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
if (r < 0 || r > 255 ||
|
|
|
|
g < 0 || g > 255 ||
|
|
|
|
b < 0 || b > 255)
|
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"RGB value out of range in line %d."),
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file), linenum);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-13 06:28:13 +08:00
|
|
|
/* don't call gimp_palette_add_entry here, it's rather inefficient */
|
2007-05-23 05:59:19 +08:00
|
|
|
entry = g_slice_new0 (GimpPaletteEntry);
|
2004-06-13 06:28:13 +08:00
|
|
|
|
2004-06-30 19:09:44 +08:00
|
|
|
gimp_rgba_set_uchar (&entry->color,
|
|
|
|
(guchar) r,
|
|
|
|
(guchar) g,
|
|
|
|
(guchar) b,
|
|
|
|
255);
|
2001-01-22 03:53:56 +08:00
|
|
|
|
2004-06-13 06:28:13 +08:00
|
|
|
entry->name = g_strdup (tok ? tok : _("Untitled"));
|
2010-10-27 20:36:44 +08:00
|
|
|
entry->position = gimp_palette_get_n_colors (palette);
|
2004-06-13 06:28:13 +08:00
|
|
|
|
|
|
|
palette->colors = g_list_prepend (palette->colors, entry);
|
|
|
|
palette->n_colors++;
|
2004-06-30 19:09:44 +08:00
|
|
|
}
|
2001-02-12 00:14:25 +08:00
|
|
|
|
2014-07-03 21:49:58 +08:00
|
|
|
g_free (str);
|
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 21:49:58 +08:00
|
|
|
str_len = 1024;
|
|
|
|
str = g_data_input_stream_read_line (data_input, &str_len,
|
|
|
|
NULL, &my_error);
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! str && my_error)
|
2004-06-30 19:09:44 +08:00
|
|
|
{
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"Read %d colors from truncated file: %s"),
|
|
|
|
gimp_file_get_utf8_name (file),
|
|
|
|
g_list_length (palette->colors),
|
|
|
|
my_error->message);
|
|
|
|
g_clear_error (&my_error);
|
2004-06-30 19:09:44 +08:00
|
|
|
}
|
2001-01-22 03:53:56 +08:00
|
|
|
}
|
|
|
|
|
2004-06-13 06:28:13 +08:00
|
|
|
palette->colors = g_list_reverse (palette->colors);
|
|
|
|
|
2014-07-03 21:49:58 +08:00
|
|
|
g_object_unref (data_input);
|
|
|
|
|
2004-07-27 03:00:22 +08:00
|
|
|
return g_list_prepend (NULL, palette);
|
2014-07-03 21:49:58 +08:00
|
|
|
|
|
|
|
failed:
|
|
|
|
|
|
|
|
g_object_unref (data_input);
|
|
|
|
|
|
|
|
if (palette)
|
|
|
|
g_object_unref (palette);
|
|
|
|
|
2014-07-05 00:46:02 +08:00
|
|
|
g_prefix_error (error, _("In line %d of palette file: "), linenum);
|
2014-07-03 21:49:58 +08:00
|
|
|
|
|
|
|
return NULL;
|
2001-01-22 03:53:56 +08:00
|
|
|
}
|
2006-10-03 22:31:31 +08:00
|
|
|
|
|
|
|
GList *
|
2014-07-03 22:42:37 +08:00
|
|
|
gimp_palette_load_act (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2006-10-03 22:31:31 +08:00
|
|
|
{
|
|
|
|
GimpPalette *palette;
|
|
|
|
gchar *palette_name;
|
2014-07-03 22:42:37 +08:00
|
|
|
guchar color_bytes[3];
|
|
|
|
gsize bytes_read;
|
2006-10-03 22:31:31 +08:00
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2018-06-10 13:43:57 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2006-10-03 22:31:31 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2010-04-11 01:55:42 +08:00
|
|
|
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
|
2006-10-03 22:31:31 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
2014-07-03 22:42:37 +08:00
|
|
|
while (g_input_stream_read_all (input, color_bytes, sizeof (color_bytes),
|
|
|
|
&bytes_read, NULL, NULL) &&
|
|
|
|
bytes_read == sizeof (color_bytes))
|
2006-10-03 22:31:31 +08:00
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_rgba_set_uchar (&color,
|
|
|
|
color_bytes[0],
|
|
|
|
color_bytes[1],
|
|
|
|
color_bytes[2],
|
|
|
|
255);
|
|
|
|
gimp_palette_add_entry (palette, -1, NULL, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_prepend (NULL, palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
2014-07-03 22:42:37 +08:00
|
|
|
gimp_palette_load_riff (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2006-10-03 22:31:31 +08:00
|
|
|
{
|
|
|
|
GimpPalette *palette;
|
|
|
|
gchar *palette_name;
|
|
|
|
guchar color_bytes[4];
|
2014-07-03 22:42:37 +08:00
|
|
|
gsize bytes_read;
|
2006-10-03 22:31:31 +08:00
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2018-06-10 13:43:57 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2006-10-03 22:31:31 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2010-04-11 01:55:42 +08:00
|
|
|
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
|
2006-10-03 22:31:31 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
2014-07-03 22:42:37 +08:00
|
|
|
if (! g_seekable_seek (G_SEEKABLE (input), 28, G_SEEK_SET, NULL, error))
|
2014-07-03 22:59:04 +08:00
|
|
|
{
|
|
|
|
g_object_unref (palette);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-07 17:32:23 +08:00
|
|
|
|
2014-07-03 22:42:37 +08:00
|
|
|
while (g_input_stream_read_all (input, color_bytes, sizeof (color_bytes),
|
|
|
|
&bytes_read, NULL, NULL) &&
|
|
|
|
bytes_read == sizeof (color_bytes))
|
2006-10-03 22:31:31 +08:00
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_rgba_set_uchar (&color,
|
|
|
|
color_bytes[0],
|
|
|
|
color_bytes[1],
|
|
|
|
color_bytes[2],
|
|
|
|
255);
|
|
|
|
gimp_palette_add_entry (palette, -1, NULL, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_prepend (NULL, palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
2014-07-03 22:59:04 +08:00
|
|
|
gimp_palette_load_psp (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2006-10-03 22:31:31 +08:00
|
|
|
{
|
|
|
|
GimpPalette *palette;
|
|
|
|
gchar *palette_name;
|
|
|
|
guchar color_bytes[4];
|
|
|
|
gint number_of_colors;
|
2014-07-03 22:59:04 +08:00
|
|
|
gsize bytes_read;
|
2006-10-03 22:31:31 +08:00
|
|
|
gint i, j;
|
|
|
|
gboolean color_ok;
|
|
|
|
gchar buffer[4096];
|
|
|
|
/*Maximum valid file size: 256 * 4 * 3 + 256 * 2 ~= 3650 bytes */
|
|
|
|
gchar **lines;
|
|
|
|
gchar **ascii_colors;
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2018-06-10 13:43:57 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2006-10-03 22:31:31 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2010-04-11 01:55:42 +08:00
|
|
|
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
|
2006-10-03 22:31:31 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
2014-07-03 22:59:04 +08:00
|
|
|
if (! g_seekable_seek (G_SEEKABLE (input), 16, G_SEEK_SET, NULL, error))
|
|
|
|
{
|
|
|
|
g_object_unref (palette);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input, buffer, sizeof (buffer) - 1,
|
|
|
|
&bytes_read, NULL, error))
|
|
|
|
{
|
|
|
|
g_object_unref (palette);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[bytes_read] = '\0';
|
2006-10-03 22:31:31 +08:00
|
|
|
|
|
|
|
lines = g_strsplit (buffer, "\x0d\x0a", -1);
|
|
|
|
|
|
|
|
number_of_colors = atoi (lines[0]);
|
|
|
|
|
|
|
|
for (i = 0; i < number_of_colors; i++)
|
|
|
|
{
|
|
|
|
if (lines[i + 1] == NULL)
|
|
|
|
{
|
|
|
|
g_printerr ("Premature end of file reading %s.",
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2006-10-03 22:31:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ascii_colors = g_strsplit (lines[i + 1], " ", 3);
|
|
|
|
color_ok = TRUE;
|
|
|
|
|
|
|
|
for (j = 0 ; j < 3; j++)
|
|
|
|
{
|
|
|
|
if (ascii_colors[j] == NULL)
|
|
|
|
{
|
|
|
|
g_printerr ("Corrupted palette file %s.",
|
2014-07-01 20:25:37 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2006-10-03 22:31:31 +08:00
|
|
|
color_ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
color_bytes[j] = atoi (ascii_colors[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color_ok)
|
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
|
|
|
|
gimp_rgba_set_uchar (&color,
|
|
|
|
color_bytes[0],
|
|
|
|
color_bytes[1],
|
|
|
|
color_bytes[2],
|
|
|
|
255);
|
|
|
|
gimp_palette_add_entry (palette, -1, NULL, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (ascii_colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (lines);
|
|
|
|
|
|
|
|
return g_list_prepend (NULL, palette);
|
|
|
|
}
|
2006-10-03 22:54:07 +08:00
|
|
|
|
2007-08-07 21:42:55 +08:00
|
|
|
GList *
|
2014-07-03 23:23:11 +08:00
|
|
|
gimp_palette_load_aco (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2007-08-07 21:42:55 +08:00
|
|
|
{
|
|
|
|
GimpPalette *palette;
|
|
|
|
gchar *palette_name;
|
|
|
|
gint format_version;
|
|
|
|
gint number_of_colors;
|
|
|
|
gint i;
|
|
|
|
gchar header[4];
|
2014-07-03 23:23:11 +08:00
|
|
|
gsize bytes_read;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2018-06-10 13:43:57 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2007-08-07 21:42:55 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2014-07-03 23:23:11 +08:00
|
|
|
if (! g_input_stream_read_all (input, header, sizeof (header),
|
|
|
|
&bytes_read, NULL, error) ||
|
|
|
|
bytes_read != sizeof (header))
|
2007-08-07 21:42:55 +08:00
|
|
|
{
|
2014-07-05 00:46:02 +08:00
|
|
|
g_prefix_error (error,
|
|
|
|
_("Could not read header from palette file '%s': "),
|
|
|
|
gimp_file_get_utf8_name (file));
|
2008-11-07 17:32:23 +08:00
|
|
|
return NULL;
|
2007-08-07 21:42:55 +08:00
|
|
|
}
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2010-04-11 01:55:42 +08:00
|
|
|
palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
|
2008-11-07 17:32:23 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
2014-07-03 23:23:11 +08:00
|
|
|
format_version = header[1] + (header[0] << 8);
|
2007-08-07 21:42:55 +08:00
|
|
|
number_of_colors = header[3] + (header[2] << 8);
|
|
|
|
|
|
|
|
for (i = 0; i < number_of_colors; i++)
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
2014-07-03 23:23:11 +08:00
|
|
|
gchar color_info[10];
|
|
|
|
gint color_space;
|
|
|
|
gint w, x, y, z;
|
|
|
|
gboolean color_ok = FALSE;
|
|
|
|
GimpRGB color;
|
|
|
|
GError *my_error = NULL;
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input, color_info, sizeof (color_info),
|
|
|
|
&bytes_read, NULL, &my_error) ||
|
|
|
|
bytes_read != sizeof (color_info))
|
2016-11-25 12:51:03 +08:00
|
|
|
{
|
2014-07-03 23:23:11 +08:00
|
|
|
if (palette->colors)
|
|
|
|
{
|
|
|
|
g_message (_("Reading palette file '%s': "
|
|
|
|
"Read %d colors from truncated file: %s"),
|
|
|
|
gimp_file_get_utf8_name (file),
|
|
|
|
g_list_length (palette->colors),
|
|
|
|
my_error ?
|
|
|
|
my_error->message : _("Premature end of file."));
|
|
|
|
g_clear_error (&my_error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-05 00:46:02 +08:00
|
|
|
g_propagate_error (error, my_error);
|
2008-11-07 17:32:23 +08:00
|
|
|
g_object_unref (palette);
|
2014-07-03 23:23:11 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
return NULL;
|
2016-11-25 12:51:03 +08:00
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
|
|
|
|
color_space = color_info[1] + (color_info[0] << 8);
|
|
|
|
|
|
|
|
w = (guchar) color_info[3] + ((guchar) color_info[2] << 8);
|
|
|
|
x = (guchar) color_info[5] + ((guchar) color_info[4] << 8);
|
|
|
|
y = (guchar) color_info[7] + ((guchar) color_info[6] << 8);
|
|
|
|
z = (guchar) color_info[9] + ((guchar) color_info[8] << 8);
|
|
|
|
|
|
|
|
if (color_space == 0) /* RGB */
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
gdouble R = ((gdouble) w) / 65536.0;
|
|
|
|
gdouble G = ((gdouble) x) / 65536.0;
|
|
|
|
gdouble B = ((gdouble) y) / 65536.0;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gimp_rgba_set (&color, R, G, B, 1.0);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
color_ok = TRUE;
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
else if (color_space == 1) /* HSV */
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
GimpHSV hsv;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gdouble H = ((gdouble) w) / 65536.0;
|
|
|
|
gdouble S = ((gdouble) x) / 65536.0;
|
|
|
|
gdouble V = ((gdouble) y) / 65536.0;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gimp_hsva_set (&hsv, H, S, V, 1.0);
|
|
|
|
gimp_hsv_to_rgb (&hsv, &color);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
color_ok = TRUE;
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
else if (color_space == 2) /* CMYK */
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
GimpCMYK cmyk;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gdouble C = 1.0 - (((gdouble) w) / 65536.0);
|
|
|
|
gdouble M = 1.0 - (((gdouble) x) / 65536.0);
|
|
|
|
gdouble Y = 1.0 - (((gdouble) y) / 65536.0);
|
|
|
|
gdouble K = 1.0 - (((gdouble) z) / 65536.0);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0);
|
|
|
|
gimp_cmyk_to_rgb (&cmyk, &color);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
color_ok = TRUE;
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
else if (color_space == 8) /* Grayscale */
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
gdouble K = 1.0 - (((gdouble) w) / 10000.0);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gimp_rgba_set (&color, K, K, K, 1.0);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
color_ok = TRUE;
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
else if (color_space == 9) /* Wide? CMYK */
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
GimpCMYK cmyk;
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gdouble C = 1.0 - (((gdouble) w) / 10000.0);
|
|
|
|
gdouble M = 1.0 - (((gdouble) x) / 10000.0);
|
|
|
|
gdouble Y = 1.0 - (((gdouble) y) / 10000.0);
|
|
|
|
gdouble K = 1.0 - (((gdouble) z) / 10000.0);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0);
|
|
|
|
gimp_cmyk_to_rgb (&cmyk, &color);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
color_ok = TRUE;
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
else
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
|
|
|
g_printerr ("Unsupported color space (%d) in ACO file %s\n",
|
2014-07-01 20:25:37 +08:00
|
|
|
color_space, gimp_file_get_utf8_name (file));
|
2008-11-07 17:32:23 +08:00
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
|
|
|
|
if (format_version == 2)
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
2014-07-03 23:23:11 +08:00
|
|
|
gchar format2_preamble[4];
|
|
|
|
gint number_of_chars;
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input,
|
|
|
|
format2_preamble,
|
|
|
|
sizeof (format2_preamble),
|
2014-07-05 00:46:02 +08:00
|
|
|
&bytes_read, NULL, error) ||
|
2014-07-03 23:23:11 +08:00
|
|
|
bytes_read != sizeof (format2_preamble))
|
2016-11-25 12:51:03 +08:00
|
|
|
{
|
|
|
|
g_object_unref (palette);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-07 17:32:23 +08:00
|
|
|
|
|
|
|
number_of_chars = format2_preamble[3] + (format2_preamble[2] << 8);
|
2014-07-03 23:23:11 +08:00
|
|
|
|
|
|
|
if (! g_seekable_seek (G_SEEKABLE (input), number_of_chars * 2,
|
|
|
|
G_SEEK_SET, NULL, error))
|
|
|
|
{
|
|
|
|
g_object_unref (palette);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-07 17:32:23 +08:00
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
|
|
|
|
if (color_ok)
|
|
|
|
gimp_palette_add_entry (palette, -1, NULL, &color);
|
2008-11-07 17:32:23 +08:00
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
|
|
|
|
return g_list_prepend (NULL, palette);
|
|
|
|
}
|
|
|
|
|
2007-12-19 01:01:19 +08:00
|
|
|
|
|
|
|
GList *
|
2014-07-03 23:36:01 +08:00
|
|
|
gimp_palette_load_css (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2007-12-19 01:01:19 +08:00
|
|
|
{
|
2014-07-03 23:36:01 +08:00
|
|
|
GimpPalette *palette;
|
|
|
|
GDataInputStream *data_input;
|
|
|
|
gchar *name;
|
|
|
|
GRegex *regex;
|
|
|
|
gchar *buf;
|
2007-12-19 01:01:19 +08:00
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2018-06-10 13:43:57 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2007-12-19 01:01:19 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
regex = g_regex_new (".*color.*:(?P<param>.*);", G_REGEX_CASELESS, 0, error);
|
|
|
|
if (! regex)
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-01 20:25:37 +08:00
|
|
|
name = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2010-04-11 01:55:42 +08:00
|
|
|
palette = GIMP_PALETTE (gimp_palette_new (context, name));
|
2007-12-19 01:01:19 +08:00
|
|
|
g_free (name);
|
|
|
|
|
2014-07-03 23:36:01 +08:00
|
|
|
data_input = g_data_input_stream_new (input);
|
|
|
|
|
2007-12-19 01:01:19 +08:00
|
|
|
do
|
|
|
|
{
|
2014-07-03 23:36:01 +08:00
|
|
|
gsize buf_len = 1024;
|
2007-12-19 01:01:19 +08:00
|
|
|
|
2014-07-03 23:36:01 +08:00
|
|
|
buf = g_data_input_stream_read_line (data_input, &buf_len, NULL, NULL);
|
|
|
|
|
|
|
|
if (buf)
|
2008-11-07 17:32:23 +08:00
|
|
|
{
|
2014-07-03 23:36:01 +08:00
|
|
|
GMatchInfo *matches;
|
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
if (g_regex_match (regex, buf, 0, &matches))
|
|
|
|
{
|
2014-07-03 23:36:01 +08:00
|
|
|
GimpRGB color;
|
|
|
|
gchar *word = g_match_info_fetch_named (matches, "param");
|
2007-12-19 01:01:19 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
if (gimp_rgb_parse_css (&color, word, -1))
|
|
|
|
{
|
|
|
|
if (! gimp_palette_find_entry (palette, &color, NULL))
|
|
|
|
{
|
|
|
|
gimp_palette_add_entry (palette, -1, NULL, &color);
|
|
|
|
}
|
|
|
|
}
|
2007-12-19 01:01:19 +08:00
|
|
|
|
2008-11-07 17:32:23 +08:00
|
|
|
g_free (word);
|
|
|
|
}
|
2017-11-26 11:01:19 +08:00
|
|
|
g_match_info_free (matches);
|
2014-07-03 23:36:01 +08:00
|
|
|
g_free (buf);
|
2008-11-07 17:32:23 +08:00
|
|
|
}
|
2014-07-03 23:36:01 +08:00
|
|
|
}
|
|
|
|
while (buf);
|
2007-12-19 01:01:19 +08:00
|
|
|
|
|
|
|
g_regex_unref (regex);
|
2014-07-03 23:36:01 +08:00
|
|
|
g_object_unref (data_input);
|
2007-12-19 01:01:19 +08:00
|
|
|
|
|
|
|
return g_list_prepend (NULL, palette);
|
|
|
|
}
|
|
|
|
|
2006-10-03 22:54:07 +08:00
|
|
|
GimpPaletteFileFormat
|
2014-07-03 22:27:05 +08:00
|
|
|
gimp_palette_load_detect_format (GFile *file,
|
|
|
|
GInputStream *input)
|
2006-10-03 22:54:07 +08:00
|
|
|
{
|
|
|
|
GimpPaletteFileFormat format = GIMP_PALETTE_FILE_FORMAT_UNKNOWN;
|
|
|
|
gchar header[16];
|
2014-07-03 22:27:05 +08:00
|
|
|
gsize bytes_read;
|
2006-10-03 22:54:07 +08:00
|
|
|
|
2014-07-03 22:27:05 +08:00
|
|
|
if (g_input_stream_read_all (input, &header, sizeof (header),
|
|
|
|
&bytes_read, NULL, NULL) &&
|
|
|
|
bytes_read == sizeof (header))
|
2006-10-03 22:54:07 +08:00
|
|
|
{
|
2013-09-15 14:46:28 +08:00
|
|
|
if (g_str_has_prefix (header + 0, "RIFF") &&
|
|
|
|
g_str_has_prefix (header + 8, "PAL data"))
|
2006-10-03 22:54:07 +08:00
|
|
|
{
|
2013-09-15 14:46:28 +08:00
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_RIFF_PAL;
|
2006-10-03 22:54:07 +08:00
|
|
|
}
|
2013-09-15 14:46:28 +08:00
|
|
|
else if (g_str_has_prefix (header, "GIMP Palette"))
|
2007-08-07 21:42:55 +08:00
|
|
|
{
|
2013-09-15 14:46:28 +08:00
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_GPL;
|
|
|
|
}
|
|
|
|
else if (g_str_has_prefix (header, "JASC-PAL"))
|
|
|
|
{
|
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_PSP_PAL;
|
|
|
|
}
|
|
|
|
}
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2013-09-15 14:46:28 +08:00
|
|
|
if (format == GIMP_PALETTE_FILE_FORMAT_UNKNOWN)
|
|
|
|
{
|
2014-07-03 22:27:05 +08:00
|
|
|
gchar *lower = g_ascii_strdown (gimp_file_get_utf8_name (file), -1);
|
2007-08-07 21:42:55 +08:00
|
|
|
|
2014-07-03 22:27:05 +08:00
|
|
|
if (g_str_has_suffix (lower, ".aco"))
|
2013-09-15 14:46:28 +08:00
|
|
|
{
|
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_ACO;
|
2007-08-07 21:42:55 +08:00
|
|
|
}
|
2014-07-03 22:27:05 +08:00
|
|
|
else if (g_str_has_suffix (lower, ".css"))
|
2006-10-03 22:54:07 +08:00
|
|
|
{
|
2013-09-15 14:46:28 +08:00
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_CSS;
|
2006-10-03 22:54:07 +08:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:27:05 +08:00
|
|
|
g_free (lower);
|
2013-09-15 14:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format == GIMP_PALETTE_FILE_FORMAT_UNKNOWN)
|
|
|
|
{
|
2014-07-03 22:27:05 +08:00
|
|
|
GFileInfo *info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
2013-09-15 14:46:28 +08:00
|
|
|
|
2014-07-03 22:27:05 +08:00
|
|
|
if (info)
|
2013-09-15 14:46:28 +08:00
|
|
|
{
|
2014-07-03 22:27:05 +08:00
|
|
|
goffset size = g_file_info_get_size (info);
|
|
|
|
|
|
|
|
if (size == 768)
|
2013-09-15 14:46:28 +08:00
|
|
|
format = GIMP_PALETTE_FILE_FORMAT_ACT;
|
2014-07-03 22:27:05 +08:00
|
|
|
|
|
|
|
g_object_unref (info);
|
2013-09-15 14:46:28 +08:00
|
|
|
}
|
2006-10-03 22:54:07 +08:00
|
|
|
}
|
|
|
|
|
2014-07-03 22:27:05 +08:00
|
|
|
g_seekable_seek (G_SEEKABLE (input), 0, G_SEEK_SET, NULL, NULL);
|
2013-09-25 04:14:10 +08:00
|
|
|
|
2006-10-03 22:54:07 +08:00
|
|
|
return format;
|
|
|
|
}
|