]>
Commit | Line | Data |
---|---|---|
faa9b3e7 TC |
1 | package Imager::Color::Float; |
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 (@_,1) 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)/255.99,hex($2)/255.99,hex($3)/255.99,hex($4)/255.99); | |
18 | } | |
19 | if ($_[0] =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) { | |
20 | return (hex($1)/255.99,hex($2)/255.99,hex($3)/255.99,1); | |
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 | my @arg = pspec(@_); | |
36 | return @arg ? set_internal($self, $arg[0],$arg[1],$arg[2],$arg[3]) : (); | |
37 | } | |
38 | ||
39 | ||
40 | ||
41 | ||
42 | ||
43 | 1; | |
44 | ||
45 | __END__ | |
46 | ||
47 | =head1 NAME | |
48 | ||
49 | Imager::Color::Float - Rough floating point sample colour handling | |
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 | ||
69 | This module handles creating color objects used by imager. The idea is | |
70 | that in the future this module will be able to handle colorspace calculations | |
71 | as well. | |
72 | ||
73 | =over 4 | |
74 | ||
75 | =item new | |
76 | ||
77 | This creates a color object to pass to functions that need a color argument. | |
78 | ||
79 | =item set | |
80 | ||
81 | This changes an already defined color. Note that this does not affect any places | |
82 | where the color has been used previously. | |
83 | ||
84 | =item rgba | |
85 | ||
86 | This returns the rgba code of the color the object contains. | |
87 | ||
88 | =item info | |
89 | ||
90 | Calling info merely dumps the relevant colorcode to the log. | |
91 | ||
92 | =back | |
93 | ||
94 | =head1 AUTHOR | |
95 | ||
96 | Arnar M. Hrafnkelsson, addi@umich.edu | |
97 | And a great deal of help from others - see the README for a complete | |
98 | list. | |
99 | ||
100 | =head1 SEE ALSO | |
101 | ||
102 | Imager(3) | |
8f22b8d8 TC |
103 | |
104 | http://imager.perl.org/ | |
faa9b3e7 TC |
105 | |
106 | =cut | |
107 |