Bug 16987 - grid.cap() captures garbage data in last four rows
Summary: grid.cap() captures garbage data in last four rows
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Graphics (show other bugs)
Version: R 3.3.0
Hardware: x86_64/x64/amd64 (64-bit) OS X El Capitan
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-07-08 18:30 UTC by Ted Toal
Modified: 2016-07-19 00:45 UTC (History)
1 user (show)

See Also:


Attachments
R code writes "A" then captures with grid.cap, capture matrix last rows aren't all white (1.40 KB, text/plain)
2016-07-08 18:30 UTC, Ted Toal
Details
Screen shot after running code shown in comment (678.67 KB, image/png)
2016-07-18 22:58 UTC, Ted Toal
Details
.png file created by R code shown in previous attachment comments (28.60 KB, image/png)
2016-07-18 23:00 UTC, Ted Toal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Toal 2016-07-08 18:30:44 UTC
Created attachment 2117 [details]
R code writes "A" then captures with grid.cap, capture matrix last rows aren't all white

I use grid.text() to write a letter "A" to a small viewport page, then use grid.cap() to capture it.  The bitmap matrix returned by grid.cap() contains some garbage colors in the last 4 rows.  The background is white and there are no non-white regions visible at the bottom of the image.  See attachment for code.
Comment 1 Paul Murrell 2016-07-18 21:42:49 UTC
Can you please run something like ...

png("bug-16987.png")
grid.raster(cap)
dev.off()

... and post the resulting PNG file, PLUS a screen capture (e.g., via alt-prtscn or however you do it on your system, other than with R) of the R graphics window ?
Comment 2 Ted Toal 2016-07-18 22:58:57 UTC
Created attachment 2130 [details]
Screen shot after running code shown in comment

library("grid")
dev.new(width=1, height=1)
grid.newpage()
grid.text("A", gp=gpar(cex=4))
cap = grid.cap()
# Bottom rows of 'cap' should be all 'white', are they?
apply(cap, 1, function(V) all(V == "white"))
# Note four "FALSE" entries in last line above.
tail(cap[, 1:7], 6)
png("bug-16987.png")
grid.raster(cap)
dev.off()
Comment 3 Ted Toal 2016-07-18 23:00:20 UTC
Created attachment 2131 [details]
.png file created by R code shown in previous attachment comments

This .png file shows black areas at lower-left and lower-right, not present in the actual device window shown in the previous attachment screen capture.
Comment 4 Paul Murrell 2016-07-19 00:45:21 UTC
Thanks for the PNGs.

A couple of thoughts for this (and #16983):

- endianness plus forced-opacity-on-capture might explain the red pixels, i.e., opaque black RGBA [0, 0, 0, 1] is (incorrectly) captured as ABGR [1, 0, 0, 1], which replays as opaque red.

- pretty curved corners on the bottom-left and bottom-right of the graphics device window (as shown in your screen shots) might explain the black-grey corner pixels (especially if the pretty corners are done with transparency and the endianness idea above is correct).

A test of the first supposition would be to draw the rect and text "green" so the replay would come out "blue"(?)

I need to talk to Simon Urbanek (who commented in the source code about endiannes and who has an OS X machine to test on).