Taking a stab in the dark...

It may be that the colours are on a 48-bit scale in stead of 24-bit; that is, 16 bits are available for each channel (red, green, and blue).

This is becoming increasingly common in anticipation of 48-bit consumer-level hardware, ie: pretty soon you'll actually need the extra bits, and be glad that they're there.

If this is the case here (but I don't know Tk, so YMMV), the range would be 0..65535; everything else should remain unchanged. Try grabbing $widget->rgb('white') and $widget->rgb('black'), and using their triplets as the limits of your sliders:

something like...

my %colour_min, %colour_max; @colour_min{ 'red', 'green', 'blue' } = $widget->rgb('black'); @colour_max{ 'red', 'green', 'blue' } = $widget->rgb('white'); # ... my %triplet; @triplet{ 'red', 'green', 'blue' } = $widget->rgb($user_entry); my %slider; # 0..1 range [eg. 50% grey might be (.5,.5,.5) ] for my $channel ('red', 'green', 'blue') { $slider{$channel} = ( $triplet{$channel} - $colour_min{$channel} ) / + ( $colour_max{$channel} / $colour_min{$channel} ) ); }

That's probably overkill, though, since you can generally assume that black will be (0,0,0), which reduces the final block to

for my $channel ('red', 'green', 'blue') { $slider{$channel} = $triplet{$channel} / $colour_max{$channel}; }

There's also probably a right way to do this that I don't know about... :-)


In reply to Re: What's up with the RGB method? by baku
in thread What's up with the RGB method? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.