From: Roberto C. <rob...@en...> - 2003-09-06 13:48:32
|
Hello, I worked a bit on the maker note corruption problem we discussed 2 weeks ago. At that time we were thinking about a solution in which unused bytes of the original exif information are mapped and then reproduced in the output file; however I'm now convinced that it's not really necessary and I think that a simpler solution exists. The key idea is that entries/ifd that didn't grow in size (from the original exif info to the modified ones) are put in the output exif at the same offset they were in the original exif. Those that grew (or that were missing in the original exif) are put, compacted, at the offsets that follow the end of the exif info in the original file. By doing so, it's sufficient to copy the full original exif info into the new one before saving anything else to solve the problem. As a matter of fact, this guarantees that "secret" maker notes are copied exactly as they were and that the known exif info doesn't overwrite them. The price to pay is that not only compaction of exif info is no longer done, but that its size slightly increase (I'm talking about 500 bytes' increase in the typical worst case...). This algorithm is straightforward to be implemented, provided that info like the original size and offset of ifds and entry datas are marked as soon as they are loaded. I did it (I attach the patch) and I must say it works perfectly, at least on the pictures produced by my Canon Powershot. I encourage everybody with different cameras to try and report eventual problems. A good thing to say is that I didn't modify the algorithm that saves the exif info and that it allows both the old and new methods. What changes is that in the new a size that corresponds to the original exif size is immediately allocated at once and then further allocations are done only for those elements that either grew or were missing. The implementation is flexible and it's sufficient to set an internal flag of ExifDataPrivate to restore the previous behaviour (try temporarily to comment line 658 of libexif/exif-data.c and libexif will behave as usual), which still allocates each element at a time. Perhaps the user should be given the choice, or some heuristics that decide from the camera name and/or the presence of libmnote whether it is safe to compact exif information should decide in his/her stead. Finally, the patch also includes a few minor changes. Here is a summary: -) Addition of file libexif/exif-private.h, which contains the declaration of _ExifDataPrivate, _ExifContentPrivate and _ExifEntryPrivate structs. These data structures are internal (they must not be visible from libexif's interface), however several implementation files in the library must know about them. -) ExifHeader is no longer duplicated in different files, however this also means that it is no longer static. -) Nested switch removed in exif_data_load_data_content(...) function of libexif/exif-data.c Cheers, Roberto |