pointer to a description of how unsharp mask works
[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;
02d1d628
AMH
35 my @arg = pspec(@_);
36 return @arg ? set_internal($self, $arg[0],$arg[1],$arg[2],$arg[3]) : ();
37}
38
39
40
41
42
431;
44
45__END__
46
47=head1 NAME
48
49Imager::Color - Color handling for Imager.
50
51=head1 SYNOPSIS
52
53 $color = Imager::Color->new($red, $green, $blue);
54 $color = Imager::Color->new($red, $green, $blue, $alpha);
55 $color = Imager::Color->new("#C0C0FF"); # html color specification
56
57 $color->set($red, $green, $blue);
58 $color->set($red, $green, $blue, $alpha);
59 $color->set("#C0C0FF"); # html color specification
60
61 ($red, $green, $blue, $alpha) = $color->rgba();
62 @hsv = $color->hsv(); # not implemented but proposed
63
64 $color->info();
65
66
67=head1 DESCRIPTION
68
69This module handles creating color objects used by imager. The idea is
70that in the future this module will be able to handle colorspace calculations
71as well.
72
73=over 4
74
75=item new
76
77This creates a color object to pass to functions that need a color argument.
78
79=item set
80
81This changes an already defined color. Note that this does not affect any places
82where the color has been used previously.
83
84=item rgba
85
86This returns the rgba code of the color the object contains.
87
88=item info
89
90Calling info merely dumps the relevant colorcode to the log.
91
92=back
93
94=head1 AUTHOR
95
96Arnar M. Hrafnkelsson, addi@umich.edu
97And a great deal of help from others - see the README for a complete
98list.
99
100=head1 SEE ALSO
101
102Imager(3)
103http://www.eecs.umich.edu/~addi/perl/Imager/
104
105=cut
106