Commit cf538a33 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added gimp_palette_new_from_colormap().

2005-09-01  Sven Neumann  <sven@gimp.org>

	* app/core/gimppalette.[ch]: added gimp_palette_new_from_colormap().
parent 0b1a148b
2005-09-01 Sven Neumann <sven@gimp.org>
* app/core/gimppalette.[ch]: added gimp_palette_new_from_colormap().
2005-09-01 Sven Neumann <sven@gimp.org> 2005-09-01 Sven Neumann <sven@gimp.org>
* app/dialogs/quit-dialog.c * app/dialogs/quit-dialog.c
......
...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name) ...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name)
NULL); NULL);
} }
GimpData *
gimp_palette_new_from_colormap (const gchar *name,
const guchar *cmap,
gint n_colors)
{
GimpPalette *palette;
gint i;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (n_colors == 0 || cmap != NULL, NULL);
palette = g_object_new (GIMP_TYPE_PALETTE,
"name", name,
NULL);
for (i = 0; i < n_colors; i++)
{
GimpRGB color;
gchar name[256];
g_snprintf (name, sizeof (name), _("Index %d"), i + 1);
gimp_rgba_set_uchar (&color,
cmap[i*3], cmap[i*3 + 1], cmap[i*3 + 2], 255);
gimp_palette_add_entry (palette, i, name, &color);
}
return GIMP_DATA (palette);
}
GimpData * GimpData *
gimp_palette_get_standard (void) gimp_palette_get_standard (void)
{ {
......
...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name) ...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name)
NULL); NULL);
} }
GimpData *
gimp_palette_new_from_colormap (const gchar *name,
const guchar *cmap,
gint n_colors)
{
GimpPalette *palette;
gint i;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (n_colors == 0 || cmap != NULL, NULL);
palette = g_object_new (GIMP_TYPE_PALETTE,
"name", name,
NULL);
for (i = 0; i < n_colors; i++)
{
GimpRGB color;
gchar name[256];
g_snprintf (name, sizeof (name), _("Index %d"), i + 1);
gimp_rgba_set_uchar (&color,
cmap[i*3], cmap[i*3 + 1], cmap[i*3 + 2], 255);
gimp_palette_add_entry (palette, i, name, &color);
}
return GIMP_DATA (palette);
}
GimpData * GimpData *
gimp_palette_get_standard (void) gimp_palette_get_standard (void)
{ {
......
...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name) ...@@ -314,6 +314,37 @@ gimp_palette_new (const gchar *name)
NULL); NULL);
} }
GimpData *
gimp_palette_new_from_colormap (const gchar *name,
const guchar *cmap,
gint n_colors)
{
GimpPalette *palette;
gint i;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (n_colors == 0 || cmap != NULL, NULL);
palette = g_object_new (GIMP_TYPE_PALETTE,
"name", name,
NULL);
for (i = 0; i < n_colors; i++)
{
GimpRGB color;
gchar name[256];
g_snprintf (name, sizeof (name), _("Index %d"), i + 1);
gimp_rgba_set_uchar (&color,
cmap[i*3], cmap[i*3 + 1], cmap[i*3 + 2], 255);
gimp_palette_add_entry (palette, i, name, &color);
}
return GIMP_DATA (palette);
}
GimpData * GimpData *
gimp_palette_get_standard (void) gimp_palette_get_standard (void)
{ {
......
...@@ -62,23 +62,26 @@ struct _GimpPaletteClass ...@@ -62,23 +62,26 @@ struct _GimpPaletteClass
}; };
GType gimp_palette_get_type (void) G_GNUC_CONST; GType gimp_palette_get_type (void) G_GNUC_CONST;
GimpData * gimp_palette_new (const gchar *name); GimpData * gimp_palette_new (const gchar *name);
GimpData * gimp_palette_get_standard (void); GimpData * gimp_palette_new_from_colormap (const gchar *name,
GList * gimp_palette_load (const gchar *filename, const guchar *cmap,
GError **error); gint n_colors);
GimpData * gimp_palette_get_standard (void);
GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette, GList * gimp_palette_load (const gchar *filename,
gint position, GError **error);
const gchar *name,
const GimpRGB *color); GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette,
void gimp_palette_delete_entry (GimpPalette *palette, gint position,
GimpPaletteEntry *entry); const gchar *name,
const GimpRGB *color);
void gimp_palette_set_columns (GimpPalette *palette, void gimp_palette_delete_entry (GimpPalette *palette,
gint columns); GimpPaletteEntry *entry);
gint gimp_palette_get_columns (GimpPalette *palette);
void gimp_palette_set_columns (GimpPalette *palette,
gint columns);
gint gimp_palette_get_columns (GimpPalette *palette);
#endif /* __GIMP_PALETTE_H__ */ #endif /* __GIMP_PALETTE_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment