2005.07.21 18:28 "RE: [Tiff] FW: Help, I need to do some binary surgery on my tiff.", by James Carroll
> should probably contain all the
Hello Joris! Thanks for your guidance, it worked!
First I had to do my own copy that copied just under 4GB of the file to a new file, then I found the first IFD, and overwrite the offset to the next IFD with a zero.
tiffcp still tells me "Seek error accessing tiff directory" but my own code that reads the file with libtiff can view it!
I wrote the program to do the zeroing in python, and I don't want to include the destructive lines of code, but here's how I read the tags:
f = open(filename, "r+b")
# struct: h is a signed 16 bit integer,
# and L is an unsigned 32 bit integer
(order, version, offset) = struct.unpack('hhL', f.read(8))
print "header: order", hex(order), "version", version, "offset",
(numtags,) = struct.unpack('h', f.read(2))
print "numtags", numtags
bytesToSkip = numtags * 12
(nextIfd,) = struct.unpack('L', f.read(4))
print "next ifd offset:", hex(nextIfd), nextIfd
the final step was to seek backward four bytes, then write four bytes of 0.
From: Joris [mailto:email@example.com] Sent: Thursday, July 21, 2005 11:58 AM To: James Carroll; firstname.lastname@example.org Subject: Re: [Tiff] FW: Help, I need to do some binary surgery on my tiff.
Hi, I have my own version of tiffcp that I used to combine some individual
tiffs into a multi-tiff. The problem is that the result was over 4GB.
I can't see how this is possible, since the structures contain 32bit offsets. My guess is that the result is corrupted, possibly simply because offsets are truncated and only the least significant 32 bits are actually written, or worse.
Does anyone have any suggestions? I think what I need to do is create a program that opens the file in binary mode, and starts walking from tag to tag, writing everything out until I get to the second directory, then stopping.
Does this sound possible?
In theory, yes. In theory, that is exactly what I expect your own tiffcp version did to combine in the first place, though I'm not famaliar with any of the tools, including tiffcp.
Is there any quick way of commenting out parts of libtiff so
it doesn't fail when I open the tiff?
This all strikes me as odd, the thing you claimed to have build cannot exist in the first place, it must be corrupt and other things will be gowing wrong no doubt. For instance, I can't see how the size proc is able to return anything usefull, since it is declared to return a 32bit vale:
TIFFSizeProc = function(Fd: Cardinal): Cardinal; cdecl;
(That's a pascal translation, but never mind that, Cardinal is 32bit.) So quite possibly, this is part of your problem. You might want to try and override it to return a fixed value if you know a value that isn't bazurk and you know for sure all data of IFD 0 is below that offset. Other similar things may be bugging you, too.
Do let us know how this turns out!