LinuxCommandLibrary

pamfix

Fix PAM configuration after package upgrades

TLDR

Fix a Netpbm file that is missing its last part

$ pamfix [[-t|-truncate]] [path/to/corrupted.ext] > [path/to/output.ext]
copy

Fix a Netpbm file where pixel values exceed the image's maxval by lowering the offending pixels' values
$ pamfix [[-cl|-clip]] [path/to/corrupted.ext] > [path/to/output.ext]
copy

Fix a Netpbm file where pixel values exceed the image's maxval by increasing it
$ pamfix [[-ch|-changemaxval]] [path/to/corrupted.pam|pbm|pgm|ppm] > [path/to/output.pam|pbm|pgm|ppm]
copy

SYNOPSIS

pamfix [-maxval=value] [-check] [-null] [-all] [pamfile]

PARAMETERS

-maxval=value
    Specifies the maximum sample value for all samples in the output image. If not provided, pamfix attempts to determine it from the input file or automatically calculates a suitable maxval if the input is malformed.

-check
    Performs a check for problems without attempting to fix them. It reports any detected issues to standard error and exits with a non-zero status if problems are found.

-null
    Instead of correcting problematic sample values (e.g., negative or values exceeding maxval) by clamping them, this option replaces them with a zero value.

-all
    This option is often redundant as pamfix by default attempts to fix all common issues it can. Its explicit inclusion ensures all known fixable problems are addressed, though its primary effect might be on specific edge cases or for clarity in scripts.

pamfile
    The path to the input PAM image file to be processed. If this argument is omitted or specified as -, pamfix reads the image data from standard input.

DESCRIPTION

pamfix is a utility from the Netpbm image manipulation toolkit designed to rectify various common issues found in Portable Arbitrary Map (PAM) image files. PAM is a highly flexible image format, and while robust, files can occasionally be malformed due to various reasons, such as buggy image generation software or manual corruption. pamfix acts as a "sanity checker" and "repair tool" for such files.

It can correct problems like an invalid or zero maximum value (maxval), which defines the maximum sample value for the image. It also addresses sample values that are negative or exceed the specified maxval, clamping them to valid ranges. Furthermore, pamfix can resolve issues with tuple type strings in the PAM header, such as non-existent or duplicated entries, ensuring the header is correctly interpreted.

The command is particularly useful when dealing with image files produced by less strict programs that might generate slightly non-compliant PAMs. By default, pamfix reads from standard input if no file is specified and writes the corrected PAM image to standard output. Its output is always a PAM file, even if the original input was a different Netpbm format (PBM, PGM, PPM).

CAVEATS

pamfix is designed to correct common malformations in PAM images, not every conceivable form of file corruption. Severely damaged or fundamentally incorrect image data may not be recoverable.

The output of pamfix is always in the PAM format, even if the input was a different Netpbm format like PBM, PGM, or PPM. If you require the output in a specific Netpbm format, you will need to pipe the output of pamfix to another Netpbm utility (e.g., pamtopnm).

While pamfix attempts to make files compliant, it cannot guarantee that the resulting image will be visually identical to what a perfectly formed original image might have been, especially when correcting sample values by clamping or nulling them.

STANDARD I/O USAGE

If no input file is specified or if - is given as the filename, pamfix reads its input from standard input (stdin). The corrected PAM image is always written to standard output (stdout). This behavior allows pamfix to be easily integrated into shell pipelines, enabling complex image processing workflows where its output can be directly fed as input to another Netpbm utility.

EXIT STATUS

pamfix typically exits with a status of 0 upon successful execution and correction of issues. If the -check option is used and problems are found, or if a fatal error occurs (e.g., unreadable input, severe corruption), it will exit with a non-zero status, indicating failure or the presence of uncorrected issues.

HISTORY

pamfix is an integral part of the Netpbm project, a comprehensive toolkit for manipulating graphic images. The Netpbm suite has a long history dating back to the early days of Unix-like systems, evolving from the original PBMPLUS package by Jef Poskanzer.

The PAM (Portable Arbitrary Map) format itself was introduced later in the Netpbm project to provide a more flexible and extensible image format compared to the older PBM, PGM, and PPM formats, which are collectively known as PNM. pamfix was developed as a necessary utility to ensure the robustness and interoperability of PAM files, particularly when dealing with images generated by a wide variety of tools, thus contributing to the stability and utility of the Netpbm ecosystem.

SEE ALSO

pnm(5): Describes the Portable Anymap format (PBM, PGM, PPM) which are subsets of PAM., pam(5): Describes the Portable Arbitrary Map (PAM) format in detail., pnmcheck(1): Checks a Netpbm image for consistency problems. pamfix fixes issues that pnmcheck might find., anytopam(1): Converts an arbitrary image file to a PAM image., pamtopnm(1): Converts a PAM image to PBM, PGM, or PPM format.

Copied to clipboard