2000.10.26 18:50 "Re: Write tags", by Rainer Wiesenfarth
Hhm, yes what?
Yes, i have to read all and write then, or
Preferably, yes (see notes below).
Yes, there is sample code?
Maybe, but I doubt it. Most users will not need this feature.
What you might do is the following:
- read in the directory you want to change. Be sure to read it completely, i.e. read also tags you do not know the meaning of
- apply your changes to the directory read
- add two more tags: 'FreeOffsets' and 'FreeByteCount' (I am not sure about the name and have no TIFF standard laying around here)
- insert the file offset of the original directoy into FreeOffsets and the size of the original directory into FreeByteCounts
- append the new directory to the file but make sure not to write tag data that is already present in the file (keep this offsets)
- ah, and of course, if you removed tags that have data stored outside the directory, be sure to insert these areas of the file into FreeOffsets/FreeByteCounts, too
- change the pointer to the old directory to point to the new directory and let the new directory point to the old directories' successor
- oh, there might be other references to the old directory (I think they were called SubIFD or something similar). You will have to change them also. Note that there might be vendor specific tags that contain references to the old directory (bad practice, but we experienced bad practices concerning other topics (e.g. OJPEG))
- ... (maybe more points I missed at the moment)
So, I think libtiff will not help you there. I also doubt that you will find a solution that is better than quick-and-dirty, i.e. covers the most general case.
Thus my recommendation: even if the new directory is the same size as the old one (i.e. same number of tags), it is better to copy the whole file.
-- Dipl.-Inform. Rainer Wiesenfarth
-- Inpho GmbH E-mail: Rainer.Wiesenfarth@Inpho.de
-- Smaragdweg 1 Phone : +49 711 22881-10
-- 70174 Stuttgart Fax : +49 711 22881-11
-- Germany URL : http://www.inpho.de