A tool to convert Polynomial Texture Maps into regular bitmaps
Polynomial Texture Maps are special texture files which contain biquadratic polynomial coefficients per pixel, modeling the reflectance behavior under varying incident radiance. Even though the format is in heavy use in archeology, I found that the available open-source implementations are rather sparse. The following code is a one-file C++ converter which reads (at the moment) LRGB encoded PTMs (either uncompressed or with JPEG compression) and dumps the luminance coefficients and the RGB data into separate PNG images. These images can be used without the need to write a PTM reader for instance in web applications using WebGL. The neccessary scale and bias parameters are printed on the console.
If you're looking for a simple reader converting all data into regular char arrays, look no further! The code should be simple enough to parse, just have a look at ptm_dump on how to get to the data. A big Thank You! to Sean Barrett for stb_image, which I use to read JPEG compressed data and write PNG files to the disk.
The above image is tablet2.ptm from the HP Research Labs PTM set. Tablet2 is a luminance based PTM, meaning it contains 9 values per pixel, 6 luminance coefficients for the polynomial and 3 color values. It has been converted into three separate images:
a regular RGB image for colors an image with coefficients 1, 2 and 3 saved as RGB an image with coefficients 4, 5 and 6 saved as RGB Together with the bias and scale values, one can use these images with a shader and reconstruct the PTM without the need for a PTM loader.