Performant 2D Opengl Graphics in R for Fast Display of Raster Image Using Qtpaint (Qt) or Rdyncall (Sdl/Opengl) Packages

Performant 2D SDL or OpenGL graphics in R for fast display of raster image using rdyncall package and SDL/OpenGL calls

Not an SDL or OpenGL based solution (which should be faster still), but the nativeRaster format implemented in
https://github.com/coolbutuseless/nara
seems to be ca. 10x faster to display 640x480 image rasters than grid.raster().

To display the raster just call

library(remotes)
remotes::install_github("coolbutuseless/nara")
library(nara)

# Setup a fast graphics device that can render quickly
x11(type = 'dbcairo', antialias = 'none', width = 8, height = 6)
grid.raster(nara::raster_to_nr(ras), interpolate = FALSE)

where ras is a regular grid raster.

There is a couple of nice demos including an R version of pacman,
https://github.com/coolbutuseless/pacman and of the game Anotherworld,
https://github.com/coolbutuseless/anotherworld.

And also a demo where I used nara to do real-time Mandelbrot fractal zooms, cf. function zoom() in https://github.com/tomwenseleers/mandelExplorer.

See video here.

Sample Image

What is the simplest way to display raster image in R?

here's one option:

img <- readTIFF(system.file("img", "Rlogo.tiff", package="tiff"))
grid::grid.raster(img)

Software rendering versus hardware rendering for am image viewer?

Well, as opposed to SDL. Though software rendering is usually faster, SDL is very high level and therefore slower. Downvote me if you want, but this is the truth. May I ask why you can't just use the operating system's API? Image controls are very versatile.

Portable YUV Drawing Context

Use the option number 2. There's no problem in doing the YUV to RGB conversion in the shader. There's no such other "portable" way to do that.

Think like this: no matter "how big or small" your video is, the fragment shaders (where the conversion is done) will execute per pixel at the moment of the display, so you can have either a small video in full screen or big one, the computation (for the shaders) is the same, because they are displaying the same number of pixels.

Any video card in normal conditions will be able to run this kind of shader without any problem.



Related Topics



Leave a reply



Submit