psd-tools / psd-tools

Python package for reading Adobe Photoshop PSD files
https://psd-tools.readthedocs.io/
MIT License
1.14k stars 189 forks source link

Question/suggestion on changing Solid Fill Layer and compositing #256

Open lex3001 opened 3 years ago

lex3001 commented 3 years ago

Describe the bug If I open a PSD with Solid Color Fill layers, adjust the colors of one of more of those layers, and then composite() on the PSD, I notice two things:

  1. The composite operation is very slow (45+ seconds for a PSD with 8 visible solid color fill layers (two of those are inside two different groups), one pixel layer.
  2. The composite operations ignores any color changes I make to the Data of the Solid Color Fill layer.

To Reproduce

  1. Create a PSD with some solid color fill layers, set them to some colors, and save.
  2. Open in psd-tools, change some colors, and create a composite of the psd and then save to png

Expected behavior Well, I wasn't sure since I know editing is very limited. I was hoping it might be speedy and apply colors but I think that is not a feature yet. I assume this is just not implemented so I thought I might suggest it. I was also curious as what the composite feature IS doing that takes so long. (I can fire up GIMP and do all these things and export in about 8 seconds, still way longer than I would like. Sharing just for comparison purposes. I know you are not trying to replicate GIMP or Adobe PS functionality.)

Here's some python I was using to try and set the data descriptor to the new color:

def set_color(desc, color):
    rgb = ImageColor.getrgb(color)
    desc['Rd  '] = float(rgb[0])
    desc['Grn '] = float(rgb[1])
    desc['Bl  '] = float(rgb[2])

File and screenshots If applicable, add a PSD file and screenshots to help explain your problem.

Environment

Anyway I am curious to learn if I am missing anything. Really nice tool for reading PSD information, though, thank you!

kyamagu commented 3 years ago

Thanks for reporting the issue, it is likely the color did not change because the cached pixels in the PSD file is used for compositing. There is no mechanism yet to flag what is edited on compositing in psd-tools. This is one of the major feature necessary for writing support, though.

As for performance, the current compositing is implemented in numpy operations. But this still much slower than highly optimized rendering backends like OpenGL. Probably as some point the compositing should switch to low-level implementation by C/C++, but this involves huge efforts including reverse engineering how Photoshop implements rendering operations. I do not expect any major fix in a near future.