]> git.imager.perl.org - imager.git/blob - lib/Imager/Color.pm
Initial revision
[imager.git] / lib / Imager / Color.pm
1 package Imager::Color;
2
3 use Imager;
4 use strict;
5 use 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
12 sub 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
27 sub 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
33 sub 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
44 1;
45
46 __END__
47
48 =head1 NAME
49
50 Imager::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
70 This module handles creating color objects used by imager.  The idea is
71 that in the future this module will be able to handle colorspace calculations
72 as well.
73
74 =over 4
75
76 =item new
77
78 This creates a color object to pass to functions that need a color argument.
79
80 =item set
81
82 This changes an already defined color.  Note that this does not affect any places
83 where the color has been used previously.
84
85 =item rgba
86
87 This returns the rgba code of the color the object contains.
88
89 =item info
90
91 Calling info merely dumps the relevant colorcode to the log.
92
93 =back
94
95 =head1 AUTHOR
96
97 Arnar M. Hrafnkelsson, addi@umich.edu
98 And a great deal of help from others - see the README for a complete
99 list.
100
101 =head1 SEE ALSO
102
103 Imager(3)
104 http://www.eecs.umich.edu/~addi/perl/Imager/
105
106 =cut
107