I think you will all appreciate this person's commenting style. It seems very familiar to me.

XeePhotoshopLoader.m (from Xee, which is pretty good):

while([fh offsetInFile]+12<=imageoffs)
  uint32_t sign=[fh readUInt32BE];
  uint32_t marker=[fh readUInt32BE];
  uint32_t chunklen=[fh readUInt32BE];
  off_t nextchunk=[fh offsetInFile]+((chunklen+3)&~3);
At this point, I'd like to take a moment to speak to you about the Adobe PSD format. PSD is not a good format. PSD is not even a bad format. Calling it such would be an insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having worked on this code for several weeks now, my hate for PSD has grown to a raging fire that burns with the fierce passion of a million suns.

If there are two different ways of doing something, PSD will do both, in different places. It will then make up three more ways no sane human would think of, and do those too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide that these particular chunks should be aligned to four bytes, and that this alignement should not be included in the size? Other chunks in other places are either unaligned, or aligned with the alignment included in the size. Here, though, it is not included. Either one of these three behaviours would be fine. A sane format would pick one. PSD, of course, uses all three, and more.

Trying to get data out of a PSD file is like trying to find something in the attic of your eccentric old uncle who died in a freak freshwater shark attack on his 58th birthday. That last detail may not be important for the purposes of the simile, but at this point I am spending a lot of time imagining amusing fates for the people responsible for this Rube Goldberg of a file format.

Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this, I had to apply to them for permission to apply to them to have them consider sending me this sacred tome. This would have involved faxing them a copy of some document or other, probably signed in blood. I can only imagine that they make this process so difficult because they are intensely ashamed of having created this abomination. I was naturally not gullible enough to go through with this procedure, but if I had done so, I would have printed out every single page of the spec, and set them all on fire. Were it within my power, I would gather every single copy of those specs, and launch them on a spaceship directly into the sun.

PSD is not my favourite file format.

  if(sign!='8BIM') break; // sanity check

    case 'Lr16':
      layers=[XeePhotoshopLayerParser parseLayersFromHandle:fh parentImage:self alphaFlag:NULL];

Previously, previously, previously, previously, previously, previously, previously, previously.

Tags: ,

11 Responses:

  1. David M.A. says:

    Having worked with Dag before, this is very much his sort of software comment. He also created The Unarchiver, which is a great (free) unpacking utility for Macs.

  2. J. Peterson says:

    The comments are entertaining, but it indicates he doesn't understand what it takes to keep a sophisticated application both evolving and backwards compatible over a timespan of nearly a quarter century and a dozen+ major revisions.

    Joel does an excellent job of explaining why file formats like this are so complicated (he's discussing Microsoft Office files, but almost everything he writes applies to PSD as well).

    • jmags says:

      Surely JWZ will be convinced by a link to a Joel Spoelsky article.

      • Jon Dowland says:

        I hope he doesn't read it; it'd be the retired professional programmer's equivalent of the CERN collider.

        • Jon Dowland says:

          PS twitter integration is slightly broken. Sign in and the next post attempt will fail (with hidden name/email boxes); click around a bit and you get a form with name/email back and populated with the dummy values, you're then OK. I noticed first on Mobile Safari (I think, possibly mobile Chrome) and just now on regular Chrome.

    • One does not both evolve a file format and keep it backwards compatible at the same time. One either declares version 2, with a new, more sensible, design, or one sticks with the old, less sensible design, so that the same design is used throughout.

      Updating _bits_ of a design to a new format is the worst of all possible worlds.

  3. Nick Lamb says:

    Bah, still hate TIFF more. Here's a broken half-specified way to store JPEG data. Here's a "clarification" that makes it worse. And here's a "Technical Note" saying that neither way works properly and specifying a third hard-to-use and arguably still broken method. And you (JWZ) made me actually implement TIFF's stupid "Because scanner manufacturers were inconsistent in their mechanical design back in the dark ages, each file can specify which corner the pixels start at and which direction they go" functionality. Why couldn't you just have settled for manually flipping or rotating the image like any normal person? I even put up a dialog box to tell you to do that. Maybe I should have spelled it out. "This is a hateful excuse for a file format. You are a bad person for using it, pay your penance by manually flipping or rotating the image as appropriate" instead of admitting that yes, it was technically possible to fix the loader to do that for you and then spending my weekend adding the necessary feature.

    And apparently I'm a sucker for this stuff because I now have several hundred lines of medical imaging file format code sat open in an editor waiting for a spare weekend to fix the fact that my 16-bit X-rays are byte-flipped when loaded. They're not even interesting X-rays, but instead of saying "Oh, they look like crap, too bad" and deleting them I foolishly started trying to figure out what the problem is and now I'm doomed.

  4. drb says:

    Freshwater and sharks places this in Nicaragua, which seems appropriate somehow.

  5. Yeah anytime someone pestered me why I don’t work on adding built-in support for PSD or 8BF to Paint.NET, I tell them it’d take a full year of dedicated time to do it. Which is time I wouldn't have to spend time on things that don't make me want to kill myself. Now I can just point them to the plugins that some masterful wizards were generous enough to implement and post on the forum phew

    I mean hey, if you want to fund me several $100k’s per year to make it worth my time, then sure^H^H^H^H maybe^H^H^H^H^H absolutely not …

    • Bill Paul says:

      My only comment on this whole sordid affair is that I hate it when people initialize array sizes using variables instead of constants.

  • Previously