]> git.imager.perl.org - imager.git/blob - lib/Imager/Color/Float.pm
a042567821d3612088519104a3334083fbe9f8b2
[imager.git] / lib / Imager / Color / Float.pm
1 package Imager::Color::Float;
2
3 use Imager;
4 use strict;
5 use vars qw($VERSION);
6
7 $VERSION = "1.005";
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
14 sub _pspec {
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) {
19     return (hex($1)/255.99,hex($2)/255.99,hex($3)/255.99,hex($4)/255.99);
20   }
21   if ($_[0] =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
22     return (hex($1)/255.99,hex($2)/255.99,hex($3)/255.99,1);
23   }
24   return ();
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   my @arg = _pspec(@_);
36   return @arg ? set_internal($self, $arg[0],$arg[1],$arg[2],$arg[3]) : ();
37 }
38
39 sub CLONE_SKIP { 1 }
40
41 1;
42
43 __END__
44
45 =head1 NAME
46
47 Imager::Color::Float - Rough floating point sample color handling
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
67 This module handles creating color objects used by Imager.  The idea
68 is that in the future this module will be able to handle color space
69 calculations as well.
70
71 A floating point Imager color consists of up to four components, each
72 in the range 0.0 to 1.0. Unfortunately the meaning of the components
73 can change depending on the type of image you're dealing with:
74
75 =over
76
77 =item *
78
79 for 3 or 4 channel images the color components are red, green, blue,
80 alpha.
81
82 =item *
83
84 for 1 or 2 channel images the color components are gray, alpha, with
85 the other two components ignored.
86
87 =back
88
89 An alpha value of zero is fully transparent, an alpha value of 1.0 is
90 fully opaque.
91
92 =head1 METHODS
93
94 =over 4
95
96 =item new
97
98 This creates a color object to pass to functions that need a color argument.
99
100 =item set
101
102 This changes an already defined color.  Note that this does not affect any places
103 where the color has been used previously.
104
105 =item rgba()
106
107 This returns the red, green, blue and alpha channels of the color the
108 object contains.
109
110 =item info
111
112 Calling info merely dumps the relevant color to the log.
113
114 =back
115
116 =head1 AUTHOR
117
118 Arnar M. Hrafnkelsson, addi@umich.edu
119 And a great deal of help from others - see the C<README> for a complete
120 list.
121
122 =head1 SEE ALSO
123
124 Imager(3), Imager::Color.
125
126 http://imager.perl.org/
127
128 =cut
129