Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: What's up with the RGB method?

by baku (Scribe)
on Mar 28, 2001 at 00:44 UTC ( #67635=note: print w/ replies, xml ) Need Help??


in reply to What's up with the RGB method?

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... :-)


Comment on Re: What's up with the RGB method?
Select or Download Code
Re: Re: What's up with the RGB method?
by Anonymous Monk on Mar 28, 2001 at 02:30 UTC
    You are correct, the RGB compoments are 16 bits. On my machine, purple3 is 125,38,205 at 8 bits each (you might have this information in a file called rgb.txt), which corresponds exactly to the OP's colors in a 16 bit colorspace (multiply each by 257 (257 = 65535/255)).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://67635]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2014-10-22 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (119 votes), past polls