Photoshop: PNG compression, Deflate stream is slightly bigger than necessary

  • 1
  • Problem
  • Updated 5 years ago
  • (Edited)
The Deflate stream inside PNG files produced by Photoshop CS6 (or 5) contains empty blocks, this makes the file bigger for strictly nothing (Fireworks does not exhibit this problem).

For instance on this file:
http://www.photoshop.com/images/commo...

defdb logos.png
T Boundary Tokens h.size b.size
2 0 2600 925 33374
1 dac7 0 3 10
1 dac7 0 3 10
33394 bits long (3 blocks)

defdb tool is available here:
http://encode.ru/threads/1428-defdb-a...
Photo of Frédéric Kayser

Frédéric Kayser

  • 2 Posts
  • 0 Reply Likes
  • frustrated

Posted 5 years ago

  • 1
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 812 Reply Likes
Are you using "Save As" or "Save For Web"?

We're just using LibZ, so it should be pretty standard.
And last I checked our compression was pretty close to PNGCrush.
But it's possible that a bug has crept in, or the compiler has a bug (again).
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 812 Reply Likes
Looks like that example file was saved as 8 bit RGB (24 bit in PNG misnamed terms) from SaveForWeb.
Photo of Frédéric Kayser

Frédéric Kayser

  • 2 Posts
  • 0 Reply Likes
I did not produce this file since it came from the photoshop.com site, but I did some tests (CS5, CS6 Fireworks and Photoshop):
Apparently Fireworks uses a different compression engine (at least it splits the Deflate stream differently and it never produces empty blocks).
There's a small difference between CS5 and CS6 but nothing really relevant.

Both "Save as..." and "Save for Web" have the empty block problem, it's even worse for "Save for Web" since there are two empty blocks at the end.

The files are available in this archive:
http://frdx.free.fr/bigbazar/Photosho...

defdb fischer-photoshop-saveas.png
T Boundary Tokens h.size b.size
2 0 32767 816 229931
2 16a00 32767 920 228762
2 2be5b 12831 1064 87947
1 397e6 0 3 10 t mind if Photoshop could produce smaller files itself.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 812 Reply Likes
Ok, so it pretty much has to be some sort of problem with LibZ.
I'll have to debug it when I get a chance.

Also note that Fireworks' export as PNG results in a file of 5228 bytes, instead of the SFW file of 4275 bytes. (Photoshop saves as PNG a bit bigger because it includes more metadata and an ICC profile by default)