Home / Alt manpages / pbmtomda(1)

  • pbmtomda(1)
  • User command
  • linux

Convert PBM Images to MicroDesign MDA with pbmtomda

MicroDesign 2 on a vintage Atari setup only understands its own MDA area files, and pbmtomda is what turns a PBM bitmap into one.

The command writes MDA data to standard output, so you can read a file, pipe a PBM from another Netpbm command, or fold the conversion into 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 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, and 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 nothing, 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 finish: a missing input, for example, 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 whatever 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, swap the test pattern for a command that emits valid PBM. pbmtomda is a PBM reader, not a general image decoder: a PNG, JPEG or arbitrary text file is not a substitute.

4. Choose aspect-ratio compensation deliberately

MicroDesign files use an aspect ratio that can make an image look 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 too, since the manual allows the minimum unique abbreviation, but -d is the documented short option. It changes the output dimensions; it does not resize the PBM source on disk.

Do not add -d automatically to every batch. Decide first how the receiving MicroDesign software displays the image, and 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

Those byte counts come from a small test image on this machine, not a universal prediction. Image dimensions and content affect the result.

5. Invert the PBM colours when required

PBM uses two colours, but foreground and background may not match what the destination expects. Use -i, or the longer -invert spelling, to flip them 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

Example

cmp returning zero confirms 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, inspect the source first, 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. For 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

Recovery

That final command is the undo step; use it only once you have decided the new output should be discarded. Otherwise keep 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
  • Command rejects the input. Confirm it is really PBM and that a producer has not sent a different image format.
  • Output is unexpectedly tall. Compare a normal run with -d.
  • Foreground and background are reversed. Compare with -i. Options can combine, for example pbmtomda -d -i input.pbm, but choose each one for a known display requirement.

The manual notes 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.