calculate sleep time for slideshow interval more accurately
This commit is contained in:
parent
5d9b028c29
commit
ff68336c1b
1 changed files with 4 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue