Search Shortcut cmd + k | ctrl + k

duckfn_palette

SQL functions wrapping the Rust palette, csscolorparser and colorous color crates — 44 color spaces, conversion, blending, contrast, CSS, CAM16

Maintainer(s): shijianjs

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.4.4 1.4.5 1.5.5 1.5.6 2.0.0
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

Installing and Loading

INSTALL duckfn_palette FROM community;
LOAD duckfn_palette;

Example

-- A color is one STRUCT, so it can live in a column
SELECT plt_to_hex(plt_convert(plt_srgb(1, 0.5, 0), 'oklch'));
-- #ff8000

SELECT plt_to_hex(plt_mix(plt_named('red'), plt_named('blue'), 0.5));
-- #800080

SELECT plt_contrast(plt_named('white'), plt_named('black'));
-- 21.0

About duckfn_palette

Documentation: user guide · function reference - installation, every function with a runnable example, and the NULL / error rules.

duckfn_palette wraps three Rust color crates with SQL functions: palette for 44 color spaces, conversion, blending and compositing, color-difference metrics and WCAG contrast, color schemes, white points, chromatic adaptation, transfer functions, 3x3 matrices, CAM16 with custom viewing conditions and 8-bit packing; csscolorparser for CSS Color Level 4 strings; and colorous for the d3-scale-chromatic gradients and categorical palettes. Together they register 160 functions under the plt_ prefix.

A color is a single STRUCT, so it can be stored in a column and compared like any other value:

STRUCT(space VARCHAR, c1 DOUBLE, c2 DOUBLE, c3 DOUBLE, alpha DOUBLE)

Every space has a constructor of its own name, with components in palette's Color::new order:

Function Kind Input -> output
plt_srgb(r, g, b) scalar three DOUBLE -> plt_color
plt_convert(color, space) scalar plt_color, VARCHAR -> plt_color
plt_mix(a, b, factor) scalar two plt_color + DOUBLE -> plt_color
plt_difference(a, b, metric[, space]) scalar DOUBLE
plt_contrast(a, b) scalar DOUBLE (WCAG 2.1 ratio, 1..21)
plt_css_serialize(color, format) scalar plt_color, VARCHAR -> VARCHAR

NULL semantics are uniform: a NULL argument gives NULL, and anything palette cannot compute gives NULL too - never NaN and never 0. A rejected argument fails the statement with a message that starts with the function name (plt_convert: unknown color space 'nope'). Space, mode, metric and white-point names are case-insensitive and treat hyphens and spaces as underscores. Operations that palette defines only for certain spaces (saturation needs a hue space, blend modes an RGB-like one) fail with a hint to convert first.

Requires DuckDB 1.4 or newer: the extension is built for DuckDB 2.0.0 but declares the C API floor it needs (v1.2.0), so one binary loads into 1.4.x, 1.5.x and 2.0.0 alike - the C API is binary compatible across these versions, so the 2.0 release asset is the one to install on all of them and there is no separate 1.5 build. Development notes and the full function table live in the repository: https://github.com/shijianjs/duckfn-palette.

Added Functions

