Skip to content

Commit

Permalink
vector: re-order some functions.
Browse files Browse the repository at this point in the history
There are no code changes, just a re-ordering so that these files are
consistent with others in this package: OpOver, OpSrc, Mask.

Change-Id: Ib1d46a8e912dae0c760af655e919b77023688189
Reviewed-on: https://go-review.googlesource.com/30111
Reviewed-by: David Crawshaw <crawshaw@golang.org>
  • Loading branch information
rorypeckwnt4v committed May 12, 2023
1 parent fd50299 commit 3acdaf2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions vector/raster_fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,39 +199,39 @@ func (z *Rasterizer) fixedLineTo(b f32.Vec2) {
}
}

func fixedAccumulateOpSrc(dst []uint8, src []uint32) {
func fixedAccumulateOpOver(dst []uint8, src []uint32) {
acc := int2ϕ(0)
for i, v := range src {
acc += int2ϕ(v)
a := acc
if a < 0 {
a = -a
}
a >>= 2*ϕ - 8
if a > 0xff {
a = 0xff
a >>= 2*ϕ - 16
if a > 0xffff {
a = 0xffff
}
dst[i] = uint8(a)
// This algorithm comes from the standard library's image/draw package.
dstA := uint32(dst[i]) * 0x101
maskA := uint32(a)
outA := dstA*(0xffff-maskA)/0xffff + maskA
dst[i] = uint8(outA >> 8)
}
}

func fixedAccumulateOpOver(dst []uint8, src []uint32) {
func fixedAccumulateOpSrc(dst []uint8, src []uint32) {
acc := int2ϕ(0)
for i, v := range src {
acc += int2ϕ(v)
a := acc
if a < 0 {
a = -a
}
a >>= 2*ϕ - 16
if a > 0xffff {
a = 0xffff
a >>= 2*ϕ - 8
if a > 0xff {
a = 0xff
}
// This algorithm comes from the standard library's image/draw package.
dstA := uint32(dst[i]) * 0x101
maskA := uint32(a)
outA := dstA*(0xffff-maskA)/0xffff + maskA
dst[i] = uint8(outA >> 8)
dst[i] = uint8(a)
}
}

Expand Down
16 changes: 8 additions & 8 deletions vector/raster_floating.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const (
almost65536 = almost256 * 256
)

func floatingAccumulateOpSrc(dst []uint8, src []float32) {
func floatingAccumulateOpOver(dst []uint8, src []float32) {
acc := float32(0)
for i, v := range src {
acc += v
Expand All @@ -156,11 +156,15 @@ func floatingAccumulateOpSrc(dst []uint8, src []float32) {
if a > 1 {
a = 1
}
dst[i] = uint8(almost256 * a)
// This algorithm comes from the standard library's image/draw package.
dstA := uint32(dst[i]) * 0x101
maskA := uint32(almost65536 * a)
outA := dstA*(0xffff-maskA)/0xffff + maskA
dst[i] = uint8(outA >> 8)
}
}

func floatingAccumulateOpOver(dst []uint8, src []float32) {
func floatingAccumulateOpSrc(dst []uint8, src []float32) {
acc := float32(0)
for i, v := range src {
acc += v
Expand All @@ -171,11 +175,7 @@ func floatingAccumulateOpOver(dst []uint8, src []float32) {
if a > 1 {
a = 1
}
// This algorithm comes from the standard library's image/draw package.
dstA := uint32(dst[i]) * 0x101
maskA := uint32(almost65536 * a)
outA := dstA*(0xffff-maskA)/0xffff + maskA
dst[i] = uint8(outA >> 8)
dst[i] = uint8(almost256 * a)
}
}

Expand Down

0 comments on commit 3acdaf2

Please sign in to comment.