Gnus development mailing list
 help / color / mirror / Atom feed
* HTML foreground and background colors being the same... poll time!
@ 1998-12-03 14:00 William M. Perry
  1998-12-03 14:26 ` Hrvoje Niksic
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: William M. Perry @ 1998-12-03 14:00 UTC (permalink / raw)


Ok, so what should Emacs/W3 do if someone happens to lose so badly as to
specify a background or foreground color without also specifying the other?

We could:

a) Do nothing (current practice)
b) Infer the missing color by taking rgb(~r,~g,~b) 
c) Infer the color some other way?

a is ugly and bad and should change, I think we would all agree.

b is pretty easy to implement:

(defun infer-contrasting-color (r g b)
  (if (and (<= r 255)
	   (<= g 255)
	   (<= b 255))
      (format "#%02x%02x%02x"
	      (logxor r 255)
	      (logxor g 255)
	      (logxor b 255)))
  (format "#%04x%04x%04x"
	  (logxor r 65535)
	  (logxor g 65535)
	  (logxor b 65535)))


but for things like a pure red background it ends up giving you aquamarine, 
which is kind of eye searing.

I'd vote for (c), but I have no clue on how to go about finding or writing
a good contrast-finding algorithm.  Anyone out there know of one?

-Bill P.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
@ 1998-12-03 14:26 ` Hrvoje Niksic
  1998-12-03 14:37   ` Didier Verna
  1998-12-03 14:54 ` Colin Rafferty
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hrvoje Niksic @ 1998-12-03 14:26 UTC (permalink / raw)


"William M. Perry" <wmperry@aventail.com> writes:

> I'd vote for (c), but I have no clue on how to go about finding or
> writing a good contrast-finding algorithm.  Anyone out there know of
> one?

You can look at how XEmacs implements the "shadows" in redisplay-x.c.
That's one example I know of.

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
You have an unusual magnetic personality.  Don't walk too close to
metal objects which are not fastened down.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:26 ` Hrvoje Niksic
@ 1998-12-03 14:37   ` Didier Verna
  1998-12-03 14:44     ` Hrvoje Niksic
  0 siblings, 1 reply; 12+ messages in thread
From: Didier Verna @ 1998-12-03 14:37 UTC (permalink / raw)
  Cc: ding

Hrvoje Niksic writes:

Hrvoje> "William M. Perry" <wmperry@aventail.com> writes:
>> I'd vote for (c), but I have no clue on how to go about finding or writing
>> a good contrast-finding algorithm. Anyone out there know of one?

Hrvoje> You can look at how XEmacs implements the "shadows" in redisplay-x.c. 
Hrvoje> That's one example I know of.

	Not quite. All they do is modify the brightness around one color (the
widget background), and they actually [in|de]crease all RGB components by the
same amount. Finding the best contrast for a given color may involve using a
totally different one. The guys at gimp could probably help you on this.

-- 
    /     /   _   _       Didier Verna        http://www.inf.enst.fr/~verna/
 - / / - / / /_/ /      E.N.S.T. INF C201.1      mailto:verna@inf.enst.fr
/_/ / /_/ / /__ /        46 rue Barrault        Tel.   (33) 01 45 81 73 46
                      75634 Paris  cedex 13     Fax.   (33) 01 45 81 31 19


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:37   ` Didier Verna
@ 1998-12-03 14:44     ` Hrvoje Niksic
  0 siblings, 0 replies; 12+ messages in thread
From: Hrvoje Niksic @ 1998-12-03 14:44 UTC (permalink / raw)


Didier Verna <verna@inf.enst.fr> writes:

> Hrvoje Niksic writes:
> 
> Hrvoje> "William M. Perry" <wmperry@aventail.com> writes:
> >> I'd vote for (c), but I have no clue on how to go about finding
> >> or writing a good contrast-finding algorithm. Anyone out there
> >> know of one?
> 
> Hrvoje> You can look at how XEmacs implements the "shadows" in
> Hrvoje> redisplay-x.c.  That's one example I know of.
> 
> Not quite. All they do is modify the brightness around one color
> (the widget background), and they actually [in|de]crease all RGB
> components by the same amount. Finding the best contrast for a given
> color may involve using a totally different one. The guys at gimp
> could probably help you on this.

Thanks for the reality check.  I thought the stuff at redisplay-x was
general.

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
The meta-Turing test counts a thing as intelligent if it seeks to
devise and apply Turing tests to objects of its own creation.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
  1998-12-03 14:26 ` Hrvoje Niksic
