comparison src/gtkconv.c @ 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 f758af0373cb
comparison
equal deleted inserted replaced
12359:cbf9f2e26916 12360:3153661f4d5c
64 #include "gtkprivacy.h" 64 #include "gtkprivacy.h"
65 #include "gtkthemes.h" 65 #include "gtkthemes.h"
66 #include "gtkutils.h" 66 #include "gtkutils.h"
67 #include "gtkstock.h" 67 #include "gtkstock.h"
68 68
69 #include "gtknickcolors.h"
70
69 #define AUTO_RESPONSE "&lt;AUTO-REPLY&gt; : " 71 #define AUTO_RESPONSE "&lt;AUTO-REPLY&gt; : "
70 72
71 #define SEND_COLOR "#204a87" 73 #define SEND_COLOR "#204a87"
72 #define RECV_COLOR "#cc0000" 74 #define RECV_COLOR "#cc0000"
73 #define HIGHLIGHT_COLOR "#AF7F00" 75 #define HIGHLIGHT_COLOR "#AF7F00"
7536 7538
7537 /* this algorithm expects colors between 0 and 255 for each of red green and blue. 7539 /* this algorithm expects colors between 0 and 255 for each of red green and blue.
7538 * GTK on the other hand has values between 0 and 65535 7540 * GTK on the other hand has values between 0 and 65535
7539 * Err suggested I >> 8, which grabbed the high bits. 7541 * Err suggested I >> 8, which grabbed the high bits.
7540 */ 7542 */
7541 7543
7542 fred = foreground.red >> 8 ; 7544 fred = foreground.red >> 8 ;
7543 fgreen = foreground.green >> 8 ; 7545 fgreen = foreground.green >> 8 ;
7544 fblue = foreground.blue >> 8 ; 7546 fblue = foreground.blue >> 8 ;
7545 7547
7546 7548
7559 7561
7560 7562
7561 static GdkColor* 7563 static GdkColor*
7562 generate_nick_colors(guint numcolors, GdkColor background) 7564 generate_nick_colors(guint numcolors, GdkColor background)
7563 { 7565 {
7564 guint i; 7566 guint i = 0;
7565 GdkColor *colors = g_new(GdkColor, numcolors); 7567 GdkColor *colors = g_new(GdkColor, numcolors);
7566 GdkColor nick_highlight; 7568 GdkColor nick_highlight;
7567 GdkColor send_color; 7569 GdkColor send_color;
7568 7570
7569 gdk_color_parse(HIGHLIGHT_COLOR, &nick_highlight); 7571 gdk_color_parse(HIGHLIGHT_COLOR, &nick_highlight);
7570 gdk_color_parse(SEND_COLOR, &send_color); 7572 gdk_color_parse(SEND_COLOR, &send_color);
7571 7573
7572 srand(background.red + background.green + background.blue + 1); 7574 srand(background.red + background.green + background.blue + 1);
7573 7575
7574 for (i = 0; i < numcolors; ) 7576 for (i ; i < numcolors; )
7575 { 7577 {
7576 GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 }; 7578 GdkColor color = nick_seed_colors[i];
7579
7577 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && 7580 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) &&
7578 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && 7581 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
7579 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0)) 7582 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0))
7580 { 7583 {
7581 colors[i] = color; 7584 colors[i] = color;
7582 i++; 7585 i++;
7583 } 7586 }
7584 } 7587 }
7585 7588
7589 for (i ; i < numcolors; )
7590 {
7591 GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 };
7592
7593 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) &&
7594 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
7595 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0))
7596 {
7597 colors[i] = color;
7598 i++;
7599 }
7600 }
7601
7586 return colors; 7602 return colors;
7587 } 7603 }