From a0a1adef12a9f259e727745323d40a3478da0951 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Thu, 18 Apr 2019 10:55:03 +0200 Subject: [PATCH] fixed overlapping alpha --- backend/software/fill.go | 13 +++++++++++-- backend/software/software.go | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/software/fill.go b/backend/software/fill.go index 2443e90..8a07b1e 100644 --- a/backend/software/fill.go +++ b/backend/software/fill.go @@ -20,11 +20,20 @@ func (b *SoftwareBackend) Clear(pts [4][2]float64) { } func (b *SoftwareBackend) Fill(style *backendbase.FillStyle, pts [][2]float64) { + p2 := b.mask.Pix + for i := range p2 { + p2[i] = 0 + } + iterateTriangles(pts[:], func(tri [][2]float64) { b.fillTriangle(tri, func(x, y int) { if b.clip.AlphaAt(x, y).A == 0 { return } + if b.mask.AlphaAt(x, y).A > 0 { + return + } + b.mask.SetAlpha(x, y, color.Alpha{A: 255}) b.Image.SetRGBA(x, y, mix(style.Color, b.Image.RGBAAt(x, y))) }) }) @@ -90,14 +99,14 @@ func (b *SoftwareBackend) ClearClip() { } func (b *SoftwareBackend) Clip(pts [][2]float64) { - p2 := b.clip2.Pix + p2 := b.mask.Pix for i := range p2 { p2[i] = 0 } iterateTriangles(pts[:], func(tri [][2]float64) { b.fillTriangle(tri, func(x, y int) { - b.clip2.SetAlpha(x, y, color.Alpha{A: 255}) + b.mask.SetAlpha(x, y, color.Alpha{A: 255}) }) }) diff --git a/backend/software/software.go b/backend/software/software.go index 5945dbc..8a22f45 100644 --- a/backend/software/software.go +++ b/backend/software/software.go @@ -10,7 +10,7 @@ import ( type SoftwareBackend struct { Image *image.RGBA clip *image.Alpha - clip2 *image.Alpha + mask *image.Alpha w, h int } @@ -24,7 +24,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.clip2 = image.NewAlpha(image.Rect(0, 0, w, h)) + b.mask = image.NewAlpha(image.Rect(0, 0, w, h)) b.ClearClip() }