@ 1998-12-03 14:54 ` Colin Rafferty
  1998-12-03 16:08   ` Ken McGlothlen
  1998-12-03 14:56 ` Bill White
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Colin Rafferty @ 1998-12-03 14:54 UTC (permalink / raw)


William M Perry writes:

> I'd vote for (c), but I have no clue on how to go about finding or writing
> a good contrast-finding algorithm.  Anyone out there know of one?

I vote for (c), but I know that finding contrasting colors is hard to
do.  However, since all you need is a single constrasting color, you
could choose between black and white.

;; Take the "average" level, and go opposite

(defun infer-contrasting-color (r g b)
  (if (and (<= r 255)
	   (<= g 255)
	   (<= b 255))
      (if (< (+ r g b) 384) "white" "black")   ; (/ (* 256 3) 2) => 384
    (if (< (+ r g b) 98304) "white" "black"))) ; (/ (* 65536 3) 2) =>  => 382

;; Colin


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
  1998-12-03 14:26 ` Hrvoje Niksic
  1998-12-03 14:54 ` Colin Rafferty
@ 1998-12-03 14:56 ` Bill White
  1998-12-03 16:43 ` Wes Hardaker
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Bill White @ 1998-12-03 14:56 UTC (permalink / raw)
  Cc: w3-beta, ding

In message <199812031400.JAA09195@kramer.bp.aventail.com>,
"William M. Perry" <wmperry@aventail.com> wrote:

> b is pretty easy to implement:
> 
> (defun infer-contrasting-color (r g b)
>   (if (and (<= r 255)
> 	   (<= g 255)
> 	   (<= b 255))
>       (format "#%02x%02x%02x"
> 	      (logxor r 255)
> 	      (logxor g 255)
> 	      (logxor b 255)))
>   (format "#%04x%04x%04x"
> 	  (logxor r 65535)
> 	  (logxor g 65535)
> 	  (logxor b 65535)))

For (r g b) = (127 127 127) this would return (128 128 128) - not
much contrast :-(

bw
-- 
Bill White . billw@wolfram.com . http://www.wolfram.com/~billw
I have discovered a truly wonderful proof of Fermat's Last Theorem,
but unfortunately this .signature is too small to contain it.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:54 ` Colin Rafferty
@ 1998-12-03 16:08   ` Ken McGlothlen
  0 siblings, 0 replies; 12+ messages in thread
From: Ken McGlothlen @ 1998-12-03 16:08 UTC (permalink / raw)
  Cc: w3-beta, ding

colin@xemacs.org (Colin Rafferty) writes:

| William M Perry writes:
| 
| > I'd vote for (c), but I have no clue on how to go about finding or writing
| > a good contrast-finding algorithm.  Anyone out there know of one?
| 
| I vote for (c), but I know that finding contrasting colors is hard to
| do.  However, since all you need is a single constrasting color, you
| could choose between black and white.
| 
| ;; Take the "average" level, and go opposite
| 
| (defun infer-contrasting-color (r g b)
|   (if (and (<= r 255)
| 	   (<= g 255)
| 	   (<= b 255))
|       (if (< (+ r g b) 384) "white" "black")   ; (/ (* 256 3) 2) => 384
|     (if (< (+ r g b) 98304) "white" "black"))) ; (/ (* 65536 3) 2) =>  => 382
| 
| ;; Colin

This is actually a slight improvement to the one I was going to suggest; I
guess I've been doing web stuff for so long, I forgot about 16-bit color.  :)

This is perhaps slightly less boring than the complement one, but does produce
readable results in all cases, even the annoyingly borderline ones, and it's
the one I'd support.

Of course, a gnus-select-perfect-colors-based-on-subject-matter function might
be better, but might make the package run a bit slow.  :)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
                   ` (2 preceding siblings ...)
  1998-12-03 14:56 ` Bill White
@ 1998-12-03 16:43 ` Wes Hardaker
  1998-12-03 18:49 ` Matt Armstrong
  1998-12-04  1:19 ` Laurent Martelli
  5 siblings, 0 replies; 12+ messages in thread
From: Wes Hardaker @ 1998-12-03 16:43 UTC (permalink / raw)
  Cc: w3-beta, ding


>>>>> On Thu, 3 Dec 1998 09:00:21 -0500, "William M. Perry" <wmperry@aventail.com> said:

William> a) Do nothing (current practice)
William> b) Infer the missing color by taking rgb(~r,~g,~b) 
William> c) Infer the color some other way?

I think it should (of course) be a user choice...

However, something like your conversion might be the choice I would
pick...  Maybe.

-- 
"Ninjas aren't dangerous.  They're more afraid of you than you are of them."


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
                   ` (3 preceding siblings ...)
  1998-12-03 16:43 ` Wes Hardaker
