This programmer has written about the PSD format in colorful detail: "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."
https://code.google.com/p/xee/source/browse/XeePhotoshopLoad...
(ref: first link in the article)