diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index 9d96b25..6a3d2e0 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -45,7 +45,7 @@ when defined(release): proc min(a, b: uint32): uint32 {.inline.} = if a < b: a else: b -proc alphaFix(backdrop, source, mixed: ColorRGBA): ColorRGBA = +proc alphaFix(backdrop, source, mixed: ColorRGBA): ColorRGBA = ## After mixing an image, adjust its alpha value to be correct. let sa = source.a.uint32 @@ -68,7 +68,7 @@ proc alphaFix(backdrop, source, mixed: ColorRGBA): ColorRGBA = result.b = (b div a div 255).uint8 result.a = a.uint8 -proc alphaFix(backdrop, source, mixed: Color): Color = +proc alphaFix(backdrop, source, mixed: Color): Color = ## After mixing an image, adjust its alpha value to be correct. result.a = (source.a + backdrop.a * (1.0 - source.a)) if result.a == 0: @@ -165,7 +165,7 @@ proc SetSat(C: Color, s: float32): Color {.inline.} = if satC > 0: result = (C - min([C.r, C.g, C.b])) * s / satC -proc blendNormal(backdrop, source: ColorRGBX): ColorRGBX = +proc blendNormal(backdrop, source: ColorRGBX): ColorRGBX = if backdrop.a == 0: return source if source.a == 255: @@ -179,7 +179,7 @@ proc blendNormal(backdrop, source: ColorRGBX): ColorRGBX = result.b = source.b + ((backdrop.b.uint32 * k) div 255).uint8 result.a = blendAlpha(backdrop.a, source.a) -proc blendDarken(backdrop, source: ColorRGBX): ColorRGBX = +proc blendDarken(backdrop, source: ColorRGBX): ColorRGBX = proc blend( backdropColor, backdropAlpha, sourceColor, sourceAlpha: uint8 ): uint8 {.inline.} = @@ -193,7 +193,7 @@ proc blendDarken(backdrop, source: ColorRGBX): ColorRGBX = result.b = blend(backdrop.b, backdrop.a, source.b, source.a) result.a = blendAlpha(backdrop.a, source.a) -proc blendMultiply(backdrop, source: ColorRGBX): ColorRGBX = +proc blendMultiply(backdrop, source: ColorRGBX): ColorRGBX = proc blend( backdropColor, backdropAlpha, sourceColor, sourceAlpha: uint8 ): uint8 {.inline.} = @@ -218,7 +218,7 @@ proc blendMultiply(backdrop, source: ColorRGBX): ColorRGBX = # result = alphaFix(backdrop, source, result) # result = result.toPremultipliedAlpha() -proc blendColorBurn(backdrop, source: ColorRGBX): ColorRGBX = +proc blendColorBurn(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba() source = source.rgba() @@ -235,7 +235,7 @@ proc blendColorBurn(backdrop, source: ColorRGBX): ColorRGBX = blended.b = blend(backdrop.b, source.b) result = alphaFix(backdrop, source, blended).rgbx() -proc blendLighten(backdrop, source: ColorRGBX): ColorRGBX = +proc blendLighten(backdrop, source: ColorRGBX): ColorRGBX = proc blend( backdropColor, backdropAlpha, sourceColor, sourceAlpha: uint8 ): uint8 {.inline.} = @@ -249,7 +249,7 @@ proc blendLighten(backdrop, source: ColorRGBX): ColorRGBX = result.b = blend(backdrop.b, backdrop.a, source.b, source.a) result.a = blendAlpha(backdrop.a, source.a) -proc blendScreen(backdrop, source: ColorRGBX): ColorRGBX = +proc blendScreen(backdrop, source: ColorRGBX): ColorRGBX = result.r = screen(backdrop.r, source.r) result.g = screen(backdrop.g, source.g) result.b = screen(backdrop.b, source.b) @@ -265,7 +265,7 @@ proc blendScreen(backdrop, source: ColorRGBX): ColorRGBX = # result = alphaFix(backdrop, source, result) # result = result.toPremultipliedAlpha() -proc blendColorDodge(backdrop, source: ColorRGBX): ColorRGBX = +proc blendColorDodge(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba() source = source.rgba() @@ -282,13 +282,13 @@ proc blendColorDodge(backdrop, source: ColorRGBX): ColorRGBX = blended.b = blend(backdrop.b, source.b) result = alphaFix(backdrop, source, blended).rgbx() -proc blendOverlay(backdrop, source: ColorRGBX): ColorRGBX = +proc blendOverlay(backdrop, source: ColorRGBX): ColorRGBX = result.r = hardLight(source.r, source.a, backdrop.r, backdrop.a) result.g = hardLight(source.g, source.a, backdrop.g, backdrop.a) result.b = hardLight(source.b, source.a, backdrop.b, backdrop.a) result.a = blendAlpha(backdrop.a, source.a) -proc blendSoftLight(backdrop, source: ColorRGBX): ColorRGBX = +proc blendSoftLight(backdrop, source: ColorRGBX): ColorRGBX = # proc softLight(backdrop, source: int32): uint8 {.inline.} = # ## Pegtop # ( @@ -362,13 +362,13 @@ proc blendSoftLight(backdrop, source: ColorRGBX): ColorRGBX = result = rgba.rgbx() -proc blendHardLight(backdrop, source: ColorRGBX): ColorRGBX = +proc blendHardLight(backdrop, source: ColorRGBX): ColorRGBX = result.r = hardLight(backdrop.r, backdrop.a, source.r, source.a) result.g = hardLight(backdrop.g, backdrop.a, source.g, source.a) result.b = hardLight(backdrop.b, backdrop.a, source.b, source.a) result.a = blendAlpha(backdrop.a, source.a) -proc blendDifference(backdrop, source: ColorRGBX): ColorRGBX = +proc blendDifference(backdrop, source: ColorRGBX): ColorRGBX = proc blend( backdropColor, backdropAlpha, sourceColor, sourceAlpha: uint8 ): uint8 {.inline.} = @@ -384,7 +384,7 @@ proc blendDifference(backdrop, source: ColorRGBX): ColorRGBX = result.b = blend(backdrop.b, backdrop.a, source.b, source.a) result.a = blendAlpha(backdrop.a, source.a) -proc blendExclusion(backdrop, source: ColorRGBX): ColorRGBX = +proc blendExclusion(backdrop, source: ColorRGBX): ColorRGBX = proc blend(backdrop, source: uint32): uint8 {.inline.} = let v = (backdrop + source).int32 - ((2 * backdrop * source) div 255).int32 max(0, v).uint8 @@ -393,56 +393,56 @@ proc blendExclusion(backdrop, source: ColorRGBX): ColorRGBX = result.b = blend(backdrop.b.uint32, source.b.uint32) result.a = blendAlpha(backdrop.a, source.a) -proc blendColor(backdrop, source: ColorRGBX): ColorRGBX = +proc blendColor(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba().color source = source.rgba().color blended = SetLum(source, Lum(backdrop)) result = alphaFix(backdrop, source, blended).rgba.rgbx() -proc blendLuminosity(backdrop, source: ColorRGBX): ColorRGBX = +proc blendLuminosity(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba().color source = source.rgba().color blended = SetLum(backdrop, Lum(source)) result = alphaFix(backdrop, source, blended).rgba.rgbx() -proc blendHue(backdrop, source: ColorRGBX): ColorRGBX = +proc blendHue(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba().color source = source.rgba().color blended = SetLum(SetSat(source, Sat(backdrop)), Lum(backdrop)) result = alphaFix(backdrop, source, blended).rgba.rgbx() -proc blendSaturation(backdrop, source: ColorRGBX): ColorRGBX = +proc blendSaturation(backdrop, source: ColorRGBX): ColorRGBX = let backdrop = backdrop.rgba().color source = source.rgba().color 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 result.b = ((backdrop.b * k) div 255).uint8 result.a = ((backdrop.a * k) div 255).uint8 -proc blendSubtractMask(backdrop, source: ColorRGBX): ColorRGBX = +proc blendSubtractMask(backdrop, source: ColorRGBX): ColorRGBX = let a = (backdrop.a.uint32 * (255 - source.a)) div 255 result.r = ((backdrop.r * a) div 255).uint8 result.g = ((backdrop.g * a) div 255).uint8 result.b = ((backdrop.b * a) div 255).uint8 result.a = a.uint8 -proc blendExcludeMask(backdrop, source: ColorRGBX): ColorRGBX = +proc blendExcludeMask(backdrop, source: ColorRGBX): ColorRGBX = let a = max(backdrop.a, source.a).uint32 - min(backdrop.a, source.a) result.r = ((source.r * a) div 255).uint8 result.g = ((source.g * a) div 255).uint8 result.b = ((source.b * a) div 255).uint8 result.a = a.uint8 -proc blendOverwrite(backdrop, source: ColorRGBX): ColorRGBX = +proc blendOverwrite(backdrop, source: ColorRGBX): ColorRGBX = source # proc blendWhite(backdrop, source: ColorRGBX): ColorRGBX = @@ -475,21 +475,21 @@ proc blender*(blendMode: BlendMode): Blender {.raises: [].} = of bmSubtractMask: blendSubtractMask of bmExcludeMask: blendExcludeMask -proc maskNormal(backdrop, source: uint8): uint8 = +proc maskNormal(backdrop, source: uint8): uint8 = ## Blending masks blendAlpha(backdrop, source) -proc maskMask(backdrop, source: uint8): uint8 = +proc maskMask(backdrop, source: uint8): uint8 = ## Masking masks ((backdrop.uint32 * source) div 255).uint8 -proc maskSubtract(backdrop, source: uint8): uint8 = +proc maskSubtract(backdrop, source: uint8): uint8 = ((backdrop.uint32 * (255 - source)) div 255).uint8 -proc maskExclude(backdrop, source: uint8): uint8 = +proc maskExclude(backdrop, source: uint8): uint8 = max(backdrop, source) - min(backdrop, source) -proc maskOverwrite(backdrop, source: uint8): uint8 = +proc maskOverwrite(backdrop, source: uint8): uint8 = source proc masker*(blendMode: BlendMode): Masker {.raises: [PixieError].} = @@ -512,7 +512,7 @@ when defined(amd64) and not defined(pixieNoSimd): MaskerSimd* = proc(blackdrop, source: M128i): M128i {.raises: [].} ## Function signature returned by maskerSimd. - proc blendNormalSimd(backdrop, source: M128i): M128i = + proc blendNormalSimd(backdrop, source: M128i): M128i = let alphaMask = mm_set1_epi32(cast[int32](0xff000000)) oddMask = mm_set1_epi16(cast[int16](0xff00)) @@ -541,7 +541,7 @@ when defined(amd64) and not defined(pixieNoSimd): mm_or_si128(backdropEven, mm_slli_epi16(backdropOdd, 8)) ) - proc blendMaskSimd(backdrop, source: M128i): M128i = + proc blendMaskSimd(backdrop, source: M128i): M128i = let alphaMask = mm_set1_epi32(cast[int32](0xff000000)) oddMask = mm_set1_epi16(cast[int16](0xff00)) @@ -562,7 +562,7 @@ when defined(amd64) and not defined(pixieNoSimd): mm_or_si128(backdropEven, mm_slli_epi16(backdropOdd, 8)) - proc blendOverwriteSimd(backdrop, source: M128i): M128i = + proc blendOverwriteSimd(backdrop, source: M128i): M128i = source proc blenderSimd*(blendMode: BlendMode): BlenderSimd {.raises: [PixieError].} = @@ -578,7 +578,7 @@ when defined(amd64) and not defined(pixieNoSimd): ## Is there a blend function for a given blend mode with SIMD support? blendMode in {bmNormal, bmMask, bmOverwrite} - proc maskNormalSimd(backdrop, source: M128i): M128i = + proc maskNormalSimd(backdrop, source: M128i): M128i = ## Blending masks let oddMask = mm_set1_epi16(cast[int16](0xff00)) @@ -615,7 +615,7 @@ when defined(amd64) and not defined(pixieNoSimd): mm_or_si128(blendedEven, mm_slli_epi16(blendedOdd, 8)) - proc maskMaskSimd(backdrop, source: M128i): M128i = + proc maskMaskSimd(backdrop, source: M128i): M128i = let oddMask = mm_set1_epi16(cast[int16](0xff00)) div255 = mm_set1_epi16(cast[int16](0x8081)) diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index 4d8fc55..e16ed6e 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -495,7 +495,7 @@ proc getLineDash*(ctx: Context): seq[float32] {.inline, raises: [].} = proc setLineDash*(ctx: Context, lineDash: seq[float32]) {.inline, raises: [].} = ctx.lineDash = lineDash -proc getTransform*(ctx: Context): Mat3 {.inline, raises: []} = +proc getTransform*(ctx: Context): Mat3 {.inline, raises: [].} = ## Retrieves the current transform matrix being applied to the context. ctx.mat diff --git a/src/pixie/images.nim b/src/pixie/images.nim index e71b67e..d5a777a 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -884,10 +884,10 @@ proc draw*( proc drawTiled*( dst, src: Image, mat: Mat3, blendMode = bmNormal -) {.raises: [PixieError]} = +) {.raises: [PixieError].} = dst.drawCorrect(src, mat, true, blendMode) -proc resize*(srcImage: Image, width, height: int): Image {.raises: [PixieError]} = +proc resize*(srcImage: Image, width, height: int): Image {.raises: [PixieError].} = ## Resize an image to a given height and width. if width == srcImage.width and height == srcImage.height: result = srcImage.copy() @@ -904,7 +904,7 @@ proc resize*(srcImage: Image, width, height: int): Image {.raises: [PixieError]} proc shadow*( image: Image, offset: Vec2, spread, blur: float32, color: SomeColor -): Image {.raises: [PixieError]} = +): Image {.raises: [PixieError].} = ## Create a shadow of the image with the offset, spread and blur. let mask = image.newMask() @@ -916,7 +916,7 @@ proc shadow*( result.fill(color) result.draw(shifted, blendMode = bmMask) -proc superImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError]} = +proc superImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} = ## Either cuts a sub image or returns a super image with padded transparency. if x >= 0 and x + w <= image.width and y >= 0 and y + h <= image.height: result = image.subImage(x, y, w, h) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index d10be81..058556f 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1252,9 +1252,7 @@ proc computeCoverages( for j in i ..< fillStart + fillLen: coverages[j - startX] += sampleCoverage -proc clearUnsafe( - target: Image | Mask, startX, startY, toX, toY: int -) = +proc clearUnsafe(target: Image | Mask, startX, startY, toX, toY: int) = ## Clears data from [start, to). if startX == target.width or startY == target.height: return