Fossil

Check-in [39e165af]
Login

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

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | viric_newcolours
Files: files | file ages | folders
SHA1:39e165afb3646b9ab7db34fd681eaa2457122955
User & Date: viriketo 2015-02-09 10:30:42
References
2015-02-09
11:00
viric's flavour of fossil, which includes the cherry-picked changes out of trunk: [d0b1b1114] [39e165afb] [dad37196f] [f309130a8]. This outdates the branch annotate_links ([f14798e0e3]), which has some extra changes, some hard to port.

This lets the browser pick the right program to open them straight. check-in: b31afcc2 user: viriketo tags: viric_flavour

Context
2015-02-09
10:30
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. Leaf check-in: 39e165af user: viriketo tags: viric_newcolours

10:13
Omit unused c= parameters from hyperlinks in the /timeline. check-in: 65b729ac user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/timeline.c.

100
101
102
103
104
105
106
107
108
109


110


111
112

113
114
115
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
/*
** 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







<
<

>
>
|
>
>

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


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







100
101
102
103
104
105
106


107
108
109
110
111
112
113

114
115





116

117
118
119
120
121
122
123
124
125

126
127
128

129
130
131
132




133
134
135
136
137
138
139
/*
** 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];
  }

  /* 'cpc' different random values per component, between 'cmin' 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