---
name: "Graphics::Toolkit::Color::Value"
section: "3pm"
platform: "linux"
package: "libgraphics-toolkit-color-perl"
version: "1.08-1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/Graphics::Toolkit::Color::Value"
---

# Graphics::Toolkit::Color::Value(3pm)

check, convert and measure color values

## NAME

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

## SYNOPSIS

```
    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
```

## DESCRIPTION

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.

## ROUTINES

### check\_rgb

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

### check\_hsl

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

### trim\_rgb

Change RGB triplet to the nearest valid values.

### trim\_hsl

Change HSL triplet to the nearest valid values.

### hsl\_from\_rgb

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.

### rgb\_from\_hsl

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');
```

### hex\_from\_rgb

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

### rgb\_from\_hex

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

### distance\_rgb

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

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

### distance\_hsl

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

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

## COPYRIGHT & LICENSE

Copyright 2022 Herbert Breunung.

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

## AUTHOR

Herbert Breunung, \<lichtkind@cpan.org\>
