gint gimp_palette_editor_get_index (GimpPaletteEditor *editor, const GimpRGB *search) { GimpPalette *palette; g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), -1); g_return_val_if_fail (search != NULL, -1); palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data); if (palette && gimp_palette_get_n_colors (palette) > 0) { GimpPaletteEntry *entry; entry = gimp_palette_find_entry (palette, search, editor->color); if (entry) return entry->position; } return -1; }
static void gimp_color_selector_palette_set_color (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv) { GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector); if (select->context) { GimpPalette *palette = gimp_context_get_palette (select->context); if (palette && palette->n_colors > 0) { GimpPaletteEntry *entry; entry = gimp_palette_find_entry (palette, rgb, GIMP_PALETTE_VIEW (select->view)->selected); if (entry) gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (select->view), entry); } } }
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); }
GList * gimp_palette_load_css (GimpContext *context, GFile *file, GInputStream *input, GError **error) { GimpPalette *palette; GDataInputStream *data_input; gchar *name; GRegex *regex; gchar *buf; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_INPUT_STREAM (input), 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; name = g_path_get_basename (gimp_file_get_utf8_name (file)); palette = GIMP_PALETTE (gimp_palette_new (context, name)); g_free (name); data_input = g_data_input_stream_new (input); do { gsize buf_len = 1024; buf = g_data_input_stream_read_line (data_input, &buf_len, NULL, NULL); if (buf) { GMatchInfo *matches; if (g_regex_match (regex, buf, 0, &matches)) { GimpRGB color; 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); } g_match_info_free (matches); g_free (buf); } } while (buf); g_regex_unref (regex); g_object_unref (data_input); return g_list_prepend (NULL, palette); }