diff --git a/context.go b/context.go index 945ccb8..2ac2cea 100644 --- a/context.go +++ b/context.go @@ -315,6 +315,8 @@ func (ctx *context) Draw(wimg *image.RGBA) int { ctx.cmdstim = ctx.cmdstim[:0] } + transparentBorderOptimization := false + for i := range ctx.cmds { if perfUpdate { t0 = time.Now() @@ -372,6 +374,17 @@ func (ctx *context) Draw(wimg *image.RGBA) int { // first command draws the background, insure that it's always fully opaque cmd.Color.A = 0xff } + if transparentBorderOptimization { + transparentBorderOptimization = false + prevcmd := ctx.cmds[i-1].RectFilled + const m = 1<<16 - 1 + sr, sg, sb, sa := cmd.Color.RGBA() + a := (m - sa) * 0x101 + cmd.Color.R = uint8((uint32(prevcmd.Color.R)*a/m + sr) >> 8) + cmd.Color.G = uint8((uint32(prevcmd.Color.G)*a/m + sg) >> 8) + cmd.Color.B = uint8((uint32(prevcmd.Color.B)*a/m + sb) >> 8) + cmd.Color.A = uint8((uint32(prevcmd.Color.A)*a/m + sa) >> 8) + } colimg := image.NewUniform(cmd.Color) op := draw.Over if cmd.Color.A == 0xff { @@ -399,19 +412,12 @@ func (ctx *context) Draw(wimg *image.RGBA) int { // only draw parts of body if this command can be optimized to a border with the next command bordopt = true - cmd2 := &ctx.cmds[i+1] - - if cmd2.RectFilled.Color.A != 0xff { - const m = 1<<16 - 1 - sr, sg, sb, sa := cmd2.RectFilled.Color.RGBA() - a := (m - sa) * 0x101 - cmd2.RectFilled.Color.R = uint8((uint32(cmd.Color.R)*a/m + sr) >> 8) - cmd2.RectFilled.Color.G = uint8((uint32(cmd.Color.G)*a/m + sg) >> 8) - cmd2.RectFilled.Color.B = uint8((uint32(cmd.Color.B)*a/m + sb) >> 8) - cmd2.RectFilled.Color.A = uint8((uint32(cmd.Color.A)*a/m + sa) >> 8) + + if ctx.cmds[i+1].RectFilled.Color.A != 0xff { + transparentBorderOptimization = true } - border += int(cmd2.RectFilled.Rounding) + border += int(ctx.cmds[i+1].RectFilled.Rounding) top := image.Rect(body.Min.X, body.Min.Y, body.Max.X, body.Min.Y+border) bot := image.Rect(body.Min.X, body.Max.Y-border, body.Max.X, body.Max.Y)