PixelWeaver v0.5.0 /server.src.pixelweaver.effects
On this page

Fixed-dimension pixel effects such as invert, grayscale, colorize, blur, glow, and shadow, ported byte-for-byte so server-applied effects match the browser exactly.

#server.src.pixelweaver.effects

#server.src.pixelweaver.effects

Server-side pixel effects -- faithful ports of the client effect algorithms.

Mirrors plugins/builtin/effects/*.ts and the HSV helpers in src/lib/color/color-utils.ts. Each effect takes a flat RGBA buffer (width*height*4 bytes) plus its native parameters and returns a NEW buffer of the same dimensions. All rounding uses round-half-up (floor(x + 0.5)) to match JavaScript Math.round.

Fixed-dimension effects are ported here. Dimension-changing / whole-canvas transforms (rotate 90/270, scale) and any effect that cannot be reproduced byte-for-byte are surfaced as a hard error by apply_effect -- never a silent skip (see EFFECT_HARD_ERRORS).

#_round

python
def _round(x: float) -> int

Round half up, matching JS Math.round for the non-negative and negative values these effects produce.

#invert

python
def invert(buf: _Buf) -> bytearray

Invert the RGB channels (255 - value); alpha is preserved.

#grayscale

python
def grayscale(buf: _Buf) -> bytearray

Convert each pixel to its Rec. 601 luminance (0.299R + 0.587G + 0.114B); alpha is preserved.

#colorize

python
def colorize(buf: _Buf, color: str) -> bytearray

Tint each pixel toward color scaled by its own luminance; fully transparent pixels pass through unchanged.

#brightness_contrast

python
def brightness_contrast(buf: _Buf, brightness: float, contrast: float) -> bytearray

Apply a per-channel brightness offset and contrast factor (the standard 259-based contrast formula); alpha is preserved.

#hue_shift

python
def hue_shift(buf: _Buf, degrees: float) -> bytearray

Rotate each pixel's hue by degrees in HSV space; fully transparent pixels pass through unchanged.

#blur

python
def blur(buf: _Buf) -> bytearray

1px box blur (average of self + in-bounds 8-neighbors).

#sharpen

python
def sharpen(buf: _Buf, amount: float=1.0) -> bytearray

Unsharp mask: original + (original - blurred) * amount, alpha preserved.

#flip

python
def flip(buf: _Buf, direction: str) -> bytearray

Mirror the buffer horizontally (direction == "h") or vertically (direction == "v").

#outline

python
def outline(buf: _Buf, thickness: int, color: str) -> bytearray

Fill transparent pixels within Chebyshev thickness of an opaque pixel with the outline color. Starts from a copy of the buffer.

#glow

python
def glow(buf: _Buf, radius: int, color: str, opacity: float) -> bytearray

Paint a color glow into transparent pixels within radius of an opaque pixel, with linear distance falloff scaled by opacity.

#shadow

python
def shadow(buf: _Buf, offset_x: int, offset_y: int, color: str, opacity: float) -> bytearray

Cast a color drop shadow at opacity, offset by (offset_x, offset_y), into transparent pixels that do not overlap opaque source pixels.

#UnsupportedEffectError

An effect that is not (yet) faithfully portable via this path.

#apply_effect

python
def apply_effect(data: bytes, width: int, height: int, effect: str, params: dict[str, Any]) -> bytes

Apply effect to an RGBA buffer and return a new buffer.

Raises UnsupportedEffectError for dimension-changing effects and unknown effect names -- never a silent skip.

Search