add red, green, blue, alpha methods to color objects
[imager.git] / lib / Imager / Color / Float.pm
CommitLineData
faa9b3e7
TC
1package Imager::Color::Float;
2
3use Imager;
4use strict;
f17b46d8
TC
5use vars qw($VERSION);
6
0231b97e 7$VERSION = "1.006";
faa9b3e7
TC
8
9# It's just a front end to the XS creation functions.
10
11
12# Parse color spec into an a set of 4 colors
13
d5556805 14sub _pspec {
faa9b3e7
TC
15 return (@_,1) if @_ == 3;
16 return (@_ ) if @_ == 4;
17 if ($_[0] =~
18 /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
34c03f04 19 return (hex($1)/255,hex($2)/255,hex($3)/255,hex($4)/255);
faa9b3e7
TC
20 }
21 if ($_[0] =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
34c03f04 22 return (hex($1)/255,hex($2)/255,hex($3)/255,1);
faa9b3e7
TC
23 }
24 return ();
25}
26
faa9b3e7
TC
27sub new {
28 shift; # get rid of class name.
d5556805 29 my @arg = _pspec(@_);
faa9b3e7
TC
30 return @arg ? new_internal($arg[0],$arg[1],$arg[2],$arg[3]) : ();
31}
32
33sub set {
34 my $self = shift;
d5556805 35 my @arg = _pspec(@_);
faa9b3e7
TC
36 return @arg ? set_internal($self, $arg[0],$arg[1],$arg[2],$arg[3]) : ();
37}
38
ffddd407
TC
39sub CLONE_SKIP { 1 }
40
faa9b3e7
TC
411;
42
43__END__
44
45=head1 NAME
46
5715f7c3 47Imager::Color::Float - Rough floating point sample color handling
faa9b3e7
TC
48
49=head1 SYNOPSIS
50
51 $color = Imager::Color->new($red, $green, $blue);
52 $color = Imager::Color->new($red, $green, $blue, $alpha);
53 $color = Imager::Color->new("#C0C0FF"); # html color specification
54
55 $color->set($red, $green, $blue);
56 $color->set($red, $green, $blue, $alpha);
57 $color->set("#C0C0FF"); # html color specification
58
59 ($red, $green, $blue, $alpha) = $color->rgba();
60 @hsv = $color->hsv(); # not implemented but proposed
61
62 $color->info();
63
64
65=head1 DESCRIPTION
66
5715f7c3
TC
67This module handles creating color objects used by Imager. The idea
68is that in the future this module will be able to handle color space
69calculations as well.
faa9b3e7 70
0462442b
TC
71A floating point Imager color consists of up to four components, each
72in the range 0.0 to 1.0. Unfortunately the meaning of the components
73can change depending on the type of image you're dealing with:
74
75=over
76
77=item *
78
79for 3 or 4 channel images the color components are red, green, blue,
80alpha.
81
82=item *
83
84for 1 or 2 channel images the color components are gray, alpha, with
85the other two components ignored.
86
87=back
88
89An alpha value of zero is fully transparent, an alpha value of 1.0 is
90fully opaque.
91
92=head1 METHODS
93
faa9b3e7
TC
94=over 4
95
96=item new
97
98This creates a color object to pass to functions that need a color argument.
99
100=item set
101
102This changes an already defined color. Note that this does not affect any places
103where the color has been used previously.
104
5715f7c3 105=item rgba()
faa9b3e7 106
5715f7c3
TC
107This returns the red, green, blue and alpha channels of the color the
108object contains.
faa9b3e7
TC
109
110=item info
111
5715f7c3 112Calling info merely dumps the relevant color to the log.
faa9b3e7 113
0231b97e
TC
114=item red
115
116=item green
117
118=item blue
119
120=item alpha
121
122Returns the respective component as a floating point value typically
123from 0 to 1.0.
124
faa9b3e7
TC
125=back
126
127=head1 AUTHOR
128
129Arnar M. Hrafnkelsson, addi@umich.edu
5715f7c3 130And a great deal of help from others - see the C<README> for a complete
faa9b3e7
TC
131list.
132
133=head1 SEE ALSO
134
0462442b 135Imager(3), Imager::Color.
8f22b8d8
TC
136
137http://imager.perl.org/
faa9b3e7
TC
138
139=cut
140