MCPcopy Index your code
hub / github.com/Aiving/material-colors

github.com/Aiving/material-colors @0.4.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.2 ↗ · + Follow
487 symbols 1,009 edges 48 files 86 documented · 18% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Material colors

crates.io: material-colors Documentation Build Status License: MIT or Apache 2.0

An unofficial port of the material-color-utilities library for creating Material You themes and color schemes.

Features

  • std: enabled by default, disabling makes it possible to use the crate in no_std environments, provided there is an allocator available
  • image: adds support for extracting colors from images, requires std feature enabled
  • serde: adds support for JSON serialization of themes and color schemes
  • no-libm: removes the built-in implementation of FloatExt trait, which is based on libm

Examples

From HEX color:

use material_colors::{color::Argb, theme::ThemeBuilder};

let theme = ThemeBuilder::with_source(Argb::from_u32(0xffaae5a4)).build();

// Do whatever you want...

From image:

⚠️ Before obtaining an array of ARGB pixels for the image, it is recommended (but not necessary if your image is already small in size or you just don't mind about execution time) to adjust its dimensions to 128x128 by func:resize from struct:Image provided by struct:ImageReader. The reason is described here.

use material_colors::{
    image::{FilterType, ImageReader},
    theme::ThemeBuilder,
};

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let image = reqwest::get("https://picsum.photos/id/866/1920/1080")
        .await?
        .bytes()
        .await?
        .to_vec();

    let mut data = ImageReader::read(image).expect("failed to read image");

    // Lancsoz3 takes a little longer, but provides the best pixels for color extraction.
    // However, if you don't like the results, you can always try other FilterType values.
    data.resize(128, 128, FilterType::Lanczos3);

    let theme = ThemeBuilder::with_source(ImageReader::extract_color(&data)).build();

    // Do whatever you want...

    Ok(())
}

Current status of no-std support

This library requires alloc because Quantizer and Score make heavy use of Vec, and DynamicColor requires Box for function storage.

It also makes heavy use of various floating point functions, which greatly reduces the number of supported platforms. Yes, we have libm as a fallback, but it gives extremely different and inaccurate results, with unexpected consequences, and is also obviously much slower.

In case you have a platform where there are corresponding instructions for operations on floating point numbers, you will have to fork the repository yourself, as I unfortunately don't have any way to create an implementation for every platform that has corresponding instructions. If you have any suggestions, however, I'd be happy to hear them.

MSRV

The Minimum Supported Rust Version is currently 1.63.0.

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This project may not be copied, modified, or distributed except according to those terms.

Extension points exported contracts — how you extend this code

Quantizer (Interface)
(no doc) [3 implementers]
src/quantize/quantizer.rs
AsPixels (Interface)
(no doc) [1 implementers]
src/image.rs
FloatExt (Interface)
(no doc) [1 implementers]
src/utils/no_std.rs
PointProvider (Interface)
(no doc) [1 implementers]
src/quantize/point_provider.rs

Core symbols most depended-on inside this repo

mul_add
called by 118
src/utils/no_std.rs
tone
called by 66
src/palette/tonal.rs
get_hue
called by 63
src/hct/mod.rs
get_argb
called by 54
src/dynamic_color/mod.rs
get_chroma
called by 37
src/hct/mod.rs
r
called by 36
src/quantize/quantizer_wu.rs
g
called by 36
src/quantize/quantizer_wu.rs
b
called by 36
src/quantize/quantizer_wu.rs

Shape

Method 262
Function 166
Class 50
Enum 5
Interface 4

Languages

Rust100%

Modules by API surface

src/dynamic_color/dynamic_scheme.rs66 symbols
src/hct/mod.rs46 symbols
src/color.rs36 symbols
src/quantize/quantizer_wu.rs29 symbols
src/temperature.rs21 symbols
src/hct/solver.rs20 symbols
src/theme.rs19 symbols
src/scheme/mod.rs19 symbols
src/palette/tonal.rs19 symbols
src/utils/no_std.rs18 symbols
src/score.rs18 symbols
src/utils/math.rs15 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add material-colors \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact