]> git.xonotic.org Git - xonotic/mediasource.git/blob - gfx/luma/tools/luminance.pl
More icons and HUD graphics
[xonotic/mediasource.git] / gfx / luma / tools / luminance.pl
1 #!/usr/bin/perl
2 # TASK
3 #   Calculate the relative luminance of a color
4 #   http://www.w3.org/TR/WCAG20/Overview.html#relativeluminancedef
5 #
6 # USAGE
7 #   $0 RRGGBB
8
9
10 use strict;
11 use warnings;
12
13
14 my $r = hex(substr($ARGV[0], 0, 2)) / 255;
15 my $g = hex(substr($ARGV[0], 2, 2)) / 255;
16 my $b = hex(substr($ARGV[0], 4, 2)) / 255;
17
18
19 if ($r <= 0.03928) { $r = $r/12.92; } else { $r = (($r+0.055)/1.055) ** 2.4; }
20 if ($g <= 0.03928) { $g = $g/12.92; } else { $g = (($g+0.055)/1.055) ** 2.4; }
21 if ($b <= 0.03928) { $b = $b/12.92; } else { $b = (($b+0.055)/1.055) ** 2.4; }
22
23
24 printf("%.4g\n", 0.2126*$r + 0.7152*$g + 0.0722*$b);