This project has moved and is read-only. For the latest updates, please go here.


RleWriter inconsistency


While it appears to be perfectly valid, if you debug with the attached file, you'll notice that (in my case) the red channel decodes fine, but encodes with a different header to the original.

file attachments

Closed Sep 23, 2013 at 2:24 AM by taoyue


GeorgeR wrote Dec 12, 2012 at 2:06 AM

I think I got it. If a value is repeated only twice, its kept as a literal value because making it an rle packet would add an unnecessary header byte.

taoyue wrote Sep 23, 2013 at 2:24 AM

Fixed in 5517c096da08 (2013-09-22).

Thanks for debugging. The two-byte run is indeed the problem. As always, it's more complicated than just that. There are actually three different ways to handle two-byte runs in PackBits RLE: the Apple way, the TIFF way, and the Photoshop way. I have chosen to implement the Photoshop way.

Note that you should still not expect to get identical RLE compressed data. Other programs may not do it the Photoshop way. The TIFF spec actually suggested that Mac applications could call the Apple API. And with this change, the PSDPlugin actually compresses more-tightly than Photoshop, which doesn't max out all 128 bytes of a repeat packet.