|
From: Ethan A M. <sf...@us...> - 2014-03-07 20:08:45
|
On Friday, 07 March, 2014 11:06:10 Tait wrote:
> There does seem to be a problem with any approach involving using the
> alpha channel:
> gnuplot> rgba(a,r,g,b)=(a*2**24) | (r*2**16) | (g*2**8) | b
> # having << and >> operators here would be nice
I have wanted that myself more than once.
Please file a Feature Request.
I'm not sure whether the current SourceForge infrastructure allows it,
but if possibleI will attach a "Version 5 target" flag to the relevant
Bugs, Feature Requests, and Patches on the tracker.
> gnuplot> print rgba(0,0,0,0)
> 0
> gnuplot> print rgba(0x88,0,0,0)
> non-integer passed to boolean operator
> gnuplot> print rgba(0x78,0,0,0)
> 2025521152
>
> The problem, of course, is that gnuplot doesn't have an unsigned
> integer data type. The "non-integer" error can be avoided by using +
> instead of |, but then the number is promoted to float and it cannot
> be used as intended in the plot command like
> gnuplot> plot x lw 5 lc rgbcolor rgba(0x88,0x22,0x55,0x88), -x lw 5 lc rgbcolor rgba(0x88,0xBB,0x77,0x33)
>
> Even defining the function as
> gnuplot> rgba(a,r,g,b)=int((a*2**24) + (r*2**16) + (g*2**8) + b)
> doesnt seem to work right when it comes to the plot command.
Here is one way to do it. This may not cover all the desired cases:
gnuplot> argb(a,r,g,b) = sprintf("0x%.2x%.2x%.2x%.2x",a,r,g,b)
gnuplot> print argb(0x78,0,0,0)
0x78000000
gnuplot> print argb(0xff, 0, 255, 127.0)
0xff00ff7f
Yes that produces a string rather than an integer, but the plotting commands
are happy to take the string.
Although the string can evaluate to a negative value when converted by int(),
the color handling code knows to treat it as unsigned.
Using it for arithmetic might fail, but any numeric operation that is sensitive to
the signed/unsigned distinction is probably a dubious thing to apply to colors.
Ethan
|