function_name function_type description comment examples
plt_adaptation_matrix scalar The 3x3 matrix adapting XYZ values from a source white point to a target one, row-major NULL [SELECT plt_adaptation_matrix('a', 'c', 'bradford')]
plt_adaptation_methods scalar Every supported chromatic adaptation method (bradford, von_kries, unit_matrix) NULL [SELECT plt_adaptation_methods()]
plt_adobe_rgb scalar Adobe RGB (1998) color: red, green, blue in 0..1 NULL [SELECT plt_adobe_rgb(1, 0, 0)]
plt_adobe_rgb_linear scalar Linear-light Adobe RGB color: red, green, blue in 0..1 NULL [SELECT plt_adobe_rgb_linear(1, 0, 0)]
plt_alpha scalar The alpha channel of a color (0 transparent, 1 opaque) NULL [SELECT plt_alpha(plt_color('srgb', 1, 0, 0, 0.25))]
plt_analogous scalar The two analogous colors (hue - 30 and + 30 degrees) of a color NULL [SELECT plt_analogous(plt_hsl(120, 1, 0.5))]
plt_analogous_secondary scalar The next two analogous colors (hue - 60 and + 60 degrees) of a color NULL [SELECT plt_analogous_secondary(plt_hsl(120, 1, 0.5))]
plt_apply_matrix scalar Apply a 3x3 matrix to a color's three components in its current space (the space tag is kept) NULL [SELECT plt_apply_matrix(plt_adaptation_matrix('d65', 'd50', 'bradford'), plt_xyz(0.5, 0.4, 0.3))]
plt_blend scalar Blend a source color onto a destination color with a separable mode (multiply, screen, overlay, darken, lighten, dodge, burn, hard_light, soft_light, difference, exclusion) NULL [SELECT plt_blend(plt_srgb(0.5, 0.2, 0.1), plt_srgb(0.4, 0.6, 0.8), 'multiply')]
plt_blend_equations scalar Blend a source color onto a destination color with OpenGL-style source/destination factors (zero, one, source_color, one_minus_source_color, destination_color, one_minus_destination_color, source_alpha, one_minus_source_alpha, destination_alpha, one_minus_destination_alpha) NULL [SELECT plt_blend_equations(plt_with_alpha(plt_srgb(1, 0, 0), 0.5), plt_with_alpha(plt_srgb(0, 0, 1), 0.5), 'source_alpha', 'one_minus_source_alpha')]
plt_blend_modes scalar All supported blend mode names, as accepted by plt_blend NULL [SELECT plt_blend_modes()]
plt_blend_parameters scalar All supported blend factor names, as accepted by plt_blend_equations NULL [SELECT plt_blend_parameters()]
plt_brighten scalar Brighten by adding an amount (0..1 of the channel range) to every sRGB channel, clamped, and converting back to the input space NULL [SELECT plt_brighten(plt_srgb(0.2, 0.3, 0.4), 0.1)]
plt_brightness scalar YIQ brightness (0 black .. 1 white) from the sRGB channels, clamped to 0..1; alpha is ignored NULL [SELECT plt_brightness(plt_srgb(0.2, 0.6, 0.9))]
plt_cam16_default_params scalar palette's default CAM16 viewing conditions (D65, La = 40, Yb = 0.2, average surround, auto discounting) NULL [SELECT plt_cam16_default_params()]
plt_cam16_from_xyz scalar Convert an xyz color into the full CAM16 attributes (lightness, chroma, hue, brightness, colorfulness, saturation) under custom viewing conditions NULL [SELECT plt_cam16_from_xyz(plt_xyz(0.4, 0.3, 0.2), plt_cam16_default_params())]
plt_cam16_jch scalar CAM16 (J, C, h) under palette's default viewing conditions: lightness, chroma, hue in degrees NULL [SELECT plt_cam16_jch(50, 40, 120)]
plt_cam16_jmh scalar CAM16 (J, M, h) under default viewing conditions: lightness, colorfulness, hue in degrees NULL [SELECT plt_cam16_jmh(50, 40, 120)]
plt_cam16_jsh scalar CAM16 (J, s, h) under default viewing conditions: lightness, saturation, hue in degrees NULL [SELECT plt_cam16_jsh(50, 40, 120)]
plt_cam16_params scalar CAM16 viewing conditions from a named white point with a custom discounting factor (0..1), instead of auto NULL [SELECT plt_cam16_params('d65', 40, 0.2, 'dim', 0.9); SELECT plt_cam16_params('d65', 40, 0.2, 'average')]
plt_cam16_params_xyz scalar CAM16 viewing conditions from a custom white point XYZ with a custom discounting factor (0..1) NULL [SELECT plt_cam16_params_xyz(0.95047, 1, 1.08883, 40, 0.2, 'average', 0.8); SELECT plt_cam16_params_xyz(0.95047, 1, 1.08883, 40, 0.2, 'average')]
plt_cam16_partial_from_xyz scalar Convert an xyz color into a partial CAM16 space (cam16_jch, cam16_jmh, cam16_jsh, cam16_qch, cam16_qmh, cam16_qsh, cam16_ucs_jab, cam16_ucs_jmh) under custom viewing conditions NULL [SELECT plt_cam16_partial_from_xyz(plt_xyz(0.4, 0.3, 0.2), 'cam16_jch', plt_cam16_default_params())]
plt_cam16_partial_to_xyz scalar Convert a partial CAM16 color (cam16_jch etc.) back into an xyz color under custom viewing conditions NULL [SELECT plt_cam16_partial_to_xyz(plt_cam16_jch(50, 40, 120), plt_cam16_default_params())]
plt_cam16_qch scalar CAM16 (Q, C, h) under default viewing conditions: brightness, chroma, hue in degrees NULL [SELECT plt_cam16_qch(50, 40, 120)]
plt_cam16_qmh scalar CAM16 (Q, M, h) under default viewing conditions: brightness, colorfulness, hue in degrees NULL [SELECT plt_cam16_qmh(50, 40, 120)]
plt_cam16_qsh scalar CAM16 (Q, s, h) under default viewing conditions: brightness, saturation, hue in degrees NULL [SELECT plt_cam16_qsh(50, 40, 120)]
plt_cam16_spaces scalar Every CAM16 space that can be produced with custom viewing conditions NULL [SELECT plt_cam16_spaces()]
plt_cam16_surrounds scalar The named CAM16 surround presets (dark, dim, average) and their percentages NULL [SELECT plt_cam16_surrounds()]
plt_cam16_to_xyz scalar Convert the full CAM16 attributes back into an xyz color under custom viewing conditions NULL [SELECT plt_cam16_to_xyz(plt_cam16_from_xyz(plt_xyz(0.4, 0.3, 0.2), plt_cam16_default_params()), plt_cam16_default_params())]
plt_cam16_ucs_jab scalar CAM16-UCS (J', a', b') under default viewing conditions NULL [SELECT plt_cam16_ucs_jab(50, 20, -30)]
plt_cam16_ucs_jmh scalar CAM16-UCS (J', M', h) under default viewing conditions: lightness, colorfulness, hue in degrees NULL [SELECT plt_cam16_ucs_jmh(50, 40, 120)]
plt_chromatic_adapt scalar Adapt an xyz color from a source white point to a target white point (the color's components are XYZ under the source) NULL [SELECT plt_chromatic_adapt(plt_xyz(0.315756, 0.162732, 0.015905), 'a', 'c', 'bradford'); SELECT plt_chromatic_adapt(plt_xyz(0.5, 0.4, 0.3), 'd50', 'bradford')]
plt_clamp scalar Clamp a color's components to its own space's standard range NULL [SELECT plt_components(plt_clamp(plt_lab(50, 200, 200)))]
plt_color scalar Build a color in any supported space from a space name, three components and an alpha value NULL [SELECT plt_color('oklch', 0.7, 0.1, 120, 0.5); SELECT plt_color('lab', 50, 20, -30)]
plt_color_schemes scalar All supported color theory scheme names, as accepted by plt_harmony NULL [SELECT plt_color_schemes()]
plt_color_spaces scalar All supported color space names, as accepted by plt_convert and plt_color NULL [SELECT plt_color_spaces()]
plt_colorous_categorical scalar A whole colorous categorical palette, as a LIST of sRGB colors NULL [SELECT plt_colorous_categorical('tableau10')]
plt_colorous_categoricals scalar Every colorous categorical palette name NULL [SELECT plt_colorous_categoricals()]
plt_colorous_gradient scalar Sample a colorous gradient at position t (clamped to [0, 1]), as an sRGB color NULL [SELECT plt_colorous_gradient('viridis', 0.5)]
plt_colorous_palette scalar n colors evenly sampled from a colorous gradient, as a LIST of sRGB colors; n must be at least 1 NULL [SELECT plt_colorous_palette('plasma', 5)]
plt_colorous_palettes scalar Every colorous continuous gradient name (sequential, diverging and cyclical) NULL [SELECT plt_colorous_palettes()]
plt_complementary scalar The complementary color (hue + 180 degrees) of a color; the color must have a hue NULL [SELECT plt_complementary(plt_hsl(120, 1, 0.5))]
plt_component scalar One component of a color by 1-based index (1..3) NULL [SELECT plt_component(plt_srgb(0.1, 0.2, 0.3), 2)]
plt_components scalar The three components of a color as a LIST(DOUBLE), in the space's natural order NULL [SELECT plt_components(plt_srgb(0.1, 0.2, 0.3))]
plt_compose scalar Composite a source color with a destination color using a Porter-Duff operator (over, inside, outside, atop, xor, plus) NULL [SELECT plt_compose(plt_with_alpha(plt_srgb(1, 0, 0), 0.5), plt_with_alpha(plt_srgb(0, 0, 1), 0.5), 'over')]
plt_compose_modes scalar All supported composition operator names, as accepted by plt_compose NULL [SELECT plt_compose_modes()]
plt_contrast scalar WCAG 2.1 relative contrast ratio between two colors (1 to 21), computed by converting both to sRGB NULL [SELECT plt_contrast(plt_srgb(1, 1, 1), plt_srgb(0, 0, 0))]
plt_contrast_check scalar Whether two colors meet a WCAG 2.1 contrast criterion (min_text, min_large_text, enhanced_text, enhanced_large_text, min_graphics) NULL [SELECT plt_contrast_check(plt_srgb(1, 1, 1), plt_srgb(0, 0, 0), 'min_text')]
plt_contrast_criteria scalar All supported WCAG 2.1 contrast criterion names, as accepted by plt_contrast_check NULL [SELECT plt_contrast_criteria()]
plt_convert scalar Convert a color to another space without gamut clamping (palette's unclamped conversion) NULL [SELECT plt_components(plt_convert(plt_srgb(1, 0, 0), 'lab'))]
plt_convert_clamped scalar Convert a color to another space, then clamp the result to that space's standard range NULL [SELECT plt_components(plt_convert_clamped(plt_lab(50, 200, 200), 'srgb'))]
plt_css_formats scalar All supported CSS serialization format names, as accepted by plt_css_serialize NULL [SELECT plt_css_formats()]
plt_css_is_valid scalar Whether a string is a valid CSS Color Level 4 color NULL [SELECT plt_css_is_valid('#ff0000')]
plt_css_name scalar The CSS keyword name of a color when its sRGB bytes match a named color exactly, or NULL NULL [SELECT plt_css_name(plt_srgb(1, 0, 0))]
plt_css_parse scalar Parse a CSS Color Level 4 string (named colors, #rgb/#rrggbb/#rrggbbaa, rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), color(…)) into an sRGB color; NULL when unparsable NULL [SELECT plt_css_parse('hsl(120 100% 50% / 0.5)')]
plt_css_serialize scalar Serialize a color into CSS syntax (format: hex, rgb, hsl, hwb, lab, lch, oklab, oklch) NULL [SELECT plt_css_serialize(plt_srgb(1, 0, 0), 'oklch')]
plt_darken scalar Darken a color by scaling its lightness towards the minimum (factor 0..1) NULL [SELECT plt_darken(plt_hsv(0, 1, 0.5), 0.5)]
plt_darken_fixed scalar Darken a color by an absolute amount of its lightness range (amount 0..1) NULL [SELECT plt_darken_fixed(plt_hsv(0, 1, 0.4), 0.2)]
plt_dci_p3 scalar DCI-P3 color (DCI-P3 white point, gamma 2.6): red, green, blue in 0..1 NULL [SELECT plt_dci_p3(1, 0, 0)]
plt_dci_p3_linear scalar Linear-light DCI-P3 color: red, green, blue in 0..1 NULL [SELECT plt_dci_p3_linear(1, 0, 0)]
plt_decode scalar Decode one encoded component value into linear light using the space's transfer function NULL [SELECT plt_decode('srgb', 0.5)]
plt_desaturate scalar Decrease saturation or chroma by scaling towards the minimum (factor 0..1) NULL [SELECT plt_desaturate(plt_hsl(0, 0.5, 0.5), 0.5)]
plt_desaturate_fixed scalar Decrease saturation or chroma by an absolute amount (amount 0..1) NULL [SELECT plt_desaturate_fixed(plt_hsl(0, 0.4, 0.5), 0.2)]
plt_diagonal_adaptation_matrix scalar The diagonal LMS gain matrix between two white points, to be used between plt_lms_matrix and plt_lms_to_xyz_matrix NULL [SELECT plt_diagonal_adaptation_matrix('a', 'c', 'bradford')]
plt_difference scalar Color difference between two colors with a metric, computed in the given color space NULL [SELECT plt_difference(plt_srgb(1, 0, 0), plt_srgb(0, 1, 0), 'euclidean', 'oklab'); SELECT plt_difference(plt_lab(50, 2.6772, -79.7751), plt_lab(50, 0, -82.7485), 'ciede2000')]
plt_difference_metrics scalar All supported color difference metric names, as accepted by plt_difference NULL [SELECT plt_difference_metrics()]
plt_display_p3 scalar Display P3 color (D65, sRGB transfer function): red, green, blue in 0..1 NULL [SELECT plt_display_p3(1, 0, 0)]
plt_display_p3_linear scalar Linear-light Display P3 color: red, green, blue in 0..1 NULL [SELECT plt_display_p3_linear(1, 0, 0)]
plt_encode scalar Encode one linear component value with the space's transfer function NULL [SELECT plt_encode('srgb', 0.21404114)]
plt_encoding_spaces scalar Spaces that have a transfer function (RGB spaces plus luma), as accepted by plt_decode and plt_encode NULL [SELECT plt_encoding_spaces()]
plt_equals scalar Whether two colors render as the same 8-bit sRGB value and alpha (rounded to two decimals), regardless of their spaces NULL [SELECT plt_equals(plt_srgb(1, 0, 0), plt_hsl(0, 1, 0.5))]
plt_from_components scalar Build a color from a space name and a LIST(DOUBLE) of exactly three components NULL [SELECT plt_from_components('lab', [50, 20, -30])]
plt_from_components_alpha scalar Build a color from a space name and a LIST(DOUBLE) of exactly four values (three components plus alpha) NULL [SELECT plt_from_components_alpha('lab', [50, 20, -30, 0.5])]
plt_from_hex scalar Parse a hexadecimal color (#rgb, #rgba, #rrggbb, #rrggbbaa, with or without '#') using palette's hex parser; NULL when invalid NULL [SELECT plt_from_hex('#ff800080')]
plt_greyscale scalar Greyscale a color by dropping its HSL saturation to zero, returning to the input space NULL [SELECT plt_greyscale(plt_srgb(1, 0, 0))]
plt_harmony scalar The other colors of a color theory scheme by name (complementary, split_complementary, analogous, analogous_secondary, triadic, tetradic) NULL [SELECT plt_harmony(plt_oklch(0.7, 0.1, 120), 'triadic')]
plt_hsl scalar HSL color: hue in degrees, saturation 0..1, lightness 0..1 (sRGB primaries) NULL [SELECT plt_hsl(120, 0.5, 0.5)]
plt_hsluv scalar HSLuv color (D65): hue in degrees, saturation 0..100, lightness 0..100 NULL [SELECT plt_hsluv(120, 50, 50)]
plt_hsv scalar HSV color: hue in degrees, saturation 0..1, value 0..1 (sRGB primaries) NULL [SELECT plt_hsv(120, 0.5, 0.5)]
plt_hue scalar The hue of a color in degrees (0..360); gray colors report 0 NULL [SELECT plt_hue(plt_srgb(1, 0, 0))]
plt_hwb scalar HWB color: hue in degrees, whiteness 0..1, blackness 0..1 (sRGB primaries) NULL [SELECT plt_hwb(120, 0.2, 0.2)]
plt_is_dark scalar Whether a color is dark by tinycolor's YIQ rule (brightness < 128/255); alpha is ignored NULL [SELECT plt_is_dark(plt_srgb(0, 0, 0))]
plt_is_light scalar Whether a color is light by tinycolor's YIQ rule (brightness >= 128/255); alpha is ignored NULL [SELECT plt_is_light(plt_srgb(1, 1, 1))]
plt_is_within_bounds scalar Whether all components of a color are already within its space's standard range NULL [SELECT plt_is_within_bounds(plt_lab(50, 200, 200))]
plt_lab scalar CIELAB color (D65): L* 0..100, a, b roughly -128..127 NULL [SELECT plt_lab(50, 20, -30)]
plt_lch scalar CIE LCH color (D65): L* 0..100, chroma >= 0, hue in degrees NULL [SELECT plt_lch(50, 40, 120)]
plt_lchuv scalar CIE LCHuv color (D65): L* 0..100, chroma >= 0, hue in degrees (same model as HSLuv) NULL [SELECT plt_lchuv(50, 40, 120)]
plt_lighten scalar Lighten a color by scaling its lightness towards the maximum (factor 0..1) NULL [SELECT plt_lighten(plt_hsl(0, 1, 0.5), 0.5)]
plt_lighten_fixed scalar Lighten a color by an absolute amount of its lightness range (amount 0..1) NULL [SELECT plt_lighten_fixed(plt_hsl(0, 1, 0.4), 0.2)]
plt_lms scalar LMS cone response (Bradford matrix, D65): long, medium, short NULL [SELECT plt_lms(0.5, 0.4, 0.3)]
plt_lms_matrix scalar The XYZ-to-LMS matrix used by an adaptation method, row-major NULL [SELECT plt_lms_matrix('bradford')]
plt_lms_to_xyz_matrix scalar The LMS-to-XYZ matrix used by an adaptation method, row-major NULL [SELECT plt_lms_to_xyz_matrix('bradford')]
plt_lms_von_kries scalar LMS cone response (von Kries / Hunt-Pointer-Estevez matrix, D65): long, medium, short NULL [SELECT plt_lms_von_kries(0.5, 0.4, 0.3)]
plt_luma scalar sRGB-encoded luminance (grayscale) color: one component in 0..1 NULL [SELECT plt_luma(0.5)]
plt_luma_gamma scalar Gamma 2.2 encoded luminance (grayscale) color: one component in 0..1 NULL [SELECT plt_luma_gamma(0.5)]
plt_luma_linear scalar Linear-light luminance (grayscale) color: one component in 0..1 NULL [SELECT plt_luma_linear(0.5)]
plt_luv scalar CIELUV color (D65): L* 0..100, u, v NULL [SELECT plt_luv(50, 20, -30)]
plt_matrix_apply scalar Apply a 3x3 matrix to three numbers, returning LIST(DOUBLE) of 3 NULL [SELECT plt_matrix_apply(plt_matrix_identity(), 1, 2, 3)]
plt_matrix_identity scalar The 3x3 identity matrix, row-major as LIST(DOUBLE) of 9 NULL [SELECT plt_matrix_identity()]
plt_matrix_inverse scalar Invert a 3x3 matrix (row-major LIST(DOUBLE) of 9) NULL [SELECT plt_matrix_inverse(plt_matrix_scale(2, 4, 0.5))]
plt_matrix_multiply scalar Multiply two 3x3 matrices, applying the first and then the second (row-major LIST(DOUBLE) of 9) NULL [SELECT plt_matrix_multiply(plt_matrix_identity(), plt_matrix_scale(2, 2, 2))]
plt_matrix_scale scalar A diagonal 3x3 matrix with the given diagonal entries, row-major NULL [SELECT plt_matrix_scale(0.5, 0.5, 0.5)]
plt_mix scalar Mix two colors by a factor (0 = first, 1 = second) in the first color's space; alpha is mixed too NULL [SELECT plt_mix(plt_oklch(0.6, 0.1, 30), plt_oklch(0.8, 0.1, 200), 0.5)]
plt_monochromatic scalar A monochromatic scheme: count colors with the same hue and saturation, cycling HSV value by 1/count from the input's value; count must be non-negative NULL [SELECT plt_monochromatic(plt_hsv(120, 1, 0.5), 4)]
plt_most_readable scalar The candidate with the highest WCAG contrast ratio against the base color; when none meets the criterion and include_fallback is true, the more contrasting of black and white instead NULL [SELECT plt_most_readable(plt_srgb(1, 1, 1), [plt_srgb(0.9, 0.9, 0.9)], 'min_text', true); SELECT plt_most_readable(plt_srgb(1, 1, 1), [plt_srgb(0.9, 0.9, 0.9)], 'min_text'); SELECT plt_most_readable(plt_srgb(1, 1, 1), [plt_srgb(0, 0, 0), plt_srgb(0.9, 0.9, 0.9)])]
plt_named scalar An SVG/CSS3 named color such as 'rebeccapurple' as an sRGB color, or NULL for an unknown name NULL [SELECT plt_named('rebeccapurple')]
plt_named_names scalar All SVG/CSS3 named color names, sorted alphabetically NULL [SELECT plt_named_names()]
plt_nearest_named scalar The closest SVG/CSS3 named color by CIEDE2000 distance, regardless of exact match; alpha is ignored NULL [SELECT plt_nearest_named(plt_srgb(0.95, 0.05, 0.05))]
plt_okhsl scalar Okhsl color: hue in degrees, saturation 0..1, lightness 0..1 NULL [SELECT plt_okhsl(120, 0.5, 0.5)]
plt_okhsv scalar Okhsv color: hue in degrees, saturation 0..1, value 0..1 NULL [SELECT plt_okhsv(120, 0.5, 0.5)]
plt_okhwb scalar Okhwb color: hue in degrees, whiteness 0..1, blackness 0..1 NULL [SELECT plt_okhwb(120, 0.2, 0.2)]
plt_oklab scalar Oklab color: lightness 0..1, a, b (nominally -1..1) NULL [SELECT plt_oklab(0.5, 0.1, 0.1)]
plt_oklch scalar Oklch color: lightness 0..1, chroma >= 0, hue in degrees NULL [SELECT plt_oklch(0.5, 0.1, 120)]
plt_opaque scalar Make a color fully opaque (alpha = 1) NULL [SELECT plt_alpha(plt_opaque(plt_color('srgb', 1, 0, 0, 0.25)))]
plt_pack scalar Pack a color into a 32-bit ARGB integer after converting to sRGB and quantizing to 8 bits per channel NULL [SELECT plt_pack(plt_srgb(1, 0.5, 0)); SELECT plt_pack(plt_srgb(1, 0.5, 0), 'rgba')]
plt_pack_orders scalar Channel orders accepted by plt_pack and plt_unpack (argb, rgba, abgr, bgra) NULL [SELECT plt_pack_orders()]
plt_premultiply scalar Premultiply a color by its alpha (components multiplied by alpha; alpha must be in 0..1) NULL [SELECT plt_premultiply(plt_with_alpha(plt_srgb(1, 0.5, 0.25), 0.5))]
plt_prophoto_rgb scalar ProPhoto RGB color (D50 white point, gamma 1.8): red, green, blue in 0..1 NULL [SELECT plt_prophoto_rgb(1, 0, 0)]
plt_prophoto_rgb_linear scalar Linear-light ProPhoto RGB color (D50 white point): red, green, blue in 0..1 NULL [SELECT plt_prophoto_rgb_linear(1, 0, 0)]
plt_random_color scalar A reproducible random color in the given space; the BIGINT seed identifies the sequence NULL [SELECT plt_random_color('oklch', 42)]
plt_random_colors scalar A LIST of reproducible random colors from one seeded sequence; count must be non-negative NULL [SELECT plt_random_colors('srgb', 5, 42)]
plt_random_spaces scalar Every color space that can be sampled randomly (palette implements a Standard distribution for it) NULL [SELECT plt_random_spaces()]
plt_rec2020 scalar Rec. 2020 color (D65, Rec. 2020 transfer function): red, green, blue in 0..1 NULL [SELECT plt_rec2020(1, 0, 0)]
plt_rec2020_linear scalar Linear-light Rec. 2020 color: red, green, blue in 0..1 NULL [SELECT plt_rec2020_linear(1, 0, 0)]
plt_rec709 scalar Rec. 709 color (sRGB primaries, Rec. 709 transfer function): red, green, blue in 0..1 NULL [SELECT plt_rec709(1, 0, 0)]
plt_rec709_linear scalar Linear-light Rec. 709 color: red, green, blue in 0..1 NULL [SELECT plt_rec709_linear(1, 0, 0)]
plt_relative_luminance scalar WCAG 2.1 relative luminance of a color (0 is black, 1 is white), computed by converting to sRGB NULL [SELECT plt_relative_luminance(plt_srgb(0.5, 0.5, 0.5))]
plt_rgb_primaries scalar The red, green and blue primaries of an RGB space, as three yxy colors NULL [SELECT plt_rgb_primaries('srgb')]
plt_rgb_to_xyz_matrix scalar The 3x3 RGB-to-XYZ matrix of an RGB space, row-major as LIST(DOUBLE) of 9 NULL [SELECT plt_rgb_to_xyz_matrix('srgb')]
plt_saturate scalar Increase saturation or chroma by scaling towards the maximum (factor 0..1) NULL [SELECT plt_saturate(plt_hsl(0, 0.5, 0.5), 0.5)]
plt_saturate_fixed scalar Increase saturation or chroma by an absolute amount (amount 0..1) NULL [SELECT plt_saturate_fixed(plt_hsl(0, 0.4, 0.5), 0.2)]
plt_shade scalar Shade a color by mixing it towards black in sRGB by amount (0 unchanged, 1 black); alpha is unchanged NULL [SELECT plt_shade(plt_srgb(1, 0, 0), 0.5)]
plt_shift_hue scalar Rotate the hue of a color by degrees (any real number; wraps at 360) NULL [SELECT plt_shift_hue(plt_hsl(120, 1, 0.5), 120)]
plt_space scalar The color space name of a color value (as returned by plt_color_spaces) NULL [SELECT plt_space(plt_srgb(1, 0, 0))]
plt_split_complementary scalar The two split complementary colors (hue + 150 and + 210 degrees) of a color NULL [SELECT plt_split_complementary(plt_hsl(120, 1, 0.5))]
plt_srgb scalar Gamma-encoded sRGB color: red, green, blue in 0..1 NULL [SELECT plt_srgb(1, 0, 0)]
plt_srgb_gamma scalar Gamma 2.2 encoded sRGB color (palette's deprecated GammaSrgb): red, green, blue in 0..1 NULL [SELECT plt_srgb_gamma(1, 0, 0)]
plt_srgb_linear scalar Linear-light sRGB color: red, green, blue in 0..1 NULL [SELECT plt_srgb_linear(1, 0, 0)]
plt_tetradic scalar The three tetradic (square) colors (hue + 90, + 180 and + 270 degrees) of a color NULL [SELECT plt_tetradic(plt_hsl(120, 1, 0.5))]
plt_tint scalar Tint a color by mixing it towards white in sRGB by amount (0 unchanged, 1 white); alpha is unchanged NULL [SELECT plt_tint(plt_srgb(1, 0, 0), 0.5)]
plt_to_hex scalar Format a color as hexadecimal (#rrggbb, or #rrggbbaa when alpha is not 1) by converting to sRGB and quantizing to 8 bits NULL [SELECT plt_to_hex(plt_srgb(1, 0.5, 0))]
plt_to_hex6 scalar Format a color as #rrggbb, always six digits; alpha is ignored NULL [SELECT plt_to_hex6(plt_color('srgb', 1, 0.5, 0, 0.5))]
plt_to_hex8 scalar Format a color as #rrggbbaa, always eight digits (alpha = ff when opaque) NULL [SELECT plt_to_hex8(plt_srgb(1, 0.5, 0))]
plt_to_hsv_string scalar Format a color as hsv(h, s%, v%), or hsva() when alpha is not 1; hue and percentages are rounded like tinycolor NULL [SELECT plt_to_hsv_string(plt_srgb(1, 0, 0))]
plt_to_percentage_rgb scalar Format a color as CSS rgb() with percentages, or rgba() when alpha is not 1; channels and alpha are rounded like tinycolor NULL [SELECT plt_to_percentage_rgb(plt_srgb(1, 0.5, 0))]
plt_transfer_function scalar The transfer function a space uses (linear, gamma_2_2, srgb, adobe_rgb, prophoto_rgb, p3_gamma or rec_oetf) NULL [SELECT plt_transfer_function('srgb')]
plt_transfer_functions scalar Every transfer function name used by the supported spaces NULL [SELECT plt_transfer_functions()]
plt_triadic scalar The two triadic colors (hue + 120 and + 240 degrees) of a color NULL [SELECT plt_triadic(plt_hsl(120, 1, 0.5))]
plt_unpack scalar Unpack a 32-bit integer in the given channel order into an sRGB color NULL [SELECT plt_unpack(4278190335, 'rgba'); SELECT plt_unpack(4294901760)]
plt_unpremultiply scalar Undo premultiplication (components divided by alpha; zero alpha yields zero components) NULL [SELECT plt_unpremultiply(plt_premultiply(plt_with_alpha(plt_srgb(1, 0.5, 0.25), 0.5)))]
plt_white_point_of scalar The white point a color space is defined against (e.g. d65 for srgb, d50 for prophoto_rgb) NULL [SELECT plt_white_point_of('prophoto_rgb')]
plt_white_point_xy scalar The chromaticity coordinates (x, y) of a white point, as LIST(DOUBLE) of 2 NULL [SELECT plt_white_point_xy('d50')]
plt_white_point_xyz scalar The tristimulus values (X, Y, Z) of a white point, as LIST(DOUBLE) of 3 with Y = 1 NULL [SELECT plt_white_point_xyz('d65')]
plt_white_points scalar Every supported white point name (CIE illuminants plus the DCI-P3 theatre white) NULL [SELECT plt_white_points()]
plt_with_alpha scalar Set the alpha channel of a color, leaving space and components unchanged NULL [SELECT plt_alpha(plt_with_alpha(plt_srgb(1, 0, 0), 0.5))]
plt_with_hue scalar Set the hue of a color to the given degrees NULL [SELECT plt_with_hue(plt_hsl(120, 1, 0.5), 240)]
plt_xyz scalar CIE XYZ color with D65 white point: X, Y, Z NULL [SELECT plt_xyz(0.5, 0.4, 0.3)]
plt_xyz_d50 scalar CIE XYZ color with D50 white point: X, Y, Z (conversions adapt to/from D65 with Bradford) NULL [SELECT plt_xyz_d50(0.5, 0.4, 0.3)]
plt_xyz_to_rgb_matrix scalar The 3x3 XYZ-to-RGB matrix of an RGB space (the inverse of plt_rgb_to_xyz_matrix), row-major NULL [SELECT plt_xyz_to_rgb_matrix('srgb')]
plt_yxy scalar CIE xyY color (D65): chromaticity x, y and luminance Y NULL [SELECT plt_yxy(0.3, 0.3, 0.5)]

Overloaded Functions

This extension does not add any function overloads.

Added Types

type_name type_size logical_type type_category internal
plt_cam16_full 0 STRUCT COMPOSITE false
plt_cam16_params 0 STRUCT COMPOSITE false
plt_color 0 STRUCT COMPOSITE false

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog