Fossil SCM

Improvements to the background color-filter algorithm.

drh 2025-03-26 11:17 trunk
Commit fd2a718eb54e80af4d72e9b8fb77685f953d883cb54457d707cf36e06dc9a09d
1 file changed +17 -28
+17 -28
--- src/color.c
+++ src/color.c
@@ -185,11 +185,13 @@
185185
int i, v = 0;
186186
for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){
187187
v = v*16 + fossil_hexvalue(zName[i]);
188188
}
189189
if( i==4 ){
190
- for(v=0, i=1; i<4; i++) v = v*256 + fossil_hexvalue(zName[i]);
190
+ v = fossil_hexvalue(zName[1])*0x110000 +
191
+ fossil_hexvalue(zName[2])*0x1100 +
192
+ fossil_hexvalue(zName[3])*0x11;
191193
return v;
192194
}
193195
if( i==7 ){
194196
return v;
195197
}
@@ -234,17 +236,14 @@
234236
** The iFgClr parameter is normally 0. But for testing purposes, set
235237
** it to 1 for a black foregrounds and 2 for a white foreground.
236238
*/
237239
const char *reasonable_bg_color(const char *zRequested, int iFgClr){
238240
int iRGB = color_name_to_rgb(zRequested);
239
- int cc[3];
240
- int lo, hi;
241
- int r, g, b;
241
+ int r, g, b; /* RGB components of requested color */
242242
static int systemFg = 0; /* 1==black-foreground 2==white-foreground */
243243
int fg; /* Foreground color to actually use */
244244
static char zColor[10]; /* Return value */
245
- int K = 70; /* Tune for background color saturation */
246245
247246
if( iFgClr ){
248247
fg = iFgClr;
249248
}else if( systemFg==0 ){
250249
if( db_get_boolean("raw-bgcolor",0) ){
@@ -256,33 +255,23 @@
256255
fg = systemFg;
257256
}
258257
if( fg>=3 ) return zRequested;
259258
260259
if( iRGB<0 ) return 0;
261
- if( fg==0 ) fg = skin_detail_boolean("white-foreground") ? 2 : 1;
262
- cc[0] = (iRGB>>16) & 0xff;
263
- cc[1] = (iRGB>>8) & 0xff;
264
- cc[2] = iRGB & 0xff;
265
- lo = cc[0]<cc[1] ? 0 : 1;
266
- if( cc[2]<cc[lo] ) lo = 2;
267
- hi = cc[0]>cc[1] ? 0 : 1;
268
- if( cc[2]>cc[hi] ) hi = 2;
269
- if( cc[lo]==cc[hi] ){
270
- /* Requested color is some shade of gray */
271
- r = (K*cc[0])/255;
272
- if( fg==1 ) r += (255-K);
273
- g = b = r;
260
+ r = (iRGB>>16) & 0xff;
261
+ g = (iRGB>>8) & 0xff;
262
+ b = iRGB & 0xff;
263
+ if( fg==1 ){
264
+ const int K = 70;
265
+ r = (K*r)/255 + (255-K);
266
+ g = (K*g)/255 + (255-K);
267
+ b = (K*b)/255 + (255-K);
274268
}else{
275
- int d = cc[hi] - cc[lo];
276
- r = (K*(cc[0] - cc[lo]))/d;
277
- g = (K*(cc[1] - cc[lo]))/d;
278
- b = (K*(cc[2] - cc[lo]))/d;
279
- if( fg==1 ){
280
- r += (255-K);
281
- g += (255-K);
282
- b += (255-K);
283
- }
269
+ const int K = 90;
270
+ r = (K*r)/255;
271
+ g = (K*g)/255;
272
+ b = (K*b)/255;
284273
}
285274
sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
286275
return zColor;
287276
}
288277
@@ -492,11 +481,11 @@
492481
}
493482
iClr = color_name_to_rgb(zReq);
494483
r = (iClr>>16) & 0xff;
495484
g = (iClr>>8) & 0xff;
496485
b = iClr & 0xff;
497
- if( 3*r + 6*g + b > 5*255 ){
486
+ if( 3*r + 7*g + b > 6*255 ){
498487
zFg = "black";
499488
}else{
500489
zFg = "white";
501490
}
502491
if( zReq[0]!='#' ){
503492
--- src/color.c
+++ src/color.c
@@ -185,11 +185,13 @@
185 int i, v = 0;
186 for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){
187 v = v*16 + fossil_hexvalue(zName[i]);
188 }
189 if( i==4 ){
190 for(v=0, i=1; i<4; i++) v = v*256 + fossil_hexvalue(zName[i]);
 
 
191 return v;
192 }
193 if( i==7 ){
194 return v;
195 }
@@ -234,17 +236,14 @@
234 ** The iFgClr parameter is normally 0. But for testing purposes, set
235 ** it to 1 for a black foregrounds and 2 for a white foreground.
236 */
237 const char *reasonable_bg_color(const char *zRequested, int iFgClr){
238 int iRGB = color_name_to_rgb(zRequested);
239 int cc[3];
240 int lo, hi;
241 int r, g, b;
242 static int systemFg = 0; /* 1==black-foreground 2==white-foreground */
243 int fg; /* Foreground color to actually use */
244 static char zColor[10]; /* Return value */
245 int K = 70; /* Tune for background color saturation */
246
247 if( iFgClr ){
248 fg = iFgClr;
249 }else if( systemFg==0 ){
250 if( db_get_boolean("raw-bgcolor",0) ){
@@ -256,33 +255,23 @@
256 fg = systemFg;
257 }
258 if( fg>=3 ) return zRequested;
259
260 if( iRGB<0 ) return 0;
261 if( fg==0 ) fg = skin_detail_boolean("white-foreground") ? 2 : 1;
262 cc[0] = (iRGB>>16) & 0xff;
263 cc[1] = (iRGB>>8) & 0xff;
264 cc[2] = iRGB & 0xff;
265 lo = cc[0]<cc[1] ? 0 : 1;
266 if( cc[2]<cc[lo] ) lo = 2;
267 hi = cc[0]>cc[1] ? 0 : 1;
268 if( cc[2]>cc[hi] ) hi = 2;
269 if( cc[lo]==cc[hi] ){
270 /* Requested color is some shade of gray */
271 r = (K*cc[0])/255;
272 if( fg==1 ) r += (255-K);
273 g = b = r;
274 }else{
275 int d = cc[hi] - cc[lo];
276 r = (K*(cc[0] - cc[lo]))/d;
277 g = (K*(cc[1] - cc[lo]))/d;
278 b = (K*(cc[2] - cc[lo]))/d;
279 if( fg==1 ){
280 r += (255-K);
281 g += (255-K);
282 b += (255-K);
283 }
284 }
285 sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
286 return zColor;
287 }
288
@@ -492,11 +481,11 @@
492 }
493 iClr = color_name_to_rgb(zReq);
494 r = (iClr>>16) & 0xff;
495 g = (iClr>>8) & 0xff;
496 b = iClr & 0xff;
497 if( 3*r + 6*g + b > 5*255 ){
498 zFg = "black";
499 }else{
500 zFg = "white";
501 }
502 if( zReq[0]!='#' ){
503
--- src/color.c
+++ src/color.c
@@ -185,11 +185,13 @@
185 int i, v = 0;
186 for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){
187 v = v*16 + fossil_hexvalue(zName[i]);
188 }
189 if( i==4 ){
190 v = fossil_hexvalue(zName[1])*0x110000 +
191 fossil_hexvalue(zName[2])*0x1100 +
192 fossil_hexvalue(zName[3])*0x11;
193 return v;
194 }
195 if( i==7 ){
196 return v;
197 }
@@ -234,17 +236,14 @@
236 ** The iFgClr parameter is normally 0. But for testing purposes, set
237 ** it to 1 for a black foregrounds and 2 for a white foreground.
238 */
239 const char *reasonable_bg_color(const char *zRequested, int iFgClr){
240 int iRGB = color_name_to_rgb(zRequested);
241 int r, g, b; /* RGB components of requested color */
 
 
242 static int systemFg = 0; /* 1==black-foreground 2==white-foreground */
243 int fg; /* Foreground color to actually use */
244 static char zColor[10]; /* Return value */
 
245
246 if( iFgClr ){
247 fg = iFgClr;
248 }else if( systemFg==0 ){
249 if( db_get_boolean("raw-bgcolor",0) ){
@@ -256,33 +255,23 @@
255 fg = systemFg;
256 }
257 if( fg>=3 ) return zRequested;
258
259 if( iRGB<0 ) return 0;
260 r = (iRGB>>16) & 0xff;
261 g = (iRGB>>8) & 0xff;
262 b = iRGB & 0xff;
263 if( fg==1 ){
264 const int K = 70;
265 r = (K*r)/255 + (255-K);
266 g = (K*g)/255 + (255-K);
267 b = (K*b)/255 + (255-K);
 
 
 
 
 
268 }else{
269 const int K = 90;
270 r = (K*r)/255;
271 g = (K*g)/255;
272 b = (K*b)/255;
 
 
 
 
 
273 }
274 sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
275 return zColor;
276 }
277
@@ -492,11 +481,11 @@
481 }
482 iClr = color_name_to_rgb(zReq);
483 r = (iClr>>16) & 0xff;
484 g = (iClr>>8) & 0xff;
485 b = iClr & 0xff;
486 if( 3*r + 7*g + b > 6*255 ){
487 zFg = "black";
488 }else{
489 zFg = "white";
490 }
491 if( zReq[0]!='#' ){
492

Keyboard Shortcuts

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