image-js / fast-png

PNG image decoder and encoder written entirely in JavaScript
MIT License
333 stars 19 forks source link

1bit greyscale encoder support #24

Open mostley opened 2 years ago

mostley commented 2 years ago

Any plans on supporting bit depths other than 8 and 16? I would have use for a 1bit greyscale implementation. Also not averse to contributing but would like some hints why other depths weren't implemented before I spent time and dig in to avoid double work.

Great library btw. I'm really impressed with the speed, it even beat the ImageDecoder from the browser built-in WebCodecs for small greyscale pngs.

targos commented 2 years ago

Hello, would you be able to share a problematic image with us? There is nothing that specifically forbids 1bit images (https://github.com/image-js/fast-png/blob/master/src/PngDecoder.ts#L475-L486), but it is not tested because we have never encountered such images.

mostley commented 2 years ago

oh sorry, I wasn't precise enough. I meant 1bit greyscale support for the encoder: https://github.com/image-js/fast-png/blob/bdb81f93cc55aa89b312b50e5e2e8a39cdbde657/src/PngEncoder.ts#L100

We are using fast-png to create, store and read bitmasks for that images with 1bit depth would be much smaller than greyscale images. I'll see if I can create one with another encoder.

targos commented 2 years ago

I see. Feel free to try and implement it here if you want!

mostley commented 2 years ago

ok, so I gather there's no reason it wasn't done before just that there was no need up to now? Just making sure there's no reason like there's no good 1bit datastructure in javascript ;)

just for reference: test_bitmask_1bit