RSS/Atom feed Twitter
Site is read-only, email is disabled

ACO and CSS palette importing (patch attached)

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

5 of 5 messages available
Toggle history

Please log in to manage your subscriptions.

ACO and CSS palette importing (patch attached) Nicola Archibald 04 Aug 20:45
  ACO and CSS palette importing (patch attached) Michael Natterer 05 Aug 18:04
  ACO and CSS palette importing (patch attached) Sven Neumann 05 Aug 20:10
  ACO and CSS palette importing (patch attached) Michael Natterer 07 Aug 18:36
   ACO and CSS palette importing (patch attached) Sven Neumann 08 Aug 18:34
Nicola Archibald
2007-08-04 20:45:50 UTC (over 16 years ago)

ACO and CSS palette importing (patch attached)

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Hi All,

Attached is a patch, against svn, which adds ACO importing, and CSS color extraction, for the palette system.

The ACO code only reads the version 1 section at the moment, I plan on finishing the version 2 support to extract color names a little later. Color spaces supported are RGB, CMYK, HSV and greyscale, but not Lab.

The CSS import extracts colors defined in a .css file.

If this patch meets the standards, perhaps someone would like to incorporate it into the repository.

This patch would, I believe, enable the closing of Bug #316618

Thanks

Nicola. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGtMldG4yOusCUvb8RAvSVAJoD6KK24CPhq5AXsSzekqXUY3RF4wCfWDpw 5mUdq2GWEYX970J0gHzUWGE=
=ZgvZ
-----END PGP SIGNATURE-----

Index: app/core/gimppalette-import.c =================================================================== --- app/core/gimppalette-import.c (revision 23113) +++ app/core/gimppalette-import.c (working copy) @@ -511,6 +511,14 @@
palette_list = gimp_palette_load_psp (filename, error); break;

+ case GIMP_PALETTE_FILE_FORMAT_ACO: + 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, Index: app/core/gimppalette-load.c
=================================================================== --- app/core/gimppalette-load.c (revision 23113) +++ app/core/gimppalette-load.c (working copy) @@ -430,6 +430,224 @@
return g_list_prepend (NULL, palette); }

+GList *
+gimp_palette_load_aco (const gchar *filename, + GError **error) +{
+ GimpPalette *palette;
+ gchar *palette_name;
+ gint fd;
+ guchar color_bytes[4];
+ gint format_version;
+ gint number_of_colors;
+ gint i;
+ gchar header[4];
+ gchar color_info[10];
+ gchar format2_preamble[4]; + gint status;
+
+ 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); +
+ fd = g_open (filename, O_RDONLY | _O_BINARY, 0); + if (! fd)
+ {
+ g_set_error (error,
+ G_FILE_ERROR, g_file_error_from_errno (errno), + _("Could not open '%s' for reading: %s"), + gimp_filename_to_utf8 (filename), g_strerror (errno)); + return NULL;
+ }
+
+ palette_name = g_filename_display_basename (filename); + palette = GIMP_PALETTE (gimp_palette_new (palette_name)); + g_free (palette_name);
+
+ status = read(fd, header, sizeof (header)); +
+ if (status < 0)
+ {
+ close(fd);
+
+ return g_list_prepend (NULL, palette); + }
+
+ format_version = header[1] + (header[0] << 8); + number_of_colors = header[3] + (header[2] << 8); +
+ for (i = 0; i < number_of_colors; i++) + {
+ gint color_space;
+ gint w, x, y, z;
+ gboolean color_ok = FALSE;
+ GimpRGB color;
+
+ read(fd, color_info, sizeof(color_info)); + 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 */ + {
+ gdouble R = ((gdouble) w) / 65536.0; + gdouble G = ((gdouble) x) / 65536.0; + gdouble B = ((gdouble) y) / 65536.0; +
+ gimp_rgba_set( &color, R, G, B, 1.0); +
+ color_ok = TRUE;
+ }
+ else if (color_space == 1) /* HSV */ + {
+ GimpHSV hsv;
+
+ gdouble H = ((gdouble) w) / 65536.0; + gdouble S = ((gdouble) x) / 65536.0; + gdouble V = ((gdouble) y) / 65536.0; +
+ gimp_hsva_set ( &hsv, H, S, V, 1.0 ); + gimp_hsv_to_rgb( &hsv, &color);
+
+ color_ok = TRUE;
+ }
+ else if (color_space == 2) /* CMYK */ + {
+ GimpCMYK cmyk;
+
+ 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); +
+ gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0 ); + gimp_cmyk_to_rgb( &cmyk, &color); +
+ color_ok = TRUE;
+ }
+ else if (color_space == 8) /* Grayscale */ + {
+ gdouble K = 1.0 - (((gdouble) w) / 10000.0); +
+ gimp_rgba_set( &color, K, K, K, 1.0 ); +
+ color_ok = TRUE;
+ }
+ else if (color_space == 9) /* Wide? CMYK */ + {
+ GimpCMYK cmyk;
+
+ 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); +
+ gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0 ); + gimp_cmyk_to_rgb( &cmyk, &color); +
+ color_ok = TRUE;
+ }
+ else
+ {
+ g_print("Unsupported color space (%d) in ACO file\n", color_space ); + }
+
+ if (format_version == 2)
+ {
+ gint number_of_chars;
+
+ read(fd, format2_preamble, sizeof(format2_preamble)); + number_of_chars = format2_preamble[3] + (format2_preamble[2] << 8); + lseek(fd, number_of_chars * 2, SEEK_SET); + }
+
+ if (color_ok)
+ {
+ gimp_palette_add_entry (palette, -1, NULL, &color); + }
+ }
+
+ close(fd);
+
+ return g_list_prepend (NULL, palette); +}
+
+
+GList *
+gimp_palette_load_css (const gchar *filename, + GError **error)
+{
+ GimpPalette *palette;
+ gchar *palette_name;
+ FILE *file;
+ guchar color_bytes[4];
+ gint format_version;
+ gint number_of_colors;
+ gint i;
+ gchar header[4];
+ gchar color_info[10];
+ gchar format2_preamble[4]; + gint status;
+ gchar str[1024];
+ GRegex *pattern1;
+ GimpRGB color;
+
+ pattern1 = g_regex_new ( ".*color.*:(?P.*\);", G_REGEX_CASELESS, + 0,
+ error);
+ if (pattern1 == NULL)
+ return NULL;
+
+ 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); +
+ 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;
+ }
+
+ palette_name = g_filename_display_basename (filename); + palette = GIMP_PALETTE (gimp_palette_new (palette_name)); + g_free (palette_name);
+
+ do
+ {
+ GMatchInfo *matches;
+
+ if (fgets (str, sizeof(str), file) != NULL) + {
+ if (g_regex_match( pattern1,
+ str,
+ 0,
+ &matches))
+ {
+ gchar *word = g_match_info_fetch_named (matches, "param"); + if (gimp_rgb_parse_css(&color, word, -1)) + {
+ if ((gimp_palette_get_columns(palette) == 0) || + (gimp_palette_find_entry( palette, &color, NULL) == NULL)) + {
+ gimp_palette_add_entry (palette, -1, NULL, &color); + }
+ }
+ g_free (word);
+
+ }
+ }
+ } while (! feof(file) );
+ fclose(file);
+
+ return g_list_prepend (NULL, palette); +}
+
GimpPaletteFileFormat
gimp_palette_load_detect_format (const gchar *filename) {
@@ -458,6 +676,23 @@
}
}

