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.
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
R: How to Select Files in Directory Which Satisfy Conditions Both on the Beginning and End of Name
How to Call the 'Function' Function
Plot Margin of PDF Plot Device: Y-Axis Label Falling Outside Graphics Window
What Does Passing an Ellipsis (...) as an Argument Mean in R
Understanding Dates/Times (Posixc and Posixct) in R
How to Increase Stack Space Overflow for Pandoc in R
How to Store R Ggplot Graph as HTML Code Snippet
Plotting Continuous and Discrete Series in Ggplot with Facet
How to Manually Set Geom_Bar Fill Color in Ggplot
How to Prevent Objects from Automatically Loading When I Open Rstudio
Import Multiple Text Files in R and Assign Them Names from a Predetermined List
Check If Character String Is a Valid Color Representation
Observeevent Shiny Function Used in a Module Does Not Work
Importing Wikipedia Tables in R
Reshape Data from Long to Wide, with Time in New Wide Variable Name