1Convert::Color::RGB8(3)User Contributed Perl DocumentatioCnonvert::Color::RGB8(3)
2
3
4
6 "Convert::Color::RGB8" - a color value represented as red/green/blue in
7 8-bit integers
8
10 Directly:
11
12 use Convert::Color::RGB8;
13
14 my $red = Convert::Color::RGB8->new( 255, 0, 0 );
15
16 # Can also parse strings
17 my $pink = Convert::Color::RGB8->new( '255,192,192' );
18
19 # or
20 $pink = Convert::Color::RGB8->new( 'ffc0c0' );
21
22 Via Convert::Color:
23
24 use Convert::Color;
25
26 my $cyan = Convert::Color->new( 'rgb8:0,255,255' );
27
29 Objects in this class represent a color in RGB space, as a set of three
30 integer values in the range 0 to 255; i.e. as 8 bits.
31
32 For representations using floating point values, see
33 Convert::Color::RGB. For representations using 16-bit integers, see
34 Convert::Color::RGB16.
35
37 $color = Convert::Color::RGB8->new( $red, $green, $blue )
38 Returns a new object to represent the set of values given. These values
39 should be integers between 0 and 255. Values outside of this range will
40 be clamped.
41
42 $color = Convert::Color::RGB8->new( $string )
43 Parses $string for values, and construct a new object similar to the
44 above three-argument form. The string should be in the form
45
46 red,green,blue
47
48 containing the three integer values in decimal notation. It can also be
49 given in the form of a hex encoded string, such as would be returned by
50 the "rgb8_hex" method:
51
52 rrggbb
53
55 $r = $color->red
56 $g = $color->green
57 $b = $color->blue
58 Accessors for the three components of the color.
59
60 ( $red, $green, $blue ) = $color->rgb8
61 Returns the individual red, green and blue color components of the
62 color value in RGB8 space.
63
64 $str = $color->hex
65 Returns a string representation of the color components in the RGB8
66 space, in a convenient "RRGGBB" hex string, likely to be useful HTML,
67 or other similar places.
68
69 $mix = $color->alpha_blend( $other, [ $alpha ] )
70 Return a new color which is a blended combination of the two passed
71 into it. The optional $alpha parameter defines the mix ratio between
72 the two colors, defaulting to 0.5 if not defined. Values closer to 0
73 will blend more of $color, closer to 1 will blend more of $other.
74
75 $mix = $color->alpha8_blend( $other, [ $alpha ] )
76 Similar to "alpha_blend" but works with integer arithmetic. $alpha
77 should be an integer in the range 0 to 255.
78
79 $measure = $color->dst_rgb8( $other )
80 Return a measure of the distance between the two colors. This is the
81 unweighted Euclidean distance of the three color components. Two
82 identical colors will have a measure of 0, pure black and pure white
83 have a distance of 1, and all others will lie somewhere inbetween.
84
85 $measure = $color->dst_rgb8_cheap( $other )
86 Return a measure of the distance between the two colors. This is the
87 sum of the squares of the differences of each of the color components.
88 This is part of the value used to calculate "dst_rgb8", but since it
89 involves no square root it will be cheaper to calculate, for use in
90 cases where only the relative values matter, such as when picking the
91 "best match" out of a set of colors. It ranges between 0 for identical
92 colours and 3*(255^2) for the distance between pure black and pure
93 white.
94
96 ยท Convert::Color - color space conversions
97
99 Paul Evans <leonerd@leonerd.org.uk>
100
101
102
103perl v5.30.1 2020-01-29 Convert::Color::RGB8(3)