diff --git a/src/pixie/common.nim b/src/pixie/common.nim index e596169..4e11656 100644 --- a/src/pixie/common.nim +++ b/src/pixie/common.nim @@ -3,12 +3,12 @@ import bumpy, chroma, vmath type PixieError* = object of ValueError ## Raised if an operation fails. -proc lerp*(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. let t = round(t * 255).uint32 ((a * (255 - t) + b * t) div 255).uint8 -proc lerp*(a, b: ColorRGBX, t: float32): ColorRGBX {.inline, raises: [].} = +proc mix*(a, b: ColorRGBX, t: float32): ColorRGBX {.inline, raises: [].} = ## Linearly interpolate between a and b using t. let x = round(t * 255).uint32 result.r = ((a.r.uint32 * (255 - x) + b.r.uint32 * x) div 255).uint8 @@ -16,13 +16,6 @@ proc lerp*(a, b: ColorRGBX, t: float32): ColorRGBX {.inline, raises: [].} = result.b = ((a.b.uint32 * (255 - x) + b.b.uint32 * x) div 255).uint8 result.a = ((a.a.uint32 * (255 - x) + b.a.uint32 * x) div 255).uint8 -proc lerp*(a, b: Color, v: float32): Color {.inline, raises: [].} = - ## Linearly interpolate between a and b using t. - result.r = lerp(a.r, b.r, v) - result.g = lerp(a.g, b.g, v) - result.b = lerp(a.b, b.b, v) - result.a = lerp(a.a, b.a, v) - proc snapToPixels*(rect: Rect): Rect {.raises: [].} = let xMin = rect.x diff --git a/src/pixie/images.nim b/src/pixie/images.nim index b85582c..aecc670 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -571,14 +571,14 @@ proc getRgbaSmooth*( var topMix = x0y0 if xFractional > 0 and x0y0 != x1y0: - topMix = lerp(x0y0, x1y0, xFractional) + topMix = mix(x0y0, x1y0, xFractional) var bottomMix = x0y1 if xFractional > 0 and x0y1 != x1y1: - bottomMix = lerp(x0y1, x1y1, xFractional) + bottomMix = mix(x0y1, x1y1, xFractional) if yFractional != 0 and topMix != bottomMix: - lerp(topMix, bottomMix, yFractional) + mix(topMix, bottomMix, yFractional) else: topMix diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index 00b27fb..847f4d4 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -181,14 +181,14 @@ proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} = var topMix = x0y0 if xFractional > 0 and x0y0 != x1y0: - topMix = lerp(x0y0, x1y0, xFractional) + topMix = mix(x0y0, x1y0, xFractional) var bottomMix = x0y1 if xFractional > 0 and x0y1 != x1y1: - bottomMix = lerp(x0y1, x1y1, xFractional) + bottomMix = mix(x0y1, x1y1, xFractional) if yFractional != 0 and topMix != bottomMix: - lerp(topMix, bottomMix, yFractional) + mix(topMix, bottomMix, yFractional) else: topMix diff --git a/src/pixie/paints.nim b/src/pixie/paints.nim index 9baeda7..9b6ee64 100644 --- a/src/pixie/paints.nim +++ b/src/pixie/paints.nim @@ -95,7 +95,7 @@ proc gradientPut( let gs1 = stops[index] gs2 = stops[index + 1] - color = lerp( + color = mix( gs1.color, gs2.color, (t - gs1.position) / (gs2.position - gs1.position) diff --git a/tests/images/paths/arc.png b/tests/images/paths/arc.png index 76b3cb0..f8d3417 100644 Binary files a/tests/images/paths/arc.png and b/tests/images/paths/arc.png differ diff --git a/tests/images/svg/diffs/rect02.png b/tests/images/svg/diffs/rect02.png index 83f1459..ae4c604 100644 Binary files a/tests/images/svg/diffs/rect02.png and b/tests/images/svg/diffs/rect02.png differ diff --git a/tests/images/svg/rendered/rect02.png b/tests/images/svg/rendered/rect02.png index f3a1744..c843eac 100644 Binary files a/tests/images/svg/rendered/rect02.png and b/tests/images/svg/rendered/rect02.png differ