@ 1998-12-03 18:49 ` Matt Armstrong
  1998-12-09 16:06   ` William M. Perry
  1998-12-04  1:19 ` Laurent Martelli
  5 siblings, 1 reply; 12+ messages in thread
From: Matt Armstrong @ 1998-12-03 18:49 UTC (permalink / raw)
  Cc: w3-beta, ding

"William M. Perry" <wmperry@aventail.com> writes:

> Ok, so what should Emacs/W3 do if someone happens to lose so badly as to
> specify a background or foreground color without also specifying the other?
> 
> We could:
> 
> a) Do nothing (current practice)
> b) Infer the missing color by taking rgb(~r,~g,~b) 
> c) Infer the color some other way?

And how about suitable LINK, VLINK and ALINK colors?  (I don't use w3,
so perhaps this isn't a big issue)

-- 
matta



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
                   ` (4 preceding siblings ...)
  1998-12-03 18:49 ` Matt Armstrong
@ 1998-12-04  1:19 ` Laurent Martelli
  1998-12-04  5:31   ` Felix Lee
  5 siblings, 1 reply; 12+ messages in thread
From: Laurent Martelli @ 1998-12-04  1:19 UTC (permalink / raw)
  Cc: w3-beta, ding

>>>>> "WMP" == William M Perry <wmperry@aventail.com> writes:

    WMP> Ok, so what should Emacs/W3 do if someone happens to lose so
    WMP> badly as to specify a background or foreground color without
    WMP> also specifying the other?

    WMP> We could:

    WMP> a) Do nothing (current practice) b) Infer the missing color
    WMP> by taking rgb(~r,~g,~b) c) Infer the color some other way?

How about choosing one color in a set of a few carefully chosen colors ? 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-04  1:19 ` Laurent Martelli
@ 1998-12-04  5:31   ` Felix Lee
  0 siblings, 0 replies; 12+ messages in thread
From: Felix Lee @ 1998-12-04  5:31 UTC (permalink / raw)


this is a tcl function I've been using for choosing
contrasting colors.  it's not perfect (like, it tends to
think similar greens have more contrast than they do), but
it does a good job most of the time, especially if you're
only interested in choosing between very different colors
like white and black.

proc color/contrasting {w color {colors {black white}}} {
##
## Returns the color in $colors that most contrasts with
## $color in window $w.  Currently, just looks at luminance.

    set y0 [color/luminance $w $color]
    set best $color
    set dist 0
    foreach c $colors {
	set y [color/luminance $w $c]
	set d [expr {abs($y - $y0)}]
	if {$dist < $d} {
	    set best $c
	    set dist $d
	}
    }
    return $best
}

proc color/luminance {w color} {
##
## Returns the (YIQ-model) luminance of $color in window $w.

    set* {r g b} [winfo rgb $w $color]
    expr {.299 * $r / 65535 + .587 * $g / 65535 + .114 * $b / 65535}
}

proc set* {names values} {
    foreach name $names value $values {
	upvar $name var
	set var $value
    }
}


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: HTML foreground and background colors being the same... poll time!
  1998-12-03 18:49 ` Matt Armstrong
@ 1998-12-09 16:06   ` William M. Perry
  0 siblings, 0 replies; 12+ messages in thread
From: William M. Perry @ 1998-12-09 16:06 UTC (permalink / raw)
  Cc: w3-beta, ding

Matt Armstrong <mattdav+matt@best.com> writes:

> "William M. Perry" <wmperry@aventail.com> writes:
> 
> > Ok, so what should Emacs/W3 do if someone happens to lose so badly as to
> > specify a background or foreground color without also specifying the other?
> > 
> > We could:
> > 
> > a) Do nothing (current practice)
> > b) Infer the missing color by taking rgb(~r,~g,~b) 
> > c) Infer the color some other way?
> 
> And how about suitable LINK, VLINK and ALINK colors?  (I don't use w3,
> so perhaps this isn't a big issue)

  Oh fine, bring those up why don't you!

-bp


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1998-12-09 16:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-03 14:00 HTML foreground and background colors being the same... poll time! William M. Perry
1998-12-03 14:26 ` Hrvoje Niksic
1998-12-03 14:37   ` Didier Verna
1998-12-03 14:44     ` Hrvoje Niksic
1998-12-03 14:54 ` Colin Rafferty
1998-12-03 16:08   ` Ken McGlothlen
1998-12-03 14:56 ` Bill White
1998-12-03 16:43 ` Wes Hardaker
1998-12-03 18:49 ` Matt Armstrong
1998-12-09 16:06   ` William M. Perry
1998-12-04  1:19 ` Laurent Martelli
1998-12-04  5:31   ` Felix Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).