}
sub ensure_cached {
- my ($r, $avif_ok, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres) = @_;
+ my ($r, $avif_ok, $jxl_ok, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres) = @_;
my $fname = get_disk_location($r, $id);
unless (defined($xres) && (!defined($dbwidth) || !defined($dbheight) || $xres < $dbwidth || $yres < $dbheight || $xres == -1)) {
return ($fname, undef);
}
- # See if we have an up-to-date AVIF to serve.
+ # See if we have an up-to-date JPEG-XL or AVIF to serve.
# (We never generate them on-the-fly, since they're so slow.)
- my $cachename = get_cache_location($id, $xres, $yres, 'avif');
+ my $cachename = get_cache_location($id, $xres, $yres, 'jxl');
+ if ($jxl_ok && -r $cachename and (-M $cachename <= -M $fname)) {
+ return ($cachename, 'image/jxl');
+ }
+
+ $cachename = get_cache_location($id, $xres, $yres, 'avif');
if ($avif_ok && -r $cachename and (-M $cachename <= -M $fname)) {
return ($cachename, 'image/avif');
}
unlink($raw_filename);
system('MP4Box', '-quiet', '-add-image', "$ivf_filename:primary", '-ab', 'avif', '-ab', 'miaf', '-new', $cachename);
unlink($ivf_filename);
+ } elsif ($format eq 'jxl') {
+ # Similar, for JPEG-XL.
+ (my $dirname = $cachename) =~ s,/[^/]*$,,;
+ my ($fh, $raw_filename) = File::Temp::tempfile('tmp.XXXXXXXX', DIR => $dirname, SUFFIX => '.ppm');
+ my %parms = (
+ file => $fh,
+ filename => $raw_filename
+ );
+ $cimg->write(%parms);
+ close($fh);
+ system('cjxl', '-p', $raw_filename, $cachename);
+ unlink($raw_filename);
} else {
die "Unknown format $format";
}
} else {
my $accept = $r->header('Accept');
my $avif_ok = (defined($accept) && $accept =~ /(^|,)image\/avif($|,|;)/);
- ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $avif_ok, $filename, $id, $dbwidth, $dbheight, $xres, $yres);
+ my $jxl_ok = (defined($accept) && $accept =~ /(^|,)image\/jxl($|,|;)/);
+ ($fname, $mime_type) = Sesse::pr0n::Common::ensure_cached($r, $avif_ok, $jxl_ok, $filename, $id, $dbwidth, $dbheight, $xres, $yres);
$res->header('Vary' => 'Accept');
}
for my $file (<$base/$id-*-nobox.jpg>) { # TODO: --1--1.jpg, too.
my $fname = File::Basename::basename($file);
my ($width, $height) = $fname =~ /^$id-(\d+)-(\d+)-nobox\.jpg$/ or die $fname;
- (my $avif_file = $file) =~ s/jpg$/avif/;
- unless (-r $avif_file) {
+ (my $jxl_file = $file) =~ s/jpg$/jxl/;
+ unless (-r $jxl_file) {
push @res, ($width, $height);
print "$id to $width x $height...\n";
}
$dbwidth = $ref->{'width'};
$dbheight = $ref->{'height'};
- Sesse::pr0n::Common::make_cache({}, $filename, $id, $dbwidth, $dbheight, 'avif', @res);
+ Sesse::pr0n::Common::make_cache({}, $filename, $id, $dbwidth, $dbheight, 'jxl', @res);
}
}