PSD was never intended to be a data interchange format: it is the serialization format of a single program that has more individual unrelated features that actual people rely on than almost any other piece of software and has maintained striking amounts of backwards compatibility and almost unbroken forwards compatibility during its over two decades of existence. This product's "file format" needs to be critiqued in this context, along with similar mega-programs like Office.<p>I am thereby having a difficult time fathoming why anyone would think that a PSD file is thereby going to be some well-organized file format that they should easily be able to parse from their own application is just naively wishful thinking: even other products from Adobe have limitations while opening these files; to truly manipulate these files you really need to be highly-compatible with Photoshop's particular editing model (hence the conceptual difference between these two classes of file format).
Has been on HN before (<a href="http://news.ycombinator.com/item?id=575122" rel="nofollow">http://news.ycombinator.com/item?id=575122</a>) but it was years ago. I mention this just in case others are having the same feeling of deja vu as me.
I'm pretty sure the PSD format chucks are based off IFF spec from 1985<p><a href="http://www.martinreddy.net/gfx/2d/IFF.txt" rel="nofollow">http://www.martinreddy.net/gfx/2d/IFF.txt</a><p>Things were padded to 4 byte boundries because the 68000 processor would crash if you read an unaligned 32bit value. So the length of the actual data was what you find in the size field of each chuck but each chunk is padded. That way you didn't have to work around the 68000 quirks and read a byte at a time.<p>I wrote a psd reader in 93. It wasn't that hard and still works today. Maybe I chose an easy subset. It only reads the original result (merged layers) that gets saved when you chose to save backwards compatible files in photoshop.<p><a href="http://elibs.svn.sourceforge.net/viewvc/elibs/trunk/elibs/lib/echidna/photoshp.c?revision=97&view=markup" rel="nofollow">http://elibs.svn.sourceforge.net/viewvc/elibs/trunk/elibs/li...</a>
John Nack replied to this 3 years ago on his blog.<p><a href="http://blogs.adobe.com/jnack/2009/05/some_thoughts_about_the_psd_format.html" rel="nofollow">http://blogs.adobe.com/jnack/2009/05/some_thoughts_about_the...</a>
I appreciate the first code comment more after the introduction:<p><pre><code> if(sign!='8BIM') break; // sanity check
</code></pre>
"Sanity check" as in "let's make sure it's really a PSD before we go insane".
Many more for your viewing pleasure :
<a href="http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered" rel="nofollow">http://stackoverflow.com/questions/184618/what-is-the-best-c...</a>
One of my favorite blog posts from Joel Spolsky talks about this, basically explaining how these formats come to be. For mega-softwares like those, the source code is the de facto file spec www.joelonsoftware.com/items/2008/02/19.html
This reminded me of just how nice the Doom WAD format is: <a href="http://doomwiki.org/wiki/WAD" rel="nofollow">http://doomwiki.org/wiki/WAD</a><p>When a friend complained that he had a hard time figuring out which maps were present in a given WAD, I enjoyed myself while writing a utility to organize them into directories with map numbers. I kept thinking: this is how you serialize data. Looking back on the code now, it's still easy to understand.
Whilst I enjoy jwz's writings, please follow the hacker news guidelines which can be found at <a href="http://ycombinator.com/newsguidelines.html" rel="nofollow">http://ycombinator.com/newsguidelines.html</a><p>In particular:
Please submit the original source. If a blog post reports on something they found on another site, submit the latter.
The original source is
<a href="https://code.google.com/p/xee/source/browse/XeePhotoshopLoader.m#102" rel="nofollow">https://code.google.com/p/xee/source/browse/XeePhotoshopLoad...</a><p>Also:
Please use the original title, unless it is misleading or linkbait.