+ gchar *lower_filename = g_strdown(g_strdup(filename)); + if (g_str_has_suffix (lower_filename, ".aco")) + {
+ format = GIMP_PALETTE_FILE_FORMAT_ACO; + close (fd); /* ensure that if the .aco file is 768 bytes it + doesn't get mistaken for a ACT file */ + return format;
+ }
+ if (g_str_has_suffix (lower_filename, ".css")) + {
+ format = GIMP_PALETTE_FILE_FORMAT_CSS; + close (fd); /* ensure that if the .css file is 768 bytes it + doesn't get mistaken for a ACT file */ + return format;
+ }
+ g_free(lower_filename);
+
if (fstat (fd, &file_stat) >= 0) {
if (file_stat.st_size == 768) Index: app/core/gimppalette-load.h
=================================================================== --- app/core/gimppalette-load.h (revision 23113) +++ app/core/gimppalette-load.h (working copy) @@ -29,7 +29,9 @@
GIMP_PALETTE_FILE_FORMAT_GPL, /* GIMP palette */ 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_PSP_PAL, /* JASC's Paint Shop Pro color palette */ + GIMP_PALETTE_FILE_FORMAT_ACO, /* Photoshop ACO color file */ + GIMP_PALETTE_FILE_FORMAT_CSS /* Extract CSS colors */ } GimpPaletteFileFormat;


@@ -41,6 +43,10 @@
GError **error); 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);

Michael Natterer
2007-08-05 18:04:59 UTC (over 16 years ago)

ACO and CSS palette importing (patch attached)

Thanks, that patch looks generally fine, also coding style wise, however:

gimppalette-load.c: In function ‘gimp_palette_load_aco’: gimppalette-load.c:440: warning: unused variable ‘color_bytes’ gimppalette-load.c:598:28: warning: unknown escape sequence '\)' gimppalette-load.c: In function ‘gimp_palette_load_css’: gimppalette-load.c:593: warning: unused variable ‘status’ gimppalette-load.c:592: warning: unused variable ‘format2_preamble’ gimppalette-load.c:591: warning: unused variable ‘color_info’ gimppalette-load.c:590: warning: unused variable ‘header’ gimppalette-load.c:589: warning: unused variable ‘i’ gimppalette-load.c:588: warning: unused variable ‘number_of_colors’ gimppalette-load.c:587: warning: unused variable ‘format_version’ gimppalette-load.c:586: warning: unused variable ‘color_bytes’ gimppalette-load.c: In function ‘gimp_palette_load_detect_format’: gimppalette-load.c:679: warning: ISO C90 forbids mixed declarations and code

