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-12-23 00:09:07 +03:00
|
|
|
// The wrapper to make RGBA color via
|
|
|
|
// values from 0 to 1 (no value at all and the max value).
|
|
|
|
func Rgba(r, g, b, a Float) Color {
|
|
|
|
return Color {
|
|
|
|
ColorV(r*MaxColorV),
|
|
|
|
ColorV(g*MaxColorV),
|
|
|
|
ColorV(b*MaxColorV),
|
|
|
|
ColorV(a*MaxColorV),
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|