DOKK / manpages / debian 12 / libgraphics-toolkit-color-perl / Graphics::Toolkit::Color::Value.3pm.en
Graphics::Toolkit::Color::Value(3pm) User Contributed Perl Documentation Graphics::Toolkit::Color::Value(3pm)

Graphics::Toolkit::Color::Value - check, convert and measure color values

    use Graphics::Toolkit::Color::Value;         # import nothing
    use Graphics::Toolkit::Color::Value ':all';  # import all routines
    
    check_rgb( 256, 10, 12 ); # throws error 255 is the limit
    my @hsl = hsl_from_rgb( 20, 50, 70 ); # convert from RGB to HSL space

A set of helper routines to handle RGB and HSL values: bound checks, conversion, measurement. Most subs expect three numerical values, or sometimes two triplet. This module is supposed to be used by Graphics::Toolkit::Color and not directly.

Carp error message if RGB value triplet is not valid (or out of value range).

Carp error message if HSL value triplet is not valid (or out of value range).

Change RGB triplet to the nearest valid values.

Change HSL triplet to the nearest valid values.

Converting an rgb value triplet into the corresponding hsl

Red, Green and Blue are integer in 0 .. 255. Hue is an integer between 0 .. 359 (hue) and saturation and lightness are 0 .. 100 (percentage). A hue of 360 and 0 (degree in a cylindrical coordinate system) is considered to be the same, this modul deals only with the ladder.

Converting an hsl value triplet into the corresponding rgb (see rgb_from_name and hsl_from_name). Please not that back and forth conversion can lead to drifting results due to rounding.

    my @rgb = rgb_from_hsl( 0, 90, 50 );
    my @rgb = rgb_from_hsl( [0, 90, 50] ); # works too
    # for real (none integer results), any none zero value works as second arg 
    my @rgb = rgb_from_hsl( [0, 90, 50], 'real');

Converts a red green blue triplet into format: '#RRGGBB'.

Converts '#RRGGBB' or '#RGB' hex values into regular RGB triple of 0..255.

Distance in (linear) rgb color space between two coordinates.

    my $d = distance_rgb([1,1,1], [2,2,2]);  # approx 1.7

Distance in (cylindrical) hsl color space between two coordinates.

    my $d = distance_rgb([1,1,1], [356, 3, 2]); # approx 6

Copyright 2022 Herbert Breunung.

This program is free software; you can redistribute it and/or modify it under same terms as Perl itself.

Herbert Breunung, <lichtkind@cpan.org>

2023-01-30 perl v5.36.0