Add MainFrm::GetCSProj() getter method
[survex.git] / src / gdtconvert
blob381d450288e8227ff1cb00be96d680796367ebad
1 #!/usr/bin/perl -w
3 # gdtconvert
5 # Converter for POV-Ray gradient files produced by The Gimp
7 # Copyright (C) 2002 Mark R. Shinwell
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.
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.
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
23 use strict;
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;
49 else {
50 my $faralong = $next - $prevpos;
51 my $total = $pos - $prevpos;
52 my $frac = $faralong / $total;
54 my $newr = $pr + int(($r - $pr) * $frac);
55 my $newg = $pg + int(($g - $pg) * $frac);
56 my $newb = $pb + int(($b - $pb) * $frac);
58 $outputr = "$outputr, $newr";
59 $outputg = "$outputg, $newg";
60 $outputb = "$outputb, $newb";
62 $next += $interval;
64 $pr = $r;
65 $pg = $g;
66 $pb = $b;
67 $prevpos = $pos;
69 $prev = $1;
73 print "/* Generated by $0 */\n";
74 print "static const unsigned char REDS[] = {$outputr, 230};\n";
75 print "static const unsigned char GREENS[] = {$outputg, 230};\n";
76 print "static const unsigned char BLUES[] = {$outputb, 230};\n";