-
Notifications
You must be signed in to change notification settings - Fork 94
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
base: main
Are you sure you want to change the base?
Conversation
This allows the tests to be run for those who don't have yarn installed.
@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 |
@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) |
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! |
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"); |
There was a problem hiding this comment.
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
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
isfalse
, 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.