From 3acdaf2802f9aba30c3313037698a5e745bd2db2 Mon Sep 17 00:00:00 2001 From: rorypeckwnt4v Date: Fri, 12 May 2023 12:29:47 +0800 Subject: [PATCH] vector: re-order some functions. 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 --- vector/raster_fixed.go | 28 ++++++++++++++-------------- vector/raster_floating.go | 16 ++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/vector/raster_fixed.go b/vector/raster_fixed.go index ed97619..5678bab 100644 --- a/vector/raster_fixed.go +++ b/vector/raster_fixed.go @@ -199,7 +199,7 @@ 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) @@ -207,15 +207,19 @@ func fixedAccumulateOpSrc(dst []uint8, src []uint32) { 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) @@ -223,15 +227,11 @@ func fixedAccumulateOpOver(dst []uint8, src []uint32) { 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) } } diff --git a/vector/raster_floating.go b/vector/raster_floating.go index 721cfcb..fa3e7b9 100644 --- a/vector/raster_floating.go +++ b/vector/raster_floating.go @@ -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 @@ -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 @@ -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) } }