Home / Alt manpages / cameratopam(1)

  • cameratopam(1)
  • User command
  • linux

Convert a Raw Camera File to PAM with cameratopam

cameratopam turns a raw camera file into a PAM image without touching the original, and this walks through doing that safely. The examples use cameratopam from Netpbm 11.5.2, installed here as Debian package version 2:11.05.02-1.1build1. Allow about fifteen minutes for one file.

You need a readable raw camera image and the Netpbm package. The command normally runs as your ordinary user: you do not need sudo unless filesystem permissions, rather than cameratopam itself, block you from reading the input or writing the destination.

1. Check the installed command

Confirm which executable is being used and record its Netpbm build. This is read-only:

$ command -v cameratopam
/usr/bin/cameratopam
$ cameratopam -version
cameratopam: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
cameratopam: Built from source dated 2024-03-31 09:09:47
cameratopam: Built by Debian
...

The final lines describe the local build and may differ on your system. The installed manual is the contract to follow: it says an input file name is optional, and that options can be abbreviated to the shortest unique prefix. Use full option names in scripts anyway, so a later change cannot make a short form ambiguous.

Checkpoint

Continue only if command -v points to the Netpbm executable you intended to test.

2. Identify the raw file before converting it

Use -identify_only for format detection with no output image. It reports to standard error and fails if the format is not recognised:

$ cameratopam -identify_only /path/to/PHOTO.RAW
format information is printed by cameratopam

The exact identification text depends on the camera file, so do not build a script around a particular wording. A non-zero exit status means the installed decoder did not recognise this file. Check the path and preserve the original while you investigate:

$ test -r /path/to/PHOTO.RAW && echo readable
readable
$ printf 'identify status: %s\n' "$?"
identify status: 0

A readable file is not the same as a supported file. Run that status check straight after the command it is testing, not later.

3. Make a first PAM conversion safely

Shell redirection writes standard output to a file, so choose a new destination: a failed conversion should never be able to truncate a useful existing image.

$ cameratopam /path/to/PHOTO.RAW > PHOTO.pam.new
$ status=$?
$ printf 'conversion status: %s\n' "$status"
conversion status: 0
$ test "$status" -eq 0 && test -s PHOTO.pam.new && echo 'non-empty PAM candidate'
non-empty PAM candidate

A zero exit and a non-empty file prove the command produced data, nothing about whether the composition or exposure is what you want. Keep PHOTO.RAW: the converter reads it and never needs to modify it.

Only after checking the new file should you give it the final name, and treat that move as destructive: it replaces any existing PHOTO.pam. Back it up first if that path holds something useful:

$ test ! -e PHOTO.pam || cp --preserve=all PHOTO.pam PHOTO.pam.bak
$ mv PHOTO.pam.new PHOTO.pam
  • Have not moved it yet? Delete the candidate with rm PHOTO.pam.new.
  • Made a backup and the replacement is wrong? Restore it with mv PHOTO.pam.bak PHOTO.pam.
  • Either way, keep the backup until you have inspected the result.

4. Choose interpolation for the job

The default is a slower, high-quality adaptive interpolation. Keep it when image quality matters more than processing time. For a quicker result, use bilinear interpolation instead:

$ cameratopam -quick_interpolate /path/to/PHOTO.RAW > PHOTO-quick.pam

-half_size is faster again: it reduces each 2 by 2 sensor block to one output pixel instead of interpolating, so the output is smaller too. Good for a quick proof or a reduced working copy, not a like-for-like full-size conversion:

$ cameratopam -half_size /path/to/PHOTO.RAW > PHOTO-half.pam

Reach for four-colour RGB only when the converted image shows false 2 by 2 mesh patterns, such as in blue sky. The manual warns it costs a slight loss of detail:

$ cameratopam -four_color_rgb /path/to/PHOTO.RAW > PHOTO-four-colour.pam

All of these choices affect the output file only. None of them touch the raw source.

5. Set colour and brightness deliberately

By default, cameratopam converts to sRGB using a fixed balance based on a white card photographed in sunlight. For a different result, choose one balance mode explicitly:

$ cameratopam -balance_auto /path/to/PHOTO.RAW > PHOTO-auto-balance.pam
$ cameratopam -balance_camera /path/to/PHOTO.RAW > PHOTO-camera-balance.pam

-balance_camera uses the setting the camera recorded; if that information is missing, cameratopam warns and falls back to its default. -balance_auto asks for automatic colour balance instead. Do not judge these by exit status alone: inspect the rendered image too.

Red and blue scale multiply their respective channels and default to 1.0. Brightness also defaults to 1.0:

$ cameratopam -red_scale=1.05 -blue_scale=0.95 -brightness=0.90 \
    /path/to/PHOTO.RAW > PHOTO-adjusted.pam

Start with small changes and keep the unmodified conversion as a comparison. Option values can take whitespace instead of an equals sign, but the equals form makes the value boundary obvious on review.

6. Know when the specialist modes apply

-document_mode shows the raw data as greyscale with no interpolation: use it for a black and white document, not a normal colour photograph. -secondary is specifically for Fuji Super CCD SR cameras: it uses the secondary sensors and effectively underexposes by four stops to reveal highlight detail. It is silently ignored on other cameras, so do not press it into service as a general exposure control.

-rgb writes raw camera colours instead of the default sRGB conversion. -linear changes the sample representation for workflows that need samples proportional to light intensity. Without it, the output maxval is 255 at one byte per sample. With it, the maxval is 65535 at two bytes per sample, so confirm the next tool in your pipeline can read that before you choose it:

$ cameratopam -linear /path/to/PHOTO.RAW > PHOTO-linear.pam
$ file PHOTO-linear.pam
PHOTO-linear.pam: ...

The exact file description varies by version. That check is there to catch an empty or misnamed destination, not to replace an image viewer or a PAM-aware inspection tool.

7. Turn on diagnostics when a result is unclear

Use -verbose to send processing detail to standard error while the PAM data still goes to standard output:

$ cameratopam -verbose /path/to/PHOTO.RAW > PHOTO-verbose.pam
processing details are printed on standard error

Warning

Never redirect both streams into the same file when a later command consumes the PAM bytes. Diagnostic text mixed into the image data corrupts it.

If recognition fails, go back to -identify_only, check the path, and try another raw file from the same camera. A warning about camera balance is not the same problem as a decoder failure: the former has a documented fallback, the latter gives you no usable conversion at all.

Done means

  • Version checked. The installed Netpbm version and executable were confirmed.
  • File identified first. -identify_only recognised the raw file before conversion.
  • Candidate verified. The PAM output landed in a new path and was non-empty before it got the final name.
  • Choices were deliberate. Interpolation, colour balance, brightness and linear mode were each picked for a stated reason.
  • Original untouched. The raw file remains as it was, and any replacement can be restored from its backup.