2020-05-15 07:20:44 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2020-05-15 12:20:07 +00:00
|
|
|
|
|
|
|
"opslag.de/schobers/zntg"
|
2020-05-15 07:20:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ImageSource interface {
|
|
|
|
CreateImage() (image.Image, error)
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
type ImageSourceFile string
|
2020-05-15 07:20:44 +00:00
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
var _ ImageSource = ImageSourceFile("")
|
2020-05-15 07:20:44 +00:00
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
func (s ImageSourceFile) CreateImage() (image.Image, error) {
|
|
|
|
return zntg.DecodeImage(string(s))
|
2020-05-15 07:20:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
type ImageSourceGo struct {
|
2020-05-15 07:20:44 +00:00
|
|
|
image.Image
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
var _ ImageSource = ImageSourceGo{}
|
2020-05-15 07:20:44 +00:00
|
|
|
|
2020-05-15 12:20:07 +00:00
|
|
|
func (s ImageSourceGo) CreateImage() (image.Image, error) {
|
2020-05-15 07:20:44 +00:00
|
|
|
return s.Image, nil
|
|
|
|
}
|
2020-05-15 12:20:07 +00:00
|
|
|
|
|
|
|
type ImageSourceResource struct {
|
|
|
|
Resources Resources
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ImageSourceResource) CreateImage() (image.Image, error) {
|
|
|
|
src, err := s.Resources.OpenResource(s.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
value, err := zntg.ImageDecoder(src)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return value.(image.Image), nil
|
|
|
|
}
|