Lossless compression for JPEG
Javier Gutiérrez Chamorro (Guti) Open source projects
Brought to you by:
nikkho
Could you add a lossless JPEG compression option?
The jpegtran tool included with IJG's project, libjpeg-turbo's project, and the MozJPEG project is capable of taking a JPEG as input, stripping all nonessential metadata, re-optimizing entropy encoding, and of course writing the file as non-interlaced even if the input file was interlaced.
This tends to provide anywhere from 5-15% improvement in my tests--more if the input file was interlaced—and it would be nice to have a JPEG optimization method that's completely lossless in terms of image data. I invoke jpegtran with these flags:
jpegtran -copy none -optimize -perfect "${i}"
I haven't looked, but I suspect that there are other lossless re-compression approaches for JPEG.
Actually, FO's default JPG mode is lossless recompression, using several methods. What's newer is (lossless) arithmetic &/or lossy recompression.
Is there documentation for this? I wasn't able to find any references in the help (CHM) file, and I didn't locate any other form of documentation.
You mention a newer option for lossy recompression; how does this work? I have 10.100.1889 installed, and the only options are labeled "Copy metadata" and "Use arithmetic encoding". There's no reference to lossy vs. lossless [re]compression.
The one time I've tested JPEG optimization, I got notably different file sizes after running the same input through more than once, implying generational loss.
Overall, FileOptimizer is seriously lacking in descriptions for its optimization switches. I'm also discovering other bugs with the help system; for example, choosing "Help topics" from the menu and pressing F1 are both broken. I ended up opening the included CHM file manually from Voidtools Everything.
CHM help is not always up-to-date. Updating it is tedious, so you can refer to the website and the FAQ: http://nikkhokkho.sourceforge.net/static.php?page=FileOptimizer
For instance: "FileOptimizer is an advanced file optimizer featuring a lossless (no quality loss)". In 10.x you will need to enable it by modifying FileOptimizer.ini. On 11.x, they are added on the options window too. Where have you FO installed/extracted?
Sorry, I don't understand. Is 11.x released? I only see up through the 10.x series here on SourceForge. And are you saying that there is lossless JPEG optimization in FileOptimizer? FileOptimizer.ini has only three options tagged "JPEG":
JPEGCopyMetadata=false
JPEGUseArithmeticEncoding=false
JPEGAllowLossy=false
If there's already lossless optimization, great! That's what I was looking for. I don't need or want lossy optimization, so I'm not looking for a way to enable it.
So that I'm clear in the future: is all optimization in FileOptimizer lossless by default, as per the description you referred to? Are there any exceptions?
Also, as I mentioned above, I optimized several JPEG files with FileOptimizer to test the results, and multiple runs on the same files produced files of varying sizes. (I think this was back in the 8.x or 9.x series. I'm not sure.) If the optimization is lossless, can you account for this strange result? Can you confirm what method FileOptimizer is using to optimize JPEGs?
Thanks!
FileOptimizer 11 is not yet released, currently at public beta 3 stage:https://sourceforge.net/p/nikkhokkho/discussion/fileoptimizer/thread/aa04c229/
All optimizations in FileOptimizer are by default lossless, this is why its description says "no quality loss". Optionally, you can enable lossy optimizations, which are the XXXAllowLossy options in FileOptimizer.ini.
Please share some JPEG files so I can try different consecutive runs.
Sure, let me see if I still have the files I tested with.
Meantime, can you confirm the method you're using for lossless optimization? Is it the jpegtran tool, or are there other tools in use behind the scenes? If it's jpegtran, is it from the libjpeg-turbo project, for speed?
For lossless JPEG optimization, FO is using jhead, Leanify, ect, pingo, jpegoptim, jpegtran, mozjpegtran.
The jpegtran tool comes from official JPEG, while mozjpegtran comes from official Mozilla repository. You can see the links on the used plugins in the FO web page.
You could simplify a bit by removing jhead; jpegtran has a command line option to strip metadata. 😉
BTW, just took a look at mozjpegtran in libjpeg-turbo, and it is still using regular JPEG DLL (libjpeg-62.dll), and not the turbo one, as I suposed (libturbojpeg.dll), so there should not be any speed difference.
Well, that's a problem. Can that be fixed via simple DLL rename or source patch?
TPS, have not tested that. Anyway, I would like a jpegtran with libjpeg turbo statically linked, so the DLL is not needed. Maybe I will compile it myself in the future.
Yes Rebecca Menessec. There are some redundant plugins in FileOptimizer that with the time, have become obsolete or unneeded. The problem is that in some rare cases, they make the difference, and are able to further squeeze the size of the files. So it is required to do a serious benchmark of files, detecting which can be removed. My approach is to not remove anyone, if there are cases where they have some advantage.
There are some contributors doing thoses testings, but of course any help is welcome, and if after a serious test, jhead is concluded to be unneded, I will remove it. This will make FileOptimizer faster, and smaller.
Original issue by rmenessec has been already solved and clarified.
If you are happy, please, consider making a donation:
https://nikkhokkho.sourceforge.io/images/FileOptimizerDonate.html