Please fix these warnings and attach the updated patch to bugzilla. This way it won't get lost.

The patch can unfortunately not be included in 2.4 because we are too close to a release, and we don't depend on a glib version that has GRegex yet. I'll look into applying it after the 2.4 release so it will be in 2.6.

thanks, --mitch

On Sat, 2007-08-04 at 19:45 +0100, Nicola Archibald wrote:

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Hi All,

Attached is a patch, against svn, which adds ACO importing, and CSS color extraction, for the palette system.

The ACO code only reads the version 1 section at the moment, I plan on finishing the version 2 support to extract color names a little later. Color spaces supported are RGB, CMYK, HSV and greyscale, but not Lab.

The CSS import extracts colors defined in a .css file.

If this patch meets the standards, perhaps someone would like to incorporate it into the repository.

This patch would, I believe, enable the closing of Bug #316618

Sven Neumann
2007-08-05 20:10:22 UTC (over 16 years ago)

ACO and CSS palette importing (patch attached)

Hi,

On Sat, 2007-08-04 at 19:45 +0100, Nicola Archibald wrote:

Attached is a patch, against svn, which adds ACO importing, and CSS color extraction, for the palette system.

The ACO code only reads the version 1 section at the moment, I plan on finishing the version 2 support to extract color names a little later. Color spaces supported are RGB, CMYK, HSV and greyscale, but not Lab.

The CSS import extracts colors defined in a .css file.

If this patch meets the standards, perhaps someone would like to incorporate it into the repository.

This patch would, I believe, enable the closing of Bug #316618

Very nice, thank you. Could you please attach these patches to the bug report? That will make sure that they aren't forgotten. Perhaps I can even get to review them later tonight. But it would still be nice to have them attached to the bug report.

Sven

Michael Natterer
2007-08-07 18:36:41 UTC (over 16 years ago)

ACO and CSS palette importing (patch attached)

[resending, apparently the firts try didn't make it...]

Thanks, that patch looks generally fine, also coding style wise, however:

gimppalette-load.c: In function ‘gimp_palette_load_aco’: gimppalette-load.c:440: warning: unused variable ‘color_bytes’ gimppalette-load.c:598:28: warning: unknown escape sequence '\)' gimppalette-load.c: In function ‘gimp_palette_load_css’: gimppalette-load.c:593: warning: unused variable ‘status’ gimppalette-load.c:592: warning: unused variable ‘format2_preamble’ gimppalette-load.c:591: warning: unused variable ‘color_info’ gimppalette-load.c:590: warning: unused variable ‘header’ gimppalette-load.c:589: warning: unused variable ‘i’ gimppalette-load.c:588: warning: unused variable ‘number_of_colors’ gimppalette-load.c:587: warning: unused variable ‘format_version’ gimppalette-load.c:586: warning: unused variable ‘color_bytes’ gimppalette-load.c: In function ‘gimp_palette_load_detect_format’: gimppalette-load.c:679: warning: ISO C90 forbids mixed declarations and code

Please fix these warnings and attach the updated patch to bugzilla. This way it won't get lost.

The patch can unfortunately not be included in 2.4 because we are too close to a release, and we don't depend on a glib version that has GRegex yet. I'll look into applying it after the 2.4 release so it will be in 2.6.

thanks, --mitch

On Sat, 2007-08-04 at 19:45 +0100, Nicola Archibald wrote:

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Hi All,

Attached is a patch, against svn, which adds ACO importing, and CSS color extraction, for the palette system.

The ACO code only reads the version 1 section at the moment, I plan on finishing the version 2 support to extract color names a little later. Color spaces supported are RGB, CMYK, HSV and greyscale, but not Lab.

The CSS import extracts colors defined in a .css file.

If this patch meets the standards, perhaps someone would like to incorporate it into the repository.

This patch would, I believe, enable the closing of Bug #316618

Sven Neumann
2007-08-08 18:34:30 UTC (over 16 years ago)

ACO and CSS palette importing (patch attached)

Hi,

On Tue, 2007-08-07 at 18:36 +0200, Michael Natterer wrote:

Please fix these warnings and attach the updated patch to bugzilla. This way it won't get lost.

The patch can unfortunately not be included in 2.4 because we are too close to a release, and we don't depend on a glib version that has GRegex yet. I'll look into applying it after the 2.4 release so it will be in 2.6.

I already applied the ACO import part of the patch. Nicola has attached a patch with the CSS import code to bug #464480. We will look at that for GIMP 2.6.

Sven