-
Notifications
You must be signed in to change notification settings - Fork 4
/
fade_table.pl
executable file
·38 lines (30 loc) · 926 Bytes
/
fade_table.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl
# This is a perl script for generating lookup tables
# for sub-pixel values that fade gracefully.
#
# Invoke as ./fade_table.pl 100 255 2.5
# Where 100 is the number of lines in the table, 255
# is the maximum value and 2.5 is the power (larger
# number make tables more sensitibve at dim values).
use strict;
use warnings;
my $numvals = shift;
my $maxval = shift;
my $power = shift;
print "/* Generated by fade_table.pl $numvals $maxval $power */\n";
print "static const unsigned char SUBP_${maxval}[] = {\n ";
my $i;
for ( $i = 0 ; $i < $numvals ; $i++ ) {
#normalise value to maxvalue
my $val = $i / ($numvals - 1) * $maxval;
#clculate the brightness
my $result = (($val / $maxval) ** $power) * $maxval;
printf "%3d", $result;
#newlines and commas
if (0 == ($i + 1) % 20 and $i != $numvals - 1) {
print ",\n ";
} elsif ($i != $numvals - 1) {
print ",";
}
}
print "};\n";