"rgb()" problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

"rgb()" problem

Christian Röver
Hi,

I experienced a problem with the "rgb()" function.
These two calls should (and do) return identical results:

  rgb(255, 128, 128, maxColorValue=255)
  rgb(1.0, 0.5, 0.5, maxColorValue=1)

However, when I specify a non-default "alpha" channel (a "transparent"
colour), I get differing results:

  rgb(255, 128, 128, alpha=0.5, maxColorValue=255)
  rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1)

where only the latter version seems to yield the actually intended
result.

Is this a bug?


You can check the actual colours' appearance this way:

  barplot(3:5, col=rgb(255, 128, 128, maxColorValue=255))
  barplot(3:5, col=rgb(1.0, 0.5, 0.5, maxColorValue=1))

  barplot(3:5, col=rgb(255, 128, 128, alpha=0.5, maxColorValue=255))
  barplot(3:5, col=rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1))

The apparently buggy version in this case seems to return white instead
of red.


Thanks,

Christian
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: "rgb()" problem

Christian Röver
Sorry, I meanwhile realized -- specifying

  rgb(255, 128, 128, alpha=0.5*255, maxColorValue=255)

and

  rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1)

gives you (virtually) identical results, i.e., you need to also specify
the "alpha" parameter in the range given by the "maxColorValue"
argument.

Sorry for the confusion,

Christian


On Fri, 2019-07-26 at 10:27 +0200, Christian Röver wrote:

> Hi,
>
> I experienced a problem with the "rgb()" function.
> These two calls should (and do) return identical results:
>
>   rgb(255, 128, 128, maxColorValue=255)
>   rgb(1.0, 0.5, 0.5, maxColorValue=1)
>
> However, when I specify a non-default "alpha" channel (a
> "transparent"
> colour), I get differing results:
>
>   rgb(255, 128, 128, alpha=0.5, maxColorValue=255)
>   rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1)
>
> where only the latter version seems to yield the actually intended
> result.
>
> Is this a bug?
>
>
> You can check the actual colours' appearance this way:
>
>   barplot(3:5, col=rgb(255, 128, 128, maxColorValue=255))
>   barplot(3:5, col=rgb(1.0, 0.5, 0.5, maxColorValue=1))
>
>   barplot(3:5, col=rgb(255, 128, 128, alpha=0.5, maxColorValue=255))
>   barplot(3:5, col=rgb(1.0, 0.5, 0.5, alpha=0.5, maxColorValue=1))
>
> The apparently buggy version in this case seems to return white
> instead
> of red.
>
>
> Thanks,
>
> Christian
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: "rgb()" problem

Ivan Krylov
In reply to this post by Christian Röver
On Fri, 26 Jul 2019 08:27:07 +0000
"Röver, Christian" <[hidden email]> wrote:

> The apparently buggy version in this case seems to return white
> instead of red.

I think it's red, but fully transparent. Alpha follows the same rules
as red, green and blue components; it is expected to be in range [0;
maxColorValue]. rgb(255, 128, 128, alpha=128, maxColorValue=255) should
give you the expected result.

--
Best regards,
Ivan

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.