Compress ATF Textures By 95%
ATF textures already contain a lot of compression: DXT, ETC, or PVRTC texture compression plus JPEG-XR and LZMA for good measure. What more can we do? As it turns out, we can drastically reduce the file size by simply applying Zlib or LZMA compression to the files. Read on for some samples with file size breakdowns.
Last week’s article showed some examples of ATF compression on three different types of textures: a leaf with alpha, a wizardess 3D character, and a VGA palette made up of a bunch of solid color squares. See the article for full details, but in a nutshell there were some very bad cases of file size bloat. An ATF of the VGA palette with all three sub-formats and mip maps turned on went from a 4 KB PNG file to a 500 KB ATF. So let’s see what happens if we compress each of ATF files from last week’s article:
VGA Palette
FILE | ORIGINAL | ZLIB | LZMA | ZLIB PERCENT | LZMA PERCENT |
---|---|---|---|---|---|
All | 524500 | 95687 | 57679 | 81.76% | 89.00% |
AllNoMip | 393316 | 49537 | 29101 | 87.41% | 92.60% |
DXT | 174876 | 19653 | 9899 | 88.76% | 94.34% |
DXTNoMip | 131172 | 7676 | 4053 | 94.15% | 96.91% |
ETC | 174876 | 21492 | 13235 | 87.71% | 92.43% |
ETCNoMip | 131172 | 7864 | 5166 | 94.00% | 96.06% |
PVR | 174948 | 53503 | 34429 | 69.42% | 80.32% |
PVRNoMip | 131172 | 32223 | 20078 | 75.43% | 84.69% |
Leaf
FILE | ORIGINAL | ZLIB | LZMA | ZLIB PERCENT | LZMA PERCENT |
---|---|---|---|---|---|
All | 218683 | 97430 | 87756 | 55.45% | 59.87% |
AllNoMip | 163931 | 67064 | 60564 | 59.09% | 63.06% |
DXT | 87499 | 36401 | 32795 | 58.40% | 62.52% |
DXTNoMip | 65627 | 25124 | 22476 | 61.72% | 65.75% |
ETC | 87499 | 35454 | 32369 | 59.48% | 63.01% |
ETCNoMip | 65627 | 24165 | 22190 | 63.18% | 66.19% |
PVR | 43867 | 23731 | 21839 | 45.90% | 50.22% |
PVRNoMip | 32859 | 17304 | 16003 | 47.34% | 51.30% |
Wizardess
FILE | ORIGINAL | ZLIB | LZMA | ZLIB PERCENT | LZMA PERCENT |
---|---|---|---|---|---|
All | 524500 | 318466 | 268123 | 39.28% | 48.88% |
AllNoMip | 393316 | 221058 | 185053 | 43.80% | 52.95% |
DXT | 174876 | 102556 | 85441 | 41.36% | 51.14% |
DXTNoMip | 131172 | 72127 | 59922 | 45.01% | 54.32% |
ETC | 174876 | 93301 | 79958 | 46.65% | 54.28% |
ETCNoMip | 131172 | 63118 | 53560 | 51.88% | 59.17% |
PVR | 174948 | 118660 | 101036 | 32.17% | 42.25% |
PVRNoMip | 131172 | 84982 | 71751 | 35.21% | 45.30% |
Applying these compression algorithms results in a wide range of effectiveness. In the worst-case scenario (wizardess PVRTC-only with mip maps) we only got 32.17% compression with Zlib. In the best-cast scenario (VGA palette DXT-only with no mip maps) we got 96.91% with LZMA! On average, Zlib compressed by 61.02% and LZMA compressed by 67.36%. LZMA was also always better than Zlib. There is a bit of a tradeoff of CPU versus file size here since LZMA is quite a bit slower than Zlib.
So why would you not always compress your ATF files? Well, it does take a little bit of time to decompress the data, but it’s probably worth your while for a 61-67% average file size savings. Honestly, I’m a little baffled as to why Adobe doesn’t do the Zlib compression for you, especially considering that they’ve already applied LZMA and JPEG-XR compression. If anybody has any idea why they don’t Zlib compress automatically or perhaps have spotted a bug in the data, post it in the comments! You’re essentially left with three options:
- Don’t compress and suffer the extra file size, but maximize CPU performance
- Compress with Zlib and get a good file size savings, but take a small CPU hit
- Compress with LZMA and get even better file size savings, but take a bigger CPU hit
#1 by makc on November 19th, 2012 ·
> Zlib was also always better than LZMA
all the graphs seem to show the opposite?
#2 by jackson on November 19th, 2012 ·
Thanks for pointing this out. I realized that I messed up my “LZMA Percent” spreadsheet column and it was being computed incorrectly, leading to the incorrect conclusion, I’ve updated the article with that column corrected as well as the conclusions at the end of the article. Thanks again!
#3 by Gil Amran on November 19th, 2012 ·
Hi,
If we are talking about SWF or APK, these files are already compressed… why would you care about compressing the images, if the result APK/SWF is being compressed?
btw: We’ve (XTDStudios) have built an open source library (DMT) for generating the bitmaps on the first run (out from Flash’s vectors), caching them and loading them on the next runs…
Works quite well… I don’t see any good reason for using compression… (When it’s good for 3D only…)
Your thoughts
Thanks
Gil
#4 by jackson on November 19th, 2012 ·
This is a good point. There are definitely cases, such as those you point out, where the data is already going to be compressed via Zlib or LZMA. For cases where it’s not getting put into a container like these, it’s probably worth compressing it yourself as the article shows.
#5 by orion elenzil on November 20th, 2012 ·
@gil – great point.
note that many HTTP requests are also commonly served with gzip or similar compression –
the client tells the server “i can deal w/ content that’s gzipped”, and the server responds with “here’s your content, by the way, it’s gzipped”.
see http://en.wikipedia.org/wiki/HTTP_compression
also fwiw,
using the ATF tools i just compressed this photographic PNG: http://elenzil.com/images/istanbul_tile_256.png
into this ATF file: http://elenzil.com/images/istanbul_tile_256.atf, and the file size shrank from 138766 bytes to 33846 as a result (1.0:0.25). so as you mentioned last time, it’s reasonable for images which compress well w/ JPEG.
#6 by kihu on June 20th, 2013 ·
How do you compress ATFs with zlib? Inside Flash or do you use some external tool? LZMA compression is optionally provided in Adobe’s ATF generator and I’m just testing it right now, but I’d like to test zlib/deflate as well.
#7 by jackson on June 20th, 2013 ·
I used
ByteArray.compress
on the uncompressed files from the previous article.#8 by kihu on July 1st, 2013 ·
Thanks. Turned out LZMA runs fast enough for me. Love your site btw, very useful and a good read.
#9 by suyin on April 8th, 2014 ·
Is there anyway to compress atf with zlib in windows ?
I am using png2atf & pvr2atf, pvrtextool. Thanks!
#10 by jackson on April 8th, 2014 ·
I don’t know of one off-hand, but perhaps you could use
gzip
orzip
as they both use zlib compression and there are Flash/AS3 libraries available for reading them.#11 by suyin on April 9th, 2014 ·
Thanks! I’ll try. I found FZip for reading zip. But it seems to be a bit outdated. May be u know smth better?
#12 by jackson on April 9th, 2014 ·
Not really, but it’s open source so you can always fix bugs yourself if it comes to that.
#13 by suyin on April 11th, 2014 ·
Seems like LZMA is fast enough. :) Thank you for all the articles! Read a lot of them.