source: git/src/gdtconvert @ a061be6a

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since a061be6a was a061be6a, checked in by Olly Betts <olly@…>, 14 years ago

src/gdtconvert: Add "Generated" comment to output file.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3420 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100755
File size: 2.2 KB
Line 
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
23use strict;
24
25my $points = 13;
26my $prev = -1.0;
27my $interval = 1.0 / ($points-1);
28my $next = 0.0;
29my $pr = 0;
30my $pg = 0;
31my $pb = 0;
32my $prevpos = 0.0;
33my $outputr = "";
34my $outputg = "";
35my $outputb = "";
36while (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
73print "/* Generated by $0 */\n";
74print "static const unsigned char REDS[]   = {$outputr, 230};\n";
75print "static const unsigned char GREENS[] = {$outputg, 230};\n";
76print "static const unsigned char BLUES[]  = {$outputb, 230};\n";
Note: See TracBrowser for help on using the repository browser.