[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
app[screen] RPi screen capture
Screen capture utility
Implements the screen capture tool to return screenshot of display to remote U8 systems.
To install the app, evaluate in a connected workspace:
SwikiCodeRobot @> #(app screen) |
After installation, you can connect a remote S8 system to browse the running system and captures creen are served as images.
Prerequisites
"Ensure required libraries are loaded"
self require: #FFIDynamicLibrary in: #(
'build/node/library/node-ffi/node-ffi.st.js'
'u8:aleReimondo/node-ffi/node-ffi.st.js'
); require: #X11 in: #(
'build/node/library/RaspberryPi/X11.st.js'
'u8:aleReimondo/RaspberryPi/X11.st.js'
); require: #Imlib2 in: #(
'build/node/library/RaspberryPi/Imlib2.st.js'
'u8:aleReimondo/RaspberryPi/Imlib2.st.js'
).!
X11 current isNil ifTrue: [
self print: '// Missing X11 library'.
^self abort
].
Imlib2 current isNil ifTrue: [
self print: '// Missing Imlib2 library'.
^self abort
].
(Imlib2 class >> #captureUrl) notNil ifTrue: [
self print: '// The screen capture application is already installed. Browse references to #captureUrl'.
^self abort
].
! Imlib2 class methodsFor: #snapshot !
snapshot
" Returns an image captured from Display. "
| x11 display screen number visual depth colormap width height root |
x11 := X11 current.
display := x11 XOpenDisplay: nil json.
screen := x11 XDefaultScreenOfDisplay: display.
number := x11 XScreenNumberOfScreen: screen.
visual := x11 XDefaultVisual: display screenNumber: number.
depth := x11 XDefaultDepth: display screenNumber: number.
colormap:= x11 XDefaultColormap: display screenNumber: number.
root := x11 XRootWindow: display screenNumber: number.
width := x11 XDisplayWidth: display screenNumber: number.
height := x11 XDisplayHeight: display screenNumber: number.
Imlib2 current
imlib_context_set_display: display;
imlib_context_set_visual: visual;
imlib_context_set_colormap: colormap;
imlib_context_set_color_modifier: nil json;
imlib_context_set_operation: 0"IMLIB_OP_COPY";
yourself.
^self current
imlib_context_set_drawable: root;
imlib_create_image_from_drawable: 0 x: 0 y: 0
width: width height: height needToGrabX: 1! !
! Imlib2 class methodsFor: #snapshot !
saveSnapshot: pathName
" Capture image from Display and save it in snapshot file at pathName. "
self current
imlib_context_set_image: self snapshot;
imlib_save_image: pathName;
yourself.! !
! Imlib2 class methodsFor: #platform-tools !
captureUrl
" Returns the URL of an image captured from Display. "
| fileName base64 |
fileName := 'Snapshot.png'.
self saveSnapshot: fileName.
base64 := (NodeJS fs readFileSync: fileName) toString: #base64.
^'data:image/png;base64,' ,base64! !
"Install screen capture tool"
! Smalltalk methodsFor: #platform-tools !
screen: aBlock
" Evaluate aBlock with the (captured) screen of the receiver. "
^Imlib2 captureUrl! !
"Screen capture tool installed"
self print: 'Now you can open/refresh the screen of connected system to get the image of Display.'