Displaying JPEG images
In this guide, you will load a Base64 encoded JPEG image, decode it, and display it on a DirectGPU screen.
Requirements
Section titled “Requirements”Before starting, make sure you have:
- CC:Tweaked installed
- DirectGPU installed
- A DirectGPU peripheral attached
- A Base64 encoded JPEG image
Finding the GPU
Section titled “Finding the GPU”First, get the DirectGPU peripheral:
local gpu = peripheral.find("directgpu")Create a display:
local displayId = gpu.autoDetectAndCreateDisplay()Decoding a JPEG
Section titled “Decoding a JPEG”DirectGPU can decode JPEG images directly.
Use decodeJPEG:
local image = gpu.decodeJPEG(base64JpegData)This returns an image table containing pixel data.
If you want to resize the image while decoding, use decodeAndScaleJPEG:
local image = gpu.decodeAndScaleJPEG( base64JpegData, 128, 128)Displaying a JPEG fullscreen
Section titled “Displaying a JPEG fullscreen”If you simply want to fill the display with an image, use loadJPEGFullscreen:
gpu.loadJPEGFullscreen( displayId, base64JpegData)Then update the display:
gpu.updateDisplay(displayId)Displaying part of an image
Section titled “Displaying part of an image”You can also update only a region of the display:
gpu.loadJPEGRegionBytes( displayId, base64JpegData, 20, 20, 128, 128)
gpu.updateDisplay(displayId)