-
TIFF IFD byte by byte
Hi folkes
I use following code to print all IFD Entry Tags of an NEF File (TIFF):
Code:
OpenFile("Bsp.NEF");
char byte[2];
unsigned long step = 10;
unsigned long tmp = 0;
fseek(pFile, 8, SEEK_SET);
fread (&byte[0], 1, 1, pFile);
fread (&byte[1], 1, 1, pFile);
unsigned long count = (byte[0] << 8) | byte[1];
for (int a = 0; a <= count; a++)
{
fseek ( pFile , step , SEEK_SET );
fread (&byte[0], 1, 1, pFile);
fread (&byte[1], 1, 1, pFile);
tmp = (byte[0] << 8) | byte[1];
cout << "Offset: " << step << " Tag: " << tmp << endl;
step = step + 12;
}
CloseFile();
the output I get is following:
PHP Code:
...
Offset: 226 Tag: 306
Offset: 238 Tag: 330
Offset: 250 Tag: 532
Offset: 262 Tag: 4294967228
As you can see at Offset 262 the tag name shows a full unsinged long value instead of the supposed 34665.
I have really no idea why at this point the reading fails.
-
34665 is 0x8769, while 4294967228 is 0xFFFFFFBC, so I'm not even seeing how those two bytes could combine to give you that number. If your char defaults to signed char, then 0x87 would be considered negative, which would give you 0xFFFF8700 when you shift.
-
yes i solved it myself already. it was a signed variable where it must be a unsigned.
-
> for (int a = 0; a <= count; a++)
This loops count+1 times, perhaps your seek/read fail on the last iteration and you print garbage?
-
You're going to have serious problems if you continue ignoring the byte-order marker which occurs in the TIFF header.