-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new trait: `ColorBase`. - rename `COLOR` namespace to `Color`. - remove `color_` prefix from namespace methods. - misc. refactoring.
- Loading branch information
Showing
5 changed files
with
64 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// devela::rend::color::base | ||
// | ||
//! | ||
// | ||
|
||
#[cfg(feature = "alloc")] | ||
use crate::{vec_ as vec, Vec}; | ||
|
||
/// 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. | ||
pub trait ColorBase { | ||
/// The type used for color components. | ||
type Component; | ||
|
||
/// Returns the number of color components. | ||
/// | ||
/// For example: | ||
/// - RGB returns `3` | ||
/// - Spectral data may return `n` | ||
fn color_component_count(&self) -> usize; | ||
|
||
/// Writes the color components to a pre-allocated buffer. | ||
/// | ||
/// # Panics | ||
/// Panics if the buffer size is less than `color_component_count()`. | ||
// TODO: Return Error | ||
fn color_components_write(&self, buffer: &mut [Self::Component]); | ||
|
||
/// Returns a vector containing the color components. | ||
#[cfg(feature = "alloc")] | ||
fn color_components_vec(&self) -> Vec<Self::Component> | ||
where | ||
Self::Component: Default + Clone, | ||
{ | ||
let mut buffer = vec![Self::Component::default(); self.color_component_count()]; | ||
self.color_components_write(&mut buffer); | ||
buffer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.