mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: rename ColorSclaeFormat -> ColorScaleMode
This commit is contained in:
parent
e237a70135
commit
8d854cbb82
22
image.go
22
image.go
@ -267,7 +267,7 @@ type Vertex struct {
|
||||
// ColorR/ColorG/ColorB/ColorA represents color scaling values.
|
||||
// Their interpretation depends on the concrete draw call used:
|
||||
// - DrawTriangles: straight-alpha or premultiplied-alpha encoded color multiplier.
|
||||
// The format is determined by ColorScaleFormat in DrawTrianglesOptions.
|
||||
// The format is determined by ColorScaleMode in DrawTrianglesOptions.
|
||||
// If ColorA is 0, the vertex is fully transparent and color is ignored.
|
||||
// If ColorA is 1, the vertex has the color (ColorR, ColorG, ColorB).
|
||||
// Vertex colors are converted to premultiplied-alpha internally and
|
||||
@ -306,17 +306,17 @@ const (
|
||||
EvenOdd
|
||||
)
|
||||
|
||||
// ColorScaleFormat is the format of color scales in vertices.
|
||||
type ColorScaleFormat int
|
||||
// ColorScaleMode is the mode of color scales in vertices.
|
||||
type ColorScaleMode int
|
||||
|
||||
const (
|
||||
// ColorScaleFormatStraightAlpha indicates color scales in vertices are
|
||||
// ColorScaleModeStraightAlpha indicates color scales in vertices are
|
||||
// straight-alpha encoded color multiplier.
|
||||
ColorScaleFormatStraightAlpha ColorScaleFormat = iota
|
||||
ColorScaleModeStraightAlpha ColorScaleMode = iota
|
||||
|
||||
// ColorScaleFormatStraightAlpha indicates color scales in vertices are
|
||||
// ColorScaleModeStraightAlpha indicates color scales in vertices are
|
||||
// premultiplied-alpha encoded color multiplier.
|
||||
ColorScaleFormatPremultipliedAlpha
|
||||
ColorScaleModePremultipliedAlpha
|
||||
)
|
||||
|
||||
// DrawTrianglesOptions represents options for DrawTriangles.
|
||||
@ -326,9 +326,9 @@ type DrawTrianglesOptions struct {
|
||||
// ColorM is applied before vertex color scale is applied.
|
||||
ColorM ColorM
|
||||
|
||||
// ColorScaleFormat is the format of color scales in vertices.
|
||||
// The default (zero) value is ColorScaleFormatStraightAlpha.
|
||||
ColorScaleFormat ColorScaleFormat
|
||||
// ColorScaleMode is the format of color scales in vertices.
|
||||
// The default (zero) value is ColorScaleModeStraightAlpha.
|
||||
ColorScaleMode ColorScaleMode
|
||||
|
||||
// CompositeMode is a composite mode to draw.
|
||||
// The default (zero) value is CompositeModeCustom (Blend is used).
|
||||
@ -435,7 +435,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
|
||||
vs := graphics.Vertices(len(vertices))
|
||||
dst := i
|
||||
if options.ColorScaleFormat == ColorScaleFormatStraightAlpha {
|
||||
if options.ColorScaleMode == ColorScaleModeStraightAlpha {
|
||||
for i, v := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||
vs[i*graphics.VertexFloatCount] = dx
|
||||
|
@ -1984,21 +1984,21 @@ func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
||||
is := []uint16{0, 1, 2, 1, 2, 3}
|
||||
dst0.DrawTriangles(vs0, is, src, op)
|
||||
|
||||
for _, format := range []ebiten.ColorScaleFormat{
|
||||
ebiten.ColorScaleFormatStraightAlpha,
|
||||
ebiten.ColorScaleFormatPremultipliedAlpha,
|
||||
for _, format := range []ebiten.ColorScaleMode{
|
||||
ebiten.ColorScaleModeStraightAlpha,
|
||||
ebiten.ColorScaleModePremultipliedAlpha,
|
||||
} {
|
||||
format := format
|
||||
t.Run(fmt.Sprintf("format%d", format), func(t *testing.T) {
|
||||
var cr, cg, cb, ca float32
|
||||
switch format {
|
||||
case ebiten.ColorScaleFormatStraightAlpha:
|
||||
case ebiten.ColorScaleModeStraightAlpha:
|
||||
// The values are the same as ColorM.Scale
|
||||
cr = 0.2
|
||||
cg = 0.4
|
||||
cb = 0.6
|
||||
ca = 0.8
|
||||
case ebiten.ColorScaleFormatPremultipliedAlpha:
|
||||
case ebiten.ColorScaleModePremultipliedAlpha:
|
||||
cr = 0.2 * 0.8
|
||||
cg = 0.4 * 0.8
|
||||
cb = 0.6 * 0.8
|
||||
@ -2049,7 +2049,7 @@ func TestImageDrawTrianglesWithColorM(t *testing.T) {
|
||||
|
||||
dst1 := ebiten.NewImage(w, h)
|
||||
op := &ebiten.DrawTrianglesOptions{}
|
||||
op.ColorScaleFormat = format
|
||||
op.ColorScaleMode = format
|
||||
dst1.DrawTriangles(vs1, is, src, op)
|
||||
|
||||
for j := 0; j < h; j++ {
|
||||
@ -2113,9 +2113,9 @@ func TestImageDrawTrianglesInterpolatesColors(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for _, format := range []ebiten.ColorScaleFormat{
|
||||
ebiten.ColorScaleFormatStraightAlpha,
|
||||
ebiten.ColorScaleFormatPremultipliedAlpha,
|
||||
for _, format := range []ebiten.ColorScaleMode{
|
||||
ebiten.ColorScaleModeStraightAlpha,
|
||||
ebiten.ColorScaleModePremultipliedAlpha,
|
||||
} {
|
||||
format := format
|
||||
t.Run(fmt.Sprintf("format%d", format), func(t *testing.T) {
|
||||
@ -2123,7 +2123,7 @@ func TestImageDrawTrianglesInterpolatesColors(t *testing.T) {
|
||||
dst.Fill(color.RGBA{0x00, 0x00, 0xff, 0xff})
|
||||
|
||||
op := &ebiten.DrawTrianglesOptions{}
|
||||
op.ColorScaleFormat = format
|
||||
op.ColorScaleMode = format
|
||||
|
||||
is := []uint16{0, 1, 2, 1, 2, 3}
|
||||
dst.DrawTriangles(vs, is, src, op)
|
||||
@ -2134,9 +2134,9 @@ func TestImageDrawTrianglesInterpolatesColors(t *testing.T) {
|
||||
// and notices that colors on the left side of the texture are fully transparent.
|
||||
var want color.RGBA
|
||||
switch format {
|
||||
case ebiten.ColorScaleFormatStraightAlpha:
|
||||
case ebiten.ColorScaleModeStraightAlpha:
|
||||
want = color.RGBA{0x00, 0x80, 0x80, 0xff}
|
||||
case ebiten.ColorScaleFormatPremultipliedAlpha:
|
||||
case ebiten.ColorScaleModePremultipliedAlpha:
|
||||
want = color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||
}
|
||||
|
||||
@ -3518,9 +3518,9 @@ func TestImageColorMAndScale(t *testing.T) {
|
||||
}
|
||||
is := []uint16{0, 1, 2, 1, 2, 3}
|
||||
|
||||
for _, format := range []ebiten.ColorScaleFormat{
|
||||
ebiten.ColorScaleFormatStraightAlpha,
|
||||
ebiten.ColorScaleFormatPremultipliedAlpha,
|
||||
for _, format := range []ebiten.ColorScaleMode{
|
||||
ebiten.ColorScaleModeStraightAlpha,
|
||||
ebiten.ColorScaleModePremultipliedAlpha,
|
||||
} {
|
||||
format := format
|
||||
t.Run(fmt.Sprintf("format%d", format), func(t *testing.T) {
|
||||
@ -3528,21 +3528,21 @@ func TestImageColorMAndScale(t *testing.T) {
|
||||
|
||||
op := &ebiten.DrawTrianglesOptions{}
|
||||
op.ColorM.Translate(0.25, 0.25, 0.25, 0)
|
||||
op.ColorScaleFormat = format
|
||||
op.ColorScaleMode = format
|
||||
dst.DrawTriangles(vs, is, src, op)
|
||||
|
||||
got := dst.At(0, 0).(color.RGBA)
|
||||
alphaBeforeScale := 0.5
|
||||
var want color.RGBA
|
||||
switch format {
|
||||
case ebiten.ColorScaleFormatStraightAlpha:
|
||||
case ebiten.ColorScaleModeStraightAlpha:
|
||||
want = color.RGBA{
|
||||
byte(math.Floor(0xff * (0.5/alphaBeforeScale + 0.25) * alphaBeforeScale * 0.5 * 0.75)),
|
||||
byte(math.Floor(0xff * (0.5/alphaBeforeScale + 0.25) * alphaBeforeScale * 0.25 * 0.75)),
|
||||
byte(math.Floor(0xff * (0.5/alphaBeforeScale + 0.25) * alphaBeforeScale * 0.5 * 0.75)),
|
||||
byte(math.Floor(0xff * alphaBeforeScale * 0.75)),
|
||||
}
|
||||
case ebiten.ColorScaleFormatPremultipliedAlpha:
|
||||
case ebiten.ColorScaleModePremultipliedAlpha:
|
||||
want = color.RGBA{
|
||||
byte(math.Floor(0xff * (0.5/alphaBeforeScale + 0.25) * alphaBeforeScale * 0.5)),
|
||||
byte(math.Floor(0xff * (0.5/alphaBeforeScale + 0.25) * alphaBeforeScale * 0.25)),
|
||||
|
@ -43,7 +43,7 @@ func drawVerticesForUtil(dst *ebiten.Image, vs []ebiten.Vertex, is []uint16, clr
|
||||
}
|
||||
|
||||
op := &ebiten.DrawTrianglesOptions{}
|
||||
op.ColorScaleFormat = ebiten.ColorScaleFormatPremultipliedAlpha
|
||||
op.ColorScaleMode = ebiten.ColorScaleModePremultipliedAlpha
|
||||
op.AntiAlias = true
|
||||
dst.DrawTriangles(vs, is, whiteSubImage, op)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user