Home / Alt manpages / jbigtopnm(1)

  • jbigtopnm(1)
  • User command
  • linux

Convert JBIG Images to PBM or PGM with jbigtopnm

You will decode a JBIG image entity (BIE) into a Netpbm PBM or PGM file, inspect the encoded header before committing to a conversion, and avoid losing an existing output file. Allow about fifteen minutes for a known-good input, or longer if you need to identify its bitplanes and resolution layers.

You need a Linux shell, a readable JBIG input file, and the netpbm package. The examples use Netpbm package version 2:11.05.02-1.1build1, with jbigtopnm installed at /usr/bin/jbigtopnm. The local manual page is dated 28 July 2020, so this is a guide to the installed interface rather than a claim that every Netpbm release behaves identically.

1. Check the installed converter

Confirm the executable and package version first. These commands only read system state and do not need elevated privileges:

$ command -v jbigtopnm
/usr/bin/jbigtopnm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

jbigtopnm reads a JBIG bi-level image entity from a file or standard input. With one bitplane, it writes PBM. With several bitplanes, it writes PGM unless you select one plane. PBM and PGM are uncompressed Netpbm formats, so they are useful intermediates even when the final destination is PNG or another format.

Checkpoint

The command path should point to the Netpbm installation you intend to use, and the input should remain untouched throughout this guide.

2. Inspect the BIE before decoding it

Use --diagnose when you do not know the encoded dimensions, number of planes or available resolution layers:

$ jbigtopnm --diagnose /path/to/input.jbg
Decomposition of BIH:

  DL = 0
  ...
  1 stripes, 0 layers, 1 planes

The exact values depend on the file. The summary is written to the terminal and the program exits without writing an image. Look for the plane count and for the layer information before choosing --plane, --xmax or --ymax. If the command cannot read the input, fix the path or permission problem first; do not compensate by running the converter as root.

A BIE can contain several concatenated resolution layers of the same image. Higher layers are stored as differences from lower ones. This is why a size limit selects an existing layer rather than rescaling arbitrary pixels.

3. Convert one-plane input to PBM

For an ordinary one-plane BIE, supply an input and a new output path:

$ jbigtopnm /path/to/input.jbg /path/to/output.pbm
jbigtopnm: WRITING PBM FILE

The status line is diagnostic output, not image data. Verify the result with a file-type check:

$ file /path/to/output.pbm
/path/to/output.pbm: Netpbm image data, size = 1600 x 1200, rawbits, bitmap
$ head -n 2 /path/to/output.pbm
P4
1600 1200

The wording from file can vary, but the PBM magic number is P4 for a raw PBM file. A successful command and a non-empty file do not prove that the chosen resolution is the one you wanted, so check the dimensions as well.

4. Use standard input and output when composing a pipeline

Omit both file names to read standard input and write the decoded image to standard output. Add --quiet so diagnostic text does not mix with binary image data:

$ jbigtopnm --quiet < /path/to/input.jbg > /path/to/output.pbm
$ head -c 2 /path/to/output.pbm
P4

Only redirect standard output. Do not redirect diagnostic output into the image. This form is useful with another Netpbm command, for example:

$ jbigtopnm --quiet /path/to/input.jbg | pnmtopng > /path/to/output.png
$ file /path/to/output.png
/path/to/output.png: PNG image data, 1600 x 1200, 1-bit grayscale

pnmtopng is a separate program. If it is not installed, keep the verified PBM or install the required package through your normal package-management process.

5. Select a resolution layer, not a made-up size

Use --xmax to choose the largest encoded layer no wider than a limit, and --ymax for height. Use both when both dimensions matter:

$ jbigtopnm --xmax 1600 --ymax 1200 /path/to/input.jbg /path/to/output-1600x1200.pbm
jbigtopnm: WRITING PBM FILE
$ file /path/to/output-1600x1200.pbm
/path/to/output-1600x1200.pbm: Netpbm image data, size = 1600 x 1200, rawbits, bitmap

If no layer satisfies a limit, the converter uses the smallest available layer. Therefore the output can still exceed a requested maximum when the BIE does not contain a layer below it. These options do not perform ordinary image resizing.

The manual also documents the short forms --x and --y, and Netpbm accepts the shortest unique option abbreviation. Full option names are clearer in scripts and less likely to become ambiguous if the interface grows.

6. Extract one bitplane when the input has several

When a BIE contains multiple bitplanes, select one plane with a zero-based number. The first plane is plane 0:

$ jbigtopnm --plane 0 /path/to/multiplane.jbg /path/to/plane-0.pbm
jbigtopnm: WRITING PBM FILE
$ file /path/to/plane-0.pbm
/path/to/plane-0.pbm: Netpbm image data, size = 1600 x 1200, rawbits, bitmap

Selecting a single plane forces PBM output. The plane number must exist in the input. Use --diagnose first if you are unsure how many planes are present.

If you decode all planes instead, jbigtopnm needs to know whether the encoder used Gray code words or binary values. Use --binary only when the encoder used binary mode:

$ jbigtopnm --binary /path/to/multiplane.jbg /path/to/output.pgm

The BIE does not record which mode was used, so the decoder cannot discover this automatically. A wrong choice can produce plausible-looking but incorrect grey values. Do not add --binary merely because the input has more than one plane; confirm the encoder's setting.

7. Protect an existing output file

> truncates its destination before the converter starts. The named-output form can also replace a file supplied as the output path. If the current result matters, write a temporary file in the same directory and replace the old result only after verification:

$ jbigtopnm --quiet /path/to/input.jbg /path/to/output.pbm.part
$ file /path/to/output.pbm.part
/path/to/output.pbm.part: Netpbm image data, size = 1600 x 1200, rawbits, bitmap
$ mv -- /path/to/output.pbm.part /path/to/output.pbm

If conversion fails, leave the original output alone and investigate the error. Remove the incomplete .part file only after checking its path. The mv is the state-changing step; it normally needs no elevated privileges when both paths belong to you. Keep the original JBIG file until the decoded image has been inspected.

8. Diagnose the likely failures

  • A missing or unreadable input is a path or permission problem. Check it with ls -l /path/to/input.jbg and test -r /path/to/input.jbg.
  • A PBM result from a one-plane file is expected. A PGM result means multiple planes were decoded together; use --plane if you need one PBM plane.
  • Unexpected dimensions usually mean that a different resolution layer was selected. Inspect the BIE, then pass explicit limits and verify the header.
  • Unexpected grey values in a multi-plane image can mean that --binary does not match the encoder. Find the encoder configuration rather than guessing.
  • Terminal text such as WRITING PBM FILE belongs on standard error. Use --quiet in binary pipelines.

This converter only reads the BIE and writes the requested image. It does not need root, does not load a service, and does not change the input. Keep privileged access out of the workflow unless filesystem permissions genuinely require an administrator to grant access.

Done means

  • jbigtopnm and the Netpbm version were checked.
  • --diagnose was used when the BIE layout or dimensions were uncertain.
  • The output format matches the intended result: PBM for one plane or a selected plane, PGM for decoded multiple planes.
  • Any resolution limits and binary-versus-Gray choice were based on the input and encoder, not guessed.
  • The output header and dimensions were verified, and an existing result was protected from premature truncation.