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