Image and JPEG
JPEG methods allow you to decode, scale, cache, and render JPEG images directly onto displays. Images are provided as Base64 encoded JPEG data unless otherwise specified.
Methods
Section titled “Methods”Generic Image Methods
Section titled “Generic Image Methods”These methods work with images in any supported format (PNG, GIF, JPEG, and others). The format is detected automatically.
clearJPEGCache
Section titled “clearJPEGCache”Clears cached JPEG decoding data.
Useful when loading many images or when you want to free cached JPEG resources.
Example
Section titled “Example”gpu.clearJPEGCache()decodeAndScaleJPEG
Section titled “decodeAndScaleJPEG”Decodes a Base64 JPEG image and scales it to the requested size.
Useful when you need image data before drawing.
Requires: base64JpegData : string, targetWidth : number, targetHeight : number
Returns: Image data table.
Example
Section titled “Example”local image = gpu.decodeAndScaleJPEG( base64JpegData, 128, 128)decodeJPEG
Section titled “decodeJPEG”Decodes a Base64 JPEG image and returns its pixel data.
Requires: base64JpegData : string
Returns: Image data table.
Example
Section titled “Example”local image = gpu.decodeJPEG(base64JpegData)getJPEGDimensions
Section titled “getJPEGDimensions”Gets the dimensions of a JPEG without fully decoding or rendering it.
Requires: base64JpegData : string
Returns:
{ width, height}Example
Section titled “Example”local dims = gpu.getJPEGDimensions(base64JpegData)
print(dims.width, dims.height)getJPEGNetworkStats
Section titled “getJPEGNetworkStats”Returns JPEG and network related statistics.
Returns: string
Example
Section titled “Example”print(gpu.getJPEGNetworkStats())getRecommendedJPEGSettings
Section titled “getRecommendedJPEGSettings”Returns recommended JPEG settings for a target resolution.
Useful for optimizing image transfer size and decoding performance.
Requires: targetWidth : number, targetHeight : number
Returns: table containing suggested settings.
Example
Section titled “Example”local settings = gpu.getRecommendedJPEGSettings( 320, 180)loadJPEGFullscreen
Section titled “loadJPEGFullscreen”Decodes a JPEG image and fills the entire display with it.
Call updateDisplay afterwards to push the framebuffer.
Requires: DisplayID, base64JpegData : string
Example
Section titled “Example”gpu.loadJPEGFullscreen(displayId, base64JpegData)gpu.updateDisplay(displayId)loadJPEGRegion
Section titled “loadJPEGRegion”Loads JPEG binary data into a specific region of a display.
Useful for updating only part of the framebuffer.
Requires: DisplayID, jpegBinaryData : string, x : number, y : number, w : number, h : number
Example
Section titled “Example”gpu.loadJPEGRegion( displayId, jpegBinaryData, 0, 0, 100, 100)loadJPEGRegionBytes
Section titled “loadJPEGRegionBytes”Loads a Base64 encoded JPEG into a specific display region.
This is the Base64 version of loadJPEGRegion.
Requires: DisplayID, base64JpegData : string, x : number, y : number, w : number, h : number
Example
Section titled “Example”gpu.loadJPEGRegionBytes( displayId, base64JpegData, 50, 50, 128, 128)preloadJPEGSequence
Section titled “preloadJPEGSequence”Preloads a sequence of JPEG images for later playback.
Useful for:
- slideshows
- animations
- video-like playback
Requires: DisplayID, jpegSequence : table
Example
Section titled “Example”gpu.preloadJPEGSequence( displayId, jpegSequence)restoreBackdrop
Section titled “restoreBackdrop”Restores the original backdrop in a rectangular region.
Requires: DisplayID, x : number, y : number, w : number, h : number
Example
Section titled “Example”gpu.restoreBackdrop(id, 100, 100, 80, 40)gpu.fillRect(id, 100, 100, 80, 40, 255, 255, 255)gpu.updateDisplay(id)gpu.restoreBackdrop(id, 100, 100, 80, 40) -- Restores.gpu.updateDisplay(id)clearBackdrop
Section titled “clearBackdrop”Discards the stored backdrop.
Requires: DisplayID
Example
Section titled “Example”gpu.clearBackdrop(id, 100, 100, 80, 40)decodeAndScaleImage
Section titled “decodeAndScaleImage”Decodes a Base64 image (any supported format) and scales it to the requested size.
The image format is detected automatically.
Useful when you need image data before drawing.
Requires: base64ImageData : string, targetWidth : number, targetHeight : number
Returns: Image data table.
Example
Section titled “Example”local image = gpu.decodeAndScaleImage( base64ImageData, 128, 128)decodeImage
Section titled “decodeImage”Decodes a Base64 image (any supported format) and returns its pixel data.
The image format is detected automatically.
Requires: base64ImageData : string
Returns: Image data table.
Example
Section titled “Example”local image = gpu.decodeImage(base64ImageData)detectImageFormat
Section titled “detectImageFormat”Detects the format of a Base64 image.
Requires: base64ImageData : string
Returns: Format name as a string (for example "png", "gif", or "jpeg").
Example
Section titled “Example”local format = gpu.detectImageFormat(base64ImageData)print(format)getImageDimensions
Section titled “getImageDimensions”Gets the dimensions of an image without fully decoding or rendering it.
The image format is detected automatically.
Requires: base64ImageData : string
Returns:
{ width, height}Example
Section titled “Example”local dims = gpu.getImageDimensions(base64ImageData)
print(dims.width, dims.height)loadImageFullscreen
Section titled “loadImageFullscreen”Decodes a Base64 image (any supported format) and fills the entire display with it.
Call updateDisplay afterwards to push the framebuffer.
Requires: DisplayID, base64ImageData : string
Example
Section titled “Example”gpu.loadImageFullscreen(displayId, base64ImageData)gpu.updateDisplay(displayId)loadImageRegionBytes
Section titled “loadImageRegionBytes”Loads a Base64 encoded image into a specific region of a display.
The image format is detected automatically.
Useful for updating only part of the framebuffer.
Requires: DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number
Example
Section titled “Example”gpu.loadImageRegionBytes( displayId, base64ImageData, 50, 50, 128, 128)loadBlurredImage
Section titled “loadBlurredImage”Loads an image and renders it as a blurred backdrop.
Requires: DisplayID, image : string, options : table
Example
Section titled “Example”gpu.loadBlurredImage( displayId, image, { blur = 30, brightness = 0.5, saturation = 1, bottomDim = 0.3 })loadBlurredImageBytes
Section titled “loadBlurredImageBytes”Loads a blurred image from encoded image bytes. Useful for things such as WebSocket, HTTP, Json, etc.
Requires: DisplayID, base64ImageData : string, options : table
Example
Section titled “Example”gpu.loadBlurredImage( displayId, image, { blur = 30, brightness = 0.5, saturation = 1, bottomDim = 0.3, x = 0, -- Optional y = 0, w = 384, h = 384, })loadCoverImageRegion
Section titled “loadCoverImageRegion”Loads an image into a rectangular region.
Requires: DisplayID, image : string, x : number, y : number, w : number, h : number, scale : number, crop : number
Example
Section titled “Example”gpu.loadCoverImageRegion( displayId, image, 20, 20, 160, 160)loadCoverImageRegionBytes
Section titled “loadCoverImageRegionBytes”Loads an image (base64 encoded) into a rectangular region. Useful for things such as WebSocket, HTTP, Json, etc.
Requires: DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number, scale : number, crop : number
Example
Section titled “Example”gpu.loadCoverImageRegionBytes( displayId, imageb64, 20, 20, 160, 160)