fast-png icon indicating copy to clipboard operation
fast-png copied to clipboard

1bit greyscale encoder support

Open mostley opened this issue 3 years ago • 4 comments

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.

mostley avatar Jan 11 '22 16:01 mostley

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.

targos avatar Jan 12 '22 06:01 targos

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.

mostley avatar Jan 12 '22 09:01 mostley

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

targos avatar Jan 12 '22 09:01 targos

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

mostley avatar Jan 12 '22 09:01 mostley