Mercurial > pidgin.yaz
changeset 12360:3153661f4d5c
[gaim-migrate @ 14664]
Faceprint is concerned about 2 things:
1)some of the random colors are very close together.
as best we can tell, there are two ways to fix this
1a) for each proposed color, iterate the entire list of selected
colors, looking to ensure that it is not too close to any of them.
this is an O(n^2) operation, with n >= 220 (the current number of
colors we look for)
1b) iterate the entire set of possible colors, skipping ahead by some
guess (rather than iterating by 1). this is an O(n^3) operation,
where n is 65535/(whatever we skip ahead by). This is not only a
more expensive operation, but because of the nature of the color
list, it is not _necessarily_ going to yield more predictable
results, skipping ahead 5 (or any other number) does not necessarily
guarantee that you've skipped 5 very similar colors.
2) as you can see, either solution to #1 is potentially a resource hog.
#1a is a random delay, #1b is inherently expensive. How often #1a will
exceed the bound #1b, if ever, is unknown.
rather than doing either of these, we settled on a middle course: a .h
file has been created containing a set of colors. currently the set we
were previously hard coded to. Gaim will search that list for usable
colors and start randomly looking only if that list does not contain
sufficient usable colors. ideally this list would be generated to have
colors that are known to be a "safe" distance appart, that is colors that
you can tell appart. and Ideally it would have a (small) multiple of the
number of colors we are searching for. This should ensure that IF we go
to randomly searching, we need do so only for a few colors.
Right now I have no good way to generate a "safe" list of colors though.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 05 Dec 2005 21:46:47 +0000 |
parents | cbf9f2e26916 |
children | 88de0d2fb68e |
files | src/Makefile.am src/gtkconv.c src/gtknickcolors.h |
diffstat | 3 files changed, 74 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am Mon Dec 05 20:35:50 2005 +0000 +++ b/src/Makefile.am Mon Dec 05 21:46:47 2005 +0000 @@ -315,6 +315,7 @@ gtklog.h \ gtkmedia.h \ gtkmenutray.h \ + gtknickcolors.h \ gtknotify.h \ gtkplugin.h \ gtkpluginpref.h \
--- a/src/gtkconv.c Mon Dec 05 20:35:50 2005 +0000 +++ b/src/gtkconv.c Mon Dec 05 21:46:47 2005 +0000 @@ -66,6 +66,8 @@ #include "gtkutils.h" #include "gtkstock.h" +#include "gtknickcolors.h" + #define AUTO_RESPONSE "<AUTO-REPLY> : " #define SEND_COLOR "#204a87" @@ -7538,7 +7540,7 @@ * GTK on the other hand has values between 0 and 65535 * Err suggested I >> 8, which grabbed the high bits. */ - + fred = foreground.red >> 8 ; fgreen = foreground.green >> 8 ; fblue = foreground.blue >> 8 ; @@ -7561,7 +7563,7 @@ static GdkColor* generate_nick_colors(guint numcolors, GdkColor background) { - guint i; + guint i = 0; GdkColor *colors = g_new(GdkColor, numcolors); GdkColor nick_highlight; GdkColor send_color; @@ -7571,9 +7573,23 @@ srand(background.red + background.green + background.blue + 1); - for (i = 0; i < numcolors; ) + for (i ; i < numcolors; ) + { + GdkColor color = nick_seed_colors[i]; + + if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && + color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && + color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0)) + { + colors[i] = color; + i++; + } + } + + for (i ; i < numcolors; ) { GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 }; + if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtknickcolors.h Mon Dec 05 21:46:47 2005 +0000 @@ -0,0 +1,54 @@ +/** + * @file gtknickcolors.h GTK+ Conversation API + * @ingroup gtkui + * + * gaim + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_GTKNICKCOLORS_H_ +#define _GAIM_GTKNICKCOLORS_H_ + +static GdkColor nick_seed_colors[] = { + {0, 47616, 46336, 43776}, /* Basic 3D Medium */ + {0, 32768, 32000, 29696}, /* Basic 3D Dark */ + {0, 22016, 20992, 18432}, /* 3D Shadow */ + {0, 33536, 42496, 32512}, /* Green Medium */ + {0, 23808, 29952, 21760}, /* Green Dark */ + {0, 17408, 22016, 12800}, /* Green Shadow */ + {0, 57344, 46592, 44800}, /* Red Hilight */ + {0, 49408, 26112, 23040}, /* Red Medium */ + {0, 34816, 17920, 12544}, /* Red Dark */ + {0, 49408, 14336, 8704}, /* Red Shadow */ + {0, 34816, 32512, 41728}, /* Purple Medium */ + {0, 25088, 23296, 33024}, /* Purple Dark */ + {0, 18688, 16384, 26112}, /* Purple Shadow */ + {0, 40192, 47104, 53760}, /* Blue Hilight */ + {0, 29952, 36864, 44544}, /* Blue Medium */ + {0, 57344, 49920, 40448}, /* Face Skin Medium */ + {0, 45824, 37120, 26880}, /* Face skin Dark */ + {0, 33280, 26112, 18176}, /* Face Skin Shadow */ + {0, 57088, 16896, 7680}, /* Accent Red */ + {0, 39168, 0, 0}, /* Accent Red Dark */ + {0, 17920, 40960, 17920}, /* Accent Green */ + {0, 9728, 50944, 9728} /* Accent Green Dark */ +}; + +#define NUM_NICK_SEED_COLORS (sizeof(nick_seed_colors) / sizeof(nick_seed_colors[0])) + +#endif