How to disable per-row byte alignment

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jobicade
Posts: 2
Joined: 2019-05-02T05:29:27-07:00
Authentication code: 1152

How to disable per-row byte alignment

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to disable per-row byte alignment

Post 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
snibgo's IM pages: im.snibgo.com
jobicade
Posts: 2
Joined: 2019-05-02T05:29:27-07:00
Authentication code: 1152

Re: How to disable per-row byte alignment

Post by jobicade »

That's perfect for my use case, and should work for anyone else who has this problem. Thanks!
Post Reply