Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of supported features #14

Open
bryab opened this issue Apr 20, 2020 · 6 comments
Open

List of supported features #14

bryab opened this issue Apr 20, 2020 · 6 comments

Comments

@bryab
Copy link

bryab commented Apr 20, 2020

Hey fellas, thanks for making this library. I am currently using the "psd_tools" library for Python, but was considering rewriting this tool I've made in Rust. However I'm pretty sure this library is not nearly as complete as that one. Do you have a list of supported/unsupported features?

My requirement is just the ability to "merge" (composite) a layer group into a single image, with respect to the following features:

  • Adjustment Layers
  • Blending Modes
  • Clipping Masks
  • Masks

Is this currently possible? Would be happy to help but I am unfortunately not a Rust expert. I will say, the psd_tools library may be a good resource for you all for reference.

@chinedufn
Copy link
Owner

chinedufn commented Apr 20, 2020

Hey!

There isn't currently a list of supported/unsupported features - but you're totally right that it's something that we need. I'll leave this issue open until that exists.

I'll go feature by feature on what you're looking for:

Compositing layer groups

A week ago #13 landed introducing support for layer groups.

You can retrieve all of the groups or a group by name using methods such as:

https://docs.rs/psd/0.1.7/psd/struct.Psd.html#method.group_by_name

Then use Psd.flatten_layers_rgba to flatten only the layers in that group

Adjustment layers

Right now we respect the size of layers when compositing

psd/src/lib.rs

Lines 266 to 272 in 9709677

// If this pixel is out of bounds of this layer we return the pixel below it.
// If there is no pixel below it we return a transparent pixel
if pixel_left < layer.layer_properties.layer_left as usize
|| pixel_left > layer.layer_properties.layer_right as usize
|| pixel_top < layer.layer_properties.layer_top as usize
|| pixel_top > layer.layer_properties.layer_bottom as usize
{

but not much else.

Supporting adjustment layers would come down to tweaking our layer blending to respect the settings of the layer.

Blending Modes

Right now we blend layers linearly and don't respect the blending mode.

psd/src/lib.rs

Lines 342 to 348 in 9709677

// blend the two pixels.
//
// TODO: Take the layer's blend mode into account when blending layers. Right now
// we just use ONE_MINUS_SRC_ALPHA blending regardless of the layer.
// Didn't bother cleaning this up to be readable since we need to replace it
// anyways. Need to blend based on the layer's blend mode.
fn blend_pixels(top: [u8; 4], bottom: [u8; 4], out: &mut [u8; 4]) {

Changing this would involve looking at the layer's blend mode and using that to decide what function to call to blend two pixels.

Clipping masks / masks

Same here - we don't respect it - but would just boil down to sprinkling in some code to look at the clipping mask and do the right thing.

Why aren't these things supported?

So far the psd crate has evolved from people's needs.

Most recently someone needed support for groups - boom they PRd group support.

The process of adding new functionality typically boils down to adding a test against a new test psd file (or an existing one if applicable)

https://github.com/chinedufn/psd/tree/master/tests/fixtures

Would be happy to help but I am unfortunately not a Rust expert

I'd be more than happy to give you very detailed notes, thoughts and direction on how to add any functionality that you might want to add.

We're already reading all of the data that is needed - we just end up ignoring a lot of it right now.

So adding functionality typically involves adding a test .psd file and then sprinkling in code in a few self-contained locations to make the test pass - which I'd be more than happy to point you towards.

So yeah - if you have the interest I'm more than happy to help with detailed pointers/guidance through where to add things, otherwise feel free to check back in the future when more of this is hopefully in place!

@bryab
Copy link
Author

bryab commented Apr 20, 2020

Thanks!! Glad to see you all are interested in building up this library. I would love to help and I might try to dive in and try implementing some of those things. I have done a lot of work with blending modes in various contexts, so I'm pretty familiar with the math involved.

@chinedufn
Copy link
Owner

That's awesome! Your experience with blending modes would be super useful.

Cool - let me know if you ever end up diving in since I'm more than happy (excited) to answer any questions that you might have about the codebase / Rust / etc.

@chinedufn
Copy link
Owner

@bryab welp it looks like @tdakkota swooped in and knocked out a bunch of stuff. Check it out! #15

@chinedufn
Copy link
Owner

chinedufn commented Jun 5, 2020

Now that #15 landed most of this is supported but I'll keep this issue open until I make time to add some documentation to the guide.

@targrub
Copy link

targrub commented Jul 26, 2022

I wanted to make you aware of the C++ .psd code library, at https://github.com/MolecularMatters/psd_sdk, which uses the BSD-2-Clause license. Overview page at https://molecular-matters.com/products_psd_sdk.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants