From c6f59b96925763a14baea241b56303330518927b Mon Sep 17 00:00:00 2001 From: treeform Date: Sat, 12 Feb 2022 10:18:39 -0800 Subject: [PATCH] Rename BlendMode enum. --- README.md | 2 +- examples/blur.nim | 2 +- experiments/benchmark_cairo.nim | 2 +- experiments/benchmark_cairo_draw.nim | 4 +- experiments/sweeps.nim | 2 +- experiments/sweeps2.nim | 2 +- experiments/trapezoid.nim | 2 +- experiments/trapezoid2.nim | 2 +- src/pixie/blends.nim | 70 ++++++++++----------- src/pixie/common.nim | 44 ++++++------- src/pixie/contexts.nim | 4 +- src/pixie/images.nim | 40 ++++++------ src/pixie/paths.nim | 56 ++++++++--------- tests/benchmark_drawCorrect_vs_drawUber.nim | 8 +-- tests/benchmark_images_draw.nim | 26 ++++---- tests/megatest_emoji.nim | 2 +- tests/megatest_icons.nim | 2 +- tests/test_contexts.nim | 2 +- tests/test_paths.nim | 16 ++--- 19 files changed, 144 insertions(+), 144 deletions(-) diff --git a/README.md b/README.md index 83f2c1c..ea6230b 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ let mask = newMask(200, 200) mask.fillPath(path) blur.blur(20) -blur.draw(mask, blendMode = bmMask) +blur.draw(mask, blendMode = BlendMask) image.draw(trees) image.draw(blur) diff --git a/examples/blur.nim b/examples/blur.nim index a160ac8..a5b5319 100644 --- a/examples/blur.nim +++ b/examples/blur.nim @@ -14,7 +14,7 @@ let mask = newMask(200, 200) mask.fillPath(path) blur.blur(20) -blur.draw(mask, blendMode = bmMask) +blur.draw(mask, blendMode = BlendMask) image.draw(trees) image.draw(blur) diff --git a/experiments/benchmark_cairo.nim b/experiments/benchmark_cairo.nim index ea66bdc..8175a85 100644 --- a/experiments/benchmark_cairo.nim +++ b/experiments/benchmark_cairo.nim @@ -360,7 +360,7 @@ block: var b: Image let paint = newPaint(pkSolid) paint.color = color(1, 0, 0, 0.5) - paint.blendMode = bmOverwrite + paint.blendMode = BlendOverwrite timeIt "pixie4 overwrite": b = newImage(1000, 1000) diff --git a/experiments/benchmark_cairo_draw.nim b/experiments/benchmark_cairo_draw.nim index 778589d..c41848c 100644 --- a/experiments/benchmark_cairo_draw.nim +++ b/experiments/benchmark_cairo_draw.nim @@ -78,7 +78,7 @@ block: timeIt "pixie draw overwrite": # tmp.fill(rgbx(127, 127, 127, 255)) - tmp.draw(backdrop, blendMode = bmOverwrite) + tmp.draw(backdrop, blendMode = BlendOverwrite) tmp.draw(source) # tmp.writeFile("tmp2.png") @@ -124,7 +124,7 @@ block: timeIt "pixie draw mask": tmp.draw(backdrop) - tmp.draw(source, blendMode = bmMask) + tmp.draw(source, blendMode = BlendMask) # tmp.writeFile("tmp_masked2.png") diff --git a/experiments/sweeps.nim b/experiments/sweeps.nim index 0fae4a8..919eea0 100644 --- a/experiments/sweeps.nim +++ b/experiments/sweeps.nim @@ -716,7 +716,7 @@ block: # var mask = newMask(image) # mask.fillPath2(p) -# image.draw(mask, blendMode = bmOverwrite) +# image.draw(mask, blendMode = BlendOverwrite) # image.writeFile("experiments/trapezoids/heart.png") diff --git a/experiments/sweeps2.nim b/experiments/sweeps2.nim index 990bf7a..c2ad328 100644 --- a/experiments/sweeps2.nim +++ b/experiments/sweeps2.nim @@ -157,7 +157,7 @@ proc binaryInsert(arr: var seq[float32], v: float32) = 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 let rgbx = color.rgbx var segments = p.commandsToShapes(true, 1.0).shapesToSegments() diff --git a/experiments/trapezoid.nim b/experiments/trapezoid.nim index 981c150..0873f9a 100644 --- a/experiments/trapezoid.nim +++ b/experiments/trapezoid.nim @@ -274,7 +274,7 @@ block: # var mask = newMask(image) # mask.fillPath2(p) -# image.draw(mask, blendMode = bmOverwrite) +# image.draw(mask, blendMode = BlendOverwrite) # image.writeFile("experiments/trapezoids/heart.png") diff --git a/experiments/trapezoid2.nim b/experiments/trapezoid2.nim index b0741db..54fca3e 100644 --- a/experiments/trapezoid2.nim +++ b/experiments/trapezoid2.nim @@ -472,7 +472,7 @@ block: # var mask = newMask(image) # mask.fillPath2(p) -# image.draw(mask, blendMode = bmOverwrite) +# image.draw(mask, blendMode = BlendOverwrite) # image.writeFile("experiments/trapezoids/heart.png") diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index e0683fd..79deb17 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -425,28 +425,28 @@ proc blendOverwrite(backdrop, source: ColorRGBX): ColorRGBX = proc blender*(blendMode: BlendMode): Blender {.raises: [].} = ## Returns a blend function for a given blend mode. case blendMode: - of bmNormal: blendNormal - of bmDarken: blendDarken - of bmMultiply: blendMultiply - # of bmLinearBurn: blendLinearBurn - of bmColorBurn: blendColorBurn - of bmLighten: blendLighten - of bmScreen: blendScreen - # of bmLinearDodge: blendLinearDodge - of bmColorDodge: blendColorDodge - of bmOverlay: blendOverlay - of bmSoftLight: blendSoftLight - of bmHardLight: blendHardLight - of bmDifference: blendDifference - of bmExclusion: blendExclusion - of bmHue: blendHue - of bmSaturation: blendSaturation - of bmColor: blendColor - of bmLuminosity: blendLuminosity - of bmMask: blendMask - of bmOverwrite: blendOverwrite - of bmSubtractMask: blendSubtractMask - of bmExcludeMask: blendExcludeMask + of BlendNormal: blendNormal + of BlendDarken: blendDarken + of BlendMultiply: blendMultiply + # of BlendLinearBurn: blendLinearBurn + of BlendColorBurn: blendColorBurn + of BlendLighten: blendLighten + of BlendScreen: blendScreen + # of BlendLinearDodge: blendLinearDodge + of BlendColorDodge: blendColorDodge + of BlendOverlay: blendOverlay + of BlendSoftLight: blendSoftLight + of BlendHardLight: blendHardLight + of BlendDifference: blendDifference + of BlendExclusion: blendExclusion + of BlendHue: blendHue + of BlendSaturation: blendSaturation + of BlendColor: blendColor + of BlendLuminosity: blendLuminosity + of BlendMask: blendMask + of BlendOverwrite: blendOverwrite + of BlendSubtractMask: blendSubtractMask + of BlendExcludeMask: blendExcludeMask proc maskNormal(backdrop, source: uint8): uint8 = ## Blending masks @@ -471,11 +471,11 @@ proc maskOverwrite(backdrop, source: uint8): uint8 = proc masker*(blendMode: BlendMode): Masker {.raises: [PixieError].} = ## Returns a blend masking function for a given blend masking mode. case blendMode: - of bmNormal: maskNormal - of bmMask: maskMask - of bmOverwrite: maskOverwrite - of bmSubtractMask: maskSubtract - of bmExcludeMask: maskExclude + of BlendNormal: maskNormal + of BlendMask: maskMask + of BlendOverwrite: maskOverwrite + of BlendSubtractMask: maskSubtract + of BlendExcludeMask: maskExclude else: 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].} = ## Returns a blend function for a given blend mode with SIMD support. case blendMode: - of bmNormal: blendNormalSimd - of bmMask: blendMaskSimd - of bmOverwrite: blendOverwriteSimd + of BlendNormal: blendNormalSimd + of BlendMask: blendMaskSimd + of BlendOverwrite: blendOverwriteSimd else: raise newException(PixieError, "No SIMD blender for " & $blendMode) proc hasSimdBlender*(blendMode: BlendMode): bool {.inline, raises: [].} = ## 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.} = ## Blending masks @@ -625,15 +625,15 @@ when defined(amd64) and not defined(pixieNoSimd): proc maskerSimd*(blendMode: BlendMode): MaskerSimd {.raises: [PixieError].} = ## Returns a blend masking function with SIMD support. case blendMode: - of bmNormal: maskNormalSimd - of bmMask: maskMaskSimd - of bmOverwrite: blendOverwriteSimd + of BlendNormal: maskNormalSimd + of BlendMask: maskMaskSimd + of BlendOverwrite: blendOverwriteSimd else: raise newException(PixieError, "No SIMD masker for " & $blendMode) proc hasSimdMasker*(blendMode: BlendMode): bool {.inline, raises: [].} = ## Is there a blend masking function with SIMD support? - blendMode in {bmNormal, bmMask, bmOverwrite} + blendMode in {BlendNormal, BlendMask, BlendOverwrite} when defined(release): {.pop.} diff --git a/src/pixie/common.nim b/src/pixie/common.nim index a3f7eea..94aa89d 100644 --- a/src/pixie/common.nim +++ b/src/pixie/common.nim @@ -4,29 +4,29 @@ type PixieError* = object of ValueError ## Raised if an operation fails. BlendMode* = enum - bmNormal - bmDarken - bmMultiply - # bmLinearBurn - bmColorBurn - bmLighten - bmScreen - # bmLinearDodge - bmColorDodge - bmOverlay - bmSoftLight - bmHardLight - bmDifference - bmExclusion - bmHue - bmSaturation - bmColor - bmLuminosity + BlendNormal + BlendDarken + BlendMultiply + # BlendLinearBurn + BlendColorBurn + BlendLighten + BlendScreen + # BlendLinearDodge + BlendColorDodge + BlendOverlay + BlendSoftLight + BlendHardLight + BlendDifference + BlendExclusion + BlendHue + BlendSaturation + BlendColor + BlendLuminosity - bmMask ## Special blend mode that is used for masking - bmOverwrite ## Special blend mode that just copies pixels - bmSubtractMask ## Inverse mask - bmExcludeMask + BlendMask ## Special blend mode that is used for masking + BlendOverwrite ## Special blend mode that just copies pixels + BlendSubtractMask ## Inverse mask + BlendExcludeMask proc mix*(a, b: uint8, t: float32): uint8 {.inline, raises: [].} = ## Linearly interpolate between a and b using t. diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index 268558c..14419ce 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -370,7 +370,7 @@ proc clip*( ctx.mask = newMask(ctx.image.width, ctx.image.height) ctx.mask.fillPath(path, windingRule = windingRule) else: - ctx.mask.fillPath(path, windingRule = windingRule, blendMode = bmMask) + ctx.mask.fillPath(path, windingRule = windingRule, blendMode = BlendMask) proc clip*( ctx: Context, windingRule = wrNonZero @@ -398,7 +398,7 @@ proc stroke*(ctx: Context) {.inline, raises: [PixieError].} = proc clearRect*(ctx: Context, rect: Rect) {.raises: [PixieError].} = ## Erases the pixels in a rectangular area. let paint = newPaint(pkSolid) - paint.blendMode = bmOverwrite + paint.blendMode = BlendOverwrite let path = newPath() path.rect(rect) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 22e16e3..0456fa0 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -595,7 +595,7 @@ proc getRgbaSmooth*( topMix proc drawCorrect( - a, b: Image | Mask, transform = mat3(), blendMode = bmNormal, tiled = false + a, b: Image | Mask, transform = mat3(), blendMode = BlendNormal, tiled = false ) {.raises: [PixieError].} = ## Draws one image onto another using matrix with color blending. @@ -719,7 +719,7 @@ proc drawUber( else: # a is a Mask let masker = blendMode.masker() - if blendMode == bmMask: + if blendMode == BlendMask: if yMin > 0: zeroMem(a.data[0].addr, 4 * yMin * a.width) @@ -754,7 +754,7 @@ proc drawUber( if xStart == a.width or xStop == 0: continue - if blendMode == bmMask: + if blendMode == BlendMask: if xStart > 0: zeroMem(a.data[a.dataIndex(0, y)].addr, 4 * xStart) @@ -793,7 +793,7 @@ proc drawUber( var sx = srcPos.x.int 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): copyMem( a.data[a.dataIndex(x, y)].addr, @@ -804,7 +804,7 @@ proc drawUber( when defined(amd64) and not defined(pixieNoSimd): case blendMode: - of bmOverwrite: + of BlendOverwrite: for _ in 0 ..< (xStop - xStart) div 16: when type(a) is Image: when type(b) is Image: @@ -831,7 +831,7 @@ proc drawUber( mm_storeu_si128(a.data[a.dataIndex(x, y)].addr, sourceVec) x += 16 sx += 16 - of bmNormal: + of BlendNormal: let vec255 = mm_set1_epi32(cast[int32](uint32.high)) for _ in 0 ..< (xStop - xStart) div 16: when type(a) is Image: @@ -889,7 +889,7 @@ proc drawUber( ) x += 16 sx += 16 - of bmMask: + of BlendMask: let vec255 = mm_set1_epi32(cast[int32](uint32.high)) for _ in 0 ..< (xStop - xStart) div 16: when type(a) is Image: @@ -1004,7 +1004,7 @@ proc drawUber( ) case blendMode: - of bmOverwrite: + of BlendOverwrite: for x in x ..< xStop: let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32) when type(a) is Image: @@ -1022,7 +1022,7 @@ proc drawUber( if source > 0: a.unsafe[x, y] = source srcPos += dx - of bmNormal: + of BlendNormal: for x in x ..< xStop: let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32) when type(a) is Image: @@ -1048,7 +1048,7 @@ proc drawUber( let backdrop = a.unsafe[x, y] a.unsafe[x, y] = blendAlpha(backdrop, source) srcPos += dx - of bmMask: + of BlendMask: for x in x ..< xStop: let samplePos = ivec2((srcPos.x - h).int32, (srcPos.y - h).int32) when type(a) is Image: @@ -1095,16 +1095,16 @@ proc drawUber( a.unsafe[x, y] = masker(backdrop, sample) srcPos += dx - if blendMode == bmMask: + if blendMode == BlendMask: if a.width - xStop > 0: zeroMem(a.data[a.dataIndex(xStop, y)].addr, 4 * (a.width - xStop)) - if blendMode == bmMask: + if blendMode == BlendMask: if a.height - yMax > 0: zeroMem(a.data[a.dataIndex(0, yMax)].addr, 4 * a.width * (a.height - yMax)) proc draw*( - a, b: Image, transform = mat3(), blendMode = bmNormal + a, b: Image, transform = mat3(), blendMode = BlendNormal ) {.inline, raises: [PixieError].} = ## Draws one image onto another using matrix with color blending. when type(transform) is Vec2: @@ -1113,7 +1113,7 @@ proc draw*( a.drawUber(b, transform, blendMode) proc draw*( - a, b: Mask, transform = mat3(), blendMode = bmMask + a, b: Mask, transform = mat3(), blendMode = BlendMask ) {.inline, raises: [PixieError].} = ## Draws a mask onto a mask using a matrix with color blending. when type(transform) is Vec2: @@ -1122,7 +1122,7 @@ proc draw*( a.drawUber(b, transform, blendMode) proc draw*( - image: Image, mask: Mask, transform = mat3(), blendMode = bmMask + image: Image, mask: Mask, transform = mat3(), blendMode = BlendMask ) {.inline, raises: [PixieError].} = ## Draws a mask onto an image using a matrix with color blending. when type(transform) is Vec2: @@ -1131,7 +1131,7 @@ proc draw*( image.drawUber(mask, transform, blendMode) proc draw*( - mask: Mask, image: Image, transform = mat3(), blendMode = bmMask + mask: Mask, image: Image, transform = mat3(), blendMode = BlendMask ) {.inline, raises: [PixieError].} = ## Draws a image onto a mask using a matrix with color blending. when type(transform) is Vec2: @@ -1140,7 +1140,7 @@ proc draw*( mask.drawUber(image, transform, blendMode) proc drawTiled*( - dst, src: Image, mat: Mat3, blendMode = bmNormal + dst, src: Image, mat: Mat3, blendMode = BlendNormal ) {.raises: [PixieError].} = 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, height.float32 / srcImage.height.float32 )), - bmOverwrite + BlendOverwrite ) proc shadow*( @@ -1170,7 +1170,7 @@ proc shadow*( shifted = mask else: shifted = newMask(mask.width, mask.height) - shifted.draw(mask, translate(offset), bmOverwrite) + shifted.draw(mask, translate(offset), BlendOverwrite) shifted.spread(spread) shifted.blur(blur) @@ -1188,7 +1188,7 @@ proc superImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} result = newImage(w, h) else: 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): {.pop.} diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 361dcc5..8b59f56 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1335,10 +1335,10 @@ proc fillCoverage( # If the coverages are not all zero if mm_movemask_epi8(mm_cmpeq_epi32(coverageVec, vec255)) == 0xffff: # If the coverages are all 255 - if blendMode == bmOverwrite: + if blendMode == BlendOverwrite: for i in 0 ..< 4: mm_storeu_si128(image.data[index + i * 4].addr, colorVec) - elif blendMode == bmNormal: + elif blendMode == BlendNormal: if rgbx.a == 255: for i in 0 ..< 4: 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)) - if blendMode == bmOverwrite: + if blendMode == BlendOverwrite: mm_storeu_si128(image.data[index + i * 4].addr, source) else: let backdrop = mm_loadu_si128(image.data[index + i * 4].addr) @@ -1389,12 +1389,12 @@ proc fillCoverage( coverageVec = mm_srli_si128(coverageVec, 4) - if blendMode == bmNormal: + if blendMode == BlendNormal: useCoverage(blendNormalInlineSimd) else: useCoverage(blenderSimd) - elif blendMode == bmMask: + elif blendMode == BlendMask: for i in 0 ..< 4: mm_storeu_si128(image.data[index + i * 4].addr, vecZero) @@ -1403,8 +1403,8 @@ proc fillCoverage( let blender = blendMode.blender() 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: + if coverage != 0 or blendMode == BlendExcludeMask: + if blendMode == BlendNormal and coverage == 255 and rgbx.a == 255: # Skip blending image.unsafe[x, y] = rgbx continue @@ -1416,15 +1416,15 @@ proc fillCoverage( source.b = ((source.b.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 else: let backdrop = image.unsafe[x, y] image.unsafe[x, y] = blender(backdrop, source) - elif blendMode == bmMask: + elif blendMode == BlendMask: image.unsafe[x, y] = rgbx(0, 0, 0, 0) - if blendMode == bmMask: + if blendMode == BlendMask: image.clearUnsafe(0, y, startX, y) image.clearUnsafe(startX + coverages.len, y, image.width, y) @@ -1446,7 +1446,7 @@ proc fillCoverage( coverageVec = mm_loadu_si128(coverages[x - startX].unsafeAddr) if mm_movemask_epi8(mm_cmpeq_epi16(coverageVec, vecZero)) != 0xffff: # If the coverages are not all zero - if blendMode == bmOverwrite: + if blendMode == BlendOverwrite: mm_storeu_si128(mask.data[index].addr, coverageVec) else: let backdrop = mm_loadu_si128(mask.data[index].addr) @@ -1454,23 +1454,23 @@ proc fillCoverage( mask.data[index].addr, maskerSimd(backdrop, coverageVec) ) - elif blendMode == bmMask: + elif blendMode == BlendMask: mm_storeu_si128(mask.data[index].addr, vecZero) x += 16 let masker = blendMode.masker() for x in x ..< startX + coverages.len: let coverage = coverages[x - startX] - if coverage != 0 or blendMode == bmExcludeMask: - if blendMode == bmOverwrite: + if coverage != 0 or blendMode == BlendExcludeMask: + if blendMode == BlendOverwrite: mask.unsafe[x, y] = coverage else: let backdrop = mask.unsafe[x, y] mask.unsafe[x, y] = masker(backdrop, coverage) - elif blendMode == bmMask: + elif blendMode == BlendMask: mask.unsafe[x, y] = 0 - if blendMode == bmMask: + if blendMode == BlendMask: mask.clearUnsafe(0, y, startX, y) mask.clearUnsafe(startX + coverages.len, y, mask.width, y) @@ -1496,7 +1496,7 @@ proc fillHits( 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) continue @@ -1505,8 +1505,8 @@ proc fillHits( if blendMode.hasSimdBlender(): # When supported, SIMD blend as much as possible let colorVec = mm_set1_epi32(cast[int32](rgbx)) - if blendMode == bmNormal: - # For path filling, bmNormal is almost always used. + if blendMode == BlendNormal: + # For path filling, BlendNormal is almost always used. # Inline SIMD is faster here. for _ in 0 ..< fillLen div 4: let @@ -1533,7 +1533,7 @@ proc fillHits( let backdrop = image.unsafe[x, y] image.unsafe[x, y] = blender(backdrop, rgbx) - if blendMode == bmMask: + if blendMode == BlendMask: image.clearUnsafe(0, y, startX, y) image.clearUnsafe(filledTo, y, image.width, y) @@ -1558,7 +1558,7 @@ proc fillHits( filledTo = fillStart + fillLen - if blendMode in {bmNormal, bmOverwrite}: + if blendMode in {BlendNormal, BlendOverwrite}: fillUnsafe(mask.data, 255, mask.dataIndex(fillStart, y), fillLen) continue @@ -1582,7 +1582,7 @@ proc fillHits( let backdrop = mask.unsafe[x, y] mask.unsafe[x, y] = masker(backdrop, 255) - if blendMode == bmMask: + if blendMode == BlendMask: mask.clearUnsafe(0, y, startX, y) mask.clearUnsafe(filledTo, y, mask.width, y) @@ -1650,7 +1650,7 @@ proc fillShapes( blendMode ) - if blendMode == bmMask: + if blendMode == BlendMask: image.clearUnsafe(0, 0, 0, startY) image.clearUnsafe(0, pathHeight, 0, image.height) @@ -1699,7 +1699,7 @@ proc fillShapes( else: mask.fillHits(startX, y, hits, numHits, windingRule, blendMode) - if blendMode == bmMask: + if blendMode == BlendMask: mask.clearUnsafe(0, 0, 0, startY) mask.clearUnsafe(0, pathHeight, 0, mask.height) @@ -1883,7 +1883,7 @@ proc fillPath*( path: SomePath, transform = mat3(), windingRule = wrNonZero, - blendMode = bmNormal + blendMode = BlendNormal ) {.raises: [PixieError].} = ## Fills a path. var shapes = parseSomePath(path, true, transform.pixelScale()) @@ -1902,7 +1902,7 @@ proc fillPath*( return 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()) shapes.transform(transform) var color = paint.color @@ -1948,7 +1948,7 @@ proc strokePath*( lineJoin = ljMiter, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[], - blendMode = bmNormal + blendMode = BlendNormal ) {.raises: [PixieError].} = ## Strokes a path. let pixelScale = transform.pixelScale() @@ -1980,7 +1980,7 @@ proc strokePath*( return 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( parseSomePath(path, false, transform.pixelScale()), strokeWidth, diff --git a/tests/benchmark_drawCorrect_vs_drawUber.nim b/tests/benchmark_drawCorrect_vs_drawUber.nim index 2cd166d..ceb3a8b 100644 --- a/tests/benchmark_drawCorrect_vs_drawUber.nim +++ b/tests/benchmark_drawCorrect_vs_drawUber.nim @@ -10,7 +10,7 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) block: @@ -21,7 +21,7 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) block: @@ -32,7 +32,7 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) block: @@ -43,5 +43,5 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) diff --git a/tests/benchmark_images_draw.nim b/tests/benchmark_images_draw.nim index 3083c05..c0b6aaf 100644 --- a/tests/benchmark_images_draw.nim +++ b/tests/benchmark_images_draw.nim @@ -7,8 +7,8 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - timeIt "draw small-on-big bmNormal": - a.draw(b, translate(vec2(25, 25)), bmNormal) + timeIt "draw small-on-big BlendNormal": + a.draw(b, translate(vec2(25, 25)), BlendNormal) keep(b) block: @@ -18,8 +18,8 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - timeIt "draw small-on-big Smooth bmNormal": - a.draw(b, translate(vec2(25.2, 25.2)), bmNormal) + timeIt "draw small-on-big Smooth BlendNormal": + a.draw(b, translate(vec2(25.2, 25.2)), BlendNormal) keep(b) block: @@ -29,8 +29,8 @@ block: a.fill(rgba(255, 0, 0, 255)) b.fill(rgba(0, 255, 0, 255)) - timeIt "draw big-on-bigger bmNormal": - a.draw(b, translate(vec2(25, 25)), bmNormal) + timeIt "draw big-on-bigger BlendNormal": + a.draw(b, translate(vec2(25, 25)), BlendNormal) keep(b) block: @@ -41,7 +41,7 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) block: @@ -52,7 +52,7 @@ block: b.fill(rgba(0, 255, 0, 255)) 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) block: @@ -63,7 +63,7 @@ block: b.fill(rgba(0, rand(255).uint8, 0, 255)) 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) block: @@ -74,7 +74,7 @@ block: b.fill(rgba(0, rand(255).uint8, 0, 255)) 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) block: @@ -85,7 +85,7 @@ block: b.fill(rgba(0, rand(255).uint8, 0, 255)) 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) block: @@ -96,7 +96,7 @@ block: b.fill(rgba(0, rand(255).uint8, 0, 255)) 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) block: @@ -107,7 +107,7 @@ block: b.fill(rand(255).uint8) 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) block: diff --git a/tests/megatest_emoji.nim b/tests/megatest_emoji.nim index 7e66509..7602a91 100644 --- a/tests/megatest_emoji.nim +++ b/tests/megatest_emoji.nim @@ -54,7 +54,7 @@ proc renderEmojiSet(index: int) = rendered.draw( icon, translate(pos), - bmOverwrite + BlendOverwrite ) rendered.writeFile(&"tests/fileformats/svg/{emojiSet.name}.png") diff --git a/tests/megatest_icons.nim b/tests/megatest_icons.nim index 7a94b7e..d309772 100644 --- a/tests/megatest_icons.nim +++ b/tests/megatest_icons.nim @@ -55,7 +55,7 @@ proc renderIconSet(index: int) = rendered.draw( icon, translate(pos), - bmOverwrite + BlendOverwrite ) rendered.writeFile(&"tests/fileformats/svg/{iconSet.name}.png") diff --git a/tests/test_contexts.nim b/tests/test_contexts.nim index c09eeb9..f8b196d 100644 --- a/tests/test_contexts.nim +++ b/tests/test_contexts.nim @@ -528,7 +528,7 @@ block: let paint = newPaint(pkSolid) paint.color = color(0, 0, 1, 1) - paint.blendMode = bmExclusion + paint.blendMode = BlendExclusion ctx.fillStyle = paint diff --git a/tests/test_paths.nim b/tests/test_paths.nim index e6ee881..23d268b 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -392,7 +392,7 @@ block: let paint = newPaint(pkSolid) paint.color = color(0, 1, 0, 1) - paint.blendMode = bmExcludeMask + paint.blendMode = BlendExcludeMask image.fillPath( "M 30 30 H 80 V 80 H 30 z", @@ -409,7 +409,7 @@ block: let paint = newPaint(pkSolid) paint.color = color(0, 1, 0, 1) - paint.blendMode = bmExcludeMask + paint.blendMode = BlendExcludeMask image.fillPath( "M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", @@ -426,7 +426,7 @@ block: let paint = newPaint(pkSolid) paint.color = color(0, 1, 0, 1) - paint.blendMode = bmMask + paint.blendMode = BlendMask image.fillPath( "M 30 30 H 80 V 80 H 30 z", @@ -443,7 +443,7 @@ block: let paint = newPaint(pkSolid) paint.color = color(0, 1, 0, 1) - paint.blendMode = bmMask + paint.blendMode = BlendMask image.fillPath( "M 30.1 30.1 H 80.1 V 80.1 H 30.1 z", @@ -454,25 +454,25 @@ block: block: let mask = newMask(100, 100) 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()) block: 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 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()) block: let mask = newMask(100, 100) 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()) block: 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 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()) block: