I used tiffdump to get the bitmap offset from a float tiff I wrote from developing a Nikon .nef file in RawTherapee 5.9. I expected to be able to fseek past the headed, read the file from there into memory into a float array. The numbers are all mangled and not in the [0.0 … 1.0] range.
I converted the .tif to a .rgb with ImageMagick and then converted the .raw to a .jpg to make sure it worked. The .jpg looks perfect.
Is there something else you have to do other than read the RGB bytes 12 at a time into a float32 array in memory to look at the values? I expect to see the same values shown in RT, values in the [0.0 … 1.0] range. Surely, they are in the IEEE 754 floating point format used by the C language.
Does anybody have a simple C program which reads a single, 12 byte, RGB float pixel from either a tif or an RGB-raw image and prints out the values? Does anybody see the problem in this code?
// =============================================================================
// Read and decode a specific pixel in a float32 tiff
/*
gcc -g -O0 -m64 bln/float.pixel.test.c -lm -lz -o bln/float.pixel.test
*/
#include "stdio.h"
#include "stdlib.h"
#include "stdint.h"
#include <math.h>
int osrp(char *ifn, size_t soff, size_t numf); // Open, Seek, Read, Print
// =============================================================================
void main(int argc, char *argv[]) {
char tfn[]={ "pf-274887.edge.f32.tif" }; // From RawTherapee
char rfn[]={ "pf-274887.edge.f32.tif.rgb" }; // From ImageMagick
size_t toff=13022ll, roff=0, pixoff=0; // Tif and raw-RGB header Offsets
int imgx=3, imgy=3, imgw=4916, pix_bytes=12;
pixoff = (imgy * imgw + imgx) * pix_bytes; // Byte offet to pixel (3,3)
pixoff = 0ll; // Try pixel (0, 0)
osrp(tfn, toff+pixoff, 3); // Open, seek, read, print
osrp(rfn, roff+pixoff, 3); // FileName, seek_OFFset, #_floats per pixel
exit(0); //
} // End Main().
// =============================================================================
// =============================================================================
// Open, seek, read, print. Expect floats in (0.0 .. 1.0) range
// Check for errors in number of floats read and NAN on their values
int osrp(char *ifn, size_t soff, size_t numf) {
union { // Overlay floats and 32 bit unsigned ints
float fpix[4]; // Holds 1 pixel
uint32_t ipix[4]; // UI32 and float share same bits
} fiu; // Float-Int-Union
FILE *ifp; // Image_File_Pointer
int ii, numnan=0; // Number of NANs, Not_A_Numbers
size_t numr; // uint64_t
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.fpix, sizeof(float), numf, ifp); // 3*4=12B
fclose(ifp);
if(numr != numf) {
printf("ERROR! NumR %llu != NumF %llu\n", numr, numf); }
printf("%s: Seek -> %lld, Read %llu: \nfloat: B %8.6f, G %8.6f, R %8.6f -> \nUINT32: B %10u, G %10u, R %10u\n",
ifn, soff, numf,
fiu.fpix[0], fiu.fpix[1], fiu.fpix[2],
fiu.ipix[0], fiu.ipix[1], fiu.ipix[2]);
for(ii=0; ii < numf; ii++) { // Check for Non-Number floats
if(isnan(fiu.fpix[ii])) { numnan++; } // Count NANs
}
if(numnan == 0) { printf("\n"); return(0); }
printf("%d floats, %d are NANs!\n\n", numf, numnan);
return(numnan);
}
Running the program:
float.pixel.test
pf-274887.edge.f32.tif: Seek -> 13022, Read 3:
float: B -0.000000, G -0.000003, R 0.000000 ->
UINT32: B 2634654270, G 3059326270, R 457414589
pf-274887.edge.f32.tif.rgb: Seek -> 0, Read 3:
float: B 35650027520.000000, G 1450022528.000000, R 0.000000 ->
UINT32: B 1359269508, G 1319951149, R 0
The RawTherapee values shown at pixel (0, 0) are (22.7%, 31.0% and 0%).