Fossil

Check-in [243d99d1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:I change the branch colour algorithm, for another one I can understand better. No HSV magic; simply few combinations of RGB values based on hash. This algorithm should give either different or equal colours, and not similar colours.

This way I think the hash differences are more likely to give different colours.

I had the feeling that we were getting too often too similar colours for our branches, but I can't prove that mathematically.

Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | annotate_links
Files: files | file ages | folders
SHA1: 243d99d128f35ce35bd26177830fbe91ab29c233
User & Date: viriketo 2012-04-22 09:50:15.324
Context
2012-04-22
09:56
Fix a comment in my previous commit. ... (check-in: 515e7fa0 user: viriketo tags: annotate_links)
09:50
I change the branch colour algorithm, for another one I can understand better. No HSV magic; simply few combinations of RGB values based on hash. This algorithm should give either different or equal colours, and not similar colours.

This way I think the hash differences are more likely to give different colours.

I had the feeling that we were getting too often too similar colours for our branches, but I can't prove that mathematically. ... (check-in: 243d99d1 user: viriketo tags: annotate_links)

2012-04-05
14:31
Made 'fossil commit' detect if the editor changed the file. If the editor did not change the file, ask confirmation, as if it was an empty comment.

I think svn behaves this way. ... (check-in: d2a733be user: viriketo tags: annotate_links)

Changes
Unified Diff Ignore Whitespace Patch
Changes to src/timeline.c.
116
117
118
119
120
121
122
123
124
125
126




127
128
129
130
131
132
133
134
135
136

137
138
139
140

141
142
143
144
145

146

147
148
149
150
151
152
153
154
155
156
157
158
159
/*
** Hash a string and use the hash to determine a background color.
*/
char *hash_color(const char *z){
  int i;                       /* Loop counter */
  unsigned int h = 0;          /* Hash on the branch name */
  int r, g, b;                 /* Values for red, green, and blue */
  int h1, h2, h3, h4;          /* Elements of the hash value */
  int mx, mn;                  /* Components of HSV */
  static char zColor[10];      /* The resulting color */
  static int ix[2] = {0,0};    /* Color chooser parameters */





  if( ix[0]==0 ){
    if( db_get_boolean("white-foreground", 0) ){
      ix[0] = 140;
      ix[1] = 40;
    }else{
      ix[0] = 216;
      ix[1] = 16;
    }
  }

  for(i=0; z[i]; i++ ){
    h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
  }
  h1 = h % 6;  h /= 6;

  h3 = h % 30; h /= 30;
  h4 = h % 40; h /= 40;
  mx = ix[0] - h3;
  mn = mx - h4 - ix[1];
  h2 = (h%(mx - mn)) + mn;

  switch( h1 ){

    case 0:  r = mx; g = h2, b = mn;  break;
    case 1:  r = h2; g = mx, b = mn;  break;
    case 2:  r = mn; g = mx, b = h2;  break;
    case 3:  r = mn; g = h2, b = mx;  break;
    case 4:  r = h2; g = mn, b = mx;  break;
    default: r = mx; g = mn, b = h2;  break;
  }
  sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
  return zColor;
}

/*
** COMMAND:  test-hash-color







<
<

|
>
>
>
>

|
|
<
<
<
<
<
|
<
>
|


|
>
|
|
|
|
<
>
|
>
|
|
|
<
<
<







116
117
118
119
120
121
122


123
124
125
126
127
128
129
130
131





132

133
134
135
136
137
138
139
140
141
142

143
144
145
146
147
148



149
150
151
152
153
154
155
/*
** Hash a string and use the hash to determine a background color.
*/
char *hash_color(const char *z){
  int i;                       /* Loop counter */
  unsigned int h = 0;          /* Hash on the branch name */
  int r, g, b;                 /* Values for red, green, and blue */


  static char zColor[10];      /* The resulting color */
  static int whitefg = -1;
  int cpc = 4;                 /* colours per component */
  int cfactor = 128/cpc;       /* Factor so n*cpc < 128 */
  int cmin = cfactor - 1;      /* Factor so the max component is 127
                                  and the min is different than the bg */

  if( whitefg = -1 ) 
    whitefg = db_get_boolean("white-foreground", 0);







  /* Calculate the hash based on the branch name */
  for( i=0; z[i]; i++ ){
    h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
  }

  /* 4 different random values per component, between 31 and 127 */
  r = cmin + (h % cpc) * cfactor;  h /= cpc;
  g = cmin + (h % cpc) * cfactor;  h /= cpc;
  b = cmin + (h % cpc) * cfactor;  h /= cpc;


  /* In case of blackfg, get the inverse effect */
  if( !whitefg )
  {
      r = 255 - r;
      g = 255 - g;
      b = 255 - b;



  }
  sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
  return zColor;
}

/*
** COMMAND:  test-hash-color