internal/graphicscommand: use bufio to make dumping images faster

This commit is contained in:
Hajime Hoshi 2023-08-26 00:50:45 +09:00
parent fd5e2d39c0
commit b29fc5672c

View File

@ -17,6 +17,7 @@
package graphicscommand
import (
"bufio"
"errors"
"fmt"
"image"
@ -42,7 +43,11 @@ func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackb
_ = f.Close()
}()
if err := i.dumpTo(f, graphicsDriver, blackbg, rect); err != nil {
w := bufio.NewWriter(f)
if err := i.dumpTo(w, graphicsDriver, blackbg, rect); err != nil {
return "", err
}
if err := w.Flush(); err != nil {
return "", err
}
@ -77,7 +82,11 @@ func DumpImages(images []*Image, graphicsDriver graphicsdriver.Graphics, dir str
_ = f.Close()
}()
if err := img.dumpTo(f, graphicsDriver, false, image.Rect(0, 0, img.width, img.height)); err != nil {
w := bufio.NewWriter(f)
if err := img.dumpTo(w, graphicsDriver, false, image.Rect(0, 0, img.width, img.height)); err != nil {
return "", err
}
if err := w.Flush(); err != nil {
return "", err
}
}