""" Mask generation """ import numpy as np from typing import Dict from ..core.frame_evaluator import evaluate_frame from .rasterizer import rasterize_curve from .antialiasing import apply_antialiasing def generate_single_mask( curve_data: Dict, frame_index: int, height: int, width: int, feather_amount: float = 0.0 ) -> np.ndarray: """ Generate mask for a single frame. Args: curve_data: Parsed curve data frame_index: Frame to render height: Output height width: Output width feather_amount: Amount of feathering to apply Returns: Mask array (H, W) in range [0, 1] """ # Create empty mask mask = np.zeros((height, width), dtype=np.uint8) # Get all shapes shapes = curve_data.get("shapes", {}) # Process each shape for shape_id, shape in shapes.items(): # Evaluate curves for this frame curves = evaluate_frame(shape, frame_index) # Rasterize each curve for curve in curves: rasterize_curve(mask, curve, height, width) # Apply antialiasing mask = apply_antialiasing(mask, feather_amount) # Normalize to [0, 1] mask = mask.astype(np.float32) / 255.0 return mask