[Rd] using rasterImage within image
Ben Bolker
bbolker at gmail.com
Mon Feb 14 22:17:14 CET 2011
On 02/14/2011 02:59 PM, Simon Urbanek wrote:
>
> On Feb 14, 2011, at 2:28 PM, Paul Murrell wrote:
>
>> Hi
>>
>> On 15/02/2011 8:11 a.m., Simon Urbanek wrote:
>>>
>>> On Feb 14, 2011, at 12:26 PM, Ben Bolker wrote:
>>>
>>>> Paul Murrell<p.murrell<at> auckland.ac.nz> writes:
>>>>
>>>>>
>>>>> Hi
>>>>>
>>>>> On 12/02/2011 7:22 p.m., Michael Sumner wrote:
>>>>>> Hello, that appears to have fixed it. Thank you very much.
>>>>>>
>>>>>> I can now repeat the reported workflow and the image
>>>>>> appears on the fifth (and subsequent) calls.
>>>>>
>>>>> Great. Thanks for checking.
>>>>>
>>>>> Paul
>>>>>
>>>>
>>>>
>>>> That's great.
>>>>
>>>> Just a little bump: I would encourage Simon (in his copious
>>>> spare time), or other interested members of R-core, to decide
>>>> on a good name for the argument (as a reminder, I prefer
>>>> 'method=c("raster","image")'). Furthermore, I would strongly
>>>> encourage that "raster" be made the default behavior for the
>>>> development release of R ...
>>>>
>>>
>>>
>>> Unfortunately I just encountered a speed bump today - I had no
>>> idea that the Windows device doesn't even support transparent
>>> pixels. That needs to be fixed before we can make it the
>>> default...
>>
>> See the table at the bottom of
>> http://developer.r-project.org/Raster/raster-RFC.html for the full
>> list of limitations.
>>
>
> Mea culpa - I had forgotten that the default for interpolate=TRUE
> (unfortunately) so all those dozens of warnings came from the fact
> that R was trying to interpolate on a device that doesn't support it.
> I stand corrected, transparent pixels are supported if
> interpolate=FALSE so image() should be safe.
>
> Thanks, Simon
>
Yes, but: according to the table of limitations, this
image(matrix(1:9,3),
col=rgb(rep(1,9),rep(0,9),rep(0,9),alpha=seq(0,1,length=9)))
shouldn't work with raster under Windows.
"** The Windows device can do semitransparent raster images, but ONLY if
there is a constant alpha across the entire image, i.e., it CANNOT do
per-pixel alpha (the Windows API AlphaBlend can, but GraphApp's bitmap
structures do not support "shades of alpha" - it's either transparent or
opaque). The Windows device DOES support fully transparent pixels in an
image (possibly in addition to a single level of semitransparency). In
other words, the image can have up to three different levels of alpha,
as long as fully transparent and fully opaque are two of the three. "
I *think* the following function should provide a test of when we have
to fall back to method="image" if the current device is "windows" ...
diff_alpha <- function(cstr) {
alphastr <- substr(cstr[nchar(cstr)==9],8,9)
length(unique(alphastr[!alphastr %in% c("00","FF")]))>1
}
tst2 <- c(rgb(1,0,0,1),rgb(1,0,0),rgb(1,0,0,0.5),rgb(1,1,0,0.5),
rgb(1,0,0,0.7))
diff_alpha(tst2)
diff_alpha(tst2[1:4])
(I would argue that this situation is sufficiently rare that we should
still make "raster" the default, with a fallback to "image" if
diff_alpha() && windows is TRUE [perhaps a warning if missing(method)
and an error otherwise?])
Ben Bolker
>
More information about the R-devel
mailing list