1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | # gdtconvert |
---|
4 | # |
---|
5 | # Converter for POV-Ray gradient files produced by The Gimp |
---|
6 | # |
---|
7 | # Copyright (C) 2002 Mark R. Shinwell |
---|
8 | # |
---|
9 | # This program is free software; you can redistribute it and/or modify |
---|
10 | # it under the terms of the GNU General Public License as published by |
---|
11 | # the Free Software Foundation; either version 2 of the License, or |
---|
12 | # (at your option) any later version. |
---|
13 | # |
---|
14 | # This program is distributed in the hope that it will be useful, |
---|
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | # GNU General Public License for more details. |
---|
18 | # |
---|
19 | # You should have received a copy of the GNU General Public License |
---|
20 | # along with this program; if not, write to the Free Software |
---|
21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | use strict; |
---|
24 | |
---|
25 | my $points = 13; |
---|
26 | my $prev = -1.0; |
---|
27 | my $interval = 1.0 / ($points-1); |
---|
28 | my $next = 0.0; |
---|
29 | my $pr = 0; |
---|
30 | my $pg = 0; |
---|
31 | my $pb = 0; |
---|
32 | my $prevpos = 0.0; |
---|
33 | my $outputr = ""; |
---|
34 | my $outputg = ""; |
---|
35 | my $outputb = ""; |
---|
36 | while (my $l = <>) { |
---|
37 | if ($l =~ /.*\[(\d\.\d+) color rgbt <(\d\.\d+), (\d\.\d+), (\d\.\d+).*/) { |
---|
38 | if ($prev != $1) { |
---|
39 | my $r = int($2 * 255); |
---|
40 | my $g = int($3 * 255); |
---|
41 | my $b = int($4 * 255); |
---|
42 | my $pos = $1; |
---|
43 | while ($pos >= $next) { |
---|
44 | if ($prev == -1.0) { |
---|
45 | $outputr = $r; |
---|
46 | $outputg = $g; |
---|
47 | $outputb = $b; |
---|
48 | } |
---|
49 | else { |
---|
50 | my $faralong = $next - $prevpos; |
---|
51 | my $total = $pos - $prevpos; |
---|
52 | my $frac = $faralong / $total; |
---|
53 | |
---|
54 | my $newr = $pr + int(($r - $pr) * $frac); |
---|
55 | my $newg = $pg + int(($g - $pg) * $frac); |
---|
56 | my $newb = $pb + int(($b - $pb) * $frac); |
---|
57 | |
---|
58 | $outputr = "$outputr, $newr"; |
---|
59 | $outputg = "$outputg, $newg"; |
---|
60 | $outputb = "$outputb, $newb"; |
---|
61 | } |
---|
62 | $next += $interval; |
---|
63 | } |
---|
64 | $pr = $r; |
---|
65 | $pg = $g; |
---|
66 | $pb = $b; |
---|
67 | $prevpos = $pos; |
---|
68 | } |
---|
69 | $prev = $1; |
---|
70 | } |
---|
71 | } |
---|
72 | print "static const unsigned char REDS[] = {$outputr, 230};\n"; |
---|
73 | print "static const unsigned char GREENS[] = {$outputg, 230};\n"; |
---|
74 | print "static const unsigned char BLUES[] = {$outputb, 230};\n"; |
---|