Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
63 lines
2.8 KiB
Go
63 lines
2.8 KiB
Go
package gputest
|
||
|
||
import "github.com/egoist/mygo/internal/scene"
|
||
|
||
// NV12Frame returns a w×h frame of video in NV12 with the matrix m, its
|
||
// planes in memory with rows padded past their width, as decoders pad
|
||
// them: bars of saturated colors over a gradient of luma, which the
|
||
// renderers sample as planes and the CPU renderer converts (Restore).
|
||
func NV12Frame(w, h int, m scene.YUVMatrix) *scene.Image {
|
||
ls, cs := w+13, 2*((w+1)/2)+6
|
||
cw, ch := (w+1)/2, (h+1)/2
|
||
luma, chroma := make([]byte, ls*h), make([]byte, cs*ch)
|
||
for y := range h {
|
||
for x := range w {
|
||
luma[y*ls+x] = byte(16 + (219*x)/max(w-1, 1))
|
||
}
|
||
}
|
||
// Six bars of chroma, Cb and Cr from 16 to 240.
|
||
bars := [][2]byte{{240, 128}, {16, 240}, {128, 16}, {240, 240}, {16, 16}, {90, 200}}
|
||
for y := range ch {
|
||
for x := range cw {
|
||
c := bars[x*len(bars)/cw]
|
||
if y < ch/4 {
|
||
c = [2]byte{128, 128} // gray
|
||
}
|
||
chroma[y*cs+2*x], chroma[y*cs+2*x+1] = c[0], c[1]
|
||
}
|
||
}
|
||
return SurfaceImage(&scene.Surface{
|
||
Format: scene.SurfaceNV12,
|
||
Matrix: m,
|
||
Planes: [2]scene.Plane{{Pix: luma, Stride: ls}, {Pix: chroma, Stride: cs}},
|
||
}, w, h)
|
||
}
|
||
|
||
// SurfaceImage returns an image showing s, whose pixels convert it.
|
||
func SurfaceImage(s *scene.Surface, w, h int) *scene.Image {
|
||
img := scene.NewImageRGBA(w, h, nil)
|
||
img.Surface = s
|
||
img.Restore = func() []byte { return s.RGBA(nil, w, h) }
|
||
return img
|
||
}
|
||
|
||
// VideoScene draws frames of video in NV12 of each matrix, scaled,
|
||
// rounded, faded and in grayscale, as video elements show them.
|
||
func VideoScene() *scene.Scene {
|
||
s := &scene.Scene{Width: 360, Height: 260, Clear: scene.Color{R: 255, G: 255, B: 255, A: 255}}
|
||
add := func(op scene.Op) { s.Ops = append(s.Ops, op) }
|
||
for i, m := range []scene.YUVMatrix{scene.BT601, scene.BT709, scene.BT2020, scene.BT601 + scene.FullRange, scene.BT709 + scene.FullRange, scene.BT2020 + scene.FullRange} {
|
||
img := NV12Frame(96, 54, m)
|
||
x, y := float32(8+(i%3)*116), float32(8+(i/3)*72)
|
||
add(scene.Op{Kind: scene.OpImage, Rect: scene.Rect{X: x, Y: y, W: 96, H: 54}, Image: img, Src: scene.Rect{W: 96, H: 54}})
|
||
}
|
||
big := NV12Frame(64, 36, scene.BT709)
|
||
// Scaled up, with rounded corners, faded, and in grayscale.
|
||
add(scene.Op{Kind: scene.OpImage, Rect: scene.Rect{X: 8, Y: 160, W: 160, H: 90}, Radii: [4]float32{12, 12, 12, 12}, Image: big, Src: scene.Rect{W: 64, H: 36}})
|
||
add(scene.Op{Kind: scene.OpImage, Rect: scene.Rect{X: 184, Y: 160, W: 80, H: 45}, Image: big, Src: scene.Rect{W: 64, H: 36}, Opacity: 0.5})
|
||
add(scene.Op{Kind: scene.OpImage, Rect: scene.Rect{X: 272, Y: 160, W: 80, H: 45}, Image: big, Src: scene.Rect{W: 64, H: 36}, Grayscale: true})
|
||
// An odd size, whose chroma has a half sample at its edges.
|
||
add(scene.Op{Kind: scene.OpImage, Rect: scene.Rect{X: 184, Y: 216, W: 37, H: 21}, Image: NV12Frame(37, 21, scene.BT601), Src: scene.Rect{W: 37, H: 21}})
|
||
return s
|
||
}
|