]> git.imager.perl.org - imager.git/blob - lib/Imager/Color/Float.pm
f13c98bedfbbf1fbd087aa03f9e73da7996a2c96
[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.004";
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 1;
40
41 __END__
42
43 =head1 NAME
44
45 Imager::Color::Float - Rough floating point sample colour handling
46
47 =head1 SYNOPSIS
48
49   $color = Imager::Color->new($red, $green, $blue);
50   $color = Imager::Color->new($red, $green, $blue, $alpha);
51   $color = Imager::Color->new("#C0C0FF"); # html color specification
52
53   $color->set($red, $green, $blue);
54   $color->set($red, $green, $blue, $alpha);
55   $color->set("#C0C0FF"); # html color specification
56
57   ($red, $green, $blue, $alpha) = $color->rgba();
58   @hsv = $color->hsv(); # not implemented but proposed
59
60   $color->info();
61
62
63 =head1 DESCRIPTION
64
65 This module handles creating color objects used by imager.  The idea is
66 that in the future this module will be able to handle colorspace calculations
67 as well.
68
69 A floating point Imager color consists of up to four components, each
70 in the range 0.0 to 1.0. Unfortunately the meaning of the components
71 can change depending on the type of image you're dealing with:
72
73 =over
74
75 =item *
76
77 for 3 or 4 channel images the color components are red, green, blue,
78 alpha.
79
80 =item *
81
82 for 1 or 2 channel images the color components are gray, alpha, with
83 the other two components ignored.
84
85 =back
86
87 An alpha value of zero is fully transparent, an alpha value of 1.0 is
88 fully opaque.
89
90 =head1 METHODS
91
92 =over 4
93
94 =item new
95
96 This creates a color object to pass to functions that need a color argument.
97
98 =item set
99
100 This changes an already defined color.  Note that this does not affect any places
101 where the color has been used previously.
102
103 =item rgba
104
105 This returns the rgba code of the color the object contains.
106
107 =item info
108
109 Calling info merely dumps the relevant colorcode to the log.
110
111 =back
112
113 =head1 AUTHOR
114
115 Arnar M. Hrafnkelsson, addi@umich.edu
116 And a great deal of help from others - see the README for a complete
117 list.
118
119 =head1 SEE ALSO
120
121 Imager(3), Imager::Color.
122
123 http://imager.perl.org/
124
125 =cut
126