[gimp] app: add lots of accessors to GimpPalette
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add lots of accessors to GimpPalette
- Date: Wed, 27 Oct 2010 12:38:26 +0000 (UTC)
commit f46122b862f08dd4c07c5b59db6c81b77b1f3571
Author: Michael Natterer <mitch gimp org>
Date: Wed Oct 27 14:36:44 2010 +0200
app: add lots of accessors to GimpPalette
and use them all over the place instead of directly accessing the struct.
app/actions/palettes-commands.c | 10 ++-
app/core/gimpimage-convert.c | 16 +++---
app/core/gimppalette-import.c | 2 +-
app/core/gimppalette-load.c | 4 +-
app/core/gimppalette-save.c | 7 ++-
app/core/gimppalette.c | 104 +++++++++++++++++++++++++++++++-
app/core/gimppalette.h | 56 +++++++++++------
app/dialogs/convert-dialog.c | 5 +-
app/dialogs/palette-import-dialog.c | 5 +-
app/pdb/palette-cmds.c | 69 +++++++---------------
app/pdb/palettes-cmds.c | 10 ++--
app/widgets/gimpcolorselectorpalette.c | 2 +-
app/widgets/gimppaletteeditor.c | 75 ++++++++++++-----------
app/widgets/gimppaletteselect.c | 2 +-
app/widgets/gimppaletteview.c | 21 ++++--
app/widgets/gimpviewrendererpalette.c | 20 ++++---
tools/pdbgen/pdb/palette.pdb | 69 +++++++---------------
tools/pdbgen/pdb/palettes.pdb | 10 ++--
18 files changed, 285 insertions(+), 202 deletions(-)
---
diff --git a/app/actions/palettes-commands.c b/app/actions/palettes-commands.c
index beafd8e..f04f941 100644
--- a/app/actions/palettes-commands.c
+++ b/app/actions/palettes-commands.c
@@ -94,7 +94,6 @@ palettes_merge_callback (GtkWidget *widget,
GimpContainerEditor *editor;
GimpPalette *palette;
GimpPalette *new_palette;
- GimpPaletteEntry *entry;
GList *sel_list;
editor = (GimpContainerEditor *) data;
@@ -115,7 +114,6 @@ palettes_merge_callback (GtkWidget *widget,
while (sel_list)
{
GimpListItem *list_item;
- GList *cols;
list_item = GIMP_LIST_ITEM (sel_list->data);
@@ -123,9 +121,13 @@ palettes_merge_callback (GtkWidget *widget,
if (palette)
{
- for (cols = palette->colors; cols; cols = g_list_next (cols))
+ GList *cols;
+
+ for (cols = gimp_palette_get_colors (palette);
+ cols;
+ cols = g_list_next (cols))
{
- entry = (GimpPaletteEntry *) cols->data;
+ GimpPaletteEntry *entry = cols->data;
gimp_palette_add_entry (new_palette,
entry->name,
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index c1353ac..aa69b96 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -780,12 +780,13 @@ gimp_image_convert (GimpImage *image,
g_return_val_if_fail (custom_palette == NULL ||
GIMP_IS_PALETTE (custom_palette), FALSE);
g_return_val_if_fail (custom_palette == NULL ||
- custom_palette->n_colors <= 256, FALSE);
+ gimp_palette_get_n_colors (custom_palette) <= 256,
+ FALSE);
if (! custom_palette)
palette_type = GIMP_MONO_PALETTE;
- if (custom_palette->n_colors < 1)
+ if (gimp_palette_get_n_colors (custom_palette) == 0)
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("Cannot convert image: palette is empty."));
@@ -2733,20 +2734,19 @@ webpal_pass1 (QuantizeObj *quantobj)
static void
custompal_pass1 (QuantizeObj *quantobj)
{
- gint i;
- GList *list;
- GimpPaletteEntry *entry;
- guchar r, g, b;
+ gint i;
+ GList *list;
/* fprintf(stderr,
"custompal_pass1: using (theCustomPalette %s) from (file %s)\n",
theCustomPalette->name, theCustomPalette->filename); */
- for (i = 0, list = theCustomPalette->colors;
+ for (i = 0, list = gimp_palette_get_colors (theCustomPalette);
list;
i++, list = g_list_next (list))
{
- entry = list->data;
+ GimpPaletteEntry *entry = list->data;
+ guchar r, g, b;
gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index 86fe108..2a2dd39 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -204,7 +204,7 @@ gimp_palette_import_create_image_palette (gpointer data,
n_colors = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (palette),
"import-n-colors"));
- if (palette->n_colors >= n_colors)
+ if (gimp_palette_get_n_colors (palette) >= n_colors)
return;
lab = g_strdup_printf ("%s (occurs %u)", _("Untitled"), color_tab->count);
diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c
index 4116eb8..a0cd4d7 100644
--- a/app/core/gimppalette-load.c
+++ b/app/core/gimppalette-load.c
@@ -152,7 +152,7 @@ gimp_palette_load (GimpContext *context,
columns = 0;
}
- palette->n_columns = columns;
+ gimp_palette_set_columns (palette, columns);
linenum++;
if (! fgets (str, sizeof (str), file))
@@ -221,7 +221,7 @@ gimp_palette_load (GimpContext *context,
255);
entry->name = g_strdup (tok ? tok : _("Untitled"));
- entry->position = palette->n_colors;
+ entry->position = gimp_palette_get_n_colors (palette);
palette->colors = g_list_prepend (palette->colors, entry);
palette->n_colors++;
diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c
index a1517c4..7bed0b7 100644
--- a/app/core/gimppalette-save.c
+++ b/app/core/gimppalette-save.c
@@ -60,9 +60,12 @@ gimp_palette_save (GimpData *data,
fprintf (file, "GIMP Palette\n");
fprintf (file, "Name: %s\n", gimp_object_get_name (palette));
- fprintf (file, "Columns: %d\n#\n", CLAMP (palette->n_columns, 0, 256));
+ fprintf (file, "Columns: %d\n#\n", CLAMP (gimp_palette_get_columns (palette),
+ 0, 256));
- for (list = palette->colors; list; list = g_list_next (list))
+ for (list = gimp_palette_get_colors (palette);
+ list;
+ list = g_list_next (list))
{
GimpPaletteEntry *entry = list->data;
guchar r, g, b;
diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c
index cc35b22..9c69d08 100644
--- a/app/core/gimppalette.c
+++ b/app/core/gimppalette.c
@@ -362,6 +362,25 @@ gimp_palette_get_checksum (GimpTagged *tagged)
return checksum_string;
}
+
+/* public functions */
+
+GList *
+gimp_palette_get_colors (GimpPalette *palette)
+{
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
+
+ return palette->colors;
+}
+
+gint
+gimp_palette_get_n_colors (GimpPalette *palette)
+{
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), 0);
+
+ return palette->n_colors;
+}
+
GimpPaletteEntry *
gimp_palette_add_entry (GimpPalette *palette,
gint position,
@@ -440,6 +459,89 @@ gimp_palette_delete_entry (GimpPalette *palette,
}
}
+gboolean
+gimp_palette_set_entry (GimpPalette *palette,
+ gint position,
+ const gchar *name,
+ const GimpRGB *color)
+{
+ GimpPaletteEntry *entry;
+
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), FALSE);
+ g_return_val_if_fail (color != NULL, FALSE);
+
+ entry = gimp_palette_get_entry (palette, position);
+
+ if (! entry)
+ return FALSE;
+
+ entry->color = *color;
+
+ if (entry->name)
+ g_free (entry->name);
+
+ entry->name = g_strdup (name);
+
+ gimp_data_dirty (GIMP_DATA (palette));
+
+ return TRUE;
+}
+
+gboolean
+gimp_palette_set_entry_color (GimpPalette *palette,
+ gint position,
+ const GimpRGB *color)
+{
+ GimpPaletteEntry *entry;
+
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), FALSE);
+ g_return_val_if_fail (color != NULL, FALSE);
+
+ entry = gimp_palette_get_entry (palette, position);
+
+ if (! entry)
+ return FALSE;
+
+ entry->color = *color;
+
+ gimp_data_dirty (GIMP_DATA (palette));
+
+ return TRUE;
+}
+
+gboolean
+gimp_palette_set_entry_name (GimpPalette *palette,
+ gint position,
+ const gchar *name)
+{
+ GimpPaletteEntry *entry;
+
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), FALSE);
+
+ entry = gimp_palette_get_entry (palette, position);
+
+ if (! entry)
+ return FALSE;
+
+ if (entry->name)
+ g_free (entry->name);
+
+ entry->name = g_strdup (name);
+
+ gimp_data_dirty (GIMP_DATA (palette));
+
+ return TRUE;
+}
+
+GimpPaletteEntry *
+gimp_palette_get_entry (GimpPalette *palette,
+ gint position)
+{
+ g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
+
+ return g_list_nth_data (palette->colors, position);
+}
+
void
gimp_palette_set_columns (GimpPalette *palette,
gint columns)
@@ -457,7 +559,7 @@ gimp_palette_set_columns (GimpPalette *palette,
}
gint
-gimp_palette_get_columns (GimpPalette *palette)
+gimp_palette_get_columns (GimpPalette *palette)
{
g_return_val_if_fail (GIMP_IS_PALETTE (palette), 0);
diff --git a/app/core/gimppalette.h b/app/core/gimppalette.h
index cb7a748..155901c 100644
--- a/app/core/gimppalette.h
+++ b/app/core/gimppalette.h
@@ -58,26 +58,42 @@ struct _GimpPaletteClass
};
-GType gimp_palette_get_type (void) G_GNUC_CONST;
-
-GimpData * gimp_palette_new (GimpContext *context,
- const gchar *name);
-GimpData * gimp_palette_get_standard (GimpContext *context);
-
-GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette,
- gint position,
- const gchar *name,
- const GimpRGB *color);
-void gimp_palette_delete_entry (GimpPalette *palette,
- GimpPaletteEntry *entry);
-
-void gimp_palette_set_columns (GimpPalette *palette,
- gint columns);
-gint gimp_palette_get_columns (GimpPalette *palette);
-
-GimpPaletteEntry * gimp_palette_find_entry (GimpPalette *palette,
- const GimpRGB *color,
- GimpPaletteEntry *start_from);
+GType gimp_palette_get_type (void) G_GNUC_CONST;
+
+GimpData * gimp_palette_new (GimpContext *context,
+ const gchar *name);
+GimpData * gimp_palette_get_standard (GimpContext *context);
+
+GList * gimp_palette_get_colors (GimpPalette *palette);
+gint gimp_palette_get_n_colors (GimpPalette *palette);
+
+GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette,
+ gint position,
+ const gchar *name,
+ const GimpRGB *color);
+void gimp_palette_delete_entry (GimpPalette *palette,
+ GimpPaletteEntry *entry);
+
+gboolean gimp_palette_set_entry (GimpPalette *palette,
+ gint position,
+ const gchar *name,
+ const GimpRGB *color);
+gboolean gimp_palette_set_entry_color (GimpPalette *palette,
+ gint position,
+ const GimpRGB *color);
+gboolean gimp_palette_set_entry_name (GimpPalette *palette,
+ gint position,
+ const gchar *name);
+GimpPaletteEntry * gimp_palette_get_entry (GimpPalette *palette,
+ gint position);
+
+void gimp_palette_set_columns (GimpPalette *palette,
+ gint columns);
+gint gimp_palette_get_columns (GimpPalette *palette);
+
+GimpPaletteEntry * gimp_palette_find_entry (GimpPalette *palette,
+ const GimpRGB *color,
+ GimpPaletteEntry *start_from);
#endif /* __GIMP_PALETTE_H__ */
diff --git a/app/dialogs/convert-dialog.c b/app/dialogs/convert-dialog.c
index 27b32f7..5c971e5 100644
--- a/app/dialogs/convert-dialog.c
+++ b/app/dialogs/convert-dialog.c
@@ -396,7 +396,8 @@ convert_dialog_palette_filter (const GimpObject *object,
{
GimpPalette *palette = GIMP_PALETTE (object);
- return palette->n_colors > 0 && palette->n_colors <= 256;
+ return (gimp_palette_get_n_colors (palette) > 0 &&
+ gimp_palette_get_n_colors (palette) <= 256);
}
static void
@@ -407,7 +408,7 @@ convert_dialog_palette_changed (GimpContext *context,
if (! palette)
return;
- if (palette->n_colors > 256)
+ if (gimp_palette_get_n_colors (palette) > 256)
{
gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog),
GIMP_MESSAGE_WARNING,
diff --git a/app/dialogs/palette-import-dialog.c b/app/dialogs/palette-import-dialog.c
index d3a3e3c..67848e2 100644
--- a/app/dialogs/palette-import-dialog.c
+++ b/app/dialogs/palette-import-dialog.c
@@ -864,7 +864,7 @@ palette_import_make_palette (ImportDialog *dialog)
if (dialog->palette)
g_object_unref (dialog->palette);
- palette->n_columns = n_columns;
+ gimp_palette_set_columns (palette, n_columns);
gimp_view_set_viewable (GIMP_VIEW (dialog->preview),
GIMP_VIEWABLE (palette));
@@ -873,5 +873,6 @@ palette_import_make_palette (ImportDialog *dialog)
}
gtk_widget_set_visible (dialog->no_colors_label,
- dialog->palette && dialog->palette->n_colors > 0);
+ dialog->palette &&
+ gimp_palette_get_n_colors (dialog->palette) > 0);
}
diff --git a/app/pdb/palette-cmds.c b/app/pdb/palette-cmds.c
index e3168ef..6d25e55 100644
--- a/app/pdb/palette-cmds.c
+++ b/app/pdb/palette-cmds.c
@@ -239,7 +239,7 @@ palette_get_info_invoker (GimpProcedure *procedure,
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
if (palette)
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
else
success = FALSE;
}
@@ -275,19 +275,21 @@ palette_get_colors_invoker (GimpProcedure *procedure,
if (palette)
{
- GList *list = palette->colors;
+ GList *list = gimp_palette_get_colors (palette);
gint i;
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
colors = g_new (GimpRGB, num_colors);
for (i = 0; i < num_colors; i++, list = g_list_next (list))
- colors[i] = ((GimpPaletteEntry *)(list->data))->color;
+ {
+ GimpPaletteEntry *entry = list->data;
+
+ colors[i] = entry->color;
+ }
}
else
- {
- success = FALSE;
- }
+ success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
@@ -322,7 +324,7 @@ palette_get_columns_invoker (GimpProcedure *procedure,
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
if (palette)
- num_columns = palette->n_columns;
+ num_columns = gimp_palette_get_columns (palette);
else
success = FALSE;
}
@@ -429,12 +431,10 @@ palette_delete_entry_invoker (GimpProcedure *procedure,
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- gimp_palette_delete_entry (palette, entry);
- }
+ if (entry)
+ gimp_palette_delete_entry (palette, entry);
else
success = FALSE;
}
@@ -469,12 +469,10 @@ palette_entry_get_color_invoker (GimpProcedure *procedure,
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- color = entry->color;
- }
+ if (entry)
+ color = entry->color;
else
success = FALSE;
}
@@ -513,18 +511,7 @@ palette_entry_set_color_invoker (GimpProcedure *procedure,
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, TRUE, error);
if (palette)
- {
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
-
- entry->color = color;
-
- gimp_data_dirty (GIMP_DATA (palette));
- }
- else
- success = FALSE;
- }
+ success = gimp_palette_set_entry_color (palette, entry_num, &color);
else
success = FALSE;
}
@@ -556,12 +543,10 @@ palette_entry_get_name_invoker (GimpProcedure *procedure,
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- entry_name = g_strdup (entry->name);
- }
+ if (entry)
+ entry_name = g_strdup (entry->name);
else
success = FALSE;
}
@@ -600,19 +585,7 @@ palette_entry_set_name_invoker (GimpProcedure *procedure,
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, TRUE, error);
if (palette)
- {
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
-
- g_free (entry->name);
- entry->name = g_strdup (entry_name);
-
- gimp_data_dirty (GIMP_DATA (palette));
- }
- else
- success = FALSE;
- }
+ success = gimp_palette_set_entry_name (palette, entry_num, entry_name);
else
success = FALSE;
}
diff --git a/app/pdb/palettes-cmds.c b/app/pdb/palettes-cmds.c
index 7ce9434..37f8014 100644
--- a/app/pdb/palettes-cmds.c
+++ b/app/pdb/palettes-cmds.c
@@ -105,7 +105,7 @@ palettes_get_palette_invoker (GimpProcedure *procedure,
if (palette)
{
name = g_strdup (gimp_object_get_name (palette));
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
}
else
success = FALSE;
@@ -152,12 +152,12 @@ palettes_get_palette_entry_invoker (GimpProcedure *procedure,
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
+ if (entry)
+ {
actual_name = g_strdup (gimp_object_get_name (palette));
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
color = entry->color;
}
else
diff --git a/app/widgets/gimpcolorselectorpalette.c b/app/widgets/gimpcolorselectorpalette.c
index 71f6cb3..a5fe250 100644
--- a/app/widgets/gimpcolorselectorpalette.c
+++ b/app/widgets/gimpcolorselectorpalette.c
@@ -78,7 +78,7 @@ gimp_color_selector_palette_set_color (GimpColorSelector *selector,
{
GimpPalette *palette = gimp_context_get_palette (select->context);
- if (palette && palette->n_colors > 0)
+ if (palette && gimp_palette_get_n_colors (palette) > 0)
{
GimpPaletteEntry *entry;
diff --git a/app/widgets/gimppaletteeditor.c b/app/widgets/gimppaletteeditor.c
index 5aad76c..fa1e439 100644
--- a/app/widgets/gimppaletteeditor.c
+++ b/app/widgets/gimppaletteeditor.c
@@ -347,7 +347,7 @@ gimp_palette_editor_set_data (GimpDataEditor *editor,
editor);
gtk_adjustment_set_value (palette_editor->columns_data,
- palette->n_columns);
+ gimp_palette_get_columns (palette));
palette_editor_scroll_top_left (palette_editor);
@@ -468,8 +468,9 @@ gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
break;
case GIMP_COLOR_PICK_STATE_UPDATE:
- editor->color->color = *color;
- gimp_data_dirty (data);
+ gimp_palette_set_entry_color (GIMP_PALETTE (data),
+ editor->color->position,
+ color);
break;
}
}
@@ -515,10 +516,12 @@ gimp_palette_editor_zoom (GimpPaletteEditor *editor,
gtk_widget_get_allocation (viewport, &allocation);
- columns = palette->n_columns ? palette->n_columns : COLUMNS;
- rows = palette->n_colors / columns;
+ columns = gimp_palette_get_columns (palette);
+ if (columns == 0)
+ columns = COLUMNS;
- if (palette->n_colors % columns)
+ rows = gimp_palette_get_n_colors (palette) / columns;
+ if (gimp_palette_get_n_colors (palette) % columns)
rows += 1;
rows = MAX (1, rows);
@@ -531,9 +534,8 @@ gimp_palette_editor_zoom (GimpPaletteEditor *editor,
zoom_factor = CLAMP (zoom_factor, 0.1, 4.0);
- if (palette->n_columns)
- editor->columns = palette->n_columns;
- else
+ editor->columns = gimp_palette_get_columns (palette);
+ if (editor->columns == 0)
editor->columns = COLUMNS;
palette_editor_resize (editor, editor->last_width, zoom_factor);
@@ -552,7 +554,7 @@ gimp_palette_editor_get_index (GimpPaletteEditor *editor,
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
- if (palette && palette->n_colors > 0)
+ if (palette && gimp_palette_get_n_colors (palette) > 0)
{
GimpPaletteEntry *entry;
@@ -571,26 +573,29 @@ gimp_palette_editor_set_index (GimpPaletteEditor *editor,
GimpRGB *color)
{
GimpPalette *palette;
- GList *list;
g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), FALSE);
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
- if (! palette || palette->n_colors == 0)
- return FALSE;
+ if (palette && gimp_palette_get_n_colors (palette) > 0)
+ {
+ GimpPaletteEntry *entry;
- index = CLAMP (index, 0, palette->n_colors - 1);
+ index = CLAMP (index, 0, gimp_palette_get_n_colors (palette) - 1);
- list = g_list_nth (palette->colors, index);
+ entry = gimp_palette_get_entry (palette, index);
- gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
- list->data);
+ gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
+ entry);
- if (color)
- *color = editor->color->color;
+ if (color)
+ *color = editor->color->color;
- return TRUE;
+ return TRUE;
+ }
+
+ return FALSE;
}
gint
@@ -602,10 +607,12 @@ gimp_palette_editor_max_index (GimpPaletteEditor *editor)
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
- if (! palette || palette->n_colors == 0)
- return -1;
+ if (palette && gimp_palette_get_n_colors (palette) > 0)
+ {
+ return gimp_palette_get_n_colors (palette) - 1;
+ }
- return palette->n_colors - 1;
+ return -1;
}
@@ -615,9 +622,8 @@ static void
palette_editor_invalidate_preview (GimpPalette *palette,
GimpPaletteEditor *editor)
{
- if (palette->n_columns)
- editor->columns = palette->n_columns;
- else
+ editor->columns = gimp_palette_get_columns (palette);
+ if (editor->columns == 0)
editor->columns = COLUMNS;
palette_editor_resize (editor, editor->last_width, editor->zoom_factor);
@@ -747,17 +753,12 @@ palette_editor_color_name_changed (GtkWidget *widget,
{
if (GIMP_DATA_EDITOR (editor)->data)
{
- GimpPalette *palette;
-
- palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
-
- if (editor->color->name)
- g_free (editor->color->name);
+ GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+ const gchar *name;
- editor->color->name =
- g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->color_name)));
+ name = gtk_entry_get_text (GTK_ENTRY (editor->color_name));
- gimp_data_dirty (GIMP_DATA (palette));
+ gimp_palette_set_entry_name (palette, editor->color->position, name);
}
}
@@ -799,8 +800,8 @@ palette_editor_resize (GimpPaletteEditor *editor,
if (editor->col_width < 0)
editor->col_width = 0;
- rows = palette->n_colors / editor->columns;
- if (palette->n_colors % editor->columns)
+ rows = gimp_palette_get_n_colors (palette) / editor->columns;
+ if (gimp_palette_get_n_colors (palette) % editor->columns)
rows += 1;
preview_width = (editor->col_width + SPACING) * editor->columns;
diff --git a/app/widgets/gimppaletteselect.c b/app/widgets/gimppaletteselect.c
index 8d308a9..34bb6a6 100644
--- a/app/widgets/gimppaletteselect.c
+++ b/app/widgets/gimppaletteselect.c
@@ -117,7 +117,7 @@ gimp_palette_select_run_callback (GimpPdbDialog *dialog,
NULL, error,
dialog->callback_name,
G_TYPE_STRING, gimp_object_get_name (object),
- GIMP_TYPE_INT32, palette->n_colors,
+ GIMP_TYPE_INT32, gimp_palette_get_n_colors (palette),
GIMP_TYPE_INT32, closing,
G_TYPE_NONE);
}
diff --git a/app/widgets/gimppaletteview.c b/app/widgets/gimppaletteview.c
index 5725501..4f77088 100644
--- a/app/widgets/gimppaletteview.c
+++ b/app/widgets/gimppaletteview.c
@@ -297,8 +297,12 @@ gimp_palette_view_focus (GtkWidget *widget,
{
gtk_widget_grab_focus (widget);
- if (! view->selected && palette->colors)
- gimp_palette_view_select_entry (view, palette->colors->data);
+ if (! view->selected && gimp_palette_get_n_colors (palette) > 0)
+ {
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, 0);
+
+ gimp_palette_view_select_entry (view, entry);
+ }
return TRUE;
}
@@ -337,7 +341,7 @@ gimp_palette_view_focus (GtkWidget *widget,
position = view->selected->position + skip;
- entry = g_list_nth_data (palette->colors, position);
+ entry = gimp_palette_get_entry (palette, position);
if (entry)
gimp_palette_view_select_entry (view, entry);
@@ -443,8 +447,8 @@ gimp_palette_view_find_entry (GimpPaletteView *view,
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
- entry = g_list_nth_data (palette->colors,
- row * renderer->columns + col);
+ entry = gimp_palette_get_entry (palette,
+ row * renderer->columns + col);
}
return entry;
@@ -479,8 +483,11 @@ gimp_palette_view_invalidate (GimpPalette *palette,
{
view->dnd_entry = NULL;
- if (view->selected && ! g_list_find (palette->colors, view->selected))
- gimp_palette_view_select_entry (view, NULL);
+ if (view->selected &&
+ ! g_list_find (gimp_palette_get_colors (palette), view->selected))
+ {
+ gimp_palette_view_select_entry (view, NULL);
+ }
}
static void
diff --git a/app/widgets/gimpviewrendererpalette.c b/app/widgets/gimpviewrendererpalette.c
index 3f02b26..a9e743b 100644
--- a/app/widgets/gimpviewrendererpalette.c
+++ b/app/widgets/gimpviewrendererpalette.c
@@ -91,25 +91,29 @@ gimp_view_renderer_palette_render (GimpViewRenderer *renderer,
palette = GIMP_PALETTE (renderer->viewable);
- if (palette->n_colors < 1)
+ if (gimp_palette_get_n_colors (palette) == 0)
return;
grid_width = renderpal->draw_grid ? 1 : 0;
if (renderpal->cell_size > 0)
{
- if (palette->n_columns > 0)
+ gint n_columns = gimp_palette_get_columns (palette);
+
+ if (n_columns > 0)
cell_width = MAX ((gdouble) renderpal->cell_size,
(gdouble) (renderer->width - grid_width) /
- (gdouble) palette->n_columns);
+ (gdouble) n_columns);
else
cell_width = renderpal->cell_size;
}
else
{
- if (palette->n_columns > 0)
+ gint n_columns = gimp_palette_get_columns (palette);
+
+ if (n_columns > 0)
cell_width = ((gdouble) (renderer->width - grid_width) /
- (gdouble) palette->n_columns);
+ (gdouble) n_columns);
else
cell_width = (gdouble) (renderer->width - grid_width) / 16.0;
}
@@ -120,8 +124,8 @@ gimp_view_renderer_palette_render (GimpViewRenderer *renderer,
renderpal->columns = (gdouble) (renderer->width - grid_width) / cell_width;
- renderpal->rows = palette->n_colors / renderpal->columns;
- if (palette->n_colors % renderpal->columns)
+ renderpal->rows = gimp_palette_get_n_colors (palette) / renderpal->columns;
+ if (gimp_palette_get_n_colors (palette) % renderpal->columns)
renderpal->rows += 1;
renderpal->cell_height = MAX (4, ((renderer->height - grid_width) /
@@ -131,7 +135,7 @@ gimp_view_renderer_palette_render (GimpViewRenderer *renderer,
renderpal->cell_height = MIN (renderpal->cell_height,
renderpal->cell_width);
- list = palette->colors;
+ list = gimp_palette_get_colors (palette);
if (! renderer->surface)
renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
diff --git a/tools/pdbgen/pdb/palette.pdb b/tools/pdbgen/pdb/palette.pdb
index cff5dac..af00d80 100644
--- a/tools/pdbgen/pdb/palette.pdb
+++ b/tools/pdbgen/pdb/palette.pdb
@@ -204,7 +204,7 @@ HELP
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
if (palette)
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
else
success = FALSE;
}
@@ -241,19 +241,21 @@ HELP
if (palette)
{
- GList *list = palette->colors;
+ GList *list = gimp_palette_get_colors (palette);
gint i;
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
colors = g_new (GimpRGB, num_colors);
for (i = 0; i < num_colors; i++, list = g_list_next (list))
- colors[i] = ((GimpPaletteEntry *)(list->data))->color;
+ {
+ GimpPaletteEntry *entry = list->data;
+
+ colors[i] = entry->color;
+ }
}
else
- {
- success = FALSE;
- }
+ success = FALSE;
}
CODE
);
@@ -284,7 +286,7 @@ HELP
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
if (palette)
- num_columns = palette->n_columns;
+ num_columns = gimp_palette_get_columns (palette);
else
success = FALSE;
}
@@ -390,12 +392,10 @@ HELP
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- gimp_palette_delete_entry (palette, entry);
- }
+ if (entry)
+ gimp_palette_delete_entry (palette, entry);
else
success = FALSE;
}
@@ -435,12 +435,10 @@ HELP
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- color = entry->color;
- }
+ if (entry)
+ color = entry->color;
else
success = FALSE;
}
@@ -476,18 +474,7 @@ HELP
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, TRUE, error);
if (palette)
- {
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
-
- entry->color = color;
-
- gimp_data_dirty (GIMP_DATA (palette));
- }
- else
- success = FALSE;
- }
+ success = gimp_palette_set_entry_color (palette, entry_num, &color);
else
success = FALSE;
}
@@ -524,12 +511,10 @@ HELP
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
- entry_name = g_strdup (entry->name);
- }
+ if (entry)
+ entry_name = g_strdup (entry->name);
else
success = FALSE;
}
@@ -565,19 +550,7 @@ HELP
GimpPalette *palette = gimp_pdb_get_palette (gimp, name, TRUE, error);
if (palette)
- {
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
-
- g_free (entry->name);
- entry->name = g_strdup (entry_name);
-
- gimp_data_dirty (GIMP_DATA (palette));
- }
- else
- success = FALSE;
- }
+ success = gimp_palette_set_entry_name (palette, entry_num, entry_name);
else
success = FALSE;
}
diff --git a/tools/pdbgen/pdb/palettes.pdb b/tools/pdbgen/pdb/palettes.pdb
index 164740d..6ba01eb 100644
--- a/tools/pdbgen/pdb/palettes.pdb
+++ b/tools/pdbgen/pdb/palettes.pdb
@@ -86,7 +86,7 @@ sub palettes_get_palette {
if (palette)
{
name = g_strdup (gimp_object_get_name (palette));
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
}
else
success = FALSE;
@@ -126,12 +126,12 @@ sub palettes_get_palette_entry {
if (palette)
{
- if (entry_num >= 0 && entry_num < palette->n_colors)
- {
- GimpPaletteEntry *entry = g_list_nth_data (palette->colors, entry_num);
+ GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
+ if (entry)
+ {
actual_name = g_strdup (gimp_object_get_name (palette));
- num_colors = palette->n_colors;
+ num_colors = gimp_palette_get_n_colors (palette);
color = entry->color;
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]