float -> RGB
am 23.11.2007 14:00:13 von alexxx.magni
Greetings,
I know this isnt a perlish problem,
but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
according to whichever palette you want...
but I'm not expert at all in graphics problems, so it's not clear to
me how to do it - hope somebody can drop down a couple of lines!
thanks...
Alessandro
Re: float -> RGB
am 23.11.2007 14:30:52 von Lars Haugseth
* "alexxx.magni@gmail.com" wrote:
>
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
> but I'm not expert at all in graphics problems, so it's not clear to
> me how to do it - hope somebody can drop down a couple of lines!
You haven't told us what the "float" number represent.
You haven't told us what range the RGB values should have.
You haven't told us what a palette is and how it is stored.
Until you specify this, there are an unlimited number of ways to
do such a mapping.
Here's one:
$R = $G = $B = $x;
Probably not what you want.
--
Lars Haugseth
"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer
Re: float -> RGB
am 23.11.2007 14:43:31 von 1usa
"alexxx.magni@gmail.com" wrote in
news:55d8528e-dd07-44da-b52a-684750630fab@s19g2000prg.google groups.com:
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
> but I'm not expert at all in graphics problems, so it's not clear to
> me how to do it - hope somebody can drop down a couple of lines!
This is line one.
This is line two.
You are very welcome.
On a more serious note, your question is not well-defined.
Define:
U = [0,1]
R = { 0, 1, 2, ..., 255 }
G = { 0, 1, 2, ..., 255 }
B = { 0, 1, 2, ..., 255 }
Then, the function
f : U -> R x G x B
defined by f(x) = round( (255, 255, 255)*x, 0 )
is a natural mapping of real fractions to RGB triplets.
Now, what do you mean "according to whichever palette you want"?
In any case, note that the answer to some well defined version of your
question is independent of the programming language used but anyone's
ability to provide the answer you are seeking is highly dependent on
your ability to specify the question you want to ask.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines:
Re: float -> RGB
am 23.11.2007 16:58:09 von Sherm Pendley
"alexxx.magni@gmail.com" writes:
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
RGB colors don't refer to an index in a palette.
So, you have three float values $r, $g, and $b - and you want to transform
that into what, exactly? What have you tried so far? What were the results,
and how did they differ from the results you expected?
sherm--
--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
Re: float -> RGB
am 23.11.2007 17:40:04 von bugbear
alexxx.magni@gmail.com wrote:
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
> but I'm not expert at all in graphics problems, so it's not clear to
> me how to do it - hope somebody can drop down a couple of lines!
If you're asking how to use as float as an index
into a (normal) pallette of 256 different RGB triples,
you just need to multiple the float up total size of your palette,
and round.
roughly, and without checking boundary conditions:
my $triple = $palette[int(256 * $f)];
BugBear
Re: float -> RGB
am 23.11.2007 18:58:56 von Uri Guttman
>>>>> "b" == bugbear writes:
b> my $triple = $palette[int(256 * $f)];
no need for the int() call as array indexing will do an implied int()
for you.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Re: float -> RGB
am 23.11.2007 22:28:23 von Martien Verbruggen
On Fri, 23 Nov 2007 05:00:13 -0800 (PST),
alexxx.magni@gmail.com wrote:
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
> but I'm not expert at all in graphics problems, so it's not clear to
> me how to do it - hope somebody can drop down a couple of lines!
As others have said, it's a bit vague what exactly you're trying to do.
If you're trying to calculate coordinates in different colour spaces,
maybe you can have a look at this:
http://www.manning.com/verbruggen/
Chapter 1 of that book discusses colour spaces, and is available as a
free download from that page. Perl code implementations are discussed in
Appendix B, which is not available online, but the full source code for
the book is also available from the same page, which includes those
pieces of code.
Martien
PS. disclosure: If it wasn't already clear, I am the author of that
book. This post is not meant as an advertisement, which is why I made
sure all relevant content I refer to is available to you for free.
--
|
Martien Verbruggen | Since light travels faster than sound, is
| that why some people appear bright until you
| hear them speak?