source: git/src/gdtconvert

main
Last change on this file was 0b99107, checked in by Olly Betts <olly@…>, 3 months ago

Eliminate old FSF addresses

Update GPL/LGPL licence files and boilerplate to direct people who
didn't receive the licence text to the FSF website, as the current
versions of the FSF licence texts now do, rather than giving a postal
address.

  • Property mode set to 100755
File size: 2.1 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, see
21#  <https://www.gnu.org/licenses/>.
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.