### Install Material Color Utilities Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Install the package using pip. This is the primary method for adding the library to your project. ```bash pip install material-color-utilities ``` -------------------------------- ### Run Tests with Uvicorn Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Install development dependencies and run pytest tests using uvicorn. Ensure 'uv' is installed for this command. ```bash uv sync --dev # install packages uv run pytest tests ``` -------------------------------- ### Convert Theme Object to Dictionary Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Convert a generated Theme object into a dictionary format for easier serialization or inspection. Refer to the documentation for an example theme dictionary structure. ```python theme = theme_from_color("#FF0000") theme_dict = theme.dict() ``` -------------------------------- ### TonalPalette.get() Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Retrieves a color from the TonalPalette at a specified tone. This method allows you to get a specific color shade from a pre-defined palette based on its hue and chroma. ```APIDOC ## TonalPalette.get(tone: float) -> str ### Description Get a color from this palette at the specified tone. ### Method `get` ### Parameters #### Path Parameters - **tone** (float) - Required - The tone of the color to retrieve. ### Response #### Success Response (str) - Returns the color in string format (e.g., hex). ``` -------------------------------- ### Migrate Scheme.light to SchemeTonalSpot (Java) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.light with SchemeTonalSpot for light color schemes in Java. Ensure contrastLevel is set to 0.0 for direct replacement. ```java new SchemeTonalSpot(Hct.fromInt(color), false, 0.0) ``` -------------------------------- ### Migrate Scheme.lightContent to SchemeContent (Java) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.lightContent with SchemeContent for light content color schemes in Java. Ensure contrastLevel is set to 0.0 for direct replacement. ```java new SchemeContent(Hct.fromInt(color), false, 0.0) ``` -------------------------------- ### Import Library Components Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Import necessary components from the material_color_utilities library. This includes color conversion, theme generation, and image processing utilities. ```python from material_color_utilities import ( CustomColor, Variant, argb_from_hex, hex_from_argb, prominent_colors_from_image, theme_from_color, theme_from_image, get_contrast_ratio ) ``` -------------------------------- ### Migrate MaterialLightColorScheme to SchemeTonalSpot (C++) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces MaterialLightColorScheme with SchemeTonalSpot for light color schemes in C++. Ensure contrastLevel is set to 0.0 for direct replacement. ```cpp SchemeTonalSpot(Hct(color), false, 0.0) ``` -------------------------------- ### Migrate Scheme.dark to SchemeTonalSpot (Java) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.dark with SchemeTonalSpot for dark color schemes in Java. Ensure contrastLevel is set to 0.0 for direct replacement. ```java new SchemeTonalSpot(Hct.fromInt(color), true, 0.0) ``` -------------------------------- ### Migrate Scheme.light to SchemeTonalSpot (Dart) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.light with SchemeTonalSpot for light color schemes. Ensure contrastLevel is set to 0.0 for direct replacement. ```dart SchemeTonalSpot(sourceColorHct: Hct.fromInt(color), isDark: false, contrastLevel: 0.0) ``` -------------------------------- ### Migrate MaterialLightContentColorScheme to SchemeContent (C++) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces MaterialLightContentColorScheme with SchemeContent for light content color schemes in C++. Ensure contrastLevel is set to 0.0 for direct replacement. ```cpp SchemeContent(Hct(color), false, 0.0) ``` -------------------------------- ### Migrate MaterialDarkColorScheme to SchemeTonalSpot (C++) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces MaterialDarkColorScheme with SchemeTonalSpot for dark color schemes in C++. Ensure contrastLevel is set to 0.0 for direct replacement. ```cpp SchemeTonalSpot(Hct(color), true, 0.0) ``` -------------------------------- ### C++: Convert XYZ to Cam16 Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert XYZ color components to Cam16 within specified viewing conditions. Requires CamFromXyzAndViewingConditions function. ```cpp CamFromXyzAndViewingConditions(x, y, z, vc) ``` -------------------------------- ### Migrate Scheme.darkContent to SchemeContent (Java) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.darkContent with SchemeContent for dark content color schemes in Java. Ensure contrastLevel is set to 0.0 for direct replacement. ```java new SchemeContent(Hct.fromInt(color), true, 0.0) ``` -------------------------------- ### Calculate Contrast Ratio (ARGB Colors) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Obtain the tone of ARGB colors using `ColorUtils.lstarFromArgb` before calculating the contrast ratio with `ratioOfTones`. This method is useful when working with ARGB color values. ```dart final tone1 = ColorUtils.lstarFromArgb(argb1); final tone2 = ColorUtils.lstarFromArgb(argb2); final contrastRatio = Contrast.ratioOfTones(tone1, tone2); ``` ```java double tone1 = ColorUtils.lstarFromArgb(argb1); double tone2 = ColorUtils.lstarFromArgb(argb2); double contrastRatio = Contrast.ratioOfTones(tone1, tone2); ``` ```typescript const tone1 = ColorUtils.lstarFromArgb(argb1); const tone2 = ColorUtils.lstarFromArgb(argb2); const contrastRatio = Contrast.ratioOfTones(tone1, tone2); ``` ```cpp double tone1 = LstarFromArgb(argb1); double tone2 = LstarFromArgb(argb2); double contrast_ratio = RatioOfTones(tone1, tone2); ``` ```swift let tone1 = ColorUtils.lstarFromArgb(argb1) let tone2 = ColorUtils.lstarFromArgb(argb2) let contrastRatio = Contrast.ratioOfTones(tone1, tone2) ``` -------------------------------- ### Java: Obtain Contrasting Tones Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `darker` and `lighter` to find tones with a specific contrast ratio. The 'unsafe' variants may return colors without guaranteeing contrast. ```java double original = ColorUtils.lstarFromArgb(0xFF00AA00); // 60.56 double darker = Contrast.darker(original, 3.0); // 29.63 double lighter = Contrast.lighter(original, 3.0); // 98.93 double darkerUnsafe = Contrast.darkerUnsafe(original, 3.0); // 29.63 double lighterUnsafe = Contrast.lighterUnsafe(original, 3.0); // 98.93 double darker = Contrast.darker(original, 7.0); // -1.0 double lighter = Contrast.lighter(original, 7.0); // -1.0 double darkerUnsafe = Contrast.darkerUnsafe(original, 7.0); // 0.0 double lighterUnsafe = Contrast.lighterUnsafe(original, 7.0); // 100.0 ``` -------------------------------- ### C++: Construct Cam16 from UCS Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Create a Cam16 color object from its UCS (J*, a*, b*) components and viewing conditions. Requires CamFromUcsAndViewingConditions function. ```cpp CamFromUcsAndViewingConditions(jstar, astar, bstar, vc) ``` -------------------------------- ### theme_from_color Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Generates a color theme based on a single source hex color. Allows customization of contrast and variant, and inclusion of custom colors. ```APIDOC ## theme_from_color(source: str, contrast_level: float = 0.25, variant: Variant = Variant.VIBRANT, custom_colors: list[CustomColor] = []) -> Theme ### Description Returns a theme from a source color. ### Parameters #### Path Parameters - **source** (str) - Required - A string representing the hex color code (e.g., `"#4285F4"`). - **contrast_level** (float) - Optional - An optional float specifying the contrast level (default is `0.25`). - **variant** (Variant) - Optional - An optional `Variant` specifying the color variant (default is `Variant.kVibrant`). - **custom_colors** (list[CustomColor]) - Optional - An optional list of `CustomColor` objects to apply (default is an empty list). ### Returns #### Success Response - **return_value** (Theme) - A `Theme` object representing the generated theme. ``` -------------------------------- ### theme_from_image Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Generates a color theme directly from a PIL Image object. Supports adjustable contrast, variant, and custom color application. ```APIDOC ## theme_from_image(image: PIL.Image.Image, contrast_level: float = 0.25, variant: Variant = Variant.kVibrant, custom_colors: list[CustomColor] = []) -> Theme ### Description Returns a theme from an image. ### Parameters #### Path Parameters - **image** (PIL.Image.Image) - Required - A `PIL.Image.Image` object representing the image. - **contrast_level** (float) - Optional - An optional integer specifying the contrast level (default is `0.25`). - **variant** (Variant) - Optional - An optional `Variant` specifying the color variant (default is `Variant.kVibrant`). - **custom_colors** (list[CustomColor]) - Optional - An optional list of `CustomColor` objects to apply (default is an empty list). ### Returns #### Success Response - **return_value** (Theme) - A `Theme` object representing the generated theme. ``` -------------------------------- ### C++: Obtain Contrasting Tones Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `Darker` and `Lighter` to find tones with a specific contrast ratio. The 'unsafe' variants may return colors without guaranteeing contrast. ```cpp double original = LstarFromArgb(0xFF00AA00); // 60.56 double darker = Darker(original, 3.0); // 29.63 double lighter = Lighter(original, 3.0); // 98.93 double darker_unsafe = DarkerUnsafe(original, 3.0); // 29.63 double lighter_unsafe = LighterUnsafe(original, 3.0); // 98.93 double darker = Darker(original, 7.0); // -1.0 double lighter = Lighter(original, 7.0); // -1.0 double darker_unsafe = DarkerUnsafe(original, 7.0); // 0.0 double lighter_unsafe = LighterUnsafe(original, 7.0); // 100.0 ``` -------------------------------- ### Migrate Scheme.lightContent to SchemeContent (Dart) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.lightContent with SchemeContent for light content color schemes. Ensure contrastLevel is set to 0.0 for direct replacement. ```dart SchemeContent(sourceColorHct: Hct.fromInt(color), isDark: false, contrastLevel: 0.0) ``` -------------------------------- ### Generate Theme from Image Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Generate a Material Design theme by extracting colors from an image. The package handles image processing. Optionally, provide custom colors to harmonize the theme. ```python from PIL import Image image = Image.open("path/to/image.jpg") # You can *optionally* pass a list of custom colors to generate palettes that harmonize with the source color. custom_colors = [CustomColor("#4285F4", "Google Blue", True)] theme = theme_from_image(image, 0, Variant.CONTENT, custom_colors) ``` -------------------------------- ### Migrate MaterialDarkContentColorScheme to SchemeContent (C++) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces MaterialDarkContentColorScheme with SchemeContent for dark content color schemes in C++. Ensure contrastLevel is set to 0.0 for direct replacement. ```cpp SchemeContent(Hct(color), true, 0.0) ``` -------------------------------- ### Generate Theme from Source Color Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Create a Material Design theme using a single source color. Specify the color hex code, a seed color index, and the desired theme variant. ```python theme = theme_from_color("#FC03A3", 0, Variant.EXPRESSIVE) # now apply the theme somewhere # Example, assuming dark theme: button.color = theme.schemes.dark.primary button.text_color = theme.schemes.dark.on_primary background.color = theme.schemes.dark.surface_container text_paragraph.color = theme.schemes.dark.on_surface ``` -------------------------------- ### Migrate Scheme.dark to SchemeTonalSpot (Dart) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.dark with SchemeTonalSpot for dark color schemes. Ensure contrastLevel is set to 0.0 for direct replacement. ```dart SchemeTonalSpot(sourceColorHct: Hct.fromInt(color), isDark: true, contrastLevel: 0.0) ``` -------------------------------- ### C++: Convert L*a*b* to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert L*a*b* color components back to an ARGB integer. Requires IntFromLab function. ```cpp IntFromLab(lab) ``` -------------------------------- ### Generate Scheme with Tonal Spot Variant Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Use SchemeTonalSpot to generate a scheme with light mode and default contrast from an HCT source color. Supported across multiple languages. ```Dart final scheme = SchemeTonalSpot(sourceColorHct: hct, isDark: false, contrastLevel: 0.0); ``` ```Java DynamicScheme scheme = new SchemeTonalSpot(hct, false, 0.0); ``` ```TypeScript const scheme = new SchemeTonalSpot(hct, false, 0.0); ``` ```C++ DynamicScheme scheme = SchemeTonalSpot(hct, false, 0.0); ``` ```Swift let scheme = SchemeTonalSpot( sourceColorHct: hct, isDark: false, contrastLevel: 0.0) ``` -------------------------------- ### Generate Scheme by Specifying Palettes Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Create a DynamicScheme by explicitly defining primary, secondary, tertiary, neutral, and neutral variant palettes. This method offers more granular control over the color scheme's composition. ```Dart final scheme = DynamicScheme( sourceColorArgb: 0xFFEB0057, variant: Variant.vibrant, isDark: false, contrastLevel: 0.0, primaryPalette: TonalPalette.fromHct(Hct.fromInt(0xFFEB0057)), secondaryPalette: TonalPalette.fromHct(Hct.fromInt(0xFFF46B00)), tertiaryPalette: TonalPalette.fromHct(Hct.fromInt(0xFF00AB46)), neutralPalette: TonalPalette.fromHct(Hct.fromInt(0xFF949494)), neutralVariantPalette: TonalPalette.fromHct(Hct.fromInt(0xFFBC8877)), ); ``` ```Java DynamicScheme scheme = new DynamicScheme( /*sourceColorHct=*/ Hct.fromInt(0xFFEB0057), /*variant=*/ Variant.VIBRANT, /*isDark=*/ false, /*contrastLevel=*/ 0.0, /*primaryPalette=*/ TonalPalette.fromInt(0xFFEB0057), /*secondaryPalette=*/ TonalPalette.fromInt(0xFFF46B00), /*tertiaryPalette=*/ TonalPalette.fromInt(0xFF00AB46), /*neutralPalette=*/ TonalPalette.fromInt(0xFF949494), /*neutralVariantPalette=*/ TonalPalette.fromInt(0xFFBC8877)); ``` ```TypeScript const scheme = new DynamicScheme({ sourceColorArgb: 0xFFEB0057, variant: Variant.VIBRANT, isDark: false, contrastLevel: 0.0, primaryPalette: TonalPalette.fromInt(0xFFEB0057), secondaryPalette: TonalPalette.fromInt(0xFFF46B00), tertiaryPalette: TonalPalette.fromInt(0xFF00AB46), neutralPalette: TonalPalette.fromInt(0xFF949494), neutralVariantPalette: TonalPalette.fromInt(0xFFBC8877) }); ``` ```C++ DynamicScheme scheme = DynamicScheme( /*source_color_argb=*/ 0xFFEB0057, /*variant=*/ Variant::kVibrant, /*contrast_level=*/ 0.0, /*is_dark=*/ false, /*primary_palette=*/ TonalPalette(0xFFEB0057), /*secondary_palette=*/ TonalPalette(0xFFF46B00), /*tertiary_palette=*/ TonalPalette(0xFF00AB46), /*neutral_palette=*/ TonalPalette(0xFF949494), /*neutral_variant_palette=*/ TonalPalette(0xFFBC8877)); ``` ```Swift let scheme = DynamicScheme( sourceColorArgb: 0xFFEB0057, variant: Variant.vibrant, isDark: false, contrastLevel: 0.0, primaryPalette: TonalPalette.fromHct(Hct(0xFFEB0057)), secondaryPalette: TonalPalette.fromHct(Hct(0xFFF46B00)), tertiaryPalette: TonalPalette.fromHct(Hct(0xFF00AB46)), neutralPalette: TonalPalette.fromHct(Hct(0xFF949494)), neutralVariantPalette: TonalPalette.fromHct(Hct(0xFFBC8877))) ``` -------------------------------- ### Calculate Contrast Ratio (HCT Colors) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `ratioOfTones` to measure contrast between two HCT colors. Ensure colors are in HCT format before calculating. ```dart final contrastRatio = Contrast.ratioOfTones(hct1.tone, hct2.tone); ``` ```java double contrastRatio = Contrast.ratioOfTones(hct1.getTone(), hct2.getTone()); ``` ```typescript const contrastRatio = Contrast.ratioOfTones(hct1.tone, hct2.tone); ``` ```cpp double contrast_ratio = RatioOfTones(hct1.get_tone(), hct2.get_tone()); ``` ```swift let contrastRatio = Contrast.ratioOfTones(hct1.tone, hct2.tone) ``` -------------------------------- ### C++: Convert sRGB to L*a*b* Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert an ARGB integer color to its L*a*b* representation. Requires LabFromInt function. ```cpp LabFromInt(argb) ``` -------------------------------- ### C++: Convert sRGB to HCT Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Construct an HCT color object from an ARGB integer. Requires the Hct class. ```cpp Hct::Hct(argb) ``` -------------------------------- ### Swift: Obtain Contrasting Tones Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `darker` and `lighter` to find tones with a specific contrast ratio. The 'unsafe' variants may return colors without guaranteeing contrast. ```swift let original = ColorUtils.lstarFromArgb(0xFF00AA00) // 60.56 let darker = Contrast.darker(tone: original, ratio: 3.0) // 29.63 let lighter = Contrast.lighter(tone: original, ratio: 3.0) // 98.93 let darkerUnsafe = Contrast.darkerUnsafe(tone: original, ratio: 3.0) // 29.63 let lighterUnsafe = Contrast.lighterUnsafe(tone: original, ratio: 3.0) // 98.93 let darker = Contrast.darker(tone: original, ratio: 7.0) // -1.0 let lighter = Contrast.lighter(tone: original, ratio: 7.0) // -1.0 let darkerUnsafe = Contrast.darkerUnsafe(tone: original, ratio: 7.0) // 0.0 let lighterUnsafe = Contrast.lighterUnsafe(tone: original, ratio: 7.0) // 100.0 ``` -------------------------------- ### Java: Convert Cam16 to XYZ Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert a Cam16 color object to XYZ components within specified viewing conditions. Requires the Cam16 class. ```java cam16.xyzInViewingConditions(vc, returnArray) ``` -------------------------------- ### TypeScript: Convert XYZ to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `colorUtils.argbFromXyz` to convert XYZ color components back to an ARGB integer. Requires the colorUtils object. ```typescript colorUtils.argbFromXyz(x, y, z) ``` -------------------------------- ### TypeScript: Convert L*a*b* to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `colorUtils.argbFromLab` to convert L*a*b* color components back to an ARGB integer. Requires the colorUtils object. ```typescript colorUtils.argbFromLab(l, a, b) ``` -------------------------------- ### TypeScript: Convert sRGB to L*a*b* Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `colorUtils.labFromArgb` to convert an ARGB integer color to its L*a*b* representation. Requires the colorUtils object. ```typescript colorUtils.labFromArgb(argb) ``` -------------------------------- ### Calculate Contrast Ratio Between Colors Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Calculate the contrast ratio between two colors, specified in HEX format. This is useful for accessibility checks. ```python ratio = get_contrast_ratio("#000000", "#FFFFFF") print(ratio) # Outputs: 21.0 ``` -------------------------------- ### TypeScript: Convert sRGB to XYZ Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `colorUtils.xyzFromArgb` to convert an ARGB integer color to its XYZ representation. Requires the colorUtils object. ```typescript colorUtils.xyzFromArgb(argb) ``` -------------------------------- ### TypeScript: Obtain Contrasting Tones Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `darker` and `lighter` to find tones with a specific contrast ratio. The 'unsafe' variants may return colors without guaranteeing contrast. ```typescript const original = ColorUtils.lstarFromArgb(0xFF00AA00); // 60.56 const darker = Contrast.darker(original, 3.0); // 29.63 const lighter = Contrast.lighter(original, 3.0); // 98.93 const darkerUnsafe = Contrast.darkerUnsafe(original, 3.0); // 29.63 const lighterUnsafe = Contrast.lighterUnsafe(original, 3.0); // 98.93 const darker = Contrast.darker(original, 7.0); // -1.0 const lighter = Contrast.lighter(original, 7.0); // -1.0 const darkerUnsafe = Contrast.darkerUnsafe(original, 7.0); // 0.0 const lighterUnsafe = Contrast.lighterUnsafe(original, 7.0); // 100.0 ``` -------------------------------- ### Convert Image to ARGB Pixels (Java) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/extracting_colors.md Converts a BufferedImage to an array of pixels in ARGB format. Ensure the image is resized to 128x128 for optimal performance. ```java import java.awt.image.BufferedImage; class ImageUtils { // ... public static int[] imageToPixels(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); BufferedImage outputImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); return image.getRGB(0, 0, width, height, null, 0, width); } } ``` -------------------------------- ### Migrate Scheme.darkContent to SchemeContent (Dart) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Replaces Scheme.darkContent with SchemeContent for dark content color schemes. Ensure contrastLevel is set to 0.0 for direct replacement. ```dart SchemeContent(sourceColorHct: Hct.fromInt(color), isDark: true, contrastLevel: 0.0) ``` -------------------------------- ### DynamicScheme Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Represents a dynamic color scheme generated from a source color. It provides access to various color roles and palettes. ```APIDOC ## DynamicScheme ### Description Represents a dynamic color scheme generated from a source color. ### Attributes - **source_color_hct** (Hct) - The source color in HCT format. - **variant** (Variant) - The color variant of the scheme. - **is_dark** (bool) - A boolean indicating whether the scheme is dark. - **contrast_level** (float) - The contrast level of the scheme. - **primary_palette** (TonalPalette) - The primary color palette. - **secondary_palette** (TonalPalette) - The secondary color palette. - **tertiary_palette** (TonalPalette) - The tertiary color palette. - **neutral_palette** (TonalPalette) - The neutral color palette. - **error_palette** (TonalPalette) - The error color palette. - **background** (str) - Background color - **surface** (str) - Surface color. - **surface_dim** (str) - Dim surface color. - **surface_bright** (str) - Bright surface color. - **surface_container_lowest** (str) - The lowest surface container color. - **surface_container_low** (str) - The low surface container color. - **surface_container** (str) - The surface container color. - **surface_container_high** (str) - The high surface container color. - **surface_container_highest** (str) - The highest surface container color. - **on_surface** (str) - The color for text/icons on the surface. - **surface_variant** (str) - The surface variant color. - **on_surface_variant** (str) - The color for text/icons on the surface variant. - **inverse_surface** (str) - The inverse surface color. - **inverse_on_surface** (str) - The color for text/icons on the inverse surface. - **outline** (str) - The outline color. - **outline_variant** (str) - The outline variant color. - **shadow** (str) - The shadow color. - **scrim** (str) - The scrim color. - **surface_tint** (str) - The surface tint color. - **primary** (str) - The primary color. - **on_primary** (str) - The color for text/icons on primary color. - **primary_container** (str) - The primary container color. - **on_primary_container** (str) - The color for text/icons on the primary container. - **inverse_primary** (str) - The inverse primary color. - **secondary** (str) - The secondary color. - **on_secondary** (str) - The color for text/icons on secondary color. - **secondary_container** (str) - The secondary container color. - **on_secondary_container** (str) - The color for text/icons on the secondary container. - **tertiary** (str) - The tertiary color. - **on_tertiary** (str) - The color for text/icons on tertiary color. - **tertiary_container** (str) - The tertiary container color. - **on_tertiary_container** (str) - The color for text/icons on the tertiary container. - **error** (str) - The error color. - **on_error** (str) - The color for text/icons on error color. - **error_container** (str) - The error container color. - **on_error_container** (str) - The color for text/icons on the error container. - **primary_fixed** (str) - The fixed primary color. - **primary_fixed_dim** (str) - The dimmed fixed primary color. - **on_primary_fixed** (str) - The color for text/icons on the fixed primary color. - **on_primary_fixed_variant** (str) - The color for text/icons on the fixed primary variant. - **secondary_fixed** (str) - The fixed secondary color. - **secondary_fixed_dim** (str) - The dimmed fixed secondary color. - **on_secondary_fixed** (str) - The color for text/icons on the fixed secondary color. - **on_secondary_fixed_variant** (str) - The color for text/icons on the fixed secondary variant. - **tertiary_fixed** (str) - The fixed tertiary color. - **tertiary_fixed_dim** (str) - The dimmed fixed tertiary color. - **on_tertiary_fixed** (str) - The color for text/icons on the fixed tertiary color. - **on_tertiary_fixed_variant** (str) - The color for text/icons on the fixed tertiary variant. ``` -------------------------------- ### get_contrast_ratio Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Calculates and returns the contrast ratio between two specified hex color values. This is useful for accessibility checks. ```APIDOC ## get_contrast_ratio(color1: str, color2: str) -> float ### Description Returns the contrast ratio of two colors. ### Parameters #### Path Parameters - **color1** (str) - Required - The first hex color value (e.g., `#4285F4`). - **color2** (str) - Required - The second hex color value (e.g., `#FFFFFF`). ### Returns #### Success Response - **return_value** (float) - A float representing the contrast ratio between the two colors. ``` -------------------------------- ### C++: Convert sRGB to Cam16 Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert an ARGB integer to a Cam16 color representation. Requires CamFromInt function. ```cpp CamFromInt(argb) ``` -------------------------------- ### C++: Convert Cam16 to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert a Cam16 color representation back to an ARGB integer. Requires IntFromCam function. ```cpp IntFromCam(cam) ``` -------------------------------- ### Dart: Convert XYZ to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `ColorUtils.argbFromXyz` to convert XYZ color components back to an ARGB integer. Requires the ColorUtils class. ```dart ColorUtils.argbFromXyz(x, y, z) ``` -------------------------------- ### Dart: Convert L*a*b* to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `ColorUtils.argbFromLab` to convert L*a*b* color components back to an ARGB integer. Requires the ColorUtils class. ```dart ColorUtils.argbFromLab(l, a, b) ``` -------------------------------- ### Dart: Convert sRGB to L*a*b* Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `ColorUtils.labFromArgb` to convert an ARGB integer color to its L*a*b* representation. Requires the ColorUtils class. ```dart ColorUtils.labFromArgb(argb) ``` -------------------------------- ### Dart: Construct Cam16 from UCS Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Create a Cam16 color object from its UCS (J*, a*, b*) components. Requires the Cam16 class. ```dart Cam16.fromUcs(jstar, astar, bstar) ``` -------------------------------- ### Quantize Pixels to Prominent Colors Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/extracting_colors.md Quantizes an array of pixels into a limited number of prominent colors. The maxColors parameter limits the output. A default of 128 is recommended. ```dart final quantizerResult = await QuantizerCelebi.quantize(pixels, maxColors); ``` ```java QuantizerResult quantizerResult = QuantizerCelebi.quantize(pixels, maxColors); ``` ```typescript const quantizerResult = QuantizerCelebi.quantize(pixels, maxColors); ``` ```cpp QuantizerResult quantizer_result = QuantizeCelebi(pixels, max_colors); ``` ```swift let quantizerResult = QuantizerCelebi().quantize(pixels, maxColors) ``` -------------------------------- ### Dart: Obtain Contrasting Tones Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/refining_contrast.md Use `darker` and `lighter` to find tones with a specific contrast ratio. The 'unsafe' variants may return colors without guaranteeing contrast. ```dart final original = ColorUtils.lstarFromArgb(0xFF00AA00); // 60.56 final darker = Contrast.darker(original, 3.0); // 29.63 final lighter = Contrast.lighter(original, 3.0); // 98.93 final darkerUnsafe = Contrast.darkerUnsafe(original, 3.0); // 29.63 final lighterUnsafe = Contrast.lighterUnsafe(original, 3.0); // 98.93 final darker = Contrast.darker(original, 7.0); // -1.0 final lighter = Contrast.lighter(original, 7.0); // -1.0 final darkerUnsafe = Contrast.darkerUnsafe(original, 7.0); // 0.0 final lighterUnsafe = Contrast.lighterUnsafe(original, 7.0); // 100.0 ``` -------------------------------- ### C++: Convert linRGB to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert linear RGB color components to an ARGB integer representing sRGB. Requires ArgbFromLinrgb function. ```cpp ArgbFromLinrgb(linrgb) ``` -------------------------------- ### C++: Convert HCT to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert an HCT color object back to an ARGB integer. Requires the Hct class. ```cpp Hct::ToInt() ``` -------------------------------- ### Convert ARGB Color to HEX Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Convert an ARGB integer representation of a color back into its hexadecimal string format. ```python hex_color = hex_from_argb(0xFF4285F4) print(hex_color) # Outputs: "#4285f4" ``` -------------------------------- ### TypeScript: Convert linRGB to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `colorUtils.argbFromLinrgb` to convert linear RGB color components to an ARGB integer representing sRGB. Requires the colorUtils object. ```typescript colorUtils.argbFromLinrgb(linrgb) ``` -------------------------------- ### Dart: Convert sRGB to XYZ Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `ColorUtils.xyzFromArgb` to convert an ARGB integer color to its XYZ representation. Requires the ColorUtils class. ```dart ColorUtils.xyzFromArgb(argb) ``` -------------------------------- ### Dart: Convert XYZ to Cam16 Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert XYZ color components to Cam16 within specified viewing conditions. Requires the Cam16 class. ```dart Cam16.fromXyzInViewingConditions(x, y, z, vc) ``` -------------------------------- ### hex_from_argb Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Returns the hexadecimal representation of a color from its ARGB integer value. This is the inverse of `argb_from_hex`. ```APIDOC ## hex_from_argb(argb: int) -> str ### Description Returns the hexadecimal representation of a color. ### Parameters #### Path Parameters - **argb** (int) - Required - An integer representing the ARGB color value (e.g., `0xFF4285F4`). ### Returns #### Success Response - **return_value** (str) - A string representing the hex color code (e.g., `"#4285f4"`). ``` -------------------------------- ### Dart: Construct Cam16 from JCH Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Create a Cam16 color object from its JCH (J, C, H) components. Requires the Cam16 class. ```dart Cam16.fromJch(j, c, h) ``` -------------------------------- ### Dart: Convert sRGB to Cam16 Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `Cam16.fromInt` to convert an ARGB integer to a Cam16 color. Requires the Cam16 class. ```dart Cam16.fromInt(argb) ``` -------------------------------- ### Dart: Convert sRGB to HCT Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `Hct.fromInt` to convert an ARGB integer to an HCT color. Requires the HCT class. ```dart Hct.fromInt(argb) ``` -------------------------------- ### Obtain Primary Color from Scheme Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/creating_color_scheme.md Retrieve the primary color from a generated scheme in either ARGB or HCT format. The alternative method shows how to access specific Material Dynamic Colors. ```Dart final argb = scheme.primary; ``` ```Dart final argb = MaterialDynamicColors.primary.getArgb(scheme); final hct = MaterialDynamicColors.primary.getHct(scheme); ``` ```Java int argb = scheme.getPrimary(); ``` ```Java MaterialDynamicColors materialDynamicColors = new MaterialDynamicColors(); int argb = materialDynamicColors.primary().getArgb(scheme); Hct hct = materialDynamicColors.primary().getHct(scheme); ``` ```TypeScript const argb = scheme.primary; ``` ```TypeScript const argb = MaterialDynamicColors.primary.getArgb(scheme); const hct = MaterialDynamicColors.primary.getHct(scheme); ``` ```C++ Argb argb = MaterialDynamicColors::Primary().GetArgb(s); Hct hct = MaterialDynamicColors::Primary().GetHct(s); ``` ```Swift let argb = scheme.primary ``` ```Swift let argb = MaterialDynamicColors.primary.getArgb(scheme) let hct = MaterialDynamicColors.primary.getHct(scheme) ``` -------------------------------- ### Convert HEX Color to ARGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Convert a hexadecimal color string (e.g., '#4285f4') into its ARGB integer representation. ```python argb = argb_from_hex("#4285f4") print(argb) # Outputs: 4286017588 (0xFF4285F4) ``` -------------------------------- ### Dart: Convert linRGB to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `ColorUtils.argbFromLinrgb` to convert linear RGB color components to an ARGB integer representing sRGB. Requires the ColorUtils class. ```dart ColorUtils.argbFromLinrgb(linrgb) ``` -------------------------------- ### Dart: Convert HCT to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `Hct.from(h, c, t).toInt()` to convert HCT color components (hue, chroma, tone) back to an ARGB integer. Requires the HCT class. ```dart Hct.from(h, c, t).toInt() ``` -------------------------------- ### Dart: Convert Cam16 to XYZ Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Convert a Cam16 color object to XYZ components within specified viewing conditions. Requires the Cam16 class. ```dart cam16.xyzInViewingConditions(vc) ``` -------------------------------- ### Extract Prominent Colors from Image Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/README.md Extract a specified number of prominent colors from an image. The function handles image conversion and resizing for efficiency. The output is a list of colors. ```python from PIL import Image image = Image.open("path/to/image.jpg") colors = prominent_colors_from_image(image, 5) print(colors) # Outputs a list of up to 5 prominent colors ``` -------------------------------- ### argb_from_hex Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Converts a hex color code string to its ARGB representation. This function is useful for standardizing color formats within the library. ```APIDOC ## argb_from_hex(hex: str) -> int ### Description Converts a hex color code string to its ARGB representation. ### Parameters #### Path Parameters - **hex** (str) - Required - A string representing the hex color code (e.g., `"#4285f4"`). ### Returns #### Success Response - **return_value** (int) - An integer representing the ARGB color value (e.g., `0xFF4285F4`). ``` -------------------------------- ### Score Prominent Colors for Scheme Seeding (Dart) Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/extracting_colors.md Ranks prominent colors by suitability for use as seeds in color schemes. This method uses the color counts from the quantization result. ```dart final colors = Score.score(quantizerResult.colorToCount); ``` ```java List colors = Score.score(quantizerResult); ``` ```typescript final colors = Score.score(quantizerResult); ``` ```cpp std::vector colors = RankedSuggestions(quantizer_result.color_to_count); ``` ```swift let colors = Score.score(quantizerResult.colorToCount) ``` -------------------------------- ### prominent_colors_from_image Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/docs/api.md Extracts a list of prominent hex color codes from a given PIL Image object. The image is processed internally for optimal results. ```APIDOC ## prominent_colors_from_image(image: PIL.Image.Image, max_colors: int = 128) -> list[str] ### Description Returns the prominent colors from a PIL image. ### Parameters #### Path Parameters - **image** (PIL.Image.Image) - Required - PIL Image (this will be converted to RGBA and resized to fit in 128x128 by the package) - **max_colors** (int) - Optional - An optional integer specifying the maximum number of colors to return (default is `128`). ### Returns #### Success Response - **return_value** (list[str]) - A list of hex colors representing the prominent colors. ``` -------------------------------- ### Dart: Convert Cam16 to sRGB Source: https://github.com/ruurdbijlsma/material-color-utilities/blob/main/concepts/color_spaces.md Use `cam16.toInt()` to convert a Cam16 color object back to an ARGB integer. Requires the Cam16 class. ```dart cam16.toInt() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.