#![doc(
html_logo_url = "https://repository-images.githubusercontent.com/796446264/7483a099-9280-489e-b1b0-119497d8c2da"
)]
#. "
)]
#. "
)]
#![cfg_attr(
feature = "gamut",
doc = " * The optional [`gamut`] and [`spectrum`] submodules enable the traversal
of **color space gamuts** and the **human visual gamut**, respectively."
)]
#![cfg_attr(
not(feature = "gamut"),
doc = " * The optional `gamut` and `spectrum` submodules enable the traversal
of **color space gamuts** and the **human visual gamut**, respectively."
)]
#![cfg_attr(
feature = "pyffi",
doc = "Items that are only available in Python are decorated with <i
class=python-only>Python only!</i>."
)]
#[cfg(feature = "f64")]
pub type Float = f64;
#[cfg(not(feature = "f64"))]
pub type Float = f32;
#[cfg(feature = "f64")]
pub type Bits = u64;
#[cfg(not(feature = "f64"))]
pub type Bits = u32;
mod core;
pub mod error;
mod object;
pub mod style;
pub mod termco;
pub mod theme;
mod trans;
mod util;
#[cfg(feature = "gamut")]
mod cie;
#[cfg(feature = "gamut")]
pub mod gamut {
pub use crate::core::{GamutTraversal, GamutTraversalStep};
}
#[cfg(feature = "gamut")]
pub mod spectrum;
#[cfg(feature = "pyffi")]
pub use core::close_enough;
#[doc(hidden)]
pub use core::to_eq_bits;
pub use core::{ColorSpace, HueInterpolation};
pub use object::{Color, Interpolator, OkVersion};
pub use trans::Translator;
#[cfg(feature = "pyffi")]
use pyo3::prelude::*;
#[cfg(feature = "pyffi")]
use pyo3::types::PyDict;
#[doc(hidden)]
#[cfg(feature = "pyffi")]
#[pymodule]
pub fn color(m: &Bound<'_, PyModule>) -> PyResult<()> {
let modcolor_name = m.name()?;
let modcolor_name = modcolor_name.to_str()?;
let modstyle_name = format!("{}.style", modcolor_name);
let modtermco_name = format!("{}.termco", modcolor_name);
let modtheme_name = format!("{}.theme", modcolor_name);
m.add_function(wrap_pyfunction!(close_enough, m)?)?;
m.add_class::<Color>()?;
m.add_class::<ColorSpace>()?;
m.add_class::<HueInterpolation>()?;
m.add_class::<Interpolator>()?;
m.add_class::<OkVersion>()?;
m.add_class::<Translator>()?;
let modstyle = PyModule::new(m.py(), "style")?;
modstyle.add("__package__", modcolor_name)?;
modstyle.add_class::<style::Attribute>()?;
modstyle.add_class::<style::AttributeIter>()?;
modstyle.add_class::<style::Fidelity>()?;
modstyle.add_class::<style::Format>()?;
modstyle.add_class::<style::FormatUpdate>()?;
modstyle.add_class::<style::Layer>()?;
modstyle.add_class::<style::Style>()?;
m.add_submodule(&modstyle)?;
modstyle.setattr("__name__", &modstyle_name)?;
let modtermco = PyModule::new(m.py(), "termco")?;
modtermco.add("__package__", modcolor_name)?;
modtermco.add_class::<termco::AnsiColor>()?;
modtermco.add_class::<termco::AnsiColorIterator>()?;
modtermco.add_class::<termco::Colorant>()?;
modtermco.add_class::<termco::EightBitColor>()?;
modtermco.add_class::<termco::EmbeddedRgb>()?;
modtermco.add_class::<termco::GrayGradient>()?;
modtermco.add_class::<termco::Rgb>()?;
m.add_submodule(&modtermco)?;
modtermco.setattr("__name__", &modtermco_name)?;
let modtheme = PyModule::new(m.py(), "theme")?;
modtheme.add("__package__", modcolor_name)?;
modtheme.add_class::<theme::Theme>()?;
modtheme.add_class::<theme::ThemeEntry>()?;
modtheme.add_class::<theme::ThemeEntryIterator>()?;
modtheme.add("VGA_COLORS", theme::VGA_COLORS)?;
m.add_submodule(&modtheme)?;
modtheme.setattr("__name__", &modtheme_name)?;
let py_modules: Bound<'_, PyDict> = PyModule::import(m.py(), "sys")?
.getattr("modules")?
.downcast_into()?;
py_modules.set_item(&modstyle_name, modstyle)?;
py_modules.set_item(&modtermco_name, modtermco)?;
py_modules.set_item(&modtheme_name, modtheme)?;
#[cfg(feature = "gamut")]
register_modgamut(m)?;
Ok(())
}
#[doc(hidden)]
#[cfg(all(feature = "pyffi", feature = "gamut"))]
fn register_modgamut(m: &Bound<'_, PyModule>) -> PyResult<()> {
let modcolor_name = m.name()?;
let modcolor_name = modcolor_name.to_str()?;
let modgamut_name = format!("{}.gamut", modcolor_name);
let modspectrum_name = format!("{}.spectrum", modcolor_name);
let modobserver_name = format!("{}.std_observer", modspectrum_name);
let modgamut = PyModule::new(m.py(), "gamut")?;
modgamut.add("__package__", modcolor_name)?;
modgamut.add_class::<gamut::GamutTraversal>()?;
modgamut.add_class::<gamut::GamutTraversalStep>()?;
m.add_submodule(&modgamut)?;
modgamut.setattr("__name__", &modgamut_name)?;
let modspectrum = PyModule::new(m.py(), "spectrum")?;
modspectrum.add("__package__", modcolor_name)?;
modspectrum.add(
"CIE_ILLUMINANT_D50",
spectrum::Illuminant::new(Box::new(spectrum::CIE_ILLUMINANT_D50.clone())
as Box<dyn spectrum::SpectralDistribution<Value = Float> + Send + Sync>),
)?;
modspectrum.add(
"CIE_ILLUMINANT_D65",
spectrum::Illuminant::new(Box::new(spectrum::CIE_ILLUMINANT_D65.clone())
as Box<dyn spectrum::SpectralDistribution<Value = Float> + Send + Sync>),
)?;
modspectrum.add(
"CIE_ILLUMINANT_E",
spectrum::Illuminant::new(Box::new(spectrum::CIE_ILLUMINANT_E.clone())
as Box<dyn spectrum::SpectralDistribution<Value = Float> + Send + Sync>),
)?;
modspectrum.add(
"CIE_OBSERVER_2DEG_1931",
spectrum::CIE_OBSERVER_2DEG_1931.clone(),
)?;
modspectrum.add(
"CIE_OBSERVER_10DEG_1964",
spectrum::CIE_OBSERVER_10DEG_1964.clone(),
)?;
modspectrum.add("ONE_NANOMETER", spectrum::ONE_NANOMETER)?;
modspectrum.add_class::<spectrum::Illuminant>()?;
modspectrum.add_class::<spectrum::IlluminatedObserver>()?;
modspectrum.add_class::<spectrum::Observer>()?;
modspectrum.add_class::<spectrum::SpectrumTraversal>()?;
m.add_submodule(&modspectrum)?;
modspectrum.setattr("__name__", &modspectrum_name)?;
let modobserver = PyModule::new(m.py(), "std_observer")?;
modobserver.add("__package__", modcolor_name)?;
modobserver.add_function(wrap_pyfunction!(spectrum::std_observer::x, m)?)?;
modobserver.add_function(wrap_pyfunction!(spectrum::std_observer::y, m)?)?;
modobserver.add_function(wrap_pyfunction!(spectrum::std_observer::z, m)?)?;
modspectrum.add_submodule(&modobserver)?;
modobserver.setattr("__name__", &modobserver_name)?;
let py_modules: Bound<'_, PyDict> = PyModule::import(m.py(), "sys")?
.getattr("modules")?
.downcast_into()?;
py_modules.set_item(&modgamut_name, modgamut)?;
py_modules.set_item(&modspectrum_name, modspectrum)?;
py_modules.set_item(&modobserver_name, modobserver)?;
Ok(())
}