koreader
koreader copied to clipboard
FR: Support for AVIF images in CBZ files
Hello,
today I was playing around with my CBR files and tried to convert some of them to CBZ files, since KOReader has direct support for that. I've used CBConvert for this (CBConvert@Github | CBConvert@Flathub). This works pretty nice since this tool is really easy to use.
Now I've seen CBConvert can also produce CBZ files with AVIF images inside. It's a file format being developed by the Alliance for Open Media (many tech giants): https://avif.io/
I've played around and the result is outstanding, at least with some of the files I've tried. Just one example:
CBR/JPG file size: 96.3 MB CBZ/WEBP (90 % quality) file size: 59.5 MB – nice! CBZ/AVIF (100 % quality) file size: 17.6 MB – WTF?!
I'm not 100 % sure this isn't just a bug in CBConvert but I've already heared a lot about AVIF and that its compression is outstanding. Now I've also compared the single file quality and resolution inside the archives and the result looks really great. Of course I've also conversion examples where the file size difference is smaller than above but it seems like AVIF CBZs are always smaller than WebP CBZs, without any loss I can see.
After so many words: Is there a chance KOReader could support CBZs with AVIF files in (near) future? Or could there be any technical or licensing issues?
Personally if I spent the time I'd add JXL instead. But I'd assume adding something like https://github.com/AOMediaCodec/libavif to be relatively trivial, other than the required time investment.
CBZ/WEBP (90 % quality) file size: 59.5 MB – nice!
Almost certainly looks worse.
CBZ/AVIF (100 % quality) file size: 17.6 MB – WTF?!
Next compare loading times, particularly on single-core. ;-)
Usual caveat that we target 16 shades of gray devices, which means dithering is kind of important, which means lossy compression becomes irrelevant, because they sort of all rely on quantization magic to work, which goes directly against what dithering does.
PNG >>> all the things.
Speaking of PNG, dithering also happens to work in its favor, because palettes; so that specific use-case doesn't necessarily compare unfavorably against (legacy, at least) lossy algorithms, in terms of file size.
I'd go much farther than it being suboptimal in such a highly specific context. Also see https://www.libjpeg-turbo.org/About/Mozjpeg and https://siipo.la/blog/is-webp-really-better-than-jpeg
On https://webp-test-500.b-cdn.net/ and https://webp-test-1500.b-cdn.net/ you can plainly see that cjpeg delivers the best visual quality by a mile, though mozjpeg isn't much worse.
This all comes down to:
Also, Google’s study used a different program to compute the SSIM values. In my tests, I used the dssim utility which computes multi-scale SSIM in LAB color space while the former seems to use simple SSIM in RGB color space. This means they likely give different results but it’s hard to say which is more accurate.
Google's calculations are complete and utter nonsense as far as my eyes are concerned, but even the ones in that article are borderline blind. But who can fault them; they're just algorithms.
But tl;dr WebP and AVIF look quite bad to me. Image formats that don't look worse include JPEG 2000 (try it out ;-) ) and JPEG XL.
The article does actually address how terrible they look but phrases it with a more positive outlook, effectively stating that it could be a good idea if it were actually done properly.
I see the differences described, but personally I don't find them very disturbing (at least in this example), since in the example the shutters in the JPEG compression give me the impression that they are "stained" with JPEG artifacts.
First I thought that with comics it wasn't so bad if areas look like they have a slight "smart blur" filter applied, but now I've tried converting a slightly more finely drawn comic and the details are actually a bit lost. So I see what is meant. And of course I didn't consider the single core thing. ;)
I had already tried PNG and am actually a big PNG fan, unfortunately the files I have are all scans, so the areas contain too many "details" and the files seem to be very large.
I'd rather leave it as it is, but will convert my CBR files to CBZ. My thought was that I could perhaps optimize it at the same time, but I would probably have regretted that at some point.
Thank you for the explanation! :)
in the example the shutters in the JPEG compression give me the impression that they are "stained" with JPEG artifacts.
But that's what the uncompressed original looks like! :laughing:
Yes the perfect image format for CBZs already exists and is supported by all devices already. And it is PNG! Not only it is lossless it also can compress Comics to a fracture of the size of JPEGs. The trick is to take advantage of the great freedom PNG has over JPG in terms of the color depths. A one bit Black/White PNG is less than one 1/10 of the size of an full color JPG. And a 4 bit grayscale image (which is as good as eInk can display) isn't much bigger either. Even a 5 bit color image is still less than half of the size of an JPG. And with CBZs you can compress every single image however you like to. For example, I compressed a giant hight-res 1.4GB CBZ down to 120MB, without any loss of image quality or resolution. I just converted to color pages to 5-bit and the actual drawings to 1-bit monochrome. An additional benefit is that you also need way less RAM and CPU power to decode them. JPG is great for compressing photographs, but most Comics are either black&white or very limited in the amount of colors they use, which makes JPG the least efficient format. And not speaking off all the artifacts it produces on lower quality settings...
I use News downloader to read RSS on e-ink device. Unfortunately, it does not work well for those websites that uses AVIF image, because the images won't be displayed.
@NoAnyLove I believe the news website not only provide AVIF but also JPG. Otherwise the website would not be able to support legacy device like old iPhones and iPads. I guess in the meantime you can check how to get your News Downloader obtain the JPG/WEBP from the website.
@Gabriel85 I found that Squoosh is a good website that allows you to upload any image and do a side by side comparison. You can upload comic PNG and compare the size/noise difference between AVIF/PNG
@Gabriel85 I found that Squoosh is a good website that allows you to upload any image and do a side by side comparison. You can upload comic PNG and compare the size/noise difference between AVIF/PNG
Thank you for the tip! But PNG is a lossless format, and if I want to compare it to (lossless) AVIF, I just need to compare the file size. I did compare them and AVIF is significantly better than PNG in lossless compression, but not so much that it is worth the reduced compatibility.
I did some comparisons with lossy AVIF and JPEG, too and there any conversion is more or less pointless I think. AVIF is just not a very good format for lossy compression and every conversion to a lossy format will introduce further artefacts, so that you will have hardly any reduction in file size if you want to avoid quality loss.
Personally, I don't see the point of converting anything into another lossy format, before there is not a real successor of JPG (hopefully JPEG XL). Otherwise I would have to make lossy conversions to every new format and in 20 years all me files would be totally degraded...
@Gabriel85 I think different people have different need. I watch my comics on 7" eink device. I would not be able to tell the difference between lossy and lostless (e.g. I would satisfy watching Blu Ray on 80 inch TV and won't chase for lostless video format, same thing applies to Blu Ray audio). Lossy format would be fine for me. But it could be just me.
@Gabriel85 I think different people have different need. I watch my comics on 7" eink device. I would not be able to tell the difference between lossy and lostless (e.g. I would satisfy watching Blu Ray on 80 inch TV and won't chase for lostless video format, same thing applies to Blu Ray audio). Lossy format would be fine for me. But it could be just me.
Well I agree with you 100%. Actually nobody needs a lossless format, since pretty much all comics already come as lossy JPEGs! But there are two reason why I use PNGs:
- As I said there is no alternative of those two formats, which you can be sure it will be still around in 15 years. Therefore, I would have convert them all again in the future to another lossy format. And I doubt converting already lossy JPEGs, at least twice, into other lossy formats makes much sense...
- I don't care about if a file is lossy or not, I care about file sizes! With PNGs I can get mono-colored comics down to 1/10 of the size and limited color ones to 1/5 on average. And that without, or just minimal loss of quality and the option of converting them again to any other format in the future, without drawbacks.
I don't think there is worry as long as major browser support. Major browser support means there is legacy support in the future. It also mean OS support (you could view the picture downloaded from your browser) too.
If you think you don't care about lossy/lostless then you could compare lossy avif against PNG in sqoosh again.
Major browser support means there is legacy support in the future.
https://chromestatus.com/feature/5158654475239424
I don't think there is worry as long as major browser support. Major browser support means there is legacy support in the future. It also mean OS support (you could view the picture downloaded from your browser) too.
If you think you don't care about lossy/lostless then you could compare lossy avif against PNG in sqoosh again.
Browsers add and remove formats all the time (as they should), because they are made to display dynamically generated content. But if you want to be sure that you will be able to read your favorite comic on your deathbed, there is no alternative to JPEG and PNG for now! And I doubt I will be still able to remember the syntax of Imagemagick then...
I convert a lot of images between formats and I can tell you, even if you think you converted 10 images visually "lossless", it does not mean that 100 or 1000 will also look that good with the same settings. And if you convert you files carelessly every couple of years to the latest lossy format, you probably won't be able to enjoy them anymore in 10 years...
As I said I will consider using a new lossy format, when there is a clear successor to JPG/PNG (maybe JPEGXL), but I already know that AVIF won't be it (for technical reasons). Although it is not a bad format, certainly better than PNG and some say that it is even better than JPEGXL for comics.
But I am not against supporting AVIF! I did some tests with its lossless compression, and while it is not as good as JPEGXL, it is certainly much more efficient than PNG (about 30% for comics).
Browsers add and remove formats all the time (as they should), because they are made to display dynamically generated content. But if you want to be sure that you will be able to read your favorite comic on your deathbed, there is no alternative to JPEG and PNG for now! And I doubt I will be still able to remember the syntax of Imagemagick then...
If they remove format then the browser could not view the website previously built. It would be a problem to the browser as well. I didn't compare AVIF and JXL based on quality but based on browser/photo CDN provider support (e.g. cloudinary), I believe AVIF should be the next WebP.
I think WebP would be, like JPEG, becomes legacy for a long period of time because of the popularity in the past.
I convert a lot of images between formats and I can tell you, even if you think you converted 10 images visually "lossless", it does not mean that 100 or 1000 will also look that good with the same settings. And if you convert you files carelessly every couple of years to the latest lossy format, you probably won't be able to enjoy them anymore in 10 years...
Yes getting the right setting would be an art. I think there should be some general guidelines like Opus.
As I said I will consider using a new lossy format, when there is a clear successor to JPG/PNG (maybe JPEGXL), but I already know that AVIF won't be it (for technical reasons). Although it is not a bad format, certainly better than PNG and some say that it is even better than JPEGXL for comics.
I think it would be too hard for JXL to become a major format if Chrome is not willing to support. Again I didn't know which format is better but you know Chrome has the largest amount of user so they have the power to say which image/video format is major.
But I am not against supporting AVIF! I did some tests with its lossless compression, and while it is not as good as JPEGXL, it is certainly much more efficient than PNG (about 30% for comics).
hahaha my eye is so bad I can't tell the differences after I shrink my JPG comic by 80% using MozJPEG