Reputation: 767
May be a bit subjective.
But quite a straightforward question.
What is the fastest image compression/decompression (both together)? And i mean available in c#.
I am pretty sure myself that it´s Jpeg.
But then again, jpeg has been following a standard since many years back, and must abide certain rules so it doesn´t break compatibility.
So perhaps there is something better that i don´t know off?
And when i say Fastest, i mean Latency and performance.
Meaning, let´s say, PNG for example, to compress a 1080p file, it takes 1 sec. and decompressing that takes, 30ms, then from the bitmap source to the second bitmap, it will be a 1.030 sec delay.
Jpeg is Alot faster than png for many reasons, and it´s extremely fast on decompression as well. And as many other things, the encoder/decoder does most of the job, meaning a bad encoder will produce worse results even if the standard itself can produce much better.
I am currently limited to the inbuilt jpeg encoder/decoder as i have not fully grasped how to P/invoke from other encoders/decoders (libjpeg etc), but that´s off topic to this.
So hopefully this is a valid question, though i think it may be on the edge of that.
EDIT: noticed that i had asked this before but in another term or what to call it. Though now i have written more specifically about it. But i think it´s pretty much a duplicate. I leave it in your hands Moderators.
Upvotes: 1
Views: 3165
Reputation: 11190
PNG is extremely slow, as you say. For a 10,000 x 10,000 pixel RGB image I see:
$ time vips copy wtc.jpg x.jpg
real 0m0.915s
user 0m1.652s
sys 0m0.052s
$ time vips copy wtc.png x.png
real 0m28.808s
user 0m32.448s
sys 0m0.272s
That's time to decompress and recompress again, real
is wall clock time, so it's about 30x slower.
Most of that is spent in Deflate decompress and recompress. PNG has an option to set the compression level, with 0 being no compression, ie. deflate turned off. It's still far slower than JPEG.
$ time vips copy wtc0.png x.png[compression=0]
real 0m6.552s
user 0m8.528s
sys 0m0.440s
About 7x slower, and of course with compression turned off the file will be much larger. I've no idea why libpng is so incredibly slow, it would be great if someone could make a libpng-turbo.
TIFF is probably the fastest widely-used format. I see:
$ time vips copy wtc.tif x.tif
real 0m0.637s
user 0m0.432s
sys 0m0.344s
So about 50% faster than JPEG, though again the file on disc will be much larger since the image is not compressed.
Formats like PPM are even faster. They are a simple dump of the image data with a small header giving dimensions. I see:
$ time vips copy wtc.ppm x.ppm
real 0m0.336s
user 0m0.196s
sys 0m0.296s
So almost 3x faster than JPEG. Again, the downside is that file will be huge, since there's no compression.
Upvotes: 1