codec: derive column groups from generation sequence
[sheet.git] / codec.plp
1 <(common.inc.plp)><:
2
3 my ($page, @feat) = split m{/+}, $Request || 'image';
4 $page !~ /\W/ or Html(), Abort('Invalid codec type request', 400);
5 @feat or @feat = 'default';
6 my $title = "$page codecs";
7
8 Html({
9         title => "$title cheat sheet",
10         version => '1.0',
11         description => [
12         ],
13         keywords => [qw'
14                 codec encoder encoding decode file format type mime
15                 feature comparison support benchmark compression
16                 image audio video
17         '],
18         stylesheet => [qw'light circus dark red'],
19         data => [qw'codec.inc.pl'],
20         raw => '<style>td,th {width:8%} tbody th {white-space:nowrap}</style>',
21 });
22
23 my $info = do "codec-$page.inc.pl";
24 $info and %{$info} > 1
25         or Abort("Requested codec type <q>$page</q> not available", '404 request not found', $@ // $!);
26
27 say "<h1>\u$title</h1>";
28
29 my %BOOLSCORE = (y => [5, '✔'], n => [1, '✘'], 0 => [0, 'n/a']);
30 :>
31
32 <div class="section">
33 <table class="mapped">
34 <:
35 my @codecs = sort {
36         $info->{codec}->{$a}->{available} <=> $info->{codec}->{$b}->{available}
37 } keys $info->{codec}->%*;
38 my @codeccols = @{$info->{codec}}{@codecs};
39
40 {
41         print '<col>';
42         my @spans;
43         $spans[ $_->{generation} ]++ for @codeccols;
44         print "<colgroup span=$_>" for @spans;
45 }
46 say '<thead><tr><th rowspan=2>';
47 say "\t", '<th>', $_->{name} for @codeccols;
48 print '<tr>';
49 print '<td>', $_->{available} for @codeccols;
50 say '</thead>';
51
52 while (defined (my $feat = shift @feat)) {
53         my $featinfo = $info->{feature}->{$feat} or next;
54         unshift @feat, @{$_} for $featinfo->{children} // ();
55         $featinfo->{score} or next;
56         print '<tbody>' if $featinfo->{children};
57         printf '<tr><th>%s', $featinfo->{name} // $feat;
58         for (@codecs) {
59                 my ($score, $data, $title) = map { ref ? @$_ : $_ } $featinfo->{score}->{$_};
60                 if (not defined $data) {
61                         if (my $override = $BOOLSCORE{$score}) {
62                                 ($score, $data) = @{$override};
63                         }
64                         else {
65                                 $data = '•' x ($score - 1);
66                         }
67                 }
68                 printf '<td class="l%d"', $score;
69                 printf ' title="%s"', EscapeHTML($_) for $title // ();
70                 print '>', $data;
71         }
72         say '</td>';
73 }
74
75 :></table>
76 </div>
77