Conver...::RGB16(3pm)
β¨ Convert::Color::RGB16 β a color value represented as red/green/blue in 16-bit integers β¨
okay bestie, so this is Convert::Color::RGB16, a lil Perl module (from the Convert::Color family, 3pm energy) that lets you hold a color as three chunky 16-bit integers. red, green, blue, but make it π₯bigπ₯. let's get into it π«Ά
π SYNOPSIS π
Directly, like:
use Convert::Color::RGB16;
my $red = Convert::Color::RGB16->new( 65535, 0, 0 );
# Can also parse strings
my $pink = Convert::Color::RGB16->new( '65535,49152,49152' );
# or
$pink = Convert::Color::RGB16->new( 'ffffc000c000' );
Or via Convert::Color, if you're feeling fancy:
use Convert::Color;
my $cyan = Convert::Color->new( 'rgb16:0,65535,65535' );
π DESCRIPTION π
so. objects in this class represent a color in RGB space as a set of three integer values, each one in the range 0 to 65535 β that's 16 bits each, hence the name, no cap.
if you want representations using floating point values instead, go see Convert::Color::RGB. if you want 8-bit integers, go see Convert::Color::RGB8. this one is the 16-bit girlie π
π CONSTRUCTOR π
new
$color = Convert::Color::RGB16->new( $red, $green, $blue );
Returns a new object representing the set of values you gave it. those values should be integers between 0 and 65535 β and if you hand it anything outside that range, it gets clamped. it's giving "we'll take what we can get" π
$color = Convert::Color::RGB16->new( $string );
This one parses $string for values and builds a new object, same vibe as the three-argument form above. the string should be in the form
red,green,blue
with those three integers in decimal notation. but she can ALSO accept a hex encoded string β like the kind you'd get back from the rgb16_hex method:
rrrrggggbbbb
so many ways to serve, honestly π β¨
π¦ METHODS π¦
red
$r = $color->red;
green
$g = $color->green;
blue
$b = $color->blue;
Accessors for the three components of the color. each one just hands you its piece of the vibe. π
rgb16
( $red, $green, $blue ) = $color->rgb16;
Returns the individual red, green and blue color components of the color value, expressed in RGB16 space. all three at once, list-style, iconic.
hex
$str = $color->hex;
Returns a string representation of the color components in RGB16 space, in a handy little "RRRRGGGGBBBB" hex string. yes, four hex digits per channel, that's the 16-bit lifestyle bestie.
alpha_blend
$mix = $color->alpha_blend( $other, [ $alpha ] );
Returns a new color that's a blended combination of the two colors you passed in. the optional $alpha parameter sets the mix ratio between them, and it defaults to 0.5 if you don't define it. values closer to 0 blend more of $color, and values closer to 1 blend more of $other. choose your fighter π
alpha16_blend
$mix = $color->alpha16_blend( $other, [ $alpha ] );
Similar to alpha_blend (see above bestie, it's right there) but this one works with integer arithmetic. so $alpha should be an integer in the range 0 to 65535. math but make it whole numbers π§
dst_rgb16
$measure = $color->dst_rgb16( $other );
Returns a measure of the distance between the two colors. this is the unweighted Euclidean distance of the three color components. two identical colors get a measure of 0, pure black and pure white have a distance of 1, and everybody else lands somewhere inbetween. it's a spectrum, literally π
dst_rgb16_cheap
$measure = $color->dst_rgb16_cheap( $other );
Returns a measure of the distance between the two colors β but this one is the sum of the squares of the differences of each of the color components. it's part of the value used to calculate dst_rgb16, but since it involves no square root it's cheaper to compute. perfect for when only the relative values matter, like when you're picking the "best match" out of a set of colors. it ranges between 0 for identical colours and 3*(65535^2) for the distance between pure black and pure white. budget-friendly and still correct, we love to see it π«Ά
π SEE ALSO π
Convert::Colorβ color space conversions
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
okay that's the whole thing bestie, you're officially fluent in 16-bit RGB π
little sign-off moment: this was perl, v5.40.0, dated 2024-09-16, from the User Contributed Perl Documentation, page Conver...::RGB16(3pm). go forth and render colors, mwah πβ¨
π¦ where this page comes from
- ubuntu resolute: libconvert-color-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libconvert-color-perl 0.18-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms