take const GimpRGB* instead of just GimpRGB*. Converted tabs to spaces.

2004-06-30  Michael Natterer  <mitch@gimp.org>

	* app/core/gimppalette.[ch] (gimp_palette_add_entry): take
	const GimpRGB* instead of just GimpRGB*.
	Converted tabs to spaces.
This commit is contained in:
Michael Natterer
2004-06-30 11:09:44 +00:00
committed by Michael Natterer
parent 425fd699e3
commit 12355969f6
5 changed files with 337 additions and 346 deletions

View File

@ -1,3 +1,9 @@
2004-06-30 Michael Natterer <mitch@gimp.org>
* app/core/gimppalette.[ch] (gimp_palette_add_entry): take
const GimpRGB* instead of just GimpRGB*.
Converted tabs to spaces.
2004-06-30 Michael Natterer <mitch@gimp.org> 2004-06-30 Michael Natterer <mitch@gimp.org>
* widgets/gimpselectiondata.[ch] (gimp_selection_data_get_svg): * widgets/gimpselectiondata.[ch] (gimp_selection_data_get_svg):

View File

@ -112,15 +112,10 @@ gimp_palette_get_type (void)
static void static void
gimp_palette_class_init (GimpPaletteClass *klass) gimp_palette_class_init (GimpPaletteClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class; GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class; GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
GimpDataClass *data_class; GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
data_class = GIMP_DATA_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -231,8 +226,8 @@ gimp_palette_get_popup_size (GimpViewable *viewable,
static TempBuf * static TempBuf *
gimp_palette_get_new_preview (GimpViewable *viewable, gimp_palette_get_new_preview (GimpViewable *viewable,
gint width, gint width,
gint height) gint height)
{ {
GimpPalette *palette = GIMP_PALETTE (viewable); GimpPalette *palette = GIMP_PALETTE (viewable);
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -269,28 +264,28 @@ gimp_palette_get_new_preview (GimpViewable *viewable,
memset (b, 255, width * 3); memset (b, 255, width * 3);
for (x = 0; x < columns && list; x++) for (x = 0; x < columns && list; x++)
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
list = g_list_next (list); list = g_list_next (list);
gimp_rgb_get_uchar (&entry->color, gimp_rgb_get_uchar (&entry->color,
&b[x * cell_size * 3 + 0], &b[x * cell_size * 3 + 0],
&b[x * cell_size * 3 + 1], &b[x * cell_size * 3 + 1],
&b[x * cell_size * 3 + 2]); &b[x * cell_size * 3 + 2]);
for (i = 1; i < cell_size; i++) for (i = 1; i < cell_size; i++)
{ {
b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0]; b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0];
b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1]; b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1];
b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2]; b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2];
} }
} }
for (i = 0; i < cell_size; i++) for (i = 0; i < cell_size; i++)
{ {
memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3); memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3);
} }
} }
g_free (b); g_free (b);
@ -380,13 +375,13 @@ gimp_palette_load (const gchar *filename,
{ {
/* bad magic, but maybe it has \r\n at the end of lines? */ /* bad magic, but maybe it has \r\n at the end of lines? */
if (!strcmp (str, "GIMP Palette\r")) if (!strcmp (str, "GIMP Palette\r"))
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header.\n" "Missing magic header.\n"
"Does this file need converting from DOS?"), "Does this file need converting from DOS?"),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
else else
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header."), "Missing magic header."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
@ -424,48 +419,48 @@ gimp_palette_load (const gchar *filename,
g_free (utf8); g_free (utf8);
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
if (! strncmp (str, "Columns: ", strlen ("Columns: "))) if (! strncmp (str, "Columns: ", strlen ("Columns: ")))
{ {
gint columns; gint columns;
columns = atoi (g_strstrip (&str[strlen ("Columns: ")])); columns = atoi (g_strstrip (&str[strlen ("Columns: ")]));
if (columns < 0 || columns > 256) if (columns < 0 || columns > 256)
{ {
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Invalid number of columns in line %d. " "Invalid number of columns in line %d. "
"Using default value."), "Using default value."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
columns = 0; columns = 0;
} }
palette->n_columns = columns; palette->n_columns = columns;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
} }
else /* old palette format */ else /* old palette format */
{ {
@ -484,71 +479,71 @@ gimp_palette_load (const gchar *filename,
while (! feof (file)) while (! feof (file))
{ {
if (str[0] != '#') if (str[0] != '#')
{ {
tok = strtok (str, " \t"); tok = strtok (str, " \t");
if (tok) if (tok)
r = atoi (tok); r = atoi (tok);
else else
/* maybe we should just abort? */ /* maybe we should just abort? */
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing RED component in line %d."), "Missing RED component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
g = atoi (tok); g = atoi (tok);
else else
g_message (_("Reading palette '%s': " g_message (_("Reading palette '%s': "
"Missing GREEN component in line %d."), "Missing GREEN component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
b = atoi (tok); b = atoi (tok);
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing BLUE component in line %d."), "Missing BLUE component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* optional name */ /* optional name */
tok = strtok (NULL, "\n"); tok = strtok (NULL, "\n");
if (r < 0 || r > 255 || if (r < 0 || r > 255 ||
g < 0 || g > 255 || g < 0 || g > 255 ||
b < 0 || b > 255) b < 0 || b > 255)
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"RGB value out of range in line %d."), "RGB value out of range in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* don't call gimp_palette_add_entry here, it's rather inefficient */ /* don't call gimp_palette_add_entry here, it's rather inefficient */
entry = g_new0 (GimpPaletteEntry, 1); entry = g_new0 (GimpPaletteEntry, 1);
gimp_rgba_set_uchar (&entry->color, gimp_rgba_set_uchar (&entry->color,
(guchar) r, (guchar) r,
(guchar) g, (guchar) g,
(guchar) b, (guchar) b,
255); 255);
entry->name = g_strdup (tok ? tok : _("Untitled")); entry->name = g_strdup (tok ? tok : _("Untitled"));
entry->position = palette->n_colors; entry->position = palette->n_colors;
palette->colors = g_list_prepend (palette->colors, entry); palette->colors = g_list_prepend (palette->colors, entry);
palette->n_colors++; palette->n_colors++;
} }
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
if (feof (file)) if (feof (file))
break; break;
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
@ -575,7 +570,7 @@ gimp_palette_save (GimpData *data,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (data->filename), gimp_filename_to_utf8 (data->filename),
g_strerror (errno)); g_strerror (errno));
return FALSE; return FALSE;
} }
@ -627,9 +622,9 @@ gimp_palette_duplicate (GimpData *data,
} }
GimpPaletteEntry * GimpPaletteEntry *
gimp_palette_add_entry (GimpPalette *palette, gimp_palette_add_entry (GimpPalette *palette,
const gchar *name, const gchar *name,
GimpRGB *color) const GimpRGB *color)
{ {
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -654,7 +649,7 @@ gimp_palette_add_entry (GimpPalette *palette,
void void
gimp_palette_delete_entry (GimpPalette *palette, gimp_palette_delete_entry (GimpPalette *palette,
GimpPaletteEntry *entry) GimpPaletteEntry *entry)
{ {
GList *list; GList *list;
gint pos = 0; gint pos = 0;
@ -672,24 +667,24 @@ gimp_palette_delete_entry (GimpPalette *palette,
palette->n_colors--; palette->n_colors--;
for (list = g_list_nth (palette->colors, pos); for (list = g_list_nth (palette->colors, pos);
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
entry->position = pos++; entry->position = pos++;
} }
if (palette->n_colors == 0) if (palette->n_colors == 0)
{ {
GimpRGB color; GimpRGB color;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_palette_add_entry (palette, gimp_palette_add_entry (palette,
_("Black"), _("Black"),
&color); &color);
} }
/* will make the palette dirty too */ /* will make the palette dirty too */
gimp_object_name_changed (GIMP_OBJECT (palette)); gimp_object_name_changed (GIMP_OBJECT (palette));

View File

@ -112,15 +112,10 @@ gimp_palette_get_type (void)
static void static void
gimp_palette_class_init (GimpPaletteClass *klass) gimp_palette_class_init (GimpPaletteClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class; GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class; GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
GimpDataClass *data_class; GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
data_class = GIMP_DATA_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -231,8 +226,8 @@ gimp_palette_get_popup_size (GimpViewable *viewable,
static TempBuf * static TempBuf *
gimp_palette_get_new_preview (GimpViewable *viewable, gimp_palette_get_new_preview (GimpViewable *viewable,
gint width, gint width,
gint height) gint height)
{ {
GimpPalette *palette = GIMP_PALETTE (viewable); GimpPalette *palette = GIMP_PALETTE (viewable);
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -269,28 +264,28 @@ gimp_palette_get_new_preview (GimpViewable *viewable,
memset (b, 255, width * 3); memset (b, 255, width * 3);
for (x = 0; x < columns && list; x++) for (x = 0; x < columns && list; x++)
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
list = g_list_next (list); list = g_list_next (list);
gimp_rgb_get_uchar (&entry->color, gimp_rgb_get_uchar (&entry->color,
&b[x * cell_size * 3 + 0], &b[x * cell_size * 3 + 0],
&b[x * cell_size * 3 + 1], &b[x * cell_size * 3 + 1],
&b[x * cell_size * 3 + 2]); &b[x * cell_size * 3 + 2]);
for (i = 1; i < cell_size; i++) for (i = 1; i < cell_size; i++)
{ {
b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0]; b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0];
b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1]; b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1];
b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2]; b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2];
} }
} }
for (i = 0; i < cell_size; i++) for (i = 0; i < cell_size; i++)
{ {
memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3); memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3);
} }
} }
g_free (b); g_free (b);
@ -380,13 +375,13 @@ gimp_palette_load (const gchar *filename,
{ {
/* bad magic, but maybe it has \r\n at the end of lines? */ /* bad magic, but maybe it has \r\n at the end of lines? */
if (!strcmp (str, "GIMP Palette\r")) if (!strcmp (str, "GIMP Palette\r"))
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header.\n" "Missing magic header.\n"
"Does this file need converting from DOS?"), "Does this file need converting from DOS?"),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
else else
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header."), "Missing magic header."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
@ -424,48 +419,48 @@ gimp_palette_load (const gchar *filename,
g_free (utf8); g_free (utf8);
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
if (! strncmp (str, "Columns: ", strlen ("Columns: "))) if (! strncmp (str, "Columns: ", strlen ("Columns: ")))
{ {
gint columns; gint columns;
columns = atoi (g_strstrip (&str[strlen ("Columns: ")])); columns = atoi (g_strstrip (&str[strlen ("Columns: ")]));
if (columns < 0 || columns > 256) if (columns < 0 || columns > 256)
{ {
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Invalid number of columns in line %d. " "Invalid number of columns in line %d. "
"Using default value."), "Using default value."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
columns = 0; columns = 0;
} }
palette->n_columns = columns; palette->n_columns = columns;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
} }
else /* old palette format */ else /* old palette format */
{ {
@ -484,71 +479,71 @@ gimp_palette_load (const gchar *filename,
while (! feof (file)) while (! feof (file))
{ {
if (str[0] != '#') if (str[0] != '#')
{ {
tok = strtok (str, " \t"); tok = strtok (str, " \t");
if (tok) if (tok)
r = atoi (tok); r = atoi (tok);
else else
/* maybe we should just abort? */ /* maybe we should just abort? */
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing RED component in line %d."), "Missing RED component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
g = atoi (tok); g = atoi (tok);
else else
g_message (_("Reading palette '%s': " g_message (_("Reading palette '%s': "
"Missing GREEN component in line %d."), "Missing GREEN component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
b = atoi (tok); b = atoi (tok);
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing BLUE component in line %d."), "Missing BLUE component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* optional name */ /* optional name */
tok = strtok (NULL, "\n"); tok = strtok (NULL, "\n");
if (r < 0 || r > 255 || if (r < 0 || r > 255 ||
g < 0 || g > 255 || g < 0 || g > 255 ||
b < 0 || b > 255) b < 0 || b > 255)
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"RGB value out of range in line %d."), "RGB value out of range in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* don't call gimp_palette_add_entry here, it's rather inefficient */ /* don't call gimp_palette_add_entry here, it's rather inefficient */
entry = g_new0 (GimpPaletteEntry, 1); entry = g_new0 (GimpPaletteEntry, 1);
gimp_rgba_set_uchar (&entry->color, gimp_rgba_set_uchar (&entry->color,
(guchar) r, (guchar) r,
(guchar) g, (guchar) g,
(guchar) b, (guchar) b,
255); 255);
entry->name = g_strdup (tok ? tok : _("Untitled")); entry->name = g_strdup (tok ? tok : _("Untitled"));
entry->position = palette->n_colors; entry->position = palette->n_colors;
palette->colors = g_list_prepend (palette->colors, entry); palette->colors = g_list_prepend (palette->colors, entry);
palette->n_colors++; palette->n_colors++;
} }
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
if (feof (file)) if (feof (file))
break; break;
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
@ -575,7 +570,7 @@ gimp_palette_save (GimpData *data,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (data->filename), gimp_filename_to_utf8 (data->filename),
g_strerror (errno)); g_strerror (errno));
return FALSE; return FALSE;
} }
@ -627,9 +622,9 @@ gimp_palette_duplicate (GimpData *data,
} }
GimpPaletteEntry * GimpPaletteEntry *
gimp_palette_add_entry (GimpPalette *palette, gimp_palette_add_entry (GimpPalette *palette,
const gchar *name, const gchar *name,
GimpRGB *color) const GimpRGB *color)
{ {
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -654,7 +649,7 @@ gimp_palette_add_entry (GimpPalette *palette,
void void
gimp_palette_delete_entry (GimpPalette *palette, gimp_palette_delete_entry (GimpPalette *palette,
GimpPaletteEntry *entry) GimpPaletteEntry *entry)
{ {
GList *list; GList *list;
gint pos = 0; gint pos = 0;
@ -672,24 +667,24 @@ gimp_palette_delete_entry (GimpPalette *palette,
palette->n_colors--; palette->n_colors--;
for (list = g_list_nth (palette->colors, pos); for (list = g_list_nth (palette->colors, pos);
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
entry->position = pos++; entry->position = pos++;
} }
if (palette->n_colors == 0) if (palette->n_colors == 0)
{ {
GimpRGB color; GimpRGB color;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_palette_add_entry (palette, gimp_palette_add_entry (palette,
_("Black"), _("Black"),
&color); &color);
} }
/* will make the palette dirty too */ /* will make the palette dirty too */
gimp_object_name_changed (GIMP_OBJECT (palette)); gimp_object_name_changed (GIMP_OBJECT (palette));

View File

@ -112,15 +112,10 @@ gimp_palette_get_type (void)
static void static void
gimp_palette_class_init (GimpPaletteClass *klass) gimp_palette_class_init (GimpPaletteClass *klass)
{ {
GObjectClass *object_class; GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpObjectClass *gimp_object_class; GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
GimpViewableClass *viewable_class; GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
GimpDataClass *data_class; GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
data_class = GIMP_DATA_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -231,8 +226,8 @@ gimp_palette_get_popup_size (GimpViewable *viewable,
static TempBuf * static TempBuf *
gimp_palette_get_new_preview (GimpViewable *viewable, gimp_palette_get_new_preview (GimpViewable *viewable,
gint width, gint width,
gint height) gint height)
{ {
GimpPalette *palette = GIMP_PALETTE (viewable); GimpPalette *palette = GIMP_PALETTE (viewable);
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -269,28 +264,28 @@ gimp_palette_get_new_preview (GimpViewable *viewable,
memset (b, 255, width * 3); memset (b, 255, width * 3);
for (x = 0; x < columns && list; x++) for (x = 0; x < columns && list; x++)
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
list = g_list_next (list); list = g_list_next (list);
gimp_rgb_get_uchar (&entry->color, gimp_rgb_get_uchar (&entry->color,
&b[x * cell_size * 3 + 0], &b[x * cell_size * 3 + 0],
&b[x * cell_size * 3 + 1], &b[x * cell_size * 3 + 1],
&b[x * cell_size * 3 + 2]); &b[x * cell_size * 3 + 2]);
for (i = 1; i < cell_size; i++) for (i = 1; i < cell_size; i++)
{ {
b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0]; b[(x * cell_size + i) * 3 + 0] = b[(x * cell_size) * 3 + 0];
b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1]; b[(x * cell_size + i) * 3 + 1] = b[(x * cell_size) * 3 + 1];
b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2]; b[(x * cell_size + i) * 3 + 2] = b[(x * cell_size) * 3 + 2];
} }
} }
for (i = 0; i < cell_size; i++) for (i = 0; i < cell_size; i++)
{ {
memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3); memcpy (buf + ((y * cell_size + i) * width) * 3, b, width * 3);
} }
} }
g_free (b); g_free (b);
@ -380,13 +375,13 @@ gimp_palette_load (const gchar *filename,
{ {
/* bad magic, but maybe it has \r\n at the end of lines? */ /* bad magic, but maybe it has \r\n at the end of lines? */
if (!strcmp (str, "GIMP Palette\r")) if (!strcmp (str, "GIMP Palette\r"))
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header.\n" "Missing magic header.\n"
"Does this file need converting from DOS?"), "Does this file need converting from DOS?"),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
else else
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Missing magic header."), "Missing magic header."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
@ -424,48 +419,48 @@ gimp_palette_load (const gchar *filename,
g_free (utf8); g_free (utf8);
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
if (! strncmp (str, "Columns: ", strlen ("Columns: "))) if (! strncmp (str, "Columns: ", strlen ("Columns: ")))
{ {
gint columns; gint columns;
columns = atoi (g_strstrip (&str[strlen ("Columns: ")])); columns = atoi (g_strstrip (&str[strlen ("Columns: ")]));
if (columns < 0 || columns > 256) if (columns < 0 || columns > 256)
{ {
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Invalid number of columns in line %d. " "Invalid number of columns in line %d. "
"Using default value."), "Using default value."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
columns = 0; columns = 0;
} }
palette->n_columns = columns; palette->n_columns = columns;
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
} }
else /* old palette format */ else /* old palette format */
{ {
@ -484,71 +479,71 @@ gimp_palette_load (const gchar *filename,
while (! feof (file)) while (! feof (file))
{ {
if (str[0] != '#') if (str[0] != '#')
{ {
tok = strtok (str, " \t"); tok = strtok (str, " \t");
if (tok) if (tok)
r = atoi (tok); r = atoi (tok);
else else
/* maybe we should just abort? */ /* maybe we should just abort? */
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing RED component in line %d."), "Missing RED component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
g = atoi (tok); g = atoi (tok);
else else
g_message (_("Reading palette '%s': " g_message (_("Reading palette '%s': "
"Missing GREEN component in line %d."), "Missing GREEN component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
tok = strtok (NULL, " \t"); tok = strtok (NULL, " \t");
if (tok) if (tok)
b = atoi (tok); b = atoi (tok);
else else
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"Missing BLUE component in line %d."), "Missing BLUE component in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* optional name */ /* optional name */
tok = strtok (NULL, "\n"); tok = strtok (NULL, "\n");
if (r < 0 || r > 255 || if (r < 0 || r > 255 ||
g < 0 || g > 255 || g < 0 || g > 255 ||
b < 0 || b > 255) b < 0 || b > 255)
g_message (_("Reading palette file '%s': " g_message (_("Reading palette file '%s': "
"RGB value out of range in line %d."), "RGB value out of range in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
/* don't call gimp_palette_add_entry here, it's rather inefficient */ /* don't call gimp_palette_add_entry here, it's rather inefficient */
entry = g_new0 (GimpPaletteEntry, 1); entry = g_new0 (GimpPaletteEntry, 1);
gimp_rgba_set_uchar (&entry->color, gimp_rgba_set_uchar (&entry->color,
(guchar) r, (guchar) r,
(guchar) g, (guchar) g,
(guchar) b, (guchar) b,
255); 255);
entry->name = g_strdup (tok ? tok : _("Untitled")); entry->name = g_strdup (tok ? tok : _("Untitled"));
entry->position = palette->n_colors; entry->position = palette->n_colors;
palette->colors = g_list_prepend (palette->colors, entry); palette->colors = g_list_prepend (palette->colors, entry);
palette->n_colors++; palette->n_colors++;
} }
if (! fgets (str, sizeof (str), file)) if (! fgets (str, sizeof (str), file))
{ {
if (feof (file)) if (feof (file))
break; break;
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parse error in palette file '%s': " _("Fatal parse error in palette file '%s': "
"Read error in line %d."), "Read error in line %d."),
gimp_filename_to_utf8 (filename), linenum); gimp_filename_to_utf8 (filename), linenum);
fclose (file); fclose (file);
g_object_unref (palette); g_object_unref (palette);
return NULL; return NULL;
} }
linenum++; linenum++;
} }
@ -575,7 +570,7 @@ gimp_palette_save (GimpData *data,
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"), _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (data->filename), gimp_filename_to_utf8 (data->filename),
g_strerror (errno)); g_strerror (errno));
return FALSE; return FALSE;
} }
@ -627,9 +622,9 @@ gimp_palette_duplicate (GimpData *data,
} }
GimpPaletteEntry * GimpPaletteEntry *
gimp_palette_add_entry (GimpPalette *palette, gimp_palette_add_entry (GimpPalette *palette,
const gchar *name, const gchar *name,
GimpRGB *color) const GimpRGB *color)
{ {
GimpPaletteEntry *entry; GimpPaletteEntry *entry;
@ -654,7 +649,7 @@ gimp_palette_add_entry (GimpPalette *palette,
void void
gimp_palette_delete_entry (GimpPalette *palette, gimp_palette_delete_entry (GimpPalette *palette,
GimpPaletteEntry *entry) GimpPaletteEntry *entry)
{ {
GList *list; GList *list;
gint pos = 0; gint pos = 0;
@ -672,24 +667,24 @@ gimp_palette_delete_entry (GimpPalette *palette,
palette->n_colors--; palette->n_colors--;
for (list = g_list_nth (palette->colors, pos); for (list = g_list_nth (palette->colors, pos);
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
entry = (GimpPaletteEntry *) list->data; entry = (GimpPaletteEntry *) list->data;
entry->position = pos++; entry->position = pos++;
} }
if (palette->n_colors == 0) if (palette->n_colors == 0)
{ {
GimpRGB color; GimpRGB color;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_palette_add_entry (palette, gimp_palette_add_entry (palette,
_("Black"), _("Black"),
&color); &color);
} }
/* will make the palette dirty too */ /* will make the palette dirty too */
gimp_object_name_changed (GIMP_OBJECT (palette)); gimp_object_name_changed (GIMP_OBJECT (palette));

View File

@ -73,7 +73,7 @@ GimpData * gimp_palette_load (const gchar *filename,
GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette, GimpPaletteEntry * gimp_palette_add_entry (GimpPalette *palette,
const gchar *name, const gchar *name,
GimpRGB *color); const GimpRGB *color);
void gimp_palette_delete_entry (GimpPalette *palette, void gimp_palette_delete_entry (GimpPalette *palette,
GimpPaletteEntry *entry); GimpPaletteEntry *entry);