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

Unflatten function - create an alpha channel and make white pixels fully transparent #3461

Merged
merged 12 commits into from
Apr 7, 2023

Conversation

antonmarsden
Copy link
Contributor

@antonmarsden antonmarsden commented Nov 19, 2022

@lovell A little something I'm working on. It creates a hard (0/255) alpha channel based on the pixel colour. Very keen to get your feedback on this. Note that it relates to #1648

It's currently limited to making lighter areas transparent (but easy enough to change how the threshold rules work). I'm still thinking about how to generalise it for mainstream use.

See provided images for example output (input was from the test image suite).

unflatten-swiss
unflatten-white-transparent

@lovell
Copy link
Owner

lovell commented Nov 23, 2022

Thanks for the PR, I'll be able to take a closer look in a couple of weeks.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this PR, sorry it took me a while to get around to reviewing it properly. I've added a couple of questions/thoughts inline.

lib/operation.js Outdated Show resolved Hide resolved
src/operations.cc Show resolved Hide resolved
src/operations.cc Outdated Show resolved Hide resolved
@antonmarsden
Copy link
Contributor Author

@lovell Thanks for the feedback, I'll find some time to incorporate it over the next few weeks.

@antonmarsden antonmarsden changed the title Unflatten - initial cut Unflatten function - create an alpha channel and make white pixels fully transparent Mar 24, 2023
@antonmarsden antonmarsden marked this pull request as ready for review March 24, 2023 23:58
@antonmarsden
Copy link
Contributor Author

@lovell Looks like prebuild is failing on arm64. I am doing an image compare with threshold=0. Not sure why it's breaking at this stage. Are there any platform-specific quirks to be aware of?

@lovell
Copy link
Owner

lovell commented Mar 30, 2023

libspng uses a specific NEON (SIMD) code path on ARM64 to unpack palette entries so its possible there may be a small rounding/clipping difference. It's probably nothing to worry about in the context of this change so feel free to allow a threshold of 1.

@lovell
Copy link
Owner

lovell commented Apr 1, 2023

Thank you for the updates Anton, this looks great.

Please can you add TypeScript definitions to index.d.ts then this is good to merge.

@antonmarsden
Copy link
Contributor Author

Thank you for the updates Anton, this looks great.

Please can you add TypeScript definitions to index.d.ts then this is good to merge.

Done, good to go.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, looks great, I'll merge shortly.

@lovell lovell merged commit a4c6eba into lovell:main Apr 7, 2023
@lovell lovell added this to the v0.32.1 milestone Apr 7, 2023
lovell added a commit that referenced this pull request Apr 7, 2023
@antonmarsden antonmarsden deleted the feature/unflatten branch May 8, 2023 22:42
@fyyyyy
Copy link

fyyyyy commented Aug 11, 2024

If there was a backgroundColor and threshold option for unflatten, it would be very useful. I.e. to remove background colors typically found in video game sprites.
image

@fyyyyy
Copy link

fyyyyy commented Aug 11, 2024

maybe a similar api to the trim function
#3332

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

Successfully merging this pull request may close these issues.

3 participants