Graphics-Toolkit-Color

 view release on metacpan or  search on metacpan

lib/Graphics/Toolkit/Color/Space/Hub.pm  view on Meta::CPAN


    use Graphics::Toolkit::Color::Space::Hub;
    my $true = Graphics::Toolkit::Color::Space::Hub::is_space( 'HSL' );
    my $HSL = Graphics::Toolkit::Color::Space::Hub::get_space( 'HSL');
    my $RGB = Graphics::Toolkit::Color::Space::Hub::default_space();

    Graphics::Toolkit::Color::Space::Hub::space_names();     # all space names and aliases

    $HSL->normalize([240,100, 0]);         # 2/3, 1, 0
    $HSL->convert([240, 100, 0], 'RGB');   #   0, 0, 1
    $HSL->deconvert([0, 0, 1], 'RGB');     # 2/3, 1, 0
    $RGB->denormalize([0, 0, 1]);          #   0, 0, 255
    $RGB->format([0, 0, 255], 'hex');      #   '#0000ff'

    # [0, 0, 255] , 'RGB'
    my ($values, $space_name) = Graphics::Toolkit::Color::Space::Hub::deformat( '#0000ff' );


=head1 DESCRIPTION

This module is supposed to be used only internally and not directly by
the user, unless he wants to add his own color space. Therefore it exports
no symbols and the methods are much less DWIM then the main module.
But lot of important documentation is still here.


=head1 COLOR SPACES

Up next, a listing of all supported color spaces. These are mathematical
constructs that associate each color with a point inside this space.
The numerical values of a color definition become coordinates along
axis that express different properties. The closer two
colors are along an axis the more similar are they in that property.
All color spaces are finite and only certain value ranges along an
axis are acceptable. Most spaces have 3 dimensions (axis) and are
completely lineary like in Euclidean (everyday) geometry.
A few spaces have more axis and some spaces are cylindrical. That
means that some axis are not lines but circles and the associated value
descibes an angle.

Color definitions contain either the name of a space or the names
of its axis (long or short). If the space name or its long alias is used,
the values have to be provided in the same order as the axis described here.

Color space or axis names may be written in any combination of upper and
lower case characters, but I recommended to use the spelling presented here.
Each axis has also two specific names, one long and one short, which are
in rare cases equal. To define a color according a space you need
to provide for each axis one value, that is inside the required value
range and of a specificed type (int or real with amount of decimals).

While I acknowledge that some of the spaces below should be called systems
to be technically correct, they still will be called spaces here, because
the main goal of this software is seamless interoperabilitiy between them.


=head2 RGB

... is the default color space of this CPAN module. It is used
by most computer hardware like monitors and follows the logic of additive
color mixing as produced by an overlay of three colored light beams.
The sum of all colors will be white, as in opposite to subtractive mixing.
Its is a completely Cartesian (Euclidean) 3D space and thus a RGB tuple
consists of three integer values:

B<red> (short B<r>) range: 0 .. 255, B<green> (short B<g>) range: 0 .. 255
and B<blue> (short B<b>) range: 0 .. 255.
A higher value means a stronger beam of that base color flows into the mix
above a black background, so that black is (0,0,0), white (255,255,255)
and a pure red (fully saturated color) is (255, 0, 0). The space can also
be addressed under its alias name: B<sRGB>(standard RGB).

=head2 CMY

is the opposite of L</RGB> since it follows the logic of subtractive
color mixing as used in printing. Think of it as the amount of colored
ink on white paper, so that white is (0,0,0) and black (1,1,1).
It uses normalized real value ranges: 0 .. 1.
An CMY tuple has also three values:

B<cyan> (short B<c>) is the inverse of I<red>,
B<magenta> (short B<m> ) is inverse to I<green> and
B<yellow> (short B<y>) is inverse of I<blue>.

=head2 CMYK

is an extension of L</CMY> with a fourth value named B<key> (short B<k>),
which is the amount of black ink mixed into the CMY color.
It also has an normalized range of 0 .. 1. This should not bother you
since you are free to change the range at you preference.

=head2 HSL

.. is a cylindrical space that orders colors along cognitive properties.
The first dimension is the angular one and it rotates in 360 degrees around
the rainbow of fully saturated colors: 0 = red, 15 approximates orange,
60 - yellow 120 - green, 180 - cyan, 240 - blue, 270 - violet,
300 - magenta, 330 - pink. 0 and 360 points to the same coordinate.
This module only outputs 0, even if accepting 360 as input. Thes second,
linear dimension (axis) measures the distance between a point the the center
column of the cylinder at the same height, no matter in which direction.
The center column has the value 0 (white .. gray .. black) and the outer
mantle of the cylinder contains the most saturated, purest colors.
The third, vertical axis reaches from bottom value 0 (always black no
matter the other values) to 100 (always white no matter the other values).
In summary: HSL needs three integer values: B<hue> (short B<h>) (0 .. 359),
B<saturation> (short B<s>) (0 .. 100) and B<lightness> (short B<l>) (0 .. 100).

=head2 HSV

... is also cylindrical but can be shaped like a cone.
Similar to HSL we have B<hue> and B<saturation>, but the third axis is
named B<value> (short B<v>). In L<HSL> we always get white, when I<lightness>
is 100. In HSV additionally I<saturation> has to be zero to get white.
When I<saturation> is 100 and I<value> is 100 we have the purest, most
sturated color of whatever I<hue> sets. So unlike in C<HSL>, here every
color has its unique coordinates.

=head2 HSB

Is an alias to L</HSV>, just the I<value> axis is renamed with B<brightness> (B<b>).



( run in 2.688 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )