I have researched this for my TIFF ImageIO plugin, and as far as I understand, the way Photoshop stores layer information in TIFFs is completely proprietary and not using standard TIFF mechanisms, like multi-page documents utilizing linked or nested IFDs (330/SubIFD
), or file types (254/NewSubFileType
), etc.
Instead, it stores the layer information,
along with the layer image data, in a Photoshop specific TIFF tag; 37724/ImageSourceData
, which has type UNDEFINED
(or "just bytes"). Luckily, the contents of this tag is documented in Adobe Photoshop?
TIFF Technical Notes.
The content of this tag will always start with the 0-terminated string "Adobe Photoshop Document Data Block"
. The rest of the contents is various Photoshop resources, identified by the Photoshop 4 byte resource identifier 8BIM
, followed 4 bytes resource key and 4 bytes length for each individual resource.
The interesting resource in this block, with regards to Photoshop layers, is the one identified with the resource key Layr
. This is the same structure documented in Layer and Mask Information Section in the Photoshop File Format.
There's also a different tag, 34377/Photoshop
, which contains other image resources read and written by Photoshop. It's also documented in the Image Resources Section of the above document. It does contain some information which is interesting in regards to layers, but I'm not sure how much of this you need to write. You will probably need a Photoshop installation and test using the "real thing".
I do have code to read both of these structures in the PSD ImageIO plugin, which might be worth looking at, but it doesn't yet support writing.
When you can write the contents Photoshop TIFF tags, you should be able to pass it to the TIFFImageWriter
as part of the TIFF IIOMetadata
and the writer will write it along with any other metadata and pixel data you pass.
So, as you see, this is all (mostly) documented and for sure doable in Java, but still not completely trivial.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…