faster
This commit is contained in:
parent
720e5ae019
commit
790146e553
|
@ -1394,25 +1394,29 @@ proc fillCoverage(
|
|||
|
||||
x += 16
|
||||
|
||||
proc applyCoverage(rgbx: ColorRGBX, coverage: uint8): ColorRGBX {.inline.} =
|
||||
if coverage != 255:
|
||||
result.r = ((rgbx.r.uint32 * coverage) div 255).uint8
|
||||
result.g = ((rgbx.g.uint32 * coverage) div 255).uint8
|
||||
result.b = ((rgbx.b.uint32 * coverage) div 255).uint8
|
||||
result.a = ((rgbx.a.uint32 * coverage) div 255).uint8
|
||||
else:
|
||||
result = rgbx
|
||||
|
||||
let blender = blendMode.blender()
|
||||
while x < startX + coverages.len:
|
||||
for x in x ..< startX + coverages.len:
|
||||
let coverage = coverages[x - startX]
|
||||
if coverage != 0 or blendMode == bmExcludeMask:
|
||||
if blendMode == bmNormal and coverage == 255 and rgbx.a == 255:
|
||||
# Skip blending
|
||||
image.unsafe[x, y] = rgbx
|
||||
else:
|
||||
var source = rgbx
|
||||
if coverage != 255:
|
||||
source.r = ((source.r.uint32 * coverage) div 255).uint8
|
||||
source.g = ((source.g.uint32 * coverage) div 255).uint8
|
||||
source.b = ((source.b.uint32 * coverage) div 255).uint8
|
||||
source.a = ((source.a.uint32 * coverage) div 255).uint8
|
||||
let backdrop = image.unsafe[x, y]
|
||||
let
|
||||
source = rgbx.applyCoverage(coverage)
|
||||
backdrop = image.unsafe[x, y]
|
||||
image.unsafe[x, y] = blender(backdrop, source)
|
||||
elif blendMode == bmMask:
|
||||
image.unsafe[x, y] = rgbx(0, 0, 0, 0)
|
||||
inc x
|
||||
|
||||
if blendMode == bmMask:
|
||||
image.clearUnsafe(0, y, startX, y)
|
||||
|
@ -1446,14 +1450,13 @@ proc fillCoverage(
|
|||
x += 16
|
||||
|
||||
let masker = blendMode.masker()
|
||||
while x < startX + coverages.len:
|
||||
for x in x ..< startX + coverages.len:
|
||||
let coverage = coverages[x - startX]
|
||||
if coverage != 0 or blendMode == bmExcludeMask:
|
||||
let backdrop = mask.unsafe[x, y]
|
||||
mask.unsafe[x, y] = masker(backdrop, coverage)
|
||||
elif blendMode == bmMask:
|
||||
mask.unsafe[x, y] = 0
|
||||
inc x
|
||||
|
||||
if blendMode == bmMask:
|
||||
mask.clearUnsafe(0, y, startX, y)
|
||||
|
|
Loading…
Reference in a new issue