import numpy as np LUTS = { "cinematic": { "name": "🎬 电影橙青", "matrix": np.array([[1.1, 0.0, -0.1], [0.0, 1.05, 0.0], [-0.05, 0.0, 1.15]]), "warmth": (5, 0, -5), "contrast": 1.15, }, "bw": { "name": "⬛ 经典黑白", "matrix": np.array([[0.3, 0.59, 0.11], [0.3, 0.59, 0.11], [0.3, 0.59, 0.11]]), "warmth": (0, 0, 0), "contrast": 1.3, }, "cyberpunk": { "name": "🌆 赛博朋克", "matrix": np.array([[0.8, 0.0, 0.3], [0.0, 0.9, 0.1], [0.1, 0.0, 1.3]]), "warmth": (-10, 0, 15), "contrast": 1.2, }, "warm": { "name": "☀️ 日系暖阳", "matrix": np.array([[1.1, 0.05, 0.0], [0.0, 1.0, -0.05], [-0.05, -0.05, 0.9]]), "warmth": (15, 5, -10), "contrast": 0.95, }, "noir": { "name": "🌙 夜景蓝调", "matrix": np.array([[0.7, 0.0, 0.2], [0.0, 0.8, 0.1], [0.1, 0.0, 1.2]]), "warmth": (-15, -5, 10), "contrast": 1.25, }, } def apply_lut(frame, lut_name): lut = LUTS.get(lut_name) if not lut: return frame h, w = frame.shape[:2] pixels = frame.astype(np.float32).reshape(-1, 3) transformed = np.clip(pixels @ lut["matrix"].T, 0, 255).reshape(h, w, 3) # 分离 BGR 通道,加 warmth 偏移(warmth 顺序是 R, G, B) b = np.clip(transformed[:, :, 0] + lut["warmth"][2], 0, 255) g = np.clip(transformed[:, :, 1] + lut["warmth"][1], 0, 255) r = np.clip(transformed[:, :, 2] + lut["warmth"][0], 0, 255) frame = np.stack([b, g, r], axis=2) frame = (frame - 128) * lut["contrast"] + 128 return np.clip(frame, 0, 255).astype(np.uint8)