How to disable per-row byte alignment
Posted: 2019-05-02T05:49:38-07:00
I am using ImageMagick with the -depth option to pack a 2-bpp image into RAW format for decoding on a tiny embedded system. My decoder is very simple, reading in each byte and shifting out the 4 pixels. The decoder doesn't need any alignment, but ImageMagick pads out the final byte of each row with zeroes, so that each row starts on a byte boundary, and any image that isn't a multiple of 4 pixels wide (2 pixels for 4-bpp, 8 pixels for 1-bpp) isn't tightly packed.
Here's a minimal example to be clear:
Here's the command I'm currently using for 2-bpp images:
Does ImageMagick have a way of disabling the row-alignment and just padding the very last byte of the image? Another option would be a way to "serialize" an image into one long row, placing each row to the right of the last. Then the alignment wouldn't apply.
Here's a minimal example to be clear:
Code: Select all
Image data (0-3, 6x2 image = 12 pixels):
301212
112031
Expected output (3 bytes, rows marked with /):
11000110 0110/0101 10001101
Actual output (4 bytes):
11000110 0110(0000) / 01011000 1101(0000)
Code: Select all
magick image.png -depth 2 -colorspace gray Y:image.raw