[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: automatic colour selection with good contrast



On Wed, Oct 20, 1999 at 06:38:53PM +0617, Sunjay Bhatnagar wrote:
> 
> Hi David,
> 
> I am keen on knowing the more-complex-but-more-accurate method of
> calculating the forground component.  If you do find time, I would
> appreciate any pointers etc. towards this.

   Oups, very sorry. I've been rather busy with a real-life work. OK.
   Here it is. 

 The key idea is that the human eye is very trained to detect difference
between:
  black and white (with the stick cells of the eye)
  gray and color, i.e. unsaturated and saturated color 
                  (with the cone cells of the eye).
  a color and its opposite.

  Given this, we have to work in the HSV colorimetric model.

  So. Lets call (br, bg, bb) the red, green and blue component of the
  background color (all between 0.0 and 1.0). We have to translate this
  in the hsv model.
  
  You can use the gtk_color_selection_rgb_to_hsv() function defined in
  gtkcolorsel.c for this.
  
  then you have:
    bh, which is the hue of the background color between 0 and 360
    bv, which is the value (brightness) of the background color between 0 and 1
    bs, which is the saturation of the background color between 0 and 1

  so now we can calculate the foreground parameters fh, fv and fs :
    fh = (bh + 180)%360;
    fv = (bv < 0.5) ? 1.0 : 0.0;
    fs = (bs < 0.5) ? 1.0 : 0.0;

  Then use gtk_color_selection_hsv_to_rgb() to go back to the rgb model and
  you're done.

  To be more peckish, you also should take care of the gamma of the monitor
  you're using.
    To do this, you should do a :
      br = pow(br, gamma);
      bg = pow(bg, gamma);
      bb = pow(bb, gamma);
    before the call to gtk_color_selection_rgb_to_hsv()
      and
      fr = pow(fr, 1/gamma);
      fg = pow(fg, 1/gamma);
      fb = pow(fb, 1/gamma);


    that's about it. I hope I haven't forgotten anything.

       Hope this will help.

             Regards,

                        DindinX

-- 
David.Odin@bigfoot.com

Life is a whim of several billion cells to be you for a while.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]