Hello, I have noticed that some tools (PunyPNG and ImageOptim) "clear" RGB components of fully transparent pixels, this only applies to files using a real alpha channel. I was wondering if instead of just clearing the alpha channel it would not be wiser to stuff pixels that would be easier to deflate. Since those pixels are never shown, this space could contain anything. For instance if we had to fill 5 fully transparent pixels we could simple add 5 to the length of the previous match or run-length, this means that at LZ77 level we would have to check whether a pixel is fully transparent or not.
Edited by Caveman at
Awesoken at
Re: PNGOUT: smart dirty transparency
I consider this to be lossy. I have several programs that use the alpha channel as a heightmap. I would hate to have their data destroyed because I forgot to specify a command line option. If you want to test your theory, I suggest editing the file in a separate program first.
frkay at
Caveman said at
I was wondering if instead of just clearing the alpha channel it would not be wiser to stuff pixels that would be easier to deflate. Since those pixels are never shown, this space could contain anything.
Well, it's not that easy, I tried to modify the pngstream at the filter level (basically the up filter takes pixels values from the previous scanline in case of a fully transparent alpha channel), for illustration: http://frdx.free.fr/bigbazar/cham-sidebyside.png I made some tests on about 40 files only 3 ended smaller...
("black" files have black pixels to fill fully transparent pixels, whereas "pline" files use the same pixel as in the previous line. "pngout" and "deflopt" is the tool used to produce the file, nothing beeing optipng since I hacked this app). Archive of these sample files. It saved only around 200 bytes, I will try to modify all the filters to see if it improves compression somehow.
Edited by Frédéric Kayser at
lorents at
For this purpose there is program PngKT. http://x128.ho.ua/pngutils.html
frkay at
lorents said at
For this purpose there is program PngKT. http://x128.ho.ua/pngutils.html
Does it just replace fully transparent pixels with black ones? Apparently you asked x128 to make this program based on this article. The idea here was to go beyond that and put something else that would lead to smaller files.
lorents at
X128 Works, just over it how to refine this technology
Here look at this picture
frkay at
I have finally managed to modify all the 5 PNG filters (none, sub, up, average and paeth) in such a way that the output of the filter is zero if the pixel is fully transparent, this might help compression. And effectively some of my test files became smaller using this transformation.
109823 ches-none.png 108720 ches-avg.png
22198 auto-none.png 22092 auto-sub.png
14630 cham-none.png 14489 cham-up.png
1975 twit-none.png 1953 twit-paeth.png
Archive of these sample files.
Even the butterfly sample file featured by punypng benefited from the modified sub filter (59393 bytes compared to the 62136 bytes achieved by punypng). http://frdx.free.fr/bigbazar/butterfly-sub.png
lorents at
Frédéric Kayser How you could make so images?
Edited by lorents at
caveman at
Frédéric Kayser said at
I have finally managed to modify all the 5 PNG filters (none, sub, up, average and paeth) in such a way that the output of the filter is zero if the pixel is fully transparent, this might help compression. And effectively some of my test files became smaller using this transformation.
I've been thinking about putting dummy pixels at a lower level but I had not noticed that the alpha channel and pixel values were in did part of the same pngstream and that filtering was also applied to the alpha channel. Nevertheless, your hack looks promising to me. Is there a way to get access to it, executable or source code?
frkay at
Well, it's an ugly hack but if you have access to a GNU/Linux box here is an early release: Cryopng for Linux (Intel 32-bits). I've called it "Cryopng" but it's based on optipng, it will only work on RGB+alpha 8 bits/pixels files.
The cryogend file is a shell sript I use to call cryopng, pngout and deflopt to generate all the files (cryogen is the same without deflopt). It expects to find cryopng, pngout and deflopt (I used a wrapper to fire it with Wine) in your PATH (copy them in /usr/bin/).
The cryogen(d) script creates a "-cryo" folder with the same name as the png file (without the trailing .png). For instance if you have a moldova.png file: ./cryogend moldova
will produce all these files in the moldova-cryo folder: -rw-r--r-- 1 fred fred 2176 2010-10-23 02:37 moldova-f3.png -rw-r--r-- 1 fred fred 2145 2010-10-23 02:37 moldova-f1.png -rw-r--r-- 1 fred fred 2107 2010-10-23 02:37 moldova-f0.png -rw-r--r-- 1 fred fred 2077 2010-10-23 02:37 moldova-avg.png -rw-r--r-- 1 fred fred 2058 2010-10-23 02:37 moldova-f5.png -rw-r--r-- 1 fred fred 2032 2010-10-23 02:37 moldova-nd.png -rw-r--r-- 1 fred fred 2030 2010-10-23 02:37 moldova-f2.png -rw-r--r-- 1 fred fred 1987 2010-10-23 02:37 moldova-mixed.png -rw-r--r-- 1 fred fred 1984 2010-10-23 02:37 moldova-none.png -rw-r--r-- 1 fred fred 1980 2010-10-23 02:37 moldova-f4.png -rw-r--r-- 1 fred fred 1962 2010-10-23 02:37 moldova-sub.png -rw-r--r-- 1 fred fred 1958 2010-10-23 02:37 moldova-up.png -rw-r--r-- 1 fred fred 1930 2010-10-23 02:37 moldova-paeth.png
*-f(0-5).png files are the raw output of cryopng (deflopt is also applied to them). *-(none,sub,up,avg,paeth).png are the same files recompressed by pngout and deflopt (the none file is equivalent to the dirty transparency produced by punypng or imageoptim). the -nd.png file is the original file recompressed by pngout and deflopt.
I'll try to provide a Mac OS X version in the next days.
Edit: modified the cryogen script, includes pngout
Edited by Frédéric Kayser at
lorents at
And the version for windows isn't present?
frkay at
Mac OS X (Universal Binay PowerPC and x86 Intel) version of Cryopng is now available for testing.
I'll try to make a Windows version soon.
Edited by Frédéric Kayser at
lorents at
Thanks, I will wait the version for windows
frkay at
lorents said at
Thanks, I will wait the version for windows
The wait is over, here is the Windows version. Cryopng is in the "sidekick" folder, you should also move a copy of pngout.exe into this folder.
The scripts are somewhat different, you can drag and drop a single picture on the .cmd scripts or call them with the complete png file name: cryogend moldova.png
lorents at
Now we will look, thanks.
caveman at
Wouldn't it be more efficient to run pngout with the same filter as cryopng rather than the default one?
lorents at
Frédéric Kayser good afternoon! Whether there is no method, without optimization of pictures to learn what picture better, simply optimization of each picture occupies time considerable quantity?
Edited by lorents at
frkay at
I have been trying a new script cryogenf, it addresses some of these concerns. It selects the 3 smallest files (out of the 5 filters f0 to f4, f5 - mixed - is not used) produced by cryopng, runs pngout on them using both the f5 filter and the filter previously used by cryopng (-ks switch). In the same time it tries 8 different block split thresholds (0, 128, 160, 256, 320, 512, 560, 640) and finaly runs deflopt, picks the smallest file and removes all temporary files.
It runs up to 4 instances of pngout at the same time (this can be tuned in the "cap_pngout" function just replace "> 4" by the number of simultaneous threads your computer can handle).
./cryogenf moldova Produces a 1930 bytes moldova-cryo.png file.
./cryogenf butterfly Produces a 59534 bytes butterfly-cryo.png file (...after a while)
Edited by Frédéric Kayser at
lorents at
Frédéric Kayser good afternoon! Don't prompt when to wait updating, your program?