Bug fix: ColorMatrix should treat straight alpha

This commit is contained in:
Hajime Hoshi 2014-12-22 23:08:13 +09:00
parent 1663ad2250
commit 43988399ee
2 changed files with 11 additions and 2 deletions

View File

@ -24,6 +24,11 @@ import (
const ColorMatrixDim = 5
// A ColorMatrix represents a matrix to transform coloring when rendering an image.
//
// A ColorMatrix is applied to the source alpha color
// while an Image's pixels' format is alpha premultiplied.
// Before applying a matrix, a color is un-multiplied, and after applying the matrix,
// the color is multiplied again.
type ColorMatrix struct {
Elements [ColorMatrixDim - 1][ColorMatrixDim]float64
}

View File

@ -18,9 +18,9 @@ package ebitenutil
import (
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal"
"github.com/hajimehoshi/ebiten/internal/assets"
"image/color"
"math"
)
type debugPrintState struct {
@ -55,7 +55,11 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col
locationX += assets.TextImageCharWidth
}
geo := ebiten.TranslateGeometry(float64(x)+1, float64(y))
r, g, b, a := internal.RGBA(c)
cc := color.NRGBA64Model.Convert(c).(color.NRGBA64)
r := float64(cc.R) / math.MaxUint16
g := float64(cc.G) / math.MaxUint16
b := float64(cc.B) / math.MaxUint16
a := float64(cc.A) / math.MaxUint16
clr := ebiten.ScaleColor(r, g, b, a)
rt.DrawImage(d.textImage, parts, geo, clr)
}