From ea3cb8123140d1e29858c418ce96e0ebe92fd884 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Sun, 5 May 2019 11:38:24 +0200 Subject: [PATCH] renamed mask to stencil --- backend/softwarebackend/fill.go | 12 +++++------- backend/softwarebackend/software.go | 8 ++++---- backend/softwarebackend/triangles.go | 28 ++++++++++++++-------------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/backend/softwarebackend/fill.go b/backend/softwarebackend/fill.go index 4ad0d3b..8368a4c 100644 --- a/backend/softwarebackend/fill.go +++ b/backend/softwarebackend/fill.go @@ -111,8 +111,8 @@ func (b *SoftwareBackend) FillImageMask(style *backendbase.FillStyle, mask *imag }) } -func (b *SoftwareBackend) clearMask() { - p := b.mask.Pix +func (b *SoftwareBackend) clearStencil() { + p := b.stencil.Pix for i := range p { p[i] = 0 } @@ -126,18 +126,16 @@ func (b *SoftwareBackend) ClearClip() { } func (b *SoftwareBackend) Clip(pts [][2]float64) { - p2 := b.mask.Pix - for i := range p2 { - p2[i] = 0 - } + b.clearStencil() iterateTriangles(pts[:], func(tri [][2]float64) { 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 + p2 := b.stencil.Pix for i := range p { if p2[i] == 0 { p[i] = 0 diff --git a/backend/softwarebackend/software.go b/backend/softwarebackend/software.go index db88e2a..eddc30c 100644 --- a/backend/softwarebackend/software.go +++ b/backend/softwarebackend/software.go @@ -14,9 +14,9 @@ type SoftwareBackend struct { blurSwap *image.RGBA - clip *image.Alpha - mask *image.Alpha - w, h int + clip *image.Alpha + stencil *image.Alpha + w, h int } func New(w, h int) *SoftwareBackend { @@ -29,7 +29,7 @@ func (b *SoftwareBackend) SetSize(w, h int) { b.w, b.h = w, h b.Image = image.NewRGBA(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() } diff --git a/backend/softwarebackend/triangles.go b/backend/softwarebackend/triangles.go index 6b567e0..135039a 100644 --- a/backend/softwarebackend/triangles.go +++ b/backend/softwarebackend/triangles.go @@ -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) { - b.clearMask() + b.clearStencil() if b.MSAA > 0 { 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 { return } - if b.mask.AlphaAt(x, y).A > 0 { + if b.stencil.AlphaAt(x, y).A > 0 { 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) if col.A > 0 { 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) 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 } - 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 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 { return } - if b.mask.AlphaAt(x, y).A > 0 { + if b.stencil.AlphaAt(x, y).A > 0 { 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) if col.A > 0 { 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 { return } - if b.mask.AlphaAt(x, y).A > 0 { + if b.stencil.AlphaAt(x, y).A > 0 { 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)) if col.A > 0 { 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 { return } - if b.mask.AlphaAt(x, y).A > 0 { + if b.stencil.AlphaAt(x, y).A > 0 { 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)) if col.A > 0 { 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) 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 } - 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 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) { - b.clearMask() + b.clearStencil() if b.MSAA > 0 { b.fillTrianglesMSAA(pts, b.MSAA, fn)