haraldk / TwelveMonkeys

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO
https://haraldk.github.io/TwelveMonkeys/
BSD 3-Clause "New" or "Revised" License
1.88k stars 312 forks source link

Expose the existance of PSDLayerMaskData #301

Open erikelf opened 7 years ago

erikelf commented 7 years ago

In psd, there are two possibility which is pixelDataIrrelevant is true.

One is psd group which is similar to direcotry, in this case PSDLayerMaskData is null. Another is effect and so on, in this case PSDLayerMaskData has information for it.

Since there is no way to distinguish between them, I cannot handle it seperately. I hope to expose the existance of PSDLayerMaskData , for instance "maskDataIrrelevent = true". at createLayerInfoNode at PSDMetadata.java to handle such case.

haraldk commented 7 years ago

Hi,

Thanks for your interest in the library!

I'm not sure if I fully understand your use case, and what you want to achieve using this information. Maybe if you describe in some more detail, and perhaps share some (pseudo) code on how you use (or would like to use) this, I would understand better.

I'm a little reluctant to adding a field "maskDataIrrelevent" to the meta data, because it's not something that is in the PSD format. All other fields reflect fields or flags actually in the PSD structures. Perhaps we could add a node and expose the PSDLayerMaskData fields in the metadata if present? Or we could just add the size of the data to tell if it's actually there (size = 0 if not)?

Best regards,

-- Harald K

erikelf commented 7 years ago

My code is like below / https://github.com/haraldk/TwelveMonkeys/issues/98 / IIOMetadata metadata = reader.getImageMetadata(0); IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(PSDMetadata.NATIVE_METADATA_FORMAT_NAME); NodeList layers = root.getElementsByTagName("Layers"); Node node = layers.item(0);

for ( Node n = node.getLastChild(); n != null; n = n.getPreviousSibling(), i++) { PsdLayerInfo layerInfo = new PsdLayerInfo((Element)n);

if ( layerInfo.isPixelDataIrrelevant()) {
          if ( ! layerInfo.isGroupTags()) {
                 groupMode = true;
                 /* No way to distinguish between effect layer and group layer */
                 /* All layers of above handle failed */
          } else {
                /* Skip. </Layer Group> tags indicate the end of the group */
          }
} else {
  /* Do something */

} }

The best way for me is as you suggested to expose the PSDLayerMaskData fields in the metadata if present. then I can achive not only identifying group and handle this but also identifying effect layers and possbile handle those layers decribes as "Effects Layer (Photoshop 5.0) " section in below PSD format docs http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_pgfId-1031423