gg/img.go

44 lines
613 B
Go
Raw Normal View History

2023-10-23 15:45:18 +03:00
package gg
2023-02-17 23:51:40 +03:00
import (
"github.com/hajimehoshi/ebiten/v2"
"image"
_ "image/png"
"io"
2023-05-22 23:39:01 +03:00
"math"
2023-02-17 23:51:40 +03:00
)
type Image = ebiten.Image
2023-06-15 20:18:58 +03:00
type ColorV uint32
2023-05-22 23:39:01 +03:00
type ColorM = ebiten.ColorM
type Color struct {
R, G, B, A ColorV
}
2023-02-17 23:51:40 +03:00
2023-05-22 23:39:01 +03:00
const (
MaxColorV = math.MaxUint32
)
2023-06-15 20:18:58 +03:00
2023-02-17 23:51:40 +03:00
func LoadImage(input io.Reader) (*Image, error) {
img, _, err := image.Decode(input)
if err != nil {
return nil, err
}
ret := ebiten.NewImageFromImage(img)
return ret, nil
}
2023-05-30 14:34:10 +03:00
func NewImage(w, h int) (*Image) {
return ebiten.NewImage(w, h)
}
2023-05-22 23:39:01 +03:00
func (c Color) RGBA() (r, g, b, a uint32) {
return uint32(c.R), uint32(c.G), uint32(c.B), uint32(c.A)
}