Thread: TIFF IFD byte by byte

  1. #1
    Registered User
    Join Date
    Dec 2010

    Question TIFF IFD byte by byte

    Hi folkes

    I use following code to print all IFD Entry Tags of an NEF File (TIFF):

    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;
    the output I get is following:

    PHP Code:
    Offset226       Tag306
    238       Tag330
    250       Tag532
    262       Tag4294967228 
    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.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    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.

  3. #3
    Registered User
    Join Date
    Dec 2010
    yes i solved it myself already. it was a signed variable where it must be a unsigned.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > 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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    You're going to have serious problems if you continue ignoring the byte-order marker which occurs in the TIFF header.
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 08-30-2010, 09:26 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 04:19 AM
  5. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 04:46 PM
Website Security Test