convert from ImageMagick
E.g., an 8-bit 2x3 grayscale:
printf '\x00\xFF\x88\xFF\x00\xFF' > f
convert -depth 8 -size 3x2+0 gray:f out.png
-depth 8: each color has 8 bits
+0 means starting at offset 0 in the file. If there are metadata headers, you can skip them with the offset.
gray:f: the input file is
f, and the format is
gray, as defined at http://www.imagemagick.org/script/formats.php This weird notation is used because ImageMagick usually determines the format from the extension, but here there is no extension.
The problem now is how to view the output. A direct
is not very good because the image is too small, and if you zoom in a lot
eog uses a display algorithm that mixes up pixels, which is better for most pictures, but not in our case. I found two possibilities:
gimp out.png. Image editors must show every single pixel.
convert out.png -scale 300x200 out2.png.
-scale is needed instead of
-resize mixels pixels up much like
eog by default.
printf '\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF' > f
convert -depth 8 -size 3x1+0 rgb:f out.png
Tested on Ubuntu 16.04, ImageMagick 6.8.9.