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
|
|
|
)
|
2024-05-28 11:24:12 +03:00
|
|
|
import "surdeus.su/core/gg/mx"
|
2023-02-17 23:51:40 +03:00
|
|
|
|
|
|
|
type Image = ebiten.Image
|
2024-01-13 23:46:12 +03:00
|
|
|
type ImageRect = image.Rectangle
|
|
|
|
type ImagePoint = image.Point
|
2023-06-15 20:18:58 +03:00
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
type ColorValue uint32
|
|
|
|
type ColorMode = ebiten.ColorM
|
2023-05-22 23:39:01 +03:00
|
|
|
type Color struct {
|
2024-05-28 11:24:12 +03:00
|
|
|
R, G, B, A ColorValue
|
2023-05-22 23:39:01 +03:00
|
|
|
}
|
2023-02-17 23:51:40 +03:00
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
const (
|
2024-05-28 11:24:12 +03:00
|
|
|
MaxColorValue = math.MaxUint32
|
2023-05-22 23:39:01 +03:00
|
|
|
)
|
|
|
|
|
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).
|
2024-05-28 11:24:12 +03:00
|
|
|
func RGBA(r, g, b, a mx.Float) Color {
|
2023-12-23 00:09:07 +03:00
|
|
|
return Color {
|
2024-05-28 11:24:12 +03:00
|
|
|
ColorValue(r*MaxColorValue),
|
|
|
|
ColorValue(g*MaxColorValue),
|
|
|
|
ColorValue(b*MaxColorValue),
|
|
|
|
ColorValue(a*MaxColorValue),
|
2023-12-23 00:09:07 +03:00
|
|
|
}
|
|
|
|
}
|
2023-06-15 20:18:58 +03:00
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
// Read an image from Reader and return
|
|
|
|
// a new *Image.
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
// Returns a new empty image
|
|
|
|
// with specified with and height.
|
2023-05-30 14:34:10 +03:00
|
|
|
func NewImage(w, h int) (*Image) {
|
|
|
|
return ebiten.NewImage(w, h)
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
func NewImageFromImage(img image.Image) *Image {
|
|
|
|
return ebiten.NewImageFromImage(img)
|
|
|
|
}
|
2023-05-30 14:34:10 +03:00
|
|
|
|
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)
|
2024-05-28 11:24:12 +03:00
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
}
|
|
|
|
|