Recent

Author Topic: fpexif issues while modifying date and time  (Read 3896 times)

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
fpexif issues while modifying date and time
« on: December 28, 2018, 10:49:26 pm »
Hi all,

I use WP's fpexif library in my application to modify EXIF date and time in JPEG images. However, recently a customer sent me JPEG file and the library was unable to update the date and time.

I use the following code to update EXIF's date and time. It works fine, except for a JPEG taken with a Fuji Finepix S3500

Code: Pascal  [Select][+][-]
  1.   L_ImageInfo := TImgInfo.Create;
  2.  
  3.   try
  4.     L_ImageInfo.LoadFromFile(F_FullName);
  5.     if L_ImageInfo.ExifData <> nil then
  6.     begin
  7.  
  8.       L_Tag := L_ImageInfo.ExifData.TagByName['DateTimeOriginal'];
  9.       if L_Tag <> nil then
  10.         TDateTimeTag(L_Tag).AsDateTime := F_NewPhotoDT;
  11.  
  12.       L_Tag := L_ImageInfo.ExifData.TagByName['DateTimeDigitized'];
  13.       if L_Tag <> nil then
  14.         TDateTimeTag(L_Tag).AsDateTime := F_NewPhotoDT;
  15.  
  16.       L_Tag := L_ImageInfo.ExifData.TagByName['DateTime'];
  17.       if L_Tag <> nil then
  18.         TDateTimeTag(L_Tag).AsDateTime := F_NewPhotoDT;
  19.  
  20.       try
  21.         L_ImageInfo.SaveToFile(F_FullName);
  22.  
  23.       except
  24.          .... // Update failed and this is the case for the Fuji Finepix S3500 camera
  25.       end;
  26.  
  27.  

When I change the JPEG date and time with Windows Explorer for example, then it gets's changed correctly. Using fpExif afterwards with the above code then works fine, so I assume that the initial EXIF header causes troubles to MODIFY date and time information. The library however can correctly READ the information.
Romain

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: fpexif issues while modifying date and time
« Reply #1 on: December 28, 2018, 11:18:44 pm »
I don't fully understand what the problem is. Let me put in my words: You want to update the date/time information stored in the EXIF metadata of a jpg taken with a Fuji Finepix S3500 using the code posted. But your customer reports that the date/time is not updated. What is he doing that he is able to tell that something is wrong? Which program is using to read the EXIF back from the jpeg? Is the date/time not written at all, or is it written falsely?

Is the EXIF still readable after doing the modification?

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #2 on: December 28, 2018, 11:37:24 pm »
I sent you a link to download the customer's photo.

If you have a look at the image properties in Windows Explorer, you can see that the photo has been taken in 2004. I verified with Phil Harvery's ExifTool and the EXIF header seems to be correct.

Now, the customer tries to update the EXIF date and time values with my application ( Attribute Changer ). The code used to update the values is the one I posted above. However, the data and time values in the EXIF header do net get updated. In fact, the SaveToFile method in fpExif generates an exception.

So, data is not written at all.

During my troubleshooting, I found the following ( maybe it's helpful to you to troubleshoot the issue )

- Take the customer image and change the Date Taken in Windows Explorer to a different date and time.
- Use Attribute Changer to update EXIF date and time > now works !
- Verify with Windows Explorer or Exif Tool > data and time successfully changed.

This means that the original FinePix generated photo information can not be changed, but once modified with Windows Explorer, it can be changed with the above code.

Hope, this helps.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: fpexif issues while modifying date and time
« Reply #3 on: December 29, 2018, 12:42:23 am »
Thanks for the explanation.

Can you try to analyze the image modified in Windows Explorer by means of Phil Harvey's ExifTool? (Or send me a link to this image so that I can have a look by myself). Try to find out whether the EXIF segment still contains the MakerNotes tag because I guess that Windows stripped it.

The MakerNotes are a part of the EXIF structure in which manufactures can write whatever they want, and of course this is not documented at all, there's just some inofficial documentation on several sites bases on reverse-engineering. The fatal thing is that most manufacturers use the same TIF-based file format for their data as for the other EXIF data. This means that the MakerNotes chunks can only be understood on the basis of offset values relative to the beginning of the TIF header. fpexif reads the binary undecoded MakerNotes (there are a few attempts to decode them) and writes them back unchanged. Editing some other part of the EXIF structure, however, alters the offsets to the data chunks. This does not matter for the well-documented tags for which the offsets can be corrected, but it is fatal for the maker notes where the offsets now point to wrong data.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #4 on: December 29, 2018, 09:20:25 am »
I sent you a PM with the download link.

The only modifications I did with Windows Explorer is to change the 'Date Taken' date part property to 08/08/2008

In ExifTool, the additional EXIF properties seem still to be present. Some values were modified/deleted by Windows Explorer, but for me it does not seem to be critical. However, for your library it seems to make a big difference as the 'SaveToFile' method works after this manipulation.

Hope this helps,
Romain

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: fpexif issues while modifying date and time
« Reply #5 on: December 29, 2018, 10:17:29 am »
You are right. Both original and modified image to which you sent links by PM do contain the MakerNote section. The bug must be something else.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #6 on: December 29, 2018, 10:24:50 am »
What is really strange is that your library can READ the date and time properties from both JPEG files without problems. However, updating does fail ( except for the one modified with Windows Explorer )

I'm currently doing some basic debugging and the library fails at the following code :

Code: Pascal  [Select][+][-]
  1.     // Write IFD1
  2.     if FImgInfo.HasThumbnail then
  3.       WriteIFD(AStream, subIFDList, TAGPARENT_THUMBNAIL);  
  4.  

The 'WriteIFD' for IFD1 tags generates an exception in fpeExifReadWrite.pas / TExifWriter.WriteToStream

If I comment this section out, then date is getting changed. The issue is within this code section.
« Last Edit: December 29, 2018, 10:53:58 am by Romain »

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #7 on: December 29, 2018, 11:24:48 am »
The exact crash location is here :

Code: Pascal  [Select][+][-]
  1.        // Offset to the thumbnail image
  2.         if tag.TagID = FULLTAG_THUMBSTARTOFFSET then begin
  3.           dw := FixEndian32(thumbStartOffset);
  4.           tag.AsInteger := dw;            <--- generates exception              
  5.  

in fpeExifReadWrite.pas / TExifWriter.WriteIFD

In my case, the thumbStartOffset value is 392, dw value is 2281766912

If I now use the photo, modified by Windows Explorer, the library does not even enter into this section.
« Last Edit: December 29, 2018, 11:41:50 am by Romain »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: fpexif issues while modifying date and time
« Reply #8 on: December 29, 2018, 11:48:57 am »
These values are endian-pairs: 392 = $1 88, 2281766912 = $88 01 00 00, i.e. endianness of the TIF structure of the EXIF segment (big-endian vs. little-endian) is not correctly handled.
« Last Edit: December 29, 2018, 03:10:47 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: fpexif issues while modifying date and time
« Reply #9 on: December 29, 2018, 02:16:03 pm »
Please test the current revision.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #10 on: December 29, 2018, 03:00:10 pm »
Tested latest snapshot (r6776) and the issue is fixed  :)

I will do some more tests with 'exotic' images and report back.

So far, great job ! Thanks.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: fpexif issues while modifying date and time
« Reply #11 on: December 29, 2018, 04:28:17 pm »
All my sample images work fine !

Many thanks for your great support and keep up the good work.

Romain
« Last Edit: December 29, 2018, 04:41:12 pm by Romain »

 

TinyPortal © 2005-2018