Skip to content

Instantly share code, notes, and snippets.

@dividuum
Created June 24, 2026 16:31
Show Gist options
  • Select an option

  • Save dividuum/f4c492956d7d33603518b15964d4b79b to your computer and use it in GitHub Desktop.

Select an option

Save dividuum/f4c492956d7d33603518b15964d4b79b to your computer and use it in GitHub Desktop.
info-beamer content process example of loading image from url
#!/bin/sh
GOOS=linux GOARCH=arm go build -ldflags="-s -w" -o image.exe
module contentproc
go 1.22
require golang.org/x/image v0.22.0
require golang.org/x/sys v0.30.0
package main
import (
"bytes"
"image"
_ "image/jpeg"
_ "image/png"
"io"
"log"
"net/http"
"os"
"strconv"
"time"
"golang.org/x/image/draw"
"golang.org/x/sys/unix"
)
func download(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func toBGRA(src image.Image, w, h int) []byte {
dst := image.NewRGBA(image.Rect(0, 0, w, h))
draw.CatmullRom.Scale(dst, dst.Bounds(), src, src.Bounds(), draw.Over, nil)
out := make([]byte, w*h*4)
i := 0
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
r, g, b, a := dst.At(x, y).RGBA()
out[i] = byte(b >> 8)
out[i+1] = byte(g >> 8)
out[i+2] = byte(r >> 8)
out[i+3] = byte(a >> 8)
i += 4
}
}
return out
}
func main() {
width, _ := strconv.Atoi(os.Getenv("WIDTH"))
height, _ := strconv.Atoi(os.Getenv("HEIGHT"))
url := os.Args[1]
data, err := download(url)
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
pixels := toBGRA(img, width, height)
// mmap DMA buffer (fd 3)
buf, err := unix.Mmap(3, 0, len(pixels), unix.PROT_WRITE, unix.MAP_SHARED)
if err != nil {
log.Fatal(err)
}
copy(buf, pixels)
_ = unix.Munmap(buf)
// handshake: BGRA format + ready
_, _ = os.Stdout.Write([]byte{0, 1, 1, '\n'})
_ = os.Stdout.Sync()
log.Println("image rendered")
// keep alive. Forces 'loaded' state
for {
time.Sleep(time.Second)
}
}
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
local p = resource.create_content_process{
file = "image.exe",
width = 1920,
height = 1080,
args = {
"https://librestock.com/photos/thumbs/librestock-vintage-camera-lens.jpg"
}
}
function node.render()
p:draw(0, 0, WIDTH, HEIGHT)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment