devela::media::color

Trait ColorBase

Source
pub trait ColorBase {
    type Component;

    // Required methods
    fn color_component_count(&self) -> usize ;
    fn color_components_write(&self, buffer: &mut [Self::Component]);

    // Provided method
    fn color_components_vec(&self) -> Vec<Self::Component> 
       where Self::Component: Default + Clone { ... }
}
Available on crate feature color only.
Expand description

Base trait for general color data representation.

Provides a core interface for working with color data across different formats and models, supporting both practical and scientific applications.

Required Associated Types§

Source

type Component

The type used for color components.

Required Methods§

Source

fn color_component_count(&self) -> usize

Returns the number of color components.

For example:

  • RGB returns 3
  • Spectral data may return n
Source

fn color_components_write(&self, buffer: &mut [Self::Component])

Writes the color components to a pre-allocated buffer.

§Panics

Panics if the buffer size is less than color_component_count().

Provided Methods§

Source

fn color_components_vec(&self) -> Vec<Self::Component>
where Self::Component: Default + Clone,

Returns a vector containing the color components.

Implementors§