chromata/integration/tiny_skia.rs
1//! tiny-skia 2D rendering integration.
2//!
3//! Provides [`From<Color>`](crate::Color) for
4//! [`tiny_skia::PremultipliedColorU8`].
5//!
6//! # Enable
7//!
8//! ```toml
9//! [dependencies]
10//! chromata = { version = "1", features = ["tiny-skia-integration"] }
11//! ```
12//!
13//! # Example
14//!
15//! ```rust,ignore
16//! use chromata::popular::gruvbox;
17//!
18//! let theme = gruvbox::DARK_HARD;
19//! let color: tiny_skia::PremultipliedColorU8 = theme.bg.into();
20//! ```
21
22use crate::Color;
23
24/// Convert a chromata Color to a tiny-skia premultiplied RGBA color (alpha = 255).
25impl From<Color> for ::tiny_skia::PremultipliedColorU8 {
26 fn from(c: Color) -> Self {
27 ::tiny_skia::PremultipliedColorU8::from_rgba(c.r, c.g, c.b, 255)
28 .expect("alpha 255 premultiply is always valid")
29 }
30}