Page 1 of 1

How to disable per-row byte alignment

Posted: 2019-05-02T05:49:38-07:00
by jobicade
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:

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)
Here's the command I'm currently using for 2-bpp images:

Code: Select all

magick image.png -depth 2 -colorspace gray Y:image.raw
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.

Re: How to disable per-row byte alignment

Posted: 2019-05-02T07:36:13-07:00
by snibgo
Sorry, I don't know how to prevent padding rows to byte boundaries.
jobicade wrote:Another option would be a way to "serialize" an image into one long row, placing each row to the right of the last.
That's easy:

Code: Select all

magick in.png -crop x1 +append out.png

Re: How to disable per-row byte alignment

Posted: 2019-05-02T08:21:15-07:00
by jobicade
That's perfect for my use case, and should work for anyone else who has this problem. Thanks!