codec: page request overrides image type
[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:10%} 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         <col><colgroup span=3><colgroup span=2><colgroup span=3>
35 <thead><tr><th rowspan=2>feature
36 <:
37 my @codecs = sort {
38         $info->{codec}->{$a}->{available} <=> $info->{codec}->{$b}->{available}
39 } keys $info->{codec}->%*;
40
41 print '<th>', $_->{name} for @{$info->{codec}}{@codecs};
42 print "\n<tr>";
43 print '<td>', $_->{available} for @{$info->{codec}}{@codecs};
44 say '</thead>';
45
46 while (defined (my $feat = shift @feat)) {
47         my $featinfo = $info->{feature}->{$feat} or next;
48         unshift @feat, @{$_} for $featinfo->{children} // ();
49         $featinfo->{score} or next;
50         print '<tbody>' if $featinfo->{children};
51         printf '<tr><th>%s', $featinfo->{name} // $feat;
52         for (@codecs) {
53                 my ($score, $data, $title) = map { ref ? @$_ : $_ } $featinfo->{score}->{$_};
54                 if (not defined $data) {
55                         if (my $override = $BOOLSCORE{$score}) {
56                                 ($score, $data) = @{$override};
57                         }
58                         else {
59                                 $data = '•' x ($score - 1);
60                         }
61                 }
62                 printf '<td class="l%d"', $score;
63                 printf ' title="%s"', $_ for $title // ();
64                 print '>', $data;
65         }
66         say '</td>';
67 }
68
69 :></table>
70 </div>
71