PAM (portable arbitrary map)

Ideas for improvements and requests for new features in XnView Classic

Moderators: XnTriq, helmut, xnview

User avatar
omniplex
Posts: 127
Joined: Thu Feb 10, 2011 1:52 pm
Location: Hamburg

PAM (portable arbitrary map)

Post by omniplex »

PAM is a close relative of PNM (portable any map) supported by FFmpeg (example). Like the binary PNM formats (P4..P6, the ASCII versions are P1..P3) it consists of a small text header followed by a binary bitmap. Arguably parsing a PAM header (P7 format) is simpler than parsing a PNM header.

In theory PAM can replace the PNM formats, and it "officially" supports 16 bits (MAXVAL 65535) instead of only 8 bits (MAXVAL 255) for gray maps and pix maps. Of course folks use 16 bits also for P2/P5 (PGM) and P3/P6 (PPM), so that's not very interesting. The rather odd P1/P4 format (PBM) with one bit per pixel (FFmpeg pixel_fmt monob, 1 = black) ends up as a MAXVAL=1 gray map in PAM (pixel_fmt monow, 1 = white, one byte per pixel).

The interesting PAM feature is RGBA (DEPTH=4) with an alpha channel, and DEPTH=2 for a gray map with transparency. I use FFmpeg to convert PNG to PAM, decode this in a script, "do stuff" (e.g., extract tiles from a grid in a Freeciv tileset), and eventually I convert the output PAM(s) with FFmpeg back to PNG(s). If XnView could display PAM I could skip some PNG -> PAM -> PNG -> PAM -> PNG steps. :wink:
User avatar
xnview
Author of XnView
Posts: 44589
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: PAM (portable arbitrary map)

Post by xnview »

do you have some samples?
Pierre.
User avatar
omniplex
Posts: 127
Joined: Thu Feb 10, 2011 1:52 pm
Location: Hamburg

Re: PAM (portable arbitrary map)

Post by omniplex »

xnview wrote:do you have some samples?
I saved your forum avatar as XnView.png, and converted it to PAM with...

Code: Select all

ffmpeg -hide_banner -i xnview.png -c:v pam -pix_fmt rgba xnview.pam
The forum won't let me upload the XnView.pam, I put it into a ZIP and attached that as XnView.ZIP. The input PNG is 100x100 RGBA (3009 colours.) The output PAM header is...

Code: Select all

P7
WIDTH 100
HEIGHT 100
DEPTH 4
MAXVAL 255
TUPLTYPE RGB_ALPHA
ENDHDR
The line ends are bare LFs, the header consists of 69 bytes. The PAM size is 40069=100x100x4+69. The MD5 hash of the raw bitmap determined by ffmpeg -i xnview.p?? -f md5 is 690035cc9aef9c3fae4626d65d7fc09f
You do not have the required permissions to view the files attached to this post.
User avatar
omniplex
Posts: 127
Joined: Thu Feb 10, 2011 1:52 pm
Location: Hamburg

Re: PAM (portable arbitrary map)

Post by omniplex »

xnview wrote:do you have some samples?
The infamous SignedShortLosslessBug.jpg published by the Grassroots DICOM project, MediaWiki and XnView cannot display it, but FFmpeg works:

Code: Select all

ffmpeg -i SignedShortLosslessBug.jpg SignedShortLosslessBug.pam
The PAM header is:

Code: Select all

P7
WIDTH 512
HEIGHT 512
DEPTH 1
MAXVAL 65535
TUPLTYPE GRAYSCALE
ENDHDR
The MD5 for the raw bitmap (JPG input and PAM output) is 2c81619015e9356b7349e3e8aa26e7bc. On Wikimedia commons you can see a corresponding gray16be PNG, but the MD5 is different.
You do not have the required permissions to view the files attached to this post.