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

Support writing indexed images #225

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Malvineous
Copy link

This patch adds support for writing indexed images with palettes. It also adds a new keepIndexed option when reading files, so you can read an indexed image and keep the indexed data without it being converted to RGBA. This allows you to read, modify and write .png files while the data is in palette/index format the whole time. In this case it always unpacks the pixels when reading the file, so you end up with one pixel per byte, but e.g. in a 4-bit image with colours 0..3, each byte will always be < 4. The pixels are packed again when writing, so a 1-bit image will have eight pixels stored in a single byte.

The default for keepIndexed is false, so this change is backwards compatible and an indexed image will by default be converted to RGBA as is the case before this change.

Test code is included, and all the tests are passing except for a handful that were already failing before this change.

@Malvineous
Copy link
Author

@lukeapage Any chance of getting this one merged? If not let me know and I will do a fork so I can use these changes in my other Node projects with a normal npm install. Thanks!

@lukeapage
Copy link
Collaborator

@Malvineous do you want me to give you access to this repo and the npm package? or you would prefer just this merged (with the fork comment removed)

@Malvineous
Copy link
Author

Thanks for the offer - I'm happy to help part-time with the maintenance of the project if you're willing to give me access!

@lukeapage
Copy link
Collaborator

I moved this to a org and invited you. Hopefully I will have a few hours later to set GitHub actions, upgrade deps and look at this pr etc.

@@ -0,0 +1,152 @@
let fs = require("fs");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it would make sense to add another loop in the main file or extract the testing logic so it was clear how this differs

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.

None yet

2 participants