Rename BlendMode enum.
This commit is contained in:
parent
e9f9b82bd4
commit
c6f59b9692
19 changed files with 144 additions and 144 deletions
|
@ -309,7 +309,7 @@ let mask = newMask(200, 200)
|
||||||
mask.fillPath(path)
|
mask.fillPath(path)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = BlendMask)
|
||||||
|
|
||||||
image.draw(trees)
|
image.draw(trees)
|
||||||
image.draw(blur)
|
image.draw(blur)
|
||||||
|
|
|
@ -14,7 +14,7 @@ let mask = newMask(200, 200)
|
||||||
mask.fillPath(path)
|
mask.fillPath(path)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = BlendMask)
|
||||||
|
|
||||||
image.draw(trees)
|
image.draw(trees)
|
||||||
image.draw(blur)
|
image.draw(blur)
|
||||||
|
|
|
@ -360,7 +360,7 @@ block:
|
||||||
var b: Image
|
var b: Image
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(1, 0, 0, 0.5)
|
paint.color = color(1, 0, 0, 0.5)
|
||||||
paint.blendMode = bmOverwrite
|
paint.blendMode = BlendOverwrite
|
||||||
|
|
||||||
timeIt "pixie4 overwrite":
|
timeIt "pixie4 overwrite":
|
||||||
b = newImage(1000, 1000)
|
b = newImage(1000, 1000)
|
||||||
|
|
|
@ -78,7 +78,7 @@ block:
|
||||||
|
|
||||||
timeIt "pixie draw overwrite":
|
timeIt "pixie draw overwrite":
|
||||||
# tmp.fill(rgbx(127, 127, 127, 255))
|
# tmp.fill(rgbx(127, 127, 127, 255))
|
||||||
tmp.draw(backdrop, blendMode = bmOverwrite)
|
tmp.draw(backdrop, blendMode = BlendOverwrite)
|
||||||
tmp.draw(source)
|
tmp.draw(source)
|
||||||
|
|
||||||
# tmp.writeFile("tmp2.png")
|
# tmp.writeFile("tmp2.png")
|
||||||
|
@ -124,7 +124,7 @@ block:
|
||||||
|
|
||||||
timeIt "pixie draw mask":
|
timeIt "pixie draw mask":
|
||||||
tmp.draw(backdrop)
|
tmp.draw(backdrop)
|
||||||
tmp.draw(source, blendMode = bmMask)
|
tmp.draw(source, blendMode = BlendMask)
|
||||||
|
|
||||||
# tmp.writeFile("tmp_masked2.png")
|
# tmp.writeFile("tmp_masked2.png")
|
||||||
|
|
||||||
|
|
|
@ -716,7 +716,7 @@ block:
|
||||||
# var mask = newMask(image)
|
# var mask = newMask(image)
|
||||||
# mask.fillPath2(p)
|
# mask.fillPath2(p)
|
||||||
|
|
||||||
# image.draw(mask, blendMode = bmOverwrite)
|
# image.draw(mask, blendMode = BlendOverwrite)
|
||||||
|
|
||||||
# image.writeFile("experiments/trapezoids/heart.png")
|
# image.writeFile("experiments/trapezoids/heart.png")
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ proc binaryInsert(arr: var seq[float32], v: float32) =
|
||||||
arr.insert(v, L + 1)
|
arr.insert(v, L + 1)
|
||||||
|
|
||||||
|
|
||||||
proc fillPath2(image: Image, p: Path, color: Color, windingRule = wrNonZero, blendMode = bmNormal) =
|
proc fillPath2(image: Image, p: Path, color: Color, windingRule = wrNonZero, blendMode = BlendNormal) =
|
||||||
const q = 1/256.0
|
const q = 1/256.0
|
||||||
let rgbx = color.rgbx
|
let rgbx = color.rgbx
|
||||||
var segments = p.commandsToShapes(true, 1.0).shapesToSegments()
|
var segments = p.commandsToShapes(true, 1.0).shapesToSegments()
|
||||||
|
|
|
@ -274,7 +274,7 @@ block:
|
||||||
# var mask = newMask(image)
|
# var mask = newMask(image)
|
||||||
# mask.fillPath2(p)
|
# mask.fillPath2(p)
|
||||||
|
|
||||||
# image.draw(mask, blendMode = bmOverwrite)
|
# image.draw(mask, blendMode = BlendOverwrite)
|
||||||
|
|
||||||
# image.writeFile("experiments/trapezoids/heart.png")
|
# image.writeFile("experiments/trapezoids/heart.png")
|
||||||
|
|
||||||
|
|
|
@ -472,7 +472,7 @@ block:
|
||||||
# var mask = newMask(image)
|
# var mask = newMask(image)
|
||||||
# mask.fillPath2(p)
|
# mask.fillPath2(p)
|
||||||
|
|
||||||
# image.draw(mask, blendMode = bmOverwrite)
|
# image.draw(mask, blendMode = BlendOverwrite)
|
||||||
|
|
||||||
# image.writeFile("experiments/trapezoids/heart.png")
|
# image.writeFile("experiments/trapezoids/heart.png")
|
||||||
|
|
||||||
|
|
|
@ -425,28 +425,28 @@ proc blendOverwrite(backdrop, source: ColorRGBX): ColorRGBX =
|
||||||
proc blender*(blendMode: BlendMode): Blender {.raises: [].} =
|
proc blender*(blendMode: BlendMode): Blender {.raises: [].} =
|
||||||
## Returns a blend function for a given blend mode.
|
## Returns a blend function for a given blend mode.
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmNormal: blendNormal
|
of BlendNormal: blendNormal
|
||||||
of bmDarken: blendDarken
|
of BlendDarken: blendDarken
|
||||||
of bmMultiply: blendMultiply
|
of BlendMultiply: blendMultiply
|
||||||
# of bmLinearBurn: blendLinearBurn
|
# of BlendLinearBurn: blendLinearBurn
|
||||||
of bmColorBurn: blendColorBurn
|
of BlendColorBurn: blendColorBurn
|
||||||
of bmLighten: blendLighten
|
of BlendLighten: blendLighten
|
||||||
of bmScreen: blendScreen
|
of BlendScreen: blendScreen
|
||||||
# of bmLinearDodge: blendLinearDodge
|
# of BlendLinearDodge: blendLinearDodge
|
||||||
of bmColorDodge: blendColorDodge
|
of BlendColorDodge: blendColorDodge
|
||||||
of bmOverlay: blendOverlay
|
of BlendOverlay: blendOverlay
|
||||||
of bmSoftLight: blendSoftLight
|
of BlendSoftLight: blendSoftLight
|
||||||
of bmHardLight: blendHardLight
|
of BlendHardLight: blendHardLight
|
||||||
of bmDifference: blendDifference
|
of BlendDifference: blendDifference
|
||||||
of bmExclusion: blendExclusion
|
of BlendExclusion: blendExclusion
|
||||||
of bmHue: blendHue
|
of BlendHue: blendHue
|
||||||
of bmSaturation: blendSaturation
|
of BlendSaturation: blendSaturation
|
||||||
of bmColor: blendColor
|
of BlendColor: blendColor
|
||||||
of bmLuminosity: blendLuminosity
|
of BlendLuminosity: blendLuminosity
|
||||||
of bmMask: blendMask
|
of BlendMask: blendMask
|
||||||
of bmOverwrite: blendOverwrite
|
of BlendOverwrite: blendOverwrite
|
||||||
of bmSubtractMask: blendSubtractMask
|
of BlendSubtractMask: blendSubtractMask
|
||||||
of bmExcludeMask: blendExcludeMask
|
of BlendExcludeMask: blendExcludeMask
|
||||||
|
|
||||||
proc maskNormal(backdrop, source: uint8): uint8 =
|
proc maskNormal(backdrop, source: uint8): uint8 =
|
||||||
## Blending masks
|
## Blending masks
|
||||||
|
@ -471,11 +471,11 @@ proc maskOverwrite(backdrop, source: uint8): uint8 =
|
||||||
proc masker*(blendMode: BlendMode): Masker {.raises: [PixieError].} =
|
proc masker*(blendMode: BlendMode): Masker {.raises: [PixieError].} =
|
||||||
## Returns a blend masking function for a given blend masking mode.
|
## Returns a blend masking function for a given blend masking mode.
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmNormal: maskNormal
|
of BlendNormal: maskNormal
|
||||||
of bmMask: maskMask
|
of BlendMask: maskMask
|
||||||
of bmOverwrite: maskOverwrite
|
of BlendOverwrite: maskOverwrite
|
||||||
of bmSubtractMask: maskSubtract
|
of BlendSubtractMask: maskSubtract
|
||||||
of bmExcludeMask: maskExclude
|
of BlendExcludeMask: maskExclude
|
||||||
else:
|
else:
|
||||||
raise newException(PixieError, "No masker for " & $blendMode)
|
raise newException(PixieError, "No masker for " & $blendMode)
|
||||||
|
|
||||||
|
@ -548,15 +548,15 @@ when defined(amd64) and not defined(pixieNoSimd):
|
||||||
proc blenderSimd*(blendMode: BlendMode): BlenderSimd {.raises: [PixieError].} =
|
proc blenderSimd*(blendMode: BlendMode): BlenderSimd {.raises: [PixieError].} =
|
||||||
## Returns a blend function for a given blend mode with SIMD support.
|
## Returns a blend function for a given blend mode with SIMD support.
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmNormal: blendNormalSimd
|
of BlendNormal: blendNormalSimd
|
||||||
of bmMask: blendMaskSimd
|
of BlendMask: blendMaskSimd
|
||||||
of bmOverwrite: blendOverwriteSimd
|
of BlendOverwrite: blendOverwriteSimd
|
||||||
else:
|
else:
|
||||||
raise newException(PixieError, "No SIMD blender for " & $blendMode)
|
raise newException(PixieError, "No SIMD blender for " & $blendMode)
|
||||||
|
|
||||||
proc hasSimdBlender*(blendMode: BlendMode): bool {.inline, raises: [].} =
|
proc hasSimdBlender*(blendMode: BlendMode): bool {.inline, raises: [].} =
|
||||||
## Is there a blend function for a given blend mode with SIMD support?
|
## Is there a blend function for a given blend mode with SIMD support?
|
||||||
blendMode in {bmNormal, bmMask, bmOverwrite}
|
blendMode in {BlendNormal, BlendMask, BlendOverwrite}
|
||||||
|
|
||||||
proc maskNormalInlineSimd*(backdrop, source: M128i): M128i {.inline.} =
|
proc maskNormalInlineSimd*(backdrop, source: M128i): M128i {.inline.} =
|
||||||
## Blending masks
|
## Blending masks
|
||||||
|
@ -625,15 +625,15 @@ when defined(amd64) and not defined(pixieNoSimd):
|
||||||
proc maskerSimd*(blendMode: BlendMode): MaskerSimd {.raises: [PixieError].} =
|
proc maskerSimd*(blendMode: BlendMode): MaskerSimd {.raises: [PixieError].} =
|
||||||
## Returns a blend masking function with SIMD support.
|
## Returns a blend masking function with SIMD support.
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmNormal: maskNormalSimd
|
of BlendNormal: maskNormalSimd
|
||||||
of bmMask: maskMaskSimd
|
of BlendMask: maskMaskSimd
|
||||||
of bmOverwrite: blendOverwriteSimd
|
of BlendOverwrite: blendOverwriteSimd
|
||||||
else:
|
else:
|
||||||
raise newException(PixieError, "No SIMD masker for " & $blendMode)
|
raise newException(PixieError, "No SIMD masker for " & $blendMode)
|
||||||
|
|
||||||
proc hasSimdMasker*(blendMode: BlendMode): bool {.inline, raises: [].} =
|
proc hasSimdMasker*(blendMode: BlendMode): bool {.inline, raises: [].} =
|
||||||
## Is there a blend masking function with SIMD support?
|
## Is there a blend masking function with SIMD support?
|
||||||
blendMode in {bmNormal, bmMask, bmOverwrite}
|
blendMode in {BlendNormal, BlendMask, BlendOverwrite}
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
@ -4,29 +4,29 @@ type
|
||||||
PixieError* = object of ValueError ## Raised if an operation fails.
|
PixieError* = object of ValueError ## Raised if an operation fails.
|
||||||
|
|
||||||
BlendMode* = enum
|
BlendMode* = enum
|
||||||
bmNormal
|
BlendNormal
|
||||||
bmDarken
|
BlendDarken
|
||||||
bmMultiply
|
BlendMultiply
|
||||||
# bmLinearBurn
|
# BlendLinearBurn
|
||||||
bmColorBurn
|
BlendColorBurn
|
||||||
bmLighten
|
BlendLighten
|
||||||
bmScreen
|
BlendScreen
|
||||||
# bmLinearDodge
|
# BlendLinearDodge
|
||||||
bmColorDodge
|
BlendColorDodge
|
||||||
bmOverlay
|
BlendOverlay
|
||||||
bmSoftLight
|
BlendSoftLight
|
||||||
bmHardLight
|
BlendHardLight
|
||||||
bmDifference
|
BlendDifference
|
||||||
bmExclusion
|
BlendExclusion
|
||||||
bmHue
|
BlendHue
|
||||||
bmSaturation
|
BlendSaturation
|
||||||
bmColor
|
BlendColor
|
||||||
bmLuminosity
|
BlendLuminosity
|
||||||
|
|
||||||
bmMask ## Special blend mode that is used for masking
|
BlendMask ## Special blend mode that is used for masking
|
||||||
bmOverwrite ## Special blend mode that just copies pixels
|
BlendOverwrite ## Special blend mode that just copies pixels
|
||||||
bmSubtractMask ## Inverse mask
|
BlendSubtractMask ## Inverse mask
|
||||||
bmExcludeMask
|
BlendExcludeMask
|
||||||
|
|
||||||
proc mix*(a, b: uint8, t: float32): uint8 {.inline, raises: [].} =
|
proc mix*(a, b: uint8, t: float32): uint8 {.inline, raises: [].} =
|
||||||
## Linearly interpolate between a and b using t.
|
## Linearly interpolate between a and b using t.
|
||||||
|
|
|
@ -370,7 +370,7 @@ proc clip*(
|
||||||
ctx.mask = newMask(ctx.image.width, ctx.image.height)
|
ctx.mask = newMask(ctx.image.width, ctx.image.height)
|
||||||
ctx.mask.fillPath(path, windingRule = windingRule)
|
ctx.mask.fillPath(path, windingRule = windingRule)
|
||||||
else:
|
else:
|
||||||
ctx.mask.fillPath(path, windingRule = windingRule, blendMode = bmMask)
|
ctx.mask.fillPath(path, windingRule = windingRule, blendMode = BlendMask)
|
||||||
|
|
||||||
proc clip*(
|
proc clip*(
|
||||||
ctx: Context, windingRule = wrNonZero
|
ctx: Context, windingRule = wrNonZero
|
||||||
|
@ -398,7 +398,7 @@ proc stroke*(ctx: Context) {.inline, raises: [PixieError].} =
|
||||||
proc clearRect*(ctx: Context, rect: Rect) {.raises: [PixieError].} =
|
proc clearRect*(ctx: Context, rect: Rect) {.raises: [PixieError].} =
|
||||||
## Erases the pixels in a rectangular area.
|
## Erases the pixels in a rectangular area.
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.blendMode = bmOverwrite
|
paint.blendMode = BlendOverwrite
|
||||||
|
|
||||||
let path = newPath()
|
let path = newPath()
|
||||||
path.rect(rect)
|
path.rect(rect)
|
||||||
|
|
|
@ -595,7 +595,7 @@ proc getRgbaSmooth*(
|
||||||
topMix
|
topMix
|
||||||
|
|
||||||
proc drawCorrect(
|
proc drawCorrect(
|
||||||
a, b: Image | Mask, transform = mat3(), blendMode = bmNormal, tiled = false
|
a, b: Image | Mask, transform = mat3(), blendMode = BlendNormal, tiled = false
|
||||||
) {.raises: [PixieError].} =
|
) {.raises: [PixieError].} =
|
||||||
## Draws one image onto another using matrix with color blending.
|
## Draws one image onto another using matrix with color blending.
|
||||||
|
|
||||||
|
@ -719,7 +719,7 @@ proc drawUber(
|
||||||
else: # a is a Mask
|
else: # a is a Mask
|
||||||
let masker = blendMode.masker()
|
let masker = blendMode.masker()
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
if yMin > 0:
|
if yMin > 0:
|
||||||
zeroMem(a.data[0].addr, 4 * yMin * a.width)
|
zeroMem(a.data[0].addr, 4 * yMin * a.width)
|
||||||
|
|
||||||
|
@ -754,7 +754,7 @@ proc drawUber(
|
||||||
if xStart == a.width or xStop == 0:
|
if xStart == a.width or xStop == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
if xStart > 0:
|
if xStart > 0:
|
||||||
zeroMem(a.data[a.dataIndex(0, y)].addr, 4 * xStart)
|
zeroMem(a.data[a.dataIndex(0, y)].addr, 4 * xStart)
|
||||||
|
|
||||||
|
@ -793,7 +793,7 @@ proc drawUber(
|
||||||
var sx = srcPos.x.int
|
var sx = srcPos.x.int
|
||||||
|
|
||||||
when type(a) is Image and type(b) is Image:
|
when type(a) is Image and type(b) is Image:
|
||||||
if blendMode in {bmNormal, bmOverwrite} and
|
if blendMode in {BlendNormal, BlendOverwrite} and
|
||||||
isOpaque(b.data, b.dataIndex(sx, sy), xStop - xStart):
|
isOpaque(b.data, b.dataIndex(sx, sy), xStop - xStart):
|
||||||
copyMem(
|
copyMem(
|
||||||
a.data[a.dataIndex(x, y)].addr,
|
a.data[a.dataIndex(x, y)].addr,
|
||||||
|
@ -804,7 +804,7 @@ proc drawUber(
|
||||||
|
|
||||||
when defined(amd64) and not defined(pixieNoSimd):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmOverwrite:
|
of BlendOverwrite:
|
||||||
for _ in 0 ..< (xStop - xStart) div 16:
|
for _ in 0 ..< (xStop - xStart) div 16:
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
when type(b) is Image:
|
when type(b) is Image:
|
||||||
|
@ -831,7 +831,7 @@ proc drawUber(
|
||||||
mm_storeu_si128(a.data[a.dataIndex(x, y)].addr, sourceVec)
|
mm_storeu_si128(a.data[a.dataIndex(x, y)].addr, sourceVec)
|
||||||
x += 16
|
x += 16
|
||||||
sx += 16
|
sx += 16
|
||||||
of bmNormal:
|
of BlendNormal:
|
||||||
let vec255 = mm_set1_epi32(cast[int32](uint32.high))
|
let vec255 = mm_set1_epi32(cast[int32](uint32.high))
|
||||||
for _ in 0 ..< (xStop - xStart) div 16:
|
for _ in 0 ..< (xStop - xStart) div 16:
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -889,7 +889,7 @@ proc drawUber(
|
||||||
)
|
)
|
||||||
x += 16
|
x += 16
|
||||||
sx += 16
|
sx += 16
|
||||||
of bmMask:
|
of BlendMask:
|
||||||
let vec255 = mm_set1_epi32(cast[int32](uint32.high))
|
let vec255 = mm_set1_epi32(cast[int32](uint32.high))
|
||||||
for _ in 0 ..< (xStop - xStart) div 16:
|
for _ in 0 ..< (xStop - xStart) div 16:
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -1004,7 +1004,7 @@ proc drawUber(
|
||||||
)
|
)
|
||||||
|
|
||||||
case blendMode:
|
case blendMode:
|
||||||
of bmOverwrite:
|
of BlendOverwrite:
|
||||||
for x in x ..< xStop:
|
for x in x ..< xStop:
|
||||||
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -1022,7 +1022,7 @@ proc drawUber(
|
||||||
if source > 0:
|
if source > 0:
|
||||||
a.unsafe[x, y] = source
|
a.unsafe[x, y] = source
|
||||||
srcPos += dx
|
srcPos += dx
|
||||||
of bmNormal:
|
of BlendNormal:
|
||||||
for x in x ..< xStop:
|
for x in x ..< xStop:
|
||||||
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -1048,7 +1048,7 @@ proc drawUber(
|
||||||
let backdrop = a.unsafe[x, y]
|
let backdrop = a.unsafe[x, y]
|
||||||
a.unsafe[x, y] = blendAlpha(backdrop, source)
|
a.unsafe[x, y] = blendAlpha(backdrop, source)
|
||||||
srcPos += dx
|
srcPos += dx
|
||||||
of bmMask:
|
of BlendMask:
|
||||||
for x in x ..< xStop:
|
for x in x ..< xStop:
|
||||||
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
||||||
when type(a) is Image:
|
when type(a) is Image:
|
||||||
|
@ -1095,16 +1095,16 @@ proc drawUber(
|
||||||
a.unsafe[x, y] = masker(backdrop, sample)
|
a.unsafe[x, y] = masker(backdrop, sample)
|
||||||
srcPos += dx
|
srcPos += dx
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
if a.width - xStop > 0:
|
if a.width - xStop > 0:
|
||||||
zeroMem(a.data[a.dataIndex(xStop, y)].addr, 4 * (a.width - xStop))
|
zeroMem(a.data[a.dataIndex(xStop, y)].addr, 4 * (a.width - xStop))
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
if a.height - yMax > 0:
|
if a.height - yMax > 0:
|
||||||
zeroMem(a.data[a.dataIndex(0, yMax)].addr, 4 * a.width * (a.height - yMax))
|
zeroMem(a.data[a.dataIndex(0, yMax)].addr, 4 * a.width * (a.height - yMax))
|
||||||
|
|
||||||
proc draw*(
|
proc draw*(
|
||||||
a, b: Image, transform = mat3(), blendMode = bmNormal
|
a, b: Image, transform = mat3(), blendMode = BlendNormal
|
||||||
) {.inline, raises: [PixieError].} =
|
) {.inline, raises: [PixieError].} =
|
||||||
## Draws one image onto another using matrix with color blending.
|
## Draws one image onto another using matrix with color blending.
|
||||||
when type(transform) is Vec2:
|
when type(transform) is Vec2:
|
||||||
|
@ -1113,7 +1113,7 @@ proc draw*(
|
||||||
a.drawUber(b, transform, blendMode)
|
a.drawUber(b, transform, blendMode)
|
||||||
|
|
||||||
proc draw*(
|
proc draw*(
|
||||||
a, b: Mask, transform = mat3(), blendMode = bmMask
|
a, b: Mask, transform = mat3(), blendMode = BlendMask
|
||||||
) {.inline, raises: [PixieError].} =
|
) {.inline, raises: [PixieError].} =
|
||||||
## Draws a mask onto a mask using a matrix with color blending.
|
## Draws a mask onto a mask using a matrix with color blending.
|
||||||
when type(transform) is Vec2:
|
when type(transform) is Vec2:
|
||||||
|
@ -1122,7 +1122,7 @@ proc draw*(
|
||||||
a.drawUber(b, transform, blendMode)
|
a.drawUber(b, transform, blendMode)
|
||||||
|
|
||||||
proc draw*(
|
proc draw*(
|
||||||
image: Image, mask: Mask, transform = mat3(), blendMode = bmMask
|
image: Image, mask: Mask, transform = mat3(), blendMode = BlendMask
|
||||||
) {.inline, raises: [PixieError].} =
|
) {.inline, raises: [PixieError].} =
|
||||||
## Draws a mask onto an image using a matrix with color blending.
|
## Draws a mask onto an image using a matrix with color blending.
|
||||||
when type(transform) is Vec2:
|
when type(transform) is Vec2:
|
||||||
|
@ -1131,7 +1131,7 @@ proc draw*(
|
||||||
image.drawUber(mask, transform, blendMode)
|
image.drawUber(mask, transform, blendMode)
|
||||||
|
|
||||||
proc draw*(
|
proc draw*(
|
||||||
mask: Mask, image: Image, transform = mat3(), blendMode = bmMask
|
mask: Mask, image: Image, transform = mat3(), blendMode = BlendMask
|
||||||
) {.inline, raises: [PixieError].} =
|
) {.inline, raises: [PixieError].} =
|
||||||
## Draws a image onto a mask using a matrix with color blending.
|
## Draws a image onto a mask using a matrix with color blending.
|
||||||
when type(transform) is Vec2:
|
when type(transform) is Vec2:
|
||||||
|
@ -1140,7 +1140,7 @@ proc draw*(
|
||||||
mask.drawUber(image, transform, blendMode)
|
mask.drawUber(image, transform, blendMode)
|
||||||
|
|
||||||
proc drawTiled*(
|
proc drawTiled*(
|
||||||
dst, src: Image, mat: Mat3, blendMode = bmNormal
|
dst, src: Image, mat: Mat3, blendMode = BlendNormal
|
||||||
) {.raises: [PixieError].} =
|
) {.raises: [PixieError].} =
|
||||||
dst.drawCorrect(src, mat, blendMode, true)
|
dst.drawCorrect(src, mat, blendMode, true)
|
||||||
|
|
||||||
|
@ -1156,7 +1156,7 @@ proc resize*(srcImage: Image, width, height: int): Image {.raises: [PixieError].
|
||||||
width.float32 / srcImage.width.float32,
|
width.float32 / srcImage.width.float32,
|
||||||
height.float32 / srcImage.height.float32
|
height.float32 / srcImage.height.float32
|
||||||
)),
|
)),
|
||||||
bmOverwrite
|
BlendOverwrite
|
||||||
)
|
)
|
||||||
|
|
||||||
proc shadow*(
|
proc shadow*(
|
||||||
|
@ -1170,7 +1170,7 @@ proc shadow*(
|
||||||
shifted = mask
|
shifted = mask
|
||||||
else:
|
else:
|
||||||
shifted = newMask(mask.width, mask.height)
|
shifted = newMask(mask.width, mask.height)
|
||||||
shifted.draw(mask, translate(offset), bmOverwrite)
|
shifted.draw(mask, translate(offset), BlendOverwrite)
|
||||||
|
|
||||||
shifted.spread(spread)
|
shifted.spread(spread)
|
||||||
shifted.blur(blur)
|
shifted.blur(blur)
|
||||||
|
@ -1188,7 +1188,7 @@ proc superImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].}
|
||||||
result = newImage(w, h)
|
result = newImage(w, h)
|
||||||
else:
|
else:
|
||||||
result = newImage(w, h)
|
result = newImage(w, h)
|
||||||
result.draw(image, translate(vec2(-x.float32, -y.float32)), bmOverwrite)
|
result.draw(image, translate(vec2(-x.float32, -y.float32)), BlendOverwrite)
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
@ -1335,10 +1335,10 @@ proc fillCoverage(
|
||||||
# If the coverages are not all zero
|
# If the coverages are not all zero
|
||||||
if mm_movemask_epi8(mm_cmpeq_epi32(coverageVec, vec255)) == 0xffff:
|
if mm_movemask_epi8(mm_cmpeq_epi32(coverageVec, vec255)) == 0xffff:
|
||||||
# If the coverages are all 255
|
# If the coverages are all 255
|
||||||
if blendMode == bmOverwrite:
|
if blendMode == BlendOverwrite:
|
||||||
for i in 0 ..< 4:
|
for i in 0 ..< 4:
|
||||||
mm_storeu_si128(image.data[index + i * 4].addr, colorVec)
|
mm_storeu_si128(image.data[index + i * 4].addr, colorVec)
|
||||||
elif blendMode == bmNormal:
|
elif blendMode == BlendNormal:
|
||||||
if rgbx.a == 255:
|
if rgbx.a == 255:
|
||||||
for i in 0 ..< 4:
|
for i in 0 ..< 4:
|
||||||
mm_storeu_si128(image.data[index + i * 4].addr, colorVec)
|
mm_storeu_si128(image.data[index + i * 4].addr, colorVec)
|
||||||
|
@ -1378,7 +1378,7 @@ proc fillCoverage(
|
||||||
|
|
||||||
source = mm_or_si128(sourceEven, mm_slli_epi16(sourceOdd, 8))
|
source = mm_or_si128(sourceEven, mm_slli_epi16(sourceOdd, 8))
|
||||||
|
|
||||||
if blendMode == bmOverwrite:
|
if blendMode == BlendOverwrite:
|
||||||
mm_storeu_si128(image.data[index + i * 4].addr, source)
|
mm_storeu_si128(image.data[index + i * 4].addr, source)
|
||||||
else:
|
else:
|
||||||
let backdrop = mm_loadu_si128(image.data[index + i * 4].addr)
|
let backdrop = mm_loadu_si128(image.data[index + i * 4].addr)
|
||||||
|
@ -1389,12 +1389,12 @@ proc fillCoverage(
|
||||||
|
|
||||||
coverageVec = mm_srli_si128(coverageVec, 4)
|
coverageVec = mm_srli_si128(coverageVec, 4)
|
||||||
|
|
||||||
if blendMode == bmNormal:
|
if blendMode == BlendNormal:
|
||||||
useCoverage(blendNormalInlineSimd)
|
useCoverage(blendNormalInlineSimd)
|
||||||
else:
|
else:
|
||||||
useCoverage(blenderSimd)
|
useCoverage(blenderSimd)
|
||||||
|
|
||||||
elif blendMode == bmMask:
|
elif blendMode == BlendMask:
|
||||||
for i in 0 ..< 4:
|
for i in 0 ..< 4:
|
||||||
mm_storeu_si128(image.data[index + i * 4].addr, vecZero)
|
mm_storeu_si128(image.data[index + i * 4].addr, vecZero)
|
||||||
|
|
||||||
|
@ -1403,8 +1403,8 @@ proc fillCoverage(
|
||||||
let blender = blendMode.blender()
|
let blender = blendMode.blender()
|
||||||
for x in x ..< startX + coverages.len:
|
for x in x ..< startX + coverages.len:
|
||||||
let coverage = coverages[x - startX]
|
let coverage = coverages[x - startX]
|
||||||
if coverage != 0 or blendMode == bmExcludeMask:
|
if coverage != 0 or blendMode == BlendExcludeMask:
|
||||||
if blendMode == bmNormal and coverage == 255 and rgbx.a == 255:
|
if blendMode == BlendNormal and coverage == 255 and rgbx.a == 255:
|
||||||
# Skip blending
|
# Skip blending
|
||||||
image.unsafe[x, y] = rgbx
|
image.unsafe[x, y] = rgbx
|
||||||
continue
|
continue
|
||||||
|
@ -1416,15 +1416,15 @@ proc fillCoverage(
|
||||||
source.b = ((source.b.uint32 * coverage) div 255).uint8
|
source.b = ((source.b.uint32 * coverage) div 255).uint8
|
||||||
source.a = ((source.a.uint32 * coverage) div 255).uint8
|
source.a = ((source.a.uint32 * coverage) div 255).uint8
|
||||||
|
|
||||||
if blendMode == bmOverwrite:
|
if blendMode == BlendOverwrite:
|
||||||
image.unsafe[x, y] = source
|
image.unsafe[x, y] = source
|
||||||
else:
|
else:
|
||||||
let backdrop = image.unsafe[x, y]
|
let backdrop = image.unsafe[x, y]
|
||||||
image.unsafe[x, y] = blender(backdrop, source)
|
image.unsafe[x, y] = blender(backdrop, source)
|
||||||
elif blendMode == bmMask:
|
elif blendMode == BlendMask:
|
||||||
image.unsafe[x, y] = rgbx(0, 0, 0, 0)
|
image.unsafe[x, y] = rgbx(0, 0, 0, 0)
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
image.clearUnsafe(0, y, startX, y)
|
image.clearUnsafe(0, y, startX, y)
|
||||||
image.clearUnsafe(startX + coverages.len, y, image.width, y)
|
image.clearUnsafe(startX + coverages.len, y, image.width, y)
|
||||||
|
|
||||||
|
@ -1446,7 +1446,7 @@ proc fillCoverage(
|
||||||
coverageVec = mm_loadu_si128(coverages[x - startX].unsafeAddr)
|
coverageVec = mm_loadu_si128(coverages[x - startX].unsafeAddr)
|
||||||
if mm_movemask_epi8(mm_cmpeq_epi16(coverageVec, vecZero)) != 0xffff:
|
if mm_movemask_epi8(mm_cmpeq_epi16(coverageVec, vecZero)) != 0xffff:
|
||||||
# If the coverages are not all zero
|
# If the coverages are not all zero
|
||||||
if blendMode == bmOverwrite:
|
if blendMode == BlendOverwrite:
|
||||||
mm_storeu_si128(mask.data[index].addr, coverageVec)
|
mm_storeu_si128(mask.data[index].addr, coverageVec)
|
||||||
else:
|
else:
|
||||||
let backdrop = mm_loadu_si128(mask.data[index].addr)
|
let backdrop = mm_loadu_si128(mask.data[index].addr)
|
||||||
|
@ -1454,23 +1454,23 @@ proc fillCoverage(
|
||||||
mask.data[index].addr,
|
mask.data[index].addr,
|
||||||
maskerSimd(backdrop, coverageVec)
|
maskerSimd(backdrop, coverageVec)
|
||||||
)
|
)
|
||||||
elif blendMode == bmMask:
|
elif blendMode == BlendMask:
|
||||||
mm_storeu_si128(mask.data[index].addr, vecZero)
|
mm_storeu_si128(mask.data[index].addr, vecZero)
|
||||||
x += 16
|
x += 16
|
||||||
|
|
||||||
let masker = blendMode.masker()
|
let masker = blendMode.masker()
|
||||||
for x in x ..< startX + coverages.len:
|
for x in x ..< startX + coverages.len:
|
||||||
let coverage = coverages[x - startX]
|
let coverage = coverages[x - startX]
|
||||||
if coverage != 0 or blendMode == bmExcludeMask:
|
if coverage != 0 or blendMode == BlendExcludeMask:
|
||||||
if blendMode == bmOverwrite:
|
if blendMode == BlendOverwrite:
|
||||||
mask.unsafe[x, y] = coverage
|
mask.unsafe[x, y] = coverage
|
||||||
else:
|
else:
|
||||||
let backdrop = mask.unsafe[x, y]
|
let backdrop = mask.unsafe[x, y]
|
||||||
mask.unsafe[x, y] = masker(backdrop, coverage)
|
mask.unsafe[x, y] = masker(backdrop, coverage)
|
||||||
elif blendMode == bmMask:
|
elif blendMode == BlendMask:
|
||||||
mask.unsafe[x, y] = 0
|
mask.unsafe[x, y] = 0
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
mask.clearUnsafe(0, y, startX, y)
|
mask.clearUnsafe(0, y, startX, y)
|
||||||
mask.clearUnsafe(startX + coverages.len, y, mask.width, y)
|
mask.clearUnsafe(startX + coverages.len, y, mask.width, y)
|
||||||
|
|
||||||
|
@ -1496,7 +1496,7 @@ proc fillHits(
|
||||||
|
|
||||||
filledTo = fillStart + fillLen
|
filledTo = fillStart + fillLen
|
||||||
|
|
||||||
if blendMode == bmOverwrite or (blendMode == bmNormal and rgbx.a == 255):
|
if blendMode == BlendOverwrite or (blendMode == BlendNormal and rgbx.a == 255):
|
||||||
fillUnsafe(image.data, rgbx, image.dataIndex(fillStart, y), fillLen)
|
fillUnsafe(image.data, rgbx, image.dataIndex(fillStart, y), fillLen)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1505,8 +1505,8 @@ proc fillHits(
|
||||||
if blendMode.hasSimdBlender():
|
if blendMode.hasSimdBlender():
|
||||||
# When supported, SIMD blend as much as possible
|
# When supported, SIMD blend as much as possible
|
||||||
let colorVec = mm_set1_epi32(cast[int32](rgbx))
|
let colorVec = mm_set1_epi32(cast[int32](rgbx))
|
||||||
if blendMode == bmNormal:
|
if blendMode == BlendNormal:
|
||||||
# For path filling, bmNormal is almost always used.
|
# For path filling, BlendNormal is almost always used.
|
||||||
# Inline SIMD is faster here.
|
# Inline SIMD is faster here.
|
||||||
for _ in 0 ..< fillLen div 4:
|
for _ in 0 ..< fillLen div 4:
|
||||||
let
|
let
|
||||||
|
@ -1533,7 +1533,7 @@ proc fillHits(
|
||||||
let backdrop = image.unsafe[x, y]
|
let backdrop = image.unsafe[x, y]
|
||||||
image.unsafe[x, y] = blender(backdrop, rgbx)
|
image.unsafe[x, y] = blender(backdrop, rgbx)
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
image.clearUnsafe(0, y, startX, y)
|
image.clearUnsafe(0, y, startX, y)
|
||||||
image.clearUnsafe(filledTo, y, image.width, y)
|
image.clearUnsafe(filledTo, y, image.width, y)
|
||||||
|
|
||||||
|
@ -1558,7 +1558,7 @@ proc fillHits(
|
||||||
|
|
||||||
filledTo = fillStart + fillLen
|
filledTo = fillStart + fillLen
|
||||||
|
|
||||||
if blendMode in {bmNormal, bmOverwrite}:
|
if blendMode in {BlendNormal, BlendOverwrite}:
|
||||||
fillUnsafe(mask.data, 255, mask.dataIndex(fillStart, y), fillLen)
|
fillUnsafe(mask.data, 255, mask.dataIndex(fillStart, y), fillLen)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1582,7 +1582,7 @@ proc fillHits(
|
||||||
let backdrop = mask.unsafe[x, y]
|
let backdrop = mask.unsafe[x, y]
|
||||||
mask.unsafe[x, y] = masker(backdrop, 255)
|
mask.unsafe[x, y] = masker(backdrop, 255)
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
mask.clearUnsafe(0, y, startX, y)
|
mask.clearUnsafe(0, y, startX, y)
|
||||||
mask.clearUnsafe(filledTo, y, mask.width, y)
|
mask.clearUnsafe(filledTo, y, mask.width, y)
|
||||||
|
|
||||||
|
@ -1650,7 +1650,7 @@ proc fillShapes(
|
||||||
blendMode
|
blendMode
|
||||||
)
|
)
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
image.clearUnsafe(0, 0, 0, startY)
|
image.clearUnsafe(0, 0, 0, startY)
|
||||||
image.clearUnsafe(0, pathHeight, 0, image.height)
|
image.clearUnsafe(0, pathHeight, 0, image.height)
|
||||||
|
|
||||||
|
@ -1699,7 +1699,7 @@ proc fillShapes(
|
||||||
else:
|
else:
|
||||||
mask.fillHits(startX, y, hits, numHits, windingRule, blendMode)
|
mask.fillHits(startX, y, hits, numHits, windingRule, blendMode)
|
||||||
|
|
||||||
if blendMode == bmMask:
|
if blendMode == BlendMask:
|
||||||
mask.clearUnsafe(0, 0, 0, startY)
|
mask.clearUnsafe(0, 0, 0, startY)
|
||||||
mask.clearUnsafe(0, pathHeight, 0, mask.height)
|
mask.clearUnsafe(0, pathHeight, 0, mask.height)
|
||||||
|
|
||||||
|
@ -1883,7 +1883,7 @@ proc fillPath*(
|
||||||
path: SomePath,
|
path: SomePath,
|
||||||
transform = mat3(),
|
transform = mat3(),
|
||||||
windingRule = wrNonZero,
|
windingRule = wrNonZero,
|
||||||
blendMode = bmNormal
|
blendMode = BlendNormal
|
||||||
) {.raises: [PixieError].} =
|
) {.raises: [PixieError].} =
|
||||||
## Fills a path.
|
## Fills a path.
|
||||||
var shapes = parseSomePath(path, true, transform.pixelScale())
|
var shapes = parseSomePath(path, true, transform.pixelScale())
|
||||||
|
@ -1902,7 +1902,7 @@ proc fillPath*(
|
||||||
return
|
return
|
||||||
|
|
||||||
if paint.kind == pkSolid:
|
if paint.kind == pkSolid:
|
||||||
if paint.color.a > 0 or paint.blendMode == bmOverwrite:
|
if paint.color.a > 0 or paint.blendMode == BlendOverwrite:
|
||||||
var shapes = parseSomePath(path, true, transform.pixelScale())
|
var shapes = parseSomePath(path, true, transform.pixelScale())
|
||||||
shapes.transform(transform)
|
shapes.transform(transform)
|
||||||
var color = paint.color
|
var color = paint.color
|
||||||
|
@ -1948,7 +1948,7 @@ proc strokePath*(
|
||||||
lineJoin = ljMiter,
|
lineJoin = ljMiter,
|
||||||
miterLimit = defaultMiterLimit,
|
miterLimit = defaultMiterLimit,
|
||||||
dashes: seq[float32] = @[],
|
dashes: seq[float32] = @[],
|
||||||
blendMode = bmNormal
|
blendMode = BlendNormal
|
||||||
) {.raises: [PixieError].} =
|
) {.raises: [PixieError].} =
|
||||||
## Strokes a path.
|
## Strokes a path.
|
||||||
let pixelScale = transform.pixelScale()
|
let pixelScale = transform.pixelScale()
|
||||||
|
@ -1980,7 +1980,7 @@ proc strokePath*(
|
||||||
return
|
return
|
||||||
|
|
||||||
if paint.kind == pkSolid:
|
if paint.kind == pkSolid:
|
||||||
if paint.color.a > 0 or paint.blendMode == bmOverwrite:
|
if paint.color.a > 0 or paint.blendMode == BlendOverwrite:
|
||||||
var strokeShapes = strokeShapes(
|
var strokeShapes = strokeShapes(
|
||||||
parseSomePath(path, false, transform.pixelScale()),
|
parseSomePath(path, false, transform.pixelScale()),
|
||||||
strokeWidth,
|
strokeWidth,
|
||||||
|
|
|
@ -10,7 +10,7 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "drawCorrect small-on-big":
|
timeIt "drawCorrect small-on-big":
|
||||||
a.drawCorrect(b, translate(vec2(25, 25)), blendMode = bmNormal)
|
a.drawCorrect(b, translate(vec2(25, 25)), blendMode = BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -21,7 +21,7 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "drawUber small-on-big":
|
timeIt "drawUber small-on-big":
|
||||||
a.drawUber(b, translate(vec2(25, 25)), blendMode = bmNormal)
|
a.drawUber(b, translate(vec2(25, 25)), blendMode = BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -32,7 +32,7 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "drawCorrect small-on-big smooth":
|
timeIt "drawCorrect small-on-big smooth":
|
||||||
a.drawCorrect(b, translate(vec2(25.1, 25.1)), blendMode = bmNormal)
|
a.drawCorrect(b, translate(vec2(25.1, 25.1)), blendMode = BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -43,5 +43,5 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "drawUber small-on-big smooth":
|
timeIt "drawUber small-on-big smooth":
|
||||||
a.drawUber(b, translate(vec2(25.1, 25.1)), blendMode = bmNormal)
|
a.drawUber(b, translate(vec2(25.1, 25.1)), blendMode = BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
|
@ -7,8 +7,8 @@ block:
|
||||||
a.fill(rgba(255, 0, 0, 255))
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw small-on-big bmNormal":
|
timeIt "draw small-on-big BlendNormal":
|
||||||
a.draw(b, translate(vec2(25, 25)), bmNormal)
|
a.draw(b, translate(vec2(25, 25)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -18,8 +18,8 @@ block:
|
||||||
a.fill(rgba(255, 0, 0, 255))
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw small-on-big Smooth bmNormal":
|
timeIt "draw small-on-big Smooth BlendNormal":
|
||||||
a.draw(b, translate(vec2(25.2, 25.2)), bmNormal)
|
a.draw(b, translate(vec2(25.2, 25.2)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -29,8 +29,8 @@ block:
|
||||||
a.fill(rgba(255, 0, 0, 255))
|
a.fill(rgba(255, 0, 0, 255))
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw big-on-bigger bmNormal":
|
timeIt "draw big-on-bigger BlendNormal":
|
||||||
a.draw(b, translate(vec2(25, 25)), bmNormal)
|
a.draw(b, translate(vec2(25, 25)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -41,7 +41,7 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw [scale 0.5]":
|
timeIt "draw [scale 0.5]":
|
||||||
a.draw(b, translate(vec2(25, 25)) * scale(vec2(0.5, 0.5)), bmNormal)
|
a.draw(b, translate(vec2(25, 25)) * scale(vec2(0.5, 0.5)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -52,7 +52,7 @@ block:
|
||||||
b.fill(rgba(0, 255, 0, 255))
|
b.fill(rgba(0, 255, 0, 255))
|
||||||
|
|
||||||
timeIt "draw [scale 2]":
|
timeIt "draw [scale 2]":
|
||||||
a.draw(b, translate(vec2(25, 25)) * scale(vec2(2, 2)), bmNormal)
|
a.draw(b, translate(vec2(25, 25)) * scale(vec2(2, 2)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -63,7 +63,7 @@ block:
|
||||||
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
||||||
|
|
||||||
timeIt "draw Smooth [x translate]":
|
timeIt "draw Smooth [x translate]":
|
||||||
a.draw(b, translate(vec2(25.2, 0)), bmNormal)
|
a.draw(b, translate(vec2(25.2, 0)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -74,7 +74,7 @@ block:
|
||||||
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
||||||
|
|
||||||
timeIt "draw Smooth [y translate]":
|
timeIt "draw Smooth [y translate]":
|
||||||
a.draw(b, translate(vec2(0, 25.2)), bmNormal)
|
a.draw(b, translate(vec2(0, 25.2)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -85,7 +85,7 @@ block:
|
||||||
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
||||||
|
|
||||||
timeIt "draw Smooth [x + y translate]":
|
timeIt "draw Smooth [x + y translate]":
|
||||||
a.draw(b, translate(vec2(25.2, 25.2)), bmNormal)
|
a.draw(b, translate(vec2(25.2, 25.2)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -96,7 +96,7 @@ block:
|
||||||
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
b.fill(rgba(0, rand(255).uint8, 0, 255))
|
||||||
|
|
||||||
timeIt "draw Smooth [rotate 45 deg]":
|
timeIt "draw Smooth [rotate 45 deg]":
|
||||||
a.draw(b, translate(vec2(0, 500)) * rotate(toRadians(45)), bmNormal)
|
a.draw(b, translate(vec2(0, 500)) * rotate(toRadians(45)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -107,7 +107,7 @@ block:
|
||||||
b.fill(rand(255).uint8)
|
b.fill(rand(255).uint8)
|
||||||
|
|
||||||
timeIt "draw mask Smooth [rotate 45 deg]":
|
timeIt "draw mask Smooth [rotate 45 deg]":
|
||||||
a.draw(b, translate(vec2(0, 500)) * rotate(toRadians(45)), bmNormal)
|
a.draw(b, translate(vec2(0, 500)) * rotate(toRadians(45)), BlendNormal)
|
||||||
keep(b)
|
keep(b)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
|
|
@ -54,7 +54,7 @@ proc renderEmojiSet(index: int) =
|
||||||
rendered.draw(
|
rendered.draw(
|
||||||
icon,
|
icon,
|
||||||
translate(pos),
|
translate(pos),
|
||||||
bmOverwrite
|
BlendOverwrite
|
||||||
)
|
)
|
||||||
|
|
||||||
rendered.writeFile(&"tests/fileformats/svg/{emojiSet.name}.png")
|
rendered.writeFile(&"tests/fileformats/svg/{emojiSet.name}.png")
|
||||||
|
|
|
@ -55,7 +55,7 @@ proc renderIconSet(index: int) =
|
||||||
rendered.draw(
|
rendered.draw(
|
||||||
icon,
|
icon,
|
||||||
translate(pos),
|
translate(pos),
|
||||||
bmOverwrite
|
BlendOverwrite
|
||||||
)
|
)
|
||||||
|
|
||||||
rendered.writeFile(&"tests/fileformats/svg/{iconSet.name}.png")
|
rendered.writeFile(&"tests/fileformats/svg/{iconSet.name}.png")
|
||||||
|
|
|
@ -528,7 +528,7 @@ block:
|
||||||
|
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(0, 0, 1, 1)
|
paint.color = color(0, 0, 1, 1)
|
||||||
paint.blendMode = bmExclusion
|
paint.blendMode = BlendExclusion
|
||||||
|
|
||||||
ctx.fillStyle = paint
|
ctx.fillStyle = paint
|
||||||
|
|
||||||
|
|
|
@ -392,7 +392,7 @@ block:
|
||||||
|
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(0, 1, 0, 1)
|
paint.color = color(0, 1, 0, 1)
|
||||||
paint.blendMode = bmExcludeMask
|
paint.blendMode = BlendExcludeMask
|
||||||
|
|
||||||
image.fillPath(
|
image.fillPath(
|
||||||
"M 30 30 H 80 V 80 H 30 z",
|
"M 30 30 H 80 V 80 H 30 z",
|
||||||
|
@ -409,7 +409,7 @@ block:
|
||||||
|
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(0, 1, 0, 1)
|
paint.color = color(0, 1, 0, 1)
|
||||||
paint.blendMode = bmExcludeMask
|
paint.blendMode = BlendExcludeMask
|
||||||
|
|
||||||
image.fillPath(
|
image.fillPath(
|
||||||
"M 30.1 30.1 H 80.1 V 80.1 H 30.1 z",
|
"M 30.1 30.1 H 80.1 V 80.1 H 30.1 z",
|
||||||
|
@ -426,7 +426,7 @@ block:
|
||||||
|
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(0, 1, 0, 1)
|
paint.color = color(0, 1, 0, 1)
|
||||||
paint.blendMode = bmMask
|
paint.blendMode = BlendMask
|
||||||
|
|
||||||
image.fillPath(
|
image.fillPath(
|
||||||
"M 30 30 H 80 V 80 H 30 z",
|
"M 30 30 H 80 V 80 H 30 z",
|
||||||
|
@ -443,7 +443,7 @@ block:
|
||||||
|
|
||||||
let paint = newPaint(pkSolid)
|
let paint = newPaint(pkSolid)
|
||||||
paint.color = color(0, 1, 0, 1)
|
paint.color = color(0, 1, 0, 1)
|
||||||
paint.blendMode = bmMask
|
paint.blendMode = BlendMask
|
||||||
|
|
||||||
image.fillPath(
|
image.fillPath(
|
||||||
"M 30.1 30.1 H 80.1 V 80.1 H 30.1 z",
|
"M 30.1 30.1 H 80.1 V 80.1 H 30.1 z",
|
||||||
|
@ -454,25 +454,25 @@ block:
|
||||||
block:
|
block:
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillPath("M 10 10 H 60 V 60 H 10 z")
|
mask.fillPath("M 10 10 H 60 V 60 H 10 z")
|
||||||
mask.fillPath("M 30 30 H 80 V 80 H 30 z", blendMode = bmExcludeMask)
|
mask.fillPath("M 30 30 H 80 V 80 H 30 z", blendMode = BlendExcludeMask)
|
||||||
writeFile("tests/paths/maskRectExcludeMask.png", mask.encodePng())
|
writeFile("tests/paths/maskRectExcludeMask.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillPath("M 10.1 10.1 H 60.1 V 60.1 H 10.1 z")
|
mask.fillPath("M 10.1 10.1 H 60.1 V 60.1 H 10.1 z")
|
||||||
mask.fillPath("M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", blendMode = bmExcludeMask)
|
mask.fillPath("M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", blendMode = BlendExcludeMask)
|
||||||
writeFile("tests/paths/maskRectExcludeMaskAA.png", mask.encodePng())
|
writeFile("tests/paths/maskRectExcludeMaskAA.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillPath("M 10 10 H 60 V 60 H 10 z")
|
mask.fillPath("M 10 10 H 60 V 60 H 10 z")
|
||||||
mask.fillPath("M 30 30 H 80 V 80 H 30 z", blendMode = bmMask)
|
mask.fillPath("M 30 30 H 80 V 80 H 30 z", blendMode = BlendMask)
|
||||||
writeFile("tests/paths/maskRectMask.png", mask.encodePng())
|
writeFile("tests/paths/maskRectMask.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let mask = newMask(100, 100)
|
let mask = newMask(100, 100)
|
||||||
mask.fillPath("M 10.1 10.1 H 60.1 V 60.1 H 10.1 z")
|
mask.fillPath("M 10.1 10.1 H 60.1 V 60.1 H 10.1 z")
|
||||||
mask.fillPath("M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", blendMode = bmMask)
|
mask.fillPath("M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", blendMode = BlendMask)
|
||||||
writeFile("tests/paths/maskRectMaskAA.png", mask.encodePng())
|
writeFile("tests/paths/maskRectMaskAA.png", mask.encodePng())
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
|
Loading…
Reference in a new issue