renamed mask to stencil

This commit is contained in:
Thomas Friedel 2019-05-05 11:38:24 +02:00
parent c945678725
commit ea3cb81231
3 changed files with 23 additions and 25 deletions

View file

@ -111,8 +111,8 @@ func (b *SoftwareBackend) FillImageMask(style *backendbase.FillStyle, mask *imag
}) })
} }
func (b *SoftwareBackend) clearMask() { func (b *SoftwareBackend) clearStencil() {
p := b.mask.Pix p := b.stencil.Pix
for i := range p { for i := range p {
p[i] = 0 p[i] = 0
} }
@ -126,18 +126,16 @@ func (b *SoftwareBackend) ClearClip() {
} }
func (b *SoftwareBackend) Clip(pts [][2]float64) { func (b *SoftwareBackend) Clip(pts [][2]float64) {
p2 := b.mask.Pix b.clearStencil()
for i := range p2 {
p2[i] = 0
}
iterateTriangles(pts[:], func(tri [][2]float64) { iterateTriangles(pts[:], func(tri [][2]float64) {
b.fillTriangleNoAA(tri, func(x, y int) { b.fillTriangleNoAA(tri, func(x, y int) {
b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.stencil.SetAlpha(x, y, color.Alpha{A: 255})
}) })
}) })
p := b.clip.Pix p := b.clip.Pix
p2 := b.stencil.Pix
for i := range p { for i := range p {
if p2[i] == 0 { if p2[i] == 0 {
p[i] = 0 p[i] = 0

View file

@ -14,9 +14,9 @@ type SoftwareBackend struct {
blurSwap *image.RGBA blurSwap *image.RGBA
clip *image.Alpha clip *image.Alpha
mask *image.Alpha stencil *image.Alpha
w, h int w, h int
} }
func New(w, h int) *SoftwareBackend { func New(w, h int) *SoftwareBackend {
@ -29,7 +29,7 @@ func (b *SoftwareBackend) SetSize(w, h int) {
b.w, b.h = w, h b.w, b.h = w, h
b.Image = image.NewRGBA(image.Rect(0, 0, w, h)) b.Image = image.NewRGBA(image.Rect(0, 0, w, h))
b.clip = image.NewAlpha(image.Rect(0, 0, w, h)) b.clip = image.NewAlpha(image.Rect(0, 0, w, h))
b.mask = image.NewAlpha(image.Rect(0, 0, w, h)) b.stencil = image.NewAlpha(image.Rect(0, 0, w, h))
b.ClearClip() b.ClearClip()
} }

View file

@ -401,7 +401,7 @@ func (b *SoftwareBackend) fillQuadMSAA(quad [4][2]float64, msaaLevel int, msaaPi
} }
func (b *SoftwareBackend) fillQuad(pts [4][2]float64, fn func(x, y, tx, ty float64) color.RGBA) { func (b *SoftwareBackend) fillQuad(pts [4][2]float64, fn func(x, y, tx, ty float64) color.RGBA) {
b.clearMask() b.clearStencil()
if b.MSAA > 0 { if b.MSAA > 0 {
var msaaPixelBuf [500]msaaPixel var msaaPixelBuf [500]msaaPixel
@ -411,10 +411,10 @@ func (b *SoftwareBackend) fillQuad(pts [4][2]float64, fn func(x, y, tx, ty float
if b.clip.AlphaAt(x, y).A == 0 { if b.clip.AlphaAt(x, y).A == 0 {
return return
} }
if b.mask.AlphaAt(x, y).A > 0 { if b.stencil.AlphaAt(x, y).A > 0 {
return return
} }
b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.stencil.SetAlpha(x, y, color.Alpha{A: 255})
col := fn(float64(x)+0.5, float64(y)+0.5, tx, ty) col := fn(float64(x)+0.5, float64(y)+0.5, tx, ty)
if col.A > 0 { if col.A > 0 {
b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y))) b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y)))
@ -424,10 +424,10 @@ func (b *SoftwareBackend) fillQuad(pts [4][2]float64, fn func(x, y, tx, ty float
samples := (b.MSAA + 1) * (b.MSAA + 1) samples := (b.MSAA + 1) * (b.MSAA + 1)
for i, px := range msaaPixels { for i, px := range msaaPixels {
if px.ix < 0 || b.clip.AlphaAt(px.ix, px.iy).A == 0 || b.mask.AlphaAt(px.ix, px.iy).A > 0 { if px.ix < 0 || b.clip.AlphaAt(px.ix, px.iy).A == 0 || b.stencil.AlphaAt(px.ix, px.iy).A > 0 {
continue continue
} }
b.mask.SetAlpha(px.ix, px.iy, color.Alpha{A: 255}) b.stencil.SetAlpha(px.ix, px.iy, color.Alpha{A: 255})
var mr, mg, mb, ma int var mr, mg, mb, ma int
for j, px2 := range msaaPixels[i:] { for j, px2 := range msaaPixels[i:] {
@ -458,10 +458,10 @@ func (b *SoftwareBackend) fillQuad(pts [4][2]float64, fn func(x, y, tx, ty float
if b.clip.AlphaAt(x, y).A == 0 { if b.clip.AlphaAt(x, y).A == 0 {
return return
} }
if b.mask.AlphaAt(x, y).A > 0 { if b.stencil.AlphaAt(x, y).A > 0 {
return return
} }
b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.stencil.SetAlpha(x, y, color.Alpha{A: 255})
col := fn(float64(x)+0.5, float64(y)+0.5, tx, ty) col := fn(float64(x)+0.5, float64(y)+0.5, tx, ty)
if col.A > 0 { if col.A > 0 {
b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y))) b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y)))
@ -493,10 +493,10 @@ func (b *SoftwareBackend) fillTrianglesNoAA(pts [][2]float64, fn func(x, y float
if b.clip.AlphaAt(x, y).A == 0 { if b.clip.AlphaAt(x, y).A == 0 {
return return
} }
if b.mask.AlphaAt(x, y).A > 0 { if b.stencil.AlphaAt(x, y).A > 0 {
return return
} }
b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.stencil.SetAlpha(x, y, color.Alpha{A: 255})
col := fn(float64(x), float64(y)) col := fn(float64(x), float64(y))
if col.A > 0 { if col.A > 0 {
b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y))) b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y)))
@ -514,10 +514,10 @@ func (b *SoftwareBackend) fillTrianglesMSAA(pts [][2]float64, msaaLevel int, fn
if b.clip.AlphaAt(x, y).A == 0 { if b.clip.AlphaAt(x, y).A == 0 {
return return
} }
if b.mask.AlphaAt(x, y).A > 0 { if b.stencil.AlphaAt(x, y).A > 0 {
return return
} }
b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.stencil.SetAlpha(x, y, color.Alpha{A: 255})
col := fn(float64(x), float64(y)) col := fn(float64(x), float64(y))
if col.A > 0 { if col.A > 0 {
b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y))) b.Image.SetRGBA(x, y, mix(col, b.Image.RGBAAt(x, y)))
@ -528,10 +528,10 @@ func (b *SoftwareBackend) fillTrianglesMSAA(pts [][2]float64, msaaLevel int, fn
samples := (msaaLevel + 1) * (msaaLevel + 1) samples := (msaaLevel + 1) * (msaaLevel + 1)
for i, px := range msaaPixels { for i, px := range msaaPixels {
if px.ix < 0 || b.clip.AlphaAt(px.ix, px.iy).A == 0 || b.mask.AlphaAt(px.ix, px.iy).A > 0 { if px.ix < 0 || b.clip.AlphaAt(px.ix, px.iy).A == 0 || b.stencil.AlphaAt(px.ix, px.iy).A > 0 {
continue continue
} }
b.mask.SetAlpha(px.ix, px.iy, color.Alpha{A: 255}) b.stencil.SetAlpha(px.ix, px.iy, color.Alpha{A: 255})
var mr, mg, mb, ma int var mr, mg, mb, ma int
for j, px2 := range msaaPixels[i:] { for j, px2 := range msaaPixels[i:] {
@ -559,7 +559,7 @@ func (b *SoftwareBackend) fillTrianglesMSAA(pts [][2]float64, msaaLevel int, fn
} }
func (b *SoftwareBackend) fillTriangles(pts [][2]float64, fn func(x, y float64) color.RGBA) { func (b *SoftwareBackend) fillTriangles(pts [][2]float64, fn func(x, y float64) color.RGBA) {
b.clearMask() b.clearStencil()
if b.MSAA > 0 { if b.MSAA > 0 {
b.fillTrianglesMSAA(pts, b.MSAA, fn) b.fillTrianglesMSAA(pts, b.MSAA, fn)