pngjs icon indicating copy to clipboard operation
pngjs copied to clipboard

Support writing indexed images

Open Malvineous opened this issue 4 years ago • 5 comments

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 avatar Jan 09 '21 13:01 Malvineous

@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!

Malvineous avatar Mar 06 '21 14:03 Malvineous

@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)

lukeapage avatar Feb 17 '23 18:02 lukeapage

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!

Malvineous avatar Feb 18 '23 00:02 Malvineous

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.

lukeapage avatar Feb 19 '23 09:02 lukeapage

Hello and thank you for this wonderful library! Is there any chance of a new release with this PR merged? I am in need for a way to write indexed images and would otherwise have to go with my own fork, since this and @Malvineous' fork have since diverged.

KR155E avatar Jul 22 '24 12:07 KR155E