bmMask nonsimd draw faster
This commit is contained in:
parent
ac6e6f6214
commit
be598a108b
3 changed files with 57 additions and 1 deletions
|
@ -35,6 +35,38 @@ block:
|
|||
|
||||
# tmp.writeFile("tmp2.png")
|
||||
|
||||
block:
|
||||
let
|
||||
backdrop = imageSurfaceCreateFromPng("tests/fileformats/svg/masters/dragon2.png")
|
||||
source = imageSurfaceCreateFromPng("tests/fileformats/svg/masters/Ghostscript_Tiger.png")
|
||||
tmp = imageSurfaceCreate(FORMAT_ARGB32, 1568, 940)
|
||||
ctx = tmp.create()
|
||||
|
||||
timeIt "cairo draw mask":
|
||||
ctx.setSourceRgba(1, 1, 1, 1)
|
||||
let operator = ctx.getOperator()
|
||||
ctx.setOperator(OperatorSource)
|
||||
ctx.paint()
|
||||
ctx.setOperator(operator)
|
||||
|
||||
ctx.setSource(backdrop, 0, 0)
|
||||
ctx.mask(source, 0, 0)
|
||||
tmp.flush()
|
||||
|
||||
echo tmp.writeToPng("tmp_masked.png")
|
||||
|
||||
block:
|
||||
let
|
||||
backdrop = readImage("tests/fileformats/svg/masters/dragon2.png")
|
||||
source = readImage("tests/fileformats/svg/masters/Ghostscript_Tiger.png")
|
||||
tmp = newImage(1568, 940)
|
||||
|
||||
timeIt "pixie draw mask":
|
||||
tmp.draw(backdrop)
|
||||
tmp.draw(source, blendMode = bmMask)
|
||||
|
||||
tmp.writeFile("tmp_masked2.png")
|
||||
|
||||
block:
|
||||
let
|
||||
backdrop = imageSurfaceCreateFromPng("tests/fileformats/svg/masters/dragon2.png")
|
||||
|
|
|
@ -419,7 +419,7 @@ proc blendSaturation(backdrop, source: ColorRGBX): ColorRGBX =
|
|||
blended = SetLum(SetSat(backdrop, Sat(source)), Lum(backdrop))
|
||||
result = alphaFix(backdrop, source, blended).rgba.rgbx()
|
||||
|
||||
proc blendMask(backdrop, source: ColorRGBX): ColorRGBX =
|
||||
proc blendMask*(backdrop, source: ColorRGBX): ColorRGBX =
|
||||
let k = source.a.uint32
|
||||
result.r = ((backdrop.r * k) div 255).uint8
|
||||
result.g = ((backdrop.g * k) div 255).uint8
|
||||
|
|
|
@ -955,6 +955,30 @@ proc drawUber(
|
|||
let backdrop = a.unsafe[x, y]
|
||||
a.unsafe[x, y] = blendAlpha(backdrop, source)
|
||||
srcPos += dx
|
||||
elif blendMode == bmMask:
|
||||
for x in x ..< xMax:
|
||||
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
||||
when type(a) is Image:
|
||||
when type(b) is Image:
|
||||
let source = b.unsafe[samplePos.x, samplePos.y]
|
||||
else: # b is a Mask
|
||||
let source = rgbx(0, 0, 0, b.unsafe[samplePos.x, samplePos.y])
|
||||
if source.a == 0:
|
||||
a.unsafe[x, y] = rgbx(0, 0, 0, 0)
|
||||
elif source.a != 255:
|
||||
let backdrop = a.unsafe[x, y]
|
||||
a.unsafe[x, y] = blendMask(backdrop, source)
|
||||
else: # a is a Mask
|
||||
when type(b) is Image:
|
||||
let source = b.unsafe[samplePos.x, samplePos.y].a
|
||||
else: # b is a Mask
|
||||
let source = b.unsafe[samplePos.x, samplePos.y]
|
||||
if source == 0:
|
||||
a.unsafe[x, y] = 0
|
||||
elif source != 255:
|
||||
let backdrop = a.unsafe[x, y]
|
||||
a.unsafe[x, y] = blendAlpha(backdrop, source)
|
||||
srcPos += dx
|
||||
else:
|
||||
for x in x ..< xMax:
|
||||
let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32)
|
||||
|
|
Loading…
Reference in a new issue