use super::*;
use crate::core::film::{CreateFilmBase, PixelSensor};
use crate::utils::containers::Array2D;
use crate::Arena;
use anyhow::Result;
use shared::core::camera::CameraTransform;
use shared::core::film::{Film, FilmBase, RGBFilm, RGBPixel};
use shared::core::filter::FilterTrait;
use shared::spectra::RGBColorSpace;

impl CreateFilm for RGBFilm {
    fn create(
        params: &ParameterDictionary,
        exposure_time: Float,
        filter: Filter,
        _camera_transform: Option<CameraTransform>,
        loc: &FileLoc,
        _arena: &Arena,
    ) -> Result<Film> {
        let colorspace = params.color_space.as_ref().cloned().unwrap_or_else(crate::spectra::default_colorspace_arc);
        let max_component_value = params.get_one_float("maxcomponentvalue", Float::INFINITY)?;
        let write_fp16 = params.get_one_bool("savefp16", true)?;
        let sensor = PixelSensor::create(params, colorspace.clone(), exposure_time, loc)?;
        let film_base = FilmBase::create(params, filter, Some(&sensor.device()), loc)?;
        let film = RGBFilm::new(film_base, &colorspace, max_component_value, write_fp16);
        Ok(Film::RGB(film))
    }
}
