Discussion:
[png-mng-implement] Write binary (1-bit depth) PNG image
Hai Yen
2005-12-20 07:11:28 UTC
Permalink
Hi all,

I have a grayscale 8-bit depth PNG image with only 2 possible values for any
pixel: 0 or 255 (i.e. a black and white image).

I want to convert it into a binary 1-bit depth PNG image. Is there any way
to do this using libpng?

Any pointers to relevant directions or funtions is greatly appreciated!

Thanks,

Haiyen.
Greg Roelofs
2005-12-21 16:41:13 UTC
Permalink
Post by Hai Yen
I have a grayscale 8-bit depth PNG image with only 2 possible values for any
pixel: 0 or 255 (i.e. a black and white image).
I want to convert it into a binary 1-bit depth PNG image. Is there any way
to do this using libpng?
Yes; pnmtopng (and pngtopnm) uses libpng and can do that sort of thing.
I _think_ gif2png can, too, but it's been a while since I hacked on it.
Post by Hai Yen
Any pointers to relevant directions or funtions is greatly appreciated!
Without having looked, I'm pretty sure you just need to read the grayscale
image as such (i.e., don't use png_set_expand() to expand it to "RGB") and
then call png_set_packing() (or something like that) as one of the output
transformations when writing. Search libpng.txt for "packing"; it should
be fairly obvious. (Let us know if it's not, though...)

Greg

Loading...