codec: calculate theoretical minimal overhead
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 29 Oct 2021 18:52:23 +0000 (20:52 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Nov 2021 03:14:15 +0000 (04:14 +0100)
Optimal sizes of 1x1 black images as researched by Jon Sneyers [1]
with later AVIF data [2] and 2021-10-25 breakthrough for JPEG-XL [3].

An example found for HEIC [4] may not be golfed, but kind of irrelevant
considering the container.  Its 212 byte JPEG-2000 example is larger than a
naive ImageMagick conversion.

[1] https://cloudinary.com/blog/one_pixel_is_worth_three_thousand_words
[2] https://twitter.com/jonsneyers/status/1333037638840967169
[3] https://twitter.com/jonsneyers/status/1452727349405966341
[4] https://github.com/mathiasbynens/small/commit/e05a006dd

codec.inc.pl

index 992c48869c83f7ae4d301daf090251835a345eef..f4d90e345224c8738d0ebcfb183a0f4462eed074 100644 (file)
@@ -36,7 +36,7 @@ codec => {
 },
 feature => {
        default => {
-               children => [qw( quality_photo quality_art speed limits features royalties support )],
+               children => [qw( quality_photo quality_art speed limits features royalties overhead support )],
        },
        quality_photo => {
                name => 'compression (photo)',
@@ -450,5 +450,21 @@ feature => {
                        jxl  => [2, undef, 'upcoming in most browsers'],
                },
        },
+       overhead => {
+               name => 'container overhead (file size)',
+               score => {
+                       png  => [3,  67, 'upto 70 bytes for specific RGBA'],
+                       jpeg => [2, 160, '159 bytes minimum for gray, 288 for specific colours'],
+                       gif  => [4,  35, '43 bytes for transparent'],
+                       webp => [4,  34, 'black or transparent lossless; 44-92 bytes lossy'],
+                       bpg  => [4,  31, 'lossy 29-62 bytes, lossless 37-160'],
+                       flif => [5,  14, 'black or transparent; 20 bytes for specific RGBA'],
+                       pnm  => [5,   8, 'monochrome text PBM; 12 bytes PPM; 69 bytes PAM'],
+                       jxl  => [5,  12, '512×256 black pixels'],
+                       avif => [1, 282, 'container overhead; 457 bytes with alpha'],
+                       jp2k => [2, 123, 'experimental results, likely not optimal'],
+                       heic => [1, 386],
+               },
+       },
 },
 }