#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
offline_bg.validated — 把 reference/validated_impl.py 当作**唯一真源**加载进来。

不复制、不改写、不重新发明。那份文件里的每个函数都是八轮 RTX5090 实测验证过的，
本包所有模块一律从这里取，改动只能改 reference/validated_impl.py 本身。
"""
import importlib.util
import sys
from pathlib import Path

_PATH = Path(__file__).resolve().parents[1] / "reference" / "validated_impl.py"
if not _PATH.exists():                                    # 部署时忘了带 reference/ 会在这里立刻炸，而不是运行到一半
    raise FileNotFoundError(f"找不到已验证实现真源: {_PATH}")

_spec = importlib.util.spec_from_file_location("_validated_impl", _PATH)
_m = importlib.util.module_from_spec(_spec)
sys.modules["_validated_impl"] = _m
_spec.loader.exec_module(_m)

# —— 转出：名字保持与真源一致，便于回溯 ——
to_gpu = _m.to_gpu
from_gpu = _m.from_gpu
build_feather_mask = _m.build_feather_mask
RoiSwapper = _m.RoiSwapper
estimate_light_dir = _m.estimate_light_dir
laplacian_sharpness = _m.laplacian_sharpness
color_transfer = _m.color_transfer
estimate_noise_sigma = _m.estimate_noise_sigma
match_background_to_camera = _m.match_background_to_camera
patch_unet_for_iclight = _m.patch_unet_for_iclight
gradient_light_map = _m.gradient_light_map
lr_brightness_diff = _m.lr_brightness_diff

SOURCE_PATH = str(_PATH)

__all__ = [
    "to_gpu", "from_gpu", "build_feather_mask", "RoiSwapper",
    "estimate_light_dir", "laplacian_sharpness", "color_transfer",
    "estimate_noise_sigma", "match_background_to_camera",
    "patch_unet_for_iclight", "gradient_light_map", "lr_brightness_diff",
    "SOURCE_PATH",
]
