1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
##
## wml::sup::hextriple - Convert #rrggbb String to RGB Value and vice versa
## Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved.
##
<protect pass=2>
<:
sub triple2rgb {
my ($triple) = @_;
my ($r, $g, $b);
$triple =~ s|^#||;
$triple =~ tr|A-F|a-f|;
$triple =~ m|([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])|;
($r, $g, $b) = (hex($1), hex($2), hex($3));
return ($r, $g, $b);
}
sub rgb2triple {
my ($r, $g, $b) = @_;
my ($triple);
$triple = sprintf("%02x%02x%02x", $r, $g, $b);
return $triple;
}
:>
</protect>
##EOF##
__END__
=head1 NAME
wml::sup::hextriple - Convert #rrggbb String to RGB Value and vice versa
=head1 SYNOPSIS
#use wml::sup::hextriple
<: ($r, $g, $b) = &triple2rgb($triple); :>
<: $triple = &rgb2triple($r, $g, $b); :>
=head1 DESCRIPTION
This converts between the strings C<RRGGBB> or C<#RRGGBB> and the
corresponding hextriple consisting of the value for red, green and blue.
=head1 AUTHOR
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
=head1 REQUIRES
Internal: P1, P3
External: --
=head1 SEE ALSO
HTML color attributes.
=cut
|