Skip to content

Conversation

@yixuan
Copy link
Contributor

@yixuan yixuan commented May 3, 2020

Hi, from another thread (yixuan/showtext#33 (comment)) I found a potential bug of ragg for the raster device function. Below are some minimal examples to reproduce:

mat = matrix(c("#FF000011", "#FF000066", "#FF0000AA", "#FF0000FF"), 2)
ras = as.raster(mat)

png("1.png", width = 200, height = 200)
par(mar = c(0, 0, 0, 0))
plot.new()
rasterImage(ras, xleft = 0, ybottom = 0, xright = 1, ytop = 1, interpolate = FALSE)
dev.off()

ragg::agg_png("2.png", width = 200, height = 200)
par(mar = c(0, 0, 0, 0))
plot.new()
rasterImage(ras, xleft = 0, ybottom = 0, xright = 1, ytop = 1, interpolate = FALSE)
dev.off()

ragg::agg_png("3.png", width = 200, height = 200, bitsize = 16)
par(mar = c(0, 0, 0, 0))
plot.new()
rasterImage(ras, xleft = 0, ybottom = 0, xright = 1, ytop = 1, interpolate = FALSE)
dev.off()

12_org3

You can find that the second plot was incorrectly rendered.
The reason is that the raster data need to be converted to the proper type before passed to AGG, similar to the case of AggDevice16. This patch should fix this.

@thomasp85 thomasp85 merged commit 0778f28 into r-lib:master May 4, 2020
@thomasp85
Copy link
Member

Thanks - I was sure I had tested this codepath, but apparently not :-)

@yixuan
Copy link
Contributor Author

yixuan commented May 5, 2020

In fact I had very little knowledge about AGG. I just mimicked the code in AggDevice16 and fortunately it worked. 😄

@lepennec lepennec mentioned this pull request Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants