calculate sleep time for slideshow interval more accurately

This commit is contained in:
Daniel Sommer 2023-11-24 10:10:39 +01:00
parent 5d9b028c29
commit ff68336c1b

View file

@ -21,9 +21,10 @@ var previousImage string
func Start() {
loggo.Info("starting the image slideshow...", "interval: "+strconv.FormatFloat(config.Interval.Seconds(), 'f', 0, 64)+" seconds")
var sleepTime time.Duration
var scaleTime time.Duration
var loopTime time.Duration
scaleImages := config.IsResolutionSet()
for {
loopTimestamp := time.Now()
var image string
var palette []color.Color
var data []byte
@ -34,18 +35,17 @@ func Start() {
}
}
if scaleImages {
scaleTimestamp := time.Now()
tmp, error := scale(image)
if error != nil {
loggo.Error("encountered an error scaling an image", "image: "+image, error.Error())
continue
}
data = tmp
scaleTime = time.Since(scaleTimestamp)
palette, _ = getColorPaletteRaw(data)
} else {
palette, _ = getColorPalette(image)
}
loopTime = time.Since(loopTimestamp)
if sleepTime > 0 {
loggo.Debug("sleeping for " + strconv.FormatInt(sleepTime.Milliseconds(), 10) + "ms before next image will be displayed...")
time.Sleep(sleepTime)
@ -64,7 +64,7 @@ func Start() {
}
loggo.Info("set new background image", "image: "+image)
}
sleepTime = config.Interval - scaleTime
sleepTime = config.Interval - loopTime
}
}