0

I am trying to convert a PSD file (500+ MB in size) which yields to this exception:

java.io.EOFException: Unexpected end of PackBits stream
    at com.twelvemonkeys.io.enc.PackBitsDecoder.readFully(Unknown Source)
    at com.twelvemonkeys.io.enc.PackBitsDecoder.decode(Unknown Source)
    at com.twelvemonkeys.io.enc.DecoderStream.fill(Unknown Source)
    at com.twelvemonkeys.io.enc.DecoderStream.read(Unknown Source)
    at java.io.DataInputStream.readShort(DataInputStream.java:313)
    at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.read16bitChannel(Unknown Source)
    at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readImageData(Unknown Source)
    at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.read(Unknown Source)
    at javax.imageio.ImageIO.read(ImageIO.java:1448)
    at javax.imageio.ImageIO.read(ImageIO.java:1308)

Could anybody please suggest a solution for this? Or, at least, a reason why it yields this exception (maybe newer version of photoshop?).

UPDATE:

Here is the link for the PSD file I used: heavy.psd

Prakhar Mishra
  • 1,586
  • 4
  • 28
  • 52
  • Please attach (link) the file in question, and I'll tell you. ;-) – Harald K Sep 29 '15 at 18:29
  • Hey @haraldK, thanks for reply. I have attached a link to PSD file I was trying to convert. Moreover, I am using *Java 8* with `TwelveMonkeys 3.1.1`. Please tell me if there is any other info I can provide to help you analyze the problem. – Prakhar Mishra Sep 30 '15 at 13:03
  • Can you open this PSD file in Photoshop? At least I can't open this file (properly) in any of the standard tools in OS X, like Preview. To me, it seems like the file is corrupted. – Harald K Sep 30 '15 at 13:08
  • Oh, I see. Actually I can open this file in Photoshop CS 6 (Extended). If any of the tools at your disposal can't open it, then that explains it. Can you please name the tools you are using on your machine? – Prakhar Mishra Sep 30 '15 at 13:42
  • Actually, I think it could be a bug in the code. I'm investigating... – Harald K Sep 30 '15 at 13:56

1 Answers1

0

Okay, so here's the issue:

The PSD in question is 16 bit per sample, and uses PackBits compression. For some reason, I have had no test samples with this specific configuration, so there's been a bug there for ages.

For PackBits-compressed PSDs, there's a list of each row's byte count (for easier random access I guess) at the beginning of the file. I had this value multiplied by 2 for 16 bit and 4 for 32 bit samples, but obviously a byte count is just a byte count, regardless of if the samples are 2 or 4 bytes...

Now, when I changed this, the image is read without error. However, this PSD seems to be stored without a "merged" layer (this is what most software that claims to read PSD is able to display), yet it has 7 channels, of which 4 are alpha channels. When I open it, it just comes out mostly transparent (opening in OS X's Preview, it comes out all transparent).

The above fix is now pushed to the master branch on GitHub.

Harald K
  • 26,314
  • 7
  • 65
  • 111