From b0b64e3610fbd421aa88dd5ce63fa73c875d0861 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 2 Oct 2022 14:35:56 +0900 Subject: [PATCH] ebiten: use premultiplied-alpha format for ColorScale Closes #2361 --- colorscale.go | 6 +----- shader_test.go | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/colorscale.go b/colorscale.go index 5e051879b..f800bb090 100644 --- a/colorscale.go +++ b/colorscale.go @@ -88,9 +88,5 @@ func (c *ColorScale) Scale(r, g, b, a float32) { // ScaleWithColor multiplies the given color values to the current scale. func (c *ColorScale) ScaleWithColor(clr color.Color) { cr, cg, cb, ca := clr.RGBA() - if ca == 0 { - c.Scale(0, 0, 0, 0) - return - } - c.Scale(float32(cr)/float32(ca), float32(cg)/float32(ca), float32(cb)/float32(ca), float32(ca)/0xffff) + c.Scale(float32(cr)/0xffff, float32(cg)/0xffff, float32(cb)/0xffff, float32(ca)/0xffff) } diff --git a/shader_test.go b/shader_test.go index 174e116d4..ef6572ff0 100644 --- a/shader_test.go +++ b/shader_test.go @@ -1256,7 +1256,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 { op.ColorScale.SetG(5.0 / 8.0) op.ColorScale.SetB(6.0 / 8.0) op.ColorScale.SetA(7.0 / 8.0) - op.ColorScale.Scale(1.0/4.0, 2.0/4.0, 3.0/4.0, 4.0/4.0) + op.ColorScale.ScaleWithColor(color.RGBA{0x40, 0x80, 0xc0, 0xff}) dst.DrawRectShader(w, h, s, op) for j := 0; j < h; j++ {