Fossil SCM

New way to calculate the automatic branch colours. It's a matter of taste, but I prefer this way; the colours often become more different.

viriketo 2015-02-09 10:30 trunk
Commit 39e165afb3646b9ab7db34fd681eaa2457122955
1 file changed +23 -27
+23 -27
--- src/timeline.c
+++ src/timeline.c
@@ -102,40 +102,36 @@
102102
*/
103103
char *hash_color(const char *z){
104104
int i; /* Loop counter */
105105
unsigned int h = 0; /* Hash on the branch name */
106106
int r, g, b; /* Values for red, green, and blue */
107
- int h1, h2, h3, h4; /* Elements of the hash value */
108
- int mx, mn; /* Components of HSV */
109107
static char zColor[10]; /* The resulting color */
110
- static int ix[2] = {0,0}; /* Color chooser parameters */
111
-
112
- if( ix[0]==0 ){
113
- if( db_get_boolean("white-foreground", 0) ){
114
- ix[0] = 140;
115
- ix[1] = 40;
116
- }else{
117
- ix[0] = 216;
118
- ix[1] = 16;
119
- }
120
- }
121
- for(i=0; z[i]; i++ ){
108
+ static int whitefg = -1;
109
+ int cpc = 4; /* colours per component */
110
+ int cfactor = 128/cpc; /* Factor so n*cpc < 128 */
111
+ int cmin = cfactor - 1; /* Factor so the max component is 127
112
+ and the min is different than the bg */
113
+
114
+ if(whitefg = -1)
115
+ whitefg = db_get_boolean("white-foreground", 0);
116
+
117
+ /* Calculate the hash based on the branch name */
118
+ for(i=0; z[i]; i++){
122119
h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
123120
}
124
- h1 = h % 6; h /= 6;
125
- h3 = h % 30; h /= 30;
126
- h4 = h % 40; h /= 40;
127
- mx = ix[0] - h3;
128
- mn = mx - h4 - ix[1];
129
- h2 = (h%(mx - mn)) + mn;
130
- switch( h1 ){
131
- case 0: r = mx; g = h2, b = mn; break;
132
- case 1: r = h2; g = mx, b = mn; break;
133
- case 2: r = mn; g = mx, b = h2; break;
134
- case 3: r = mn; g = h2, b = mx; break;
135
- case 4: r = h2; g = mn, b = mx; break;
136
- default: r = mx; g = mn, b = h2; break;
121
+
122
+ /* 'cpc' different random values per component, between 'cmin' and 127 */
123
+ r = cmin + (h % cpc) * cfactor; h /= cpc;
124
+ g = cmin + (h % cpc) * cfactor; h /= cpc;
125
+ b = cmin + (h % cpc) * cfactor; h /= cpc;
126
+
127
+ /* In case of blackfg, get the inverse effect */
128
+ if(!whitefg)
129
+ {
130
+ r = 255 - r;
131
+ g = 255 - g;
132
+ b = 255 - b;
137133
}
138134
sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
139135
return zColor;
140136
}
141137
142138
--- src/timeline.c
+++ src/timeline.c
@@ -102,40 +102,36 @@
102 */
103 char *hash_color(const char *z){
104 int i; /* Loop counter */
105 unsigned int h = 0; /* Hash on the branch name */
106 int r, g, b; /* Values for red, green, and blue */
107 int h1, h2, h3, h4; /* Elements of the hash value */
108 int mx, mn; /* Components of HSV */
109 static char zColor[10]; /* The resulting color */
110 static int ix[2] = {0,0}; /* Color chooser parameters */
111
112 if( ix[0]==0 ){
113 if( db_get_boolean("white-foreground", 0) ){
114 ix[0] = 140;
115 ix[1] = 40;
116 }else{
117 ix[0] = 216;
118 ix[1] = 16;
119 }
120 }
121 for(i=0; z[i]; i++ ){
122 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
123 }
124 h1 = h % 6; h /= 6;
125 h3 = h % 30; h /= 30;
126 h4 = h % 40; h /= 40;
127 mx = ix[0] - h3;
128 mn = mx - h4 - ix[1];
129 h2 = (h%(mx - mn)) + mn;
130 switch( h1 ){
131 case 0: r = mx; g = h2, b = mn; break;
132 case 1: r = h2; g = mx, b = mn; break;
133 case 2: r = mn; g = mx, b = h2; break;
134 case 3: r = mn; g = h2, b = mx; break;
135 case 4: r = h2; g = mn, b = mx; break;
136 default: r = mx; g = mn, b = h2; break;
137 }
138 sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
139 return zColor;
140 }
141
142
--- src/timeline.c
+++ src/timeline.c
@@ -102,40 +102,36 @@
102 */
103 char *hash_color(const char *z){
104 int i; /* Loop counter */
105 unsigned int h = 0; /* Hash on the branch name */
106 int r, g, b; /* Values for red, green, and blue */
 
 
107 static char zColor[10]; /* The resulting color */
108 static int whitefg = -1;
109 int cpc = 4; /* colours per component */
110 int cfactor = 128/cpc; /* Factor so n*cpc < 128 */
111 int cmin = cfactor - 1; /* Factor so the max component is 127
112 and the min is different than the bg */
113
114 if(whitefg = -1)
115 whitefg = db_get_boolean("white-foreground", 0);
116
117 /* Calculate the hash based on the branch name */
118 for(i=0; z[i]; i++){
 
119 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
120 }
121
122 /* 'cpc' different random values per component, between 'cmin' and 127 */
123 r = cmin + (h % cpc) * cfactor; h /= cpc;
124 g = cmin + (h % cpc) * cfactor; h /= cpc;
125 b = cmin + (h % cpc) * cfactor; h /= cpc;
126
127 /* In case of blackfg, get the inverse effect */
128 if(!whitefg)
129 {
130 r = 255 - r;
131 g = 255 - g;
132 b = 255 - b;
 
133 }
134 sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
135 return zColor;
136 }
137
138

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button