Press F12 to save a screen capture

This commit is contained in:
Ivan Izaguirre 2019-06-02 22:59:51 +02:00
parent 343df8a554
commit fc9e4011f9
3 changed files with 23 additions and 2 deletions

Binary file not shown.

View File

@ -101,6 +101,8 @@ func (k *sdlKeyboard) putKey(keyEvent *sdl.KeyboardEvent) {
k.a.SendCommand(apple2.CommandLoadState)
case sdl.K_F9:
k.a.SendCommand(apple2.CommandDumpDebugInfo)
case sdl.K_F12:
apple2.SaveSnapshot(k.a, "snapshot.png")
}
// Missing values 91 to 95. Usually control for [\]^_

View File

@ -95,13 +95,15 @@ func mixSnapshots(top, bottom *image.RGBA) *image.RGBA {
return out
}
func saveSnapshot(a *Apple2) {
// SaveSnapshot saves a snapshot of the screen to a png file
func SaveSnapshot(a *Apple2, filename string) {
img := Snapshot(a)
if img == nil {
return
}
img = squarishPixelsFilter(img)
f, err := os.Create("snapshot.png")
f, err := os.Create(filename)
if err != nil {
panic(err)
}
@ -112,6 +114,23 @@ func saveSnapshot(a *Apple2) {
png.Encode(f, img)
}
func squarishPixelsFilter(in *image.RGBA) *image.RGBA {
b := in.Bounds()
factor := 1200 / b.Dx()
fmt.Println(factor)
size := image.Rect(0, 0, factor*b.Dx(), b.Dy())
out := image.NewRGBA(size)
for x := b.Min.X; x < b.Max.X; x++ {
for y := b.Min.Y; y < b.Max.Y; y++ {
c := in.At(x, y)
for i := 0; i < factor; i++ {
out.Set(factor*x+i, y, c)
}
}
}
return out
}
func linesSeparatedFilter(in *image.RGBA) *image.RGBA {
b := in.Bounds()
size := image.Rect(0, 0, b.Dx(), 4*b.Dy())