mirror of
https://codeberg.org/icewind/contrast.git
synced 2026-06-03 18:04:09 +02:00
readme
This commit is contained in:
parent
767f8ca75e
commit
f5d94cd16d
2 changed files with 27 additions and 0 deletions
15
README.md
Normal file
15
README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Contrast
|
||||
|
||||
Calculate contrast between two colors as specified by [WCAG 2](http://www.w3.org/TR/WCAG20#contrast-ratiodef)
|
||||
|
||||
# Usage
|
||||
|
||||
```rust
|
||||
use contrast::contrast;
|
||||
use rgb::RGB8;
|
||||
///
|
||||
fn main() {
|
||||
let contrast: f32 = contrast(RGB8::from([255, 255, 255]), RGB8::from([255, 255, 0]));
|
||||
assert_eq!(contrast, 1.0738392);
|
||||
}
|
||||
```
|
||||
12
src/lib.rs
12
src/lib.rs
|
|
@ -28,6 +28,18 @@ fn scale_channel<T: Bounded + NumCast, F: Float + NumCast + Div>(channel: T) ->
|
|||
}
|
||||
|
||||
/// Calculate contrast between two colors as specified by [WCAG 2](http://www.w3.org/TR/WCAG20#contrast-ratiodef)
|
||||
///
|
||||
/// # Usage
|
||||
///
|
||||
/// ```rust
|
||||
/// use contrast::contrast;
|
||||
/// use rgb::RGB8;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let contrast: f32 = contrast(RGB8::from([255, 255, 255]), RGB8::from([255, 255, 0]));
|
||||
/// assert_eq!(contrast, 1.0738392);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn contrast<T: Bounded + NumCast, F: Float + NumCast + Div>(a: RGB<T>, b: RGB<T>) -> F {
|
||||
let luminance_a: F = luminance::<T, F>(a) + cast::<_, F>(0.05).unwrap();
|
||||
let luminance_b: F = luminance::<T, F>(b) + cast::<_, F>(0.05).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue