# /// script # requires-python = ">=3.10" # dependencies = ["numpy"] # /// """ @effect contrast @version 1.0.0 @author artdag @description Adjusts contrast by scaling pixel values around the midpoint (128). Higher values increase contrast, lower values flatten the image. @param factor float @range 0 3 @default 1.0 Contrast multiplier. 0.5 = low contrast, 1 = unchanged, 2 = high contrast. @example (effect contrast :factor 1.5) @example ;; Dramatic contrast on energy peaks (effect contrast :factor (bind energy :range [1.0 2.0])) """ import numpy as np def process_frame(frame: np.ndarray, params: dict, state: dict) -> tuple: """ Adjust contrast of a video frame. Args: frame: Input frame as numpy array (H, W, 3) RGB uint8 params: Effect parameters - factor: contrast multiplier (default 1.0) state: Persistent state dict (unused) Returns: Tuple of (processed_frame, new_state) """ factor = params.get("factor", 1.0) if factor == 1.0: return frame, state # Adjust contrast around midpoint (128) img_float = frame.astype(np.float32) result = 128 + factor * (img_float - 128) return np.clip(result, 0, 255).astype(np.uint8), state