Skip to content

Commit

Permalink
transparent border optimization should alter the command array
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Sep 18, 2018
1 parent 80af40e commit 5679057
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5679057

Please sign in to comment.