slideshow-api/internal/cache.go

45 lines
830 B
Go
Raw Normal View History

2023-11-28 15:52:53 +01:00
package internal
import (
"image/color"
"strconv"
)
// the internally pre buffered (and scaled) image
var cachedImage []byte
// the internally pre buffered color palette
var cachedPalette []byte
// cache an image
func cacheImage(image []byte) {
cachedImage = image
}
// cache a color palette
func cachePalette(colors []color.Color) {
var palette string
for index, color := range colors {
if index > 0 {
palette += "\n"
}
tmp := strconv.Itoa(index)
if len(tmp) < 2 {
tmp = "0" + tmp
}
tmp = "SLIDESHOW_COLOR" + tmp
palette += tmp + "=\"" + rgbToHex(color) + "\""
}
cachedPalette = []byte(palette)
}
// check if an image is cached
func hasCachedImage() bool {
return len(cachedImage) > 0
}
// check if a color palette is cached
func hasCachedColorPalette() bool {
return len(cachedPalette) > 0
}