Home / Alt manpages / pbmtomda(1)

  • pbmtomda(1)
  • User command
  • linux

Convert PBM Images to MicroDesign MDA with pbmtomda

You will convert a PBM bitmap into a MicroDesign 2 area file with pbmtomda. The command writes the MDA data to standard output, so you can read a file, pipe a PBM from another Netpbm command, or keep the conversion in a script. Allow about ten minutes if the PBM is ready. This guide uses Netpbm 11.5.2, installed here as package version 2:11.05.02-1.1build1.

The conversion is unprivileged. You need the netpbm package, a readable PBM input and a directory where you can create the MDA output. No service restart or system configuration is involved.

1. Check the installed command

Confirm which executable your shell will run and read the local manual:

$ command -v pbmtomda
/usr/bin/pbmtomda
$ man pbmtomda

The installed manual describes PBM input and MicroDesign 2 MDA output. It also says that omitting the input filename makes the command read standard input. The manual page is dated 15 September 2023, while the installed Netpbm build is 11.5.2, so use the checks below to confirm behaviour on a different package release.

Checkpoint

If command -v prints nothing, install Netpbm through your normal package-management process before continuing. Do not use sudo for the conversion itself.

2. Convert a PBM file without changing it

Give the source filename and redirect the binary output to a new destination:

$ pbmtomda /path/to/input.pbm > /path/to/output.mda

The source is read, not modified. A successful run normally prints no progress text because the output stream is the MDA file. Check both the exit status and the result:

$ printf '%s\n' "$?"
0
$ test -s /path/to/output.mda && echo 'MDA file is non-empty'
MDA file is non-empty
$ file /path/to/output.mda
/path/to/output.mda: data

The exact file description can vary. A non-zero status means the conversion did not complete. For example, a missing input produces an error about being unable to open the file and leaves an empty redirected destination. Keep the original PBM until the MDA has been checked by the program that will consume it.

3. Pipe PBM data through standard input

You can omit the filename when another command supplies PBM data. This small example uses PBM's plain-text form and writes a simple 8 by 8 test pattern:

$ printf '%s\n' \
    'P1' \
    '8 8' \
    '0 0 0 0 0 0 0 0' \
    '0 1 1 1 1 1 1 0' \
    '0 1 0 0 0 0 1 0' \
    '0 1 0 1 1 0 1 0' \
    '0 1 0 1 1 0 1 0' \
    '0 1 0 0 0 0 1 0' \
    '0 1 1 1 1 1 1 0' \
    '0 0 0 0 0 0 0 0' | pbmtomda > test-pattern.mda
$ printf '%s\n' "$?"
0
$ test -s test-pattern.mda && echo 'test-pattern.mda is ready'
test-pattern.mda is ready

In a real pipeline, replace the test pattern with a command that emits valid PBM. The format still matters: pbmtomda is a PBM reader, not a general image decoder. A PNG, JPEG or arbitrary text file is not a substitute for PBM.

4. Choose aspect-ratio compensation deliberately

MicroDesign files use an aspect ratio that can make an image appear too tall unless the output height is halved. Pass -d for that compensation:

$ pbmtomda -d /path/to/input.pbm > input-halved.mda
$ test -s input-halved.mda && echo 'scaled MDA file is non-empty'
scaled MDA file is non-empty

The synopsis also shows -dscale. Netpbm accepts that longer spelling on the installed command, and the manual says the minimum unique abbreviation is allowed, so -d is the documented short option. This option changes the output dimensions; it does not resize the PBM source on disk.

Do not add -d automatically to every batch. First decide how the receiving MicroDesign software displays the image. Keep separate output names when comparing both forms:

$ pbmtomda /path/to/input.pbm > input-normal.mda
$ pbmtomda -d /path/to/input.pbm > input-halved.mda
$ wc -c input-normal.mda input-halved.mda
  142 input-normal.mda
  135 input-halved.mda
  277 total

The byte counts above are from the small test image used on this machine, not a universal size prediction. Image dimensions and content affect the result.

5. Invert the PBM colours when required

PBM uses two colours, but the foreground and background may not match what the destination expects. Use -i, or the longer -invert spelling, to invert the colours in the output:

$ pbmtomda -i /path/to/input.pbm > input-inverted.mda
$ pbmtomda -invert /path/to/input.pbm > input-inverted-long-option.mda
$ cmp input-inverted.mda input-inverted-long-option.mda
$ printf '%s\n' "$?"
0

cmp returning zero confirms that both spellings produced identical output for this input. Inversion is a conversion choice, not a repair for a malformed PBM. If the image looks wrong, first inspect the source and then compare normal and inverted outputs in the target viewer.

6. Protect existing output files

Warning

Shell redirection with > truncates an existing destination before pbmtomda starts. Use a temporary name, verify it, then replace the old file only if that is intentional:

$ pbmtomda /path/to/input.pbm > output.mda.new
$ test -s output.mda.new
$ mv output.mda.new output.mda

If the conversion fails, leave the existing output.mda alone and remove the incomplete temporary file:

$ rm output.mda.new

That rm is destructive, so check the filename before running it. If you need an easy rollback before replacing a useful result, make a backup first:

$ cp --preserve=all output.mda output.mda.backup
$ pbmtomda -d /path/to/input.pbm > output.mda.new
$ test -s output.mda.new && mv output.mda.new output.mda
$ mv output.mda.backup output.mda

The final command is the undo operation: use it only when you have decided the new output should be discarded. Otherwise retain the backup until the MDA has been tested.

7. Handle the common failure cases

If the input cannot be opened, check the path and permissions without changing anything:

$ ls -l /path/to/input.pbm
$ test -r /path/to/input.pbm && echo readable

If the command rejects the input, confirm that it is really PBM and that a producer has not sent a different image format. If the output is unexpectedly tall, compare a normal run with -d. If foreground and background are reversed, compare with -i. These options can be combined, for example pbmtomda -d -i input.pbm, but choose each one for a known display requirement.

The manual notes that there is no way for this command to produce MicroDesign 3 format. It produces MicroDesign 2 area files only. The separate mdatopbm tool can read both formats, but that does not change what pbmtomda writes.

Done means

  • pbmtomda is installed and the PBM source is readable.
  • The command exits with status 0 and creates a non-empty MDA file.
  • Standard input is used only when the preceding command emits valid PBM.
  • -d is used only when MicroDesign display proportions need height compensation.
  • -i is used only when the destination needs inverted PBM colours.
  • Existing output is protected with a temporary file or a deliberate backup.
  • The result is understood to be MicroDesign 2, not MicroDesign 3.