diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index 6a3d2e0..fac4e03 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -609,7 +609,7 @@ when defined(amd64) and not defined(pixieNoSimd): sourceEven = mm_srli_epi16(sourceEven, 8) sourceOdd = mm_srli_epi16(sourceOdd, 8) - var + let blendedEven = mm_add_epi16(sourceEven, backdropEven) blendedOdd = mm_add_epi16(sourceOdd, backdropOdd) 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/fonts.nim b/src/pixie/fonts.nim index 59687fb..f2d019a 100644 --- a/src/pixie/fonts.nim +++ b/src/pixie/fonts.nim @@ -478,7 +478,7 @@ proc textUber( for runeIndex in start .. stop: let position = arrangement.positions[runeIndex] - var path = font.typeface.getGlyphPath(arrangement.runes[runeIndex]) + let path = font.typeface.getGlyphPath(arrangement.runes[runeIndex]) path.transform( translate(position) * scale(vec2(font.scale)) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index e4e7339..aecc670 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -368,7 +368,7 @@ proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} = else: let index = i - var values = mm_loadu_si128(target.data[index].addr) + let values = mm_loadu_si128(target.data[index].addr) let eqZero = mm_cmpeq_epi16(values, mm_setzero_si128()) if mm_movemask_epi8(eqZero) != 0xffff: @@ -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/benchmark_png.nim b/tests/benchmark_png.nim index e2257d8..137977d 100644 --- a/tests/benchmark_png.nim +++ b/tests/benchmark_png.nim @@ -6,9 +6,16 @@ let data = readFile(filePath) timeIt "pixie decode": - keep decodePng(data) + keep decodePngRaw(data) timeIt "pixie encode": + let decoded = decodePngRaw(data) + keep encodePng(decoded).len + +timeIt "pixie decode + alpha": + keep decodePng(data) + +timeIt "pixie encode + alpha": let decoded = decodePng(data) keep encodePng(decoded).len