commit
bf322e1d33
4 changed files with 34 additions and 26 deletions
13
README.md
13
README.md
|
@ -282,16 +282,11 @@ image.fillPath(path, paint)
|
||||||
### Shadow
|
### Shadow
|
||||||
[examples/shadow.nim](examples/shadow.nim)
|
[examples/shadow.nim](examples/shadow.nim)
|
||||||
```nim
|
```nim
|
||||||
|
let path = newPath()
|
||||||
|
path.polygon(vec2(100, 100), 70, sides = 8)
|
||||||
|
|
||||||
let polygonImage = newImage(200, 200)
|
let polygonImage = newImage(200, 200)
|
||||||
|
polygonImage.fillPath(path, rgba(255, 255, 255, 255))
|
||||||
let ctx = newContext(polygonImage)
|
|
||||||
ctx.fillStyle = rgba(255, 255, 255, 255)
|
|
||||||
|
|
||||||
ctx.fillPolygon(
|
|
||||||
vec2(100, 100),
|
|
||||||
70,
|
|
||||||
sides = 8
|
|
||||||
)
|
|
||||||
|
|
||||||
let shadow = polygonImage.shadow(
|
let shadow = polygonImage.shadow(
|
||||||
offset = vec2(2, 2),
|
offset = vec2(2, 2),
|
||||||
|
|
|
@ -757,24 +757,33 @@ proc drawUber(
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
if blendMode.hasSimdBlender():
|
if blendMode.hasSimdBlender():
|
||||||
let blenderSimd = blendMode.blenderSimd()
|
let blenderSimd = blendMode.blenderSimd()
|
||||||
for _ in countup(x, xMax - 4, 4):
|
for _ in countup(x, xMax - 16, 16):
|
||||||
let
|
let
|
||||||
srcPos = p + dx * x.float32 + dy * y.float32
|
srcPos = p + dx * x.float32 + dy * y.float32
|
||||||
sx = srcPos.x.int
|
sx = srcPos.x.int
|
||||||
sy = srcPos.y.int
|
sy = srcPos.y.int
|
||||||
backdrop = mm_loadu_si128(a.data[a.dataIndex(x, y)].addr)
|
|
||||||
when type(b) is Image:
|
when type(b) is Image:
|
||||||
let source = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr)
|
for q in [0, 4, 8, 12]:
|
||||||
else: # b is a Mask
|
let
|
||||||
# Need to move 4 mask values into the alpha slots
|
backdrop = mm_loadu_si128(a.data[a.dataIndex(x + q, y)].addr)
|
||||||
var source = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr)
|
source = mm_loadu_si128(b.data[b.dataIndex(sx + q, sy)].addr)
|
||||||
source = unpackAlphaValues(source)
|
|
||||||
|
|
||||||
mm_storeu_si128(
|
mm_storeu_si128(
|
||||||
a.data[a.dataIndex(x, y)].addr,
|
a.data[a.dataIndex(x + q, y)].addr,
|
||||||
blenderSimd(backdrop, source)
|
blenderSimd(backdrop, source)
|
||||||
)
|
)
|
||||||
x += 4
|
else: # b is a Mask
|
||||||
|
var values = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr)
|
||||||
|
for q in [0, 4, 8, 12]:
|
||||||
|
let
|
||||||
|
backdrop = mm_loadu_si128(a.data[a.dataIndex(x + q, y)].addr)
|
||||||
|
source = unpackAlphaValues(values)
|
||||||
|
mm_storeu_si128(
|
||||||
|
a.data[a.dataIndex(x + q, y)].addr,
|
||||||
|
blenderSimd(backdrop, source)
|
||||||
|
)
|
||||||
|
# Shuffle 32 bits off for the next iteration
|
||||||
|
values = mm_srli_si128(values, 4)
|
||||||
|
x += 16
|
||||||
else: # is a Mask
|
else: # is a Mask
|
||||||
if blendMode.hasSimdMasker():
|
if blendMode.hasSimdMasker():
|
||||||
let maskerSimd = blendMode.maskerSimd()
|
let maskerSimd = blendMode.maskerSimd()
|
||||||
|
|
|
@ -1401,9 +1401,11 @@ proc fillHits(
|
||||||
windingRule: WindingRule,
|
windingRule: WindingRule,
|
||||||
blendMode: BlendMode
|
blendMode: BlendMode
|
||||||
) =
|
) =
|
||||||
let blender = blendMode.blender()
|
let
|
||||||
|
blender = blendMode.blender()
|
||||||
|
width = image.width.float32
|
||||||
var filledTo: int
|
var filledTo: int
|
||||||
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, image.width.float32):
|
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width):
|
||||||
let
|
let
|
||||||
fillStart = prevAt.int
|
fillStart = prevAt.int
|
||||||
fillLen = at.int - fillStart
|
fillLen = at.int - fillStart
|
||||||
|
@ -1449,9 +1451,11 @@ proc fillHits(
|
||||||
windingRule: WindingRule,
|
windingRule: WindingRule,
|
||||||
blendMode: BlendMode
|
blendMode: BlendMode
|
||||||
) =
|
) =
|
||||||
let masker = blendMode.masker()
|
let
|
||||||
|
masker = blendMode.masker()
|
||||||
|
width = mask.width.float32
|
||||||
var filledTo: int
|
var filledTo: int
|
||||||
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, mask.width.float32):
|
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width):
|
||||||
let
|
let
|
||||||
fillStart = prevAt.int
|
fillStart = prevAt.int
|
||||||
fillLen = at.int - fillStart
|
fillLen = at.int - fillStart
|
||||||
|
|
|
@ -95,7 +95,7 @@ block:
|
||||||
|
|
||||||
timeIt "shadow":
|
timeIt "shadow":
|
||||||
b.fill(rgba(0, 0, 0, 255))
|
b.fill(rgba(0, 0, 0, 255))
|
||||||
a.draw(b, vec2(25, 25))
|
a.draw(b, translate(vec2(25, 25)))
|
||||||
|
|
||||||
let shadow = a.shadow(
|
let shadow = a.shadow(
|
||||||
offset = vec2(0, 0),
|
offset = vec2(0, 0),
|
||||||
|
|
Loading…
Reference in a new issue