Initial revision
[imager.git] / lib / Imager / Color.pm
CommitLineData
02d1d628
AMH
1package Imager::Color;
2
3use Imager;
4use strict;
5use vars qw();
6
7# It's just a front end to the XS creation functions.
8
9
10# Parse color spec into an a set of 4 colors
11
12sub pspec {
13 return (@_,255) if @_ == 3;
14 return (@_ ) if @_ == 4;
15 if ($_[0] =~
16 /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
17 return (hex($1),hex($2),hex($3),hex($4));
18 }
19 if ($_[0] =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
20 return (hex($1),hex($2),hex($3),255);
21 }
22 return ();
23}
24
25
26
27sub new {
28 shift; # get rid of class name.
29 my @arg = pspec(@_);
30 return @arg ? new_internal($arg[0],$arg[1],$arg[2],$arg[3]) : ();
31}
32
33sub set {
34 my $self = shift;
35 print "set: @_\n";
36 my @arg = pspec(@_);
37 return @arg ? set_internal($self, $arg[0],$arg[1],$arg[2],$arg[3]) : ();
38}
39
40
41
42
43
441;
45
46__END__
47
48=head1 NAME
49
50Imager::Color - Color handling for Imager.
51
52=head1 SYNOPSIS
53
54 $color = Imager::Color->new($red, $green, $blue);
55 $color = Imager::Color->new($red, $green, $blue, $alpha);
56 $color = Imager::Color->new("#C0C0FF"); # html color specification
57
58 $color->set($red, $green, $blue);
59 $color->set($red, $green, $blue, $alpha);
60 $color->set("#C0C0FF"); # html color specification
61
62 ($red, $green, $blue, $alpha) = $color->rgba();
63 @hsv = $color->hsv(); # not implemented but proposed
64
65 $color->info();
66
67
68=head1 DESCRIPTION
69
70This module handles creating color objects used by imager. The idea is
71that in the future this module will be able to handle colorspace calculations
72as well.
73
74=over 4
75
76=item new
77
78This creates a color object to pass to functions that need a color argument.
79
80=item set
81
82This changes an already defined color. Note that this does not affect any places
83where the color has been used previously.
84
85=item rgba
86
87This returns the rgba code of the color the object contains.
88
89=item info
90
91Calling info merely dumps the relevant colorcode to the log.
92
93=back
94
95=head1 AUTHOR
96
97Arnar M. Hrafnkelsson, addi@umich.edu
98And a great deal of help from others - see the README for a complete
99list.
100
101=head1 SEE ALSO
102
103Imager(3)
104http://www.eecs.umich.edu/~addi/perl/Imager/
105
106=cut
107