I finally fixed the quantum question for TIFF files with 32 bit quanta.
I wrote a small program to take a 32 bit tif file and the pixel XY coordinates to investigate.
It prints float, scaled uint32, int32, uint32 and hex values both plain and mangled.
At a glance, you can spot which “standard” format your data are in.
Here is the output
float.pixel.test_t pf-274887.ec0.5.tif 30 40
Cmd > /usr/local/bin/image_info_et.pl pf-274887.ec0.5.tif -sbwtfm < -> rtn > 13022
217385520 4916 7370 0 0
< [30] hdr_size=13022, bm_size=217385520, xres=4916, yres=7370, is_float=0, is_mangled=0
Img_xy=(30, 40) -> offset_bytes = 2360040
pf-274887.ec0.5.tif: Seek -> 2373062, Read 3:
float: R -78996330445845561344.00000000, G 0.00000000, B 0.00000000
Sui32: R 0.87709099, G 0.11491743, B 0.10022888
INT32: R -527890069, G 493566631, B 430479754
UINT32: R 3767077227, G 493566631, B 430479754
Hex: R 0XE089096B, G 0X1D6B3AA7, B 0X19A8998A
Bich swapped:
float: R 1.6627393e+26, G -2.5870752e-15, B -1.4796595e-32
***Sui32: R 0.41811430, G 0.65323514, B 0.54140711*** << Winner
INT32: R 1795787232, G -1489343715, B -1969641447
UINT32: R 1795787232, G 2805623581, B 2325325849
Hex: R 0X6B0989E0, G 0XA73A6B1D, B 0X8A99A819
The only one falling in the [0.0 … 1.0) range is the __BSWAP, SUI32 (Scaled UI32).
I chose to use a Perl script to spoon feed the Exif parameters of hdr_bytes, bitmap_bytes, xres, yres, is_float and is_mangled to c in a string easily digested with an sscanf() call. I call it through a popen() call.
Accessing the bitmap is as simple as:
ifp = fopen(ifn, "rb"); // Read Image in Binary mode
fseek(ifp, soff, SEEK_SET); // Seek to start of bitmap data
// Read numf * 4 bytes from bitmap, store in uint/float union
numr = fread((void *)fiu.bpix, sizeof(float), numf, ifp); // 4*3=12B
fclose(ifp);
I read a single pixel into a { float, uint32, int32, uint8 } union :
union { // Overlay floats and 32 bit unsigned ints
float fpix[4]; // Holds 1 pixel
uint32_t upix[4]; // UI32 and float share same bits
int32_t ipix[4]; // UI32 and float share same bits
uint8_t bpix[16]; // UI8 BYTE
} fiu; // Float-Int-Union
The convert “-define quantum:format=floating-point” option eliminates the scaled uint32s and appears to generate IEEE 754 floats.