brightness 
Author Message
 brightness

I am trying to build a function to determine how "bright" a color is. I
only want to know whether white or black would be the better contrasting
color. I have the following questions:

1. Has anyone done this already?

2. Can anyone recommend a decent reference on computer colors?

3. I imagine I can do this by taking a weighted sum of the r,g,b values
of the color and comparing the result to some threshold. So I have four
unknowns as it were. At the moment, I'm more concerned with getting the
rgb value of the color in a widget (a canvas rectangle, to be precise).

The point is, I can find out what was specified as the -fill color, but
how can I find out what color is actually there? There's the problem
that tk may have substituted a different color (due to colormap
problems) and the -fill may have been a name, rather than an #rgb.
Furthermore, Tk_GetColor modifies the colormap, which is not what I'm
trying to do! I'm not trying to get a color in that sense.

Can anyone offer a means of getting the rgb values of the color actually
present in a widget?
--

VP Software Engineering    412 621 8333
NeoVision Hypersystems     412 621 8337 (fax)
5001 Baum Blvd
Pittsburgh, PA 15213



Mon, 07 Jun 1999 03:00:00 GMT  
 brightness

: I am trying to build a function to determine how "bright" a color is. I
: only want to know whether white or black would be the better contrasting
: color.

Somewhat like this is used in a postscript file produced from a canvas.
For the the formula look at "man xpr" and it's -cutoff.
You might want it at about 0.65 instead of 0.5, try "green"..

And "winfo rgb" just appeared in another thread.




Tue, 08 Jun 1999 03:00:00 GMT  
 brightness

Quote:

> I am trying to build a function to determine how "bright" a color is. I
> only want to know whether white or black would be the better contrasting
> color. I have the following questions:

> 1. Has anyone done this already?

> 2. Can anyone recommend a decent reference on computer colors?

> 3. I imagine I can do this by taking a weighted sum of the r,g,b values
> of the color and comparing the result to some threshold. So I have four
> unknowns as it were. At the moment, I'm more concerned with getting the
> rgb value of the color in a widget (a canvas rectangle, to be precise).

> The point is, I can find out what was specified as the -fill color, but
> how can I find out what color is actually there? There's the problem
> that tk may have substituted a different color (due to colormap
> problems) and the -fill may have been a name, rather than an #rgb.
> Furthermore, Tk_GetColor modifies the colormap, which is not what I'm
> trying to do! I'm not trying to get a color in that sense.

> Can anyone offer a means of getting the rgb values of the color actually
> present in a widget?

I think that tcolor, which is in the tk demos, has most of what you
want.

--
? 1995,1996 Michael Salmon
All opinions expressed in this article remain the property of
Michael Salmon.  Permission is hereby granted for use in
followup articles, FAQ's and digests.



Tue, 08 Jun 1999 03:00:00 GMT  
 brightness


Quote:

>I am trying to build a function to determine how "bright" a color is. I
>only want to know whether white or black would be the better contrasting
>color. I have the following questions:

>1. Has anyone done this already?

>2. Can anyone recommend a decent reference on computer colors?

>3. I imagine I can do this by taking a weighted sum of the r,g,b values
>of the color and comparing the result to some threshold.

hmmm... well: Computer Graphics (Principles and Practice) from Addison Wesley
by Foley, vanDam, Feiner, and Hughes (2nd ed) describes in 13.3.3 the YIQ
colour model "used in US commericial TV broadcast. ... only the Y component is
shown on black-and-white".  so i presume Y would make a decent greyscale
value.  it is:
        Y = .30 R + .59 G + .11 B
i used it once to reduce colour for b&w printing; it worked well enough (it
fed F-S dithering for an impact dot-matrix printer, a somewhat inconsistent
medium :).  i suppose issues of gamma-correction come in there too, but that's
beyond me.

the colourspace FAQs at
<URL:http://www.inforamp.net/%7Epoynton/Poynton-colour.html>
may be helpful.

Quote:
>Can anyone offer a means of getting the rgb values of the color actually
>present in a widget [given that cget can return a colour name, or a raw
>colour value that's replaced by something else because of lack of room in
>the palette]?

winfo rgb  should fix the name problem, at least.  i twiddled with it for a few
minutes, and i got odd results indicating it *may* be checking into the palette
and saying what RGB you'd actually get.  (otherwise why else would it need a
window argument?)  (i'm very glad you asked this question; i think i was
wanting  winfo rgb  a couple days ago, but hadn't read the winfo manpage for a
couple of versions... :)


Tue, 08 Jun 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change Brightness, Contrast and Saturation of an image

2. Change Brightness, Contrast and Saturation of an image

 

 
Powered by phpBB® Forum Software