Real-image posters: scale and encode in the background
Done in Draw it took about 200 ms per new poster (BiLinear scale to the box plus PNG encoding), so each step to another title stalled the UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -417,3 +417,29 @@ func TestPostersAreSentAtTheBoxSize(t *testing.T) {
|
||||
t.Errorf("upload without cell size: %q", msgs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostersArePreparedInTheBackground(t *testing.T) {
|
||||
var rec recorder
|
||||
k := newKittyGraphics(rec.write)
|
||||
var queued []func()
|
||||
k.background = func(prepare func() prepared, ready func(prepared)) {
|
||||
p := prepare()
|
||||
queued = append(queued, func() { ready(p) })
|
||||
}
|
||||
img := image.NewRGBA(image.Rect(0, 0, 40, 60))
|
||||
if id, err := k.show(img, img.Bounds(), 4, 3); id != 0 || err != nil || len(rec.cmds) != 0 {
|
||||
t.Fatalf("first draw: id %d, err %v, %d commands", id, err, len(rec.cmds))
|
||||
}
|
||||
k.show(img, img.Bounds(), 4, 3) // a redraw meanwhile does not prepare it twice
|
||||
if len(queued) != 1 {
|
||||
t.Fatalf("%d preparations", len(queued))
|
||||
}
|
||||
queued[0]()
|
||||
id, err := k.show(img, img.Bounds(), 4, 3)
|
||||
if id == 0 || err != nil || len(rec.cmds) == 0 {
|
||||
t.Fatalf("once ready: id %d, err %v, %d commands", id, err, len(rec.cmds))
|
||||
}
|
||||
if again, _ := k.show(img, img.Bounds(), 4, 3); again != id || len(queued) != 1 {
|
||||
t.Errorf("uploaded posters are reused: id %d, %d preparations", again, len(queued))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user