Converting to raw MONO: images - wrong bit order within byte
Posted: 2019-06-18T01:51:12-07:00
Hi,
I am trying to convert a batch of monochrome PNGs to raw 1-bit data, i.e. 8 ON/OFF pixels represented by each byte. My issue is that the output's bit order within each byte (not the byte order) is the opposite of what I need. As a result, each successive group of 8 pixels is flipped on the X axis.
For my purposes the most significant bit should be the leftmost pixel. For example, if my input has one pixel 'ON' followed by seven pixels OFF (left to right), I'd expect a byte value of 10000000 binary, but IM outputs 00000001.
Can this be fixed? I've tried various permutations of options like:
Seems like this can be fixed for TIFF files (-define tiff:fill-order=msb|lsb), but I couldn't find such an option for MONO:, or for any format other than TIFF. Any tips or workarounds would be appreciated.
I am trying to convert a batch of monochrome PNGs to raw 1-bit data, i.e. 8 ON/OFF pixels represented by each byte. My issue is that the output's bit order within each byte (not the byte order) is the opposite of what I need. As a result, each successive group of 8 pixels is flipped on the X axis.
For my purposes the most significant bit should be the leftmost pixel. For example, if my input has one pixel 'ON' followed by seven pixels OFF (left to right), I'd expect a byte value of 10000000 binary, but IM outputs 00000001.
Can this be fixed? I've tried various permutations of options like:
Code: Select all
magick convert input.png -monochrome -depth 1 MONO:test1.raw
magick convert input.png -type bilevel MONO:test2.raw