mirror of https://github.com/GNOME/gimp.git
app/core/gimppalette-import.c applied slightly modified patch from Nicola
2007-12-18 Sven Neumann <sven@gimp.org> * app/core/gimppalette-import.c * app/core/gimppalette-load.[ch]: applied slightly modified patch from Nicola Archibald that adds import of colors from CSS files (bug #464480). * app/core/gimppalette.c (gimp_palette_find_entry): allow to call this function on an empty palette. svn path=/trunk/; revision=24393
This commit is contained in:
parent
055086aef2
commit
c86291c4f5
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-12-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/core/gimppalette-import.c
|
||||
* app/core/gimppalette-load.[ch]: applied slightly modified patch
|
||||
from Nicola Archibald that adds import of colors from CSS files
|
||||
(bug #464480).
|
||||
|
||||
* app/core/gimppalette.c (gimp_palette_find_entry): allow to call
|
||||
this function on an empty palette.
|
||||
|
||||
2007-12-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/base/tile-pyramid.c: use the coordinate parameters in
|
||||
|
|
|
@ -515,6 +515,10 @@ gimp_palette_import_from_file (const gchar *filename,
|
|||
palette_list = gimp_palette_load_aco (filename, error);
|
||||
break;
|
||||
|
||||
case GIMP_PALETTE_FILE_FORMAT_CSS:
|
||||
palette_list = gimp_palette_load_css (filename, error);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_set_error (error,
|
||||
GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
||||
|
|
|
@ -574,6 +574,69 @@ gimp_palette_load_aco (const gchar *filename,
|
|||
return g_list_prepend (NULL, palette);
|
||||
}
|
||||
|
||||
|
||||
GList *
|
||||
gimp_palette_load_css (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
GimpPalette *palette;
|
||||
gchar *name;
|
||||
FILE *file;
|
||||
GRegex *regex;
|
||||
GimpRGB color;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
|
||||
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;
|
||||
|
||||
file = g_fopen (filename, "rb");
|
||||
if (! file)
|
||||
{
|
||||
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
name = g_filename_display_basename (filename);
|
||||
palette = GIMP_PALETTE (gimp_palette_new (name));
|
||||
g_free (name);
|
||||
|
||||
do
|
||||
{
|
||||
GMatchInfo *matches;
|
||||
gchar buf[1024];
|
||||
|
||||
if (fgets (buf, sizeof (buf), file) != NULL)
|
||||
{
|
||||
if (g_regex_match (regex, buf, 0, &matches))
|
||||
{
|
||||
gchar *word = g_match_info_fetch_named (matches, "param");
|
||||
|
||||
if (gimp_rgb_parse_css (&color, word, -1))
|
||||
{
|
||||
if (! gimp_palette_find_entry (palette, &color, NULL))
|
||||
{
|
||||
gimp_palette_add_entry (palette, -1, NULL, &color);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (word);
|
||||
}
|
||||
}
|
||||
} while (! feof (file));
|
||||
|
||||
fclose (file);
|
||||
|
||||
g_regex_unref (regex);
|
||||
|
||||
return g_list_prepend (NULL, palette);
|
||||
}
|
||||
|
||||
GimpPaletteFileFormat
|
||||
gimp_palette_load_detect_format (const gchar *filename)
|
||||
{
|
||||
|
@ -606,7 +669,13 @@ gimp_palette_load_detect_format (const gchar *filename)
|
|||
gchar *lower_filename = g_ascii_strdown (filename, -1);
|
||||
|
||||
if (g_str_has_suffix (lower_filename, ".aco"))
|
||||
{
|
||||
format = GIMP_PALETTE_FILE_FORMAT_ACO;
|
||||
}
|
||||
else if (g_str_has_suffix (lower_filename, ".css"))
|
||||
{
|
||||
format = GIMP_PALETTE_FILE_FORMAT_CSS;
|
||||
}
|
||||
|
||||
g_free (lower_filename);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ typedef enum
|
|||
GIMP_PALETTE_FILE_FORMAT_RIFF_PAL, /* RIFF palette */
|
||||
GIMP_PALETTE_FILE_FORMAT_ACT, /* Photoshop binary color palette */
|
||||
GIMP_PALETTE_FILE_FORMAT_PSP_PAL, /* JASC's Paint Shop Pro color palette */
|
||||
GIMP_PALETTE_FILE_FORMAT_ACO /* Photoshop ACO color file */
|
||||
GIMP_PALETTE_FILE_FORMAT_ACO, /* Photoshop ACO color file */
|
||||
GIMP_PALETTE_FILE_FORMAT_CSS /* Cascaded Stylesheet file (CSS) */
|
||||
} GimpPaletteFileFormat;
|
||||
|
||||
|
||||
|
@ -44,6 +45,8 @@ GList * gimp_palette_load_psp (const gchar *filename,
|
|||
GError **error);
|
||||
GList * gimp_palette_load_aco (const gchar *filename,
|
||||
GError **error);
|
||||
GList * gimp_palette_load_css (const gchar *filename,
|
||||
GError **error);
|
||||
|
||||
GimpPaletteFileFormat gimp_palette_load_detect_format (const gchar *filename);
|
||||
|
||||
|
|
|
@ -427,7 +427,6 @@ gimp_palette_find_entry (GimpPalette *palette,
|
|||
|
||||
g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
g_return_val_if_fail (palette->n_colors > 0, NULL);
|
||||
|
||||
if (! start_from)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue