From d19c796234bad74441393c0a873da5f447b9b0ed Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 12 Sep 2006 10:37:45 +0000 Subject: [PATCH] applied a modified patch from David Gowers that changes the search 2006-09-12 Sven Neumann * app/widgets/gimppaletteeditor.c (gimp_palette_editor_get_index): applied a modified patch from David Gowers that changes the search behaviour to favour colors in the neighborhood of the selected color (bug #355520). --- ChangeLog | 7 ++++++ app/widgets/gimppaletteeditor.c | 42 +++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39b5f3fec0..848e63ca41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-09-12 Sven Neumann + + * app/widgets/gimppaletteeditor.c (gimp_palette_editor_get_index): + applied a modified patch from David Gowers that changes the search + behaviour to favour colors in the neighborhood of the selected color + (bug #355520). + 2006-09-12 Sven Neumann * configure.in: mention the Win32 twain plug-in in the summary. diff --git a/app/widgets/gimppaletteeditor.c b/app/widgets/gimppaletteeditor.c index ef11ae9f4a..59f34d053a 100644 --- a/app/widgets/gimppaletteeditor.c +++ b/app/widgets/gimppaletteeditor.c @@ -578,11 +578,12 @@ gimp_palette_editor_get_index (GimpPaletteEditor *editor, if (search) { - if (! editor->color || - gimp_rgb_distance (&editor->color->color, search) > EPSILON) + if (! editor->color) { GList *list; + /* search from the start */ + for (list = palette->colors; list; list = g_list_next (list)) { GimpPaletteEntry *entry = list->data; @@ -594,6 +595,43 @@ gimp_palette_editor_get_index (GimpPaletteEditor *editor, } } } + else if (gimp_rgb_distance (&editor->color->color, search) > EPSILON) + { + GList *old = g_list_nth (palette->colors, editor->color->position); + GList *next = old->next; + GList *prev = old->prev; + + /* proximity-based search */ + + while (next || prev) + { + if (next) + { + GimpPaletteEntry *entry = next->data; + + if (gimp_rgb_distance (&entry->color, search) < EPSILON) + { + index = entry->position; + break; + } + + next = next->next; + } + + if (prev) + { + GimpPaletteEntry *entry = prev->data; + + if (gimp_rgb_distance (&entry->color, search) < EPSILON) + { + index = entry->position; + break; + } + + prev = prev->prev; + } + } + } } return index;