Problems recording GPS data

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Post Reply
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Problems recording GPS data

Post by madiazg »

Hello,
I have problems to record the GPS data in a file.
I use the following code:

Code: Select all

var
  mLoadOption: TGFL_LOAD_PARAMS;
  mSaveOption: TGFL_SAVE_PARAMS;
  mOriBitmap: PGFL_BITMAP;
  mEXIFData2 : PGFL_EXIF_DATAEX;
  mError : GFL_ERROR ;
  pq: array[0..5] of GFL_UINT32;
  LatitudeRef : string;
.....
begin
.....
    gflGetDefaultLoadParams(mLoadOption);
    mLoadOption.Flags := GFL_LOAD_READ_ALL_COMMENT;
    mLoadOption.Flags := GFL_LOAD_METADATA;
    mLoadOption.Flags := GFL_LOAD_COMMENT;
    mError := gflLoadBitmap(Pchar(FileName1),mOriBitmap, mLoadOption, lInformation);
    mEXIFData2 := gflBitmapGetEXIF2(mOriBitmap);

    LatitudeRef := 'N';
    gflBitmapSetEXIFValueString2(mEXIFData2, GFL_EXIF_GPS_IFD, 1,PChar(LatitudeRef));
    pq[0] := 28;  pq[1] := 1;
    pq[2] := 26;  pq[3] := 1;
    pq[4] := 119; pq[5] := 2;
    Count := 3;
    gflBitmapSetEXIFValueRationalArray2(mEXIFData2,GFL_EXIF_GPS_IFD,2,@pq,count);
    gflBitmapRemoveMetaData(mOriBitmap);
    gflBitmapSetEXIF2(mOriBitmap,mEXIFData2);
    gflGetDefaultSaveParams(mSaveOption);
    mSaveOption.Flags := GFL_SAVE_REPLACE_EXTENSION;
    mSaveOption.Flags := GFL_SAVE_ICC_PROFILE;
    mSaveOption.FormatIndex := 0;
    mSaveOption.Quality := 50;
    gflSaveBitmap(PChar('prueba.jpg'),mOriBitmap,mSaveOption);
    gflFreeFileInformation(lInformation);
    gflFreeBitmap(mOriBitmap);
    gflFreeEXIF2(mEXIFData2);
...
end;
With this code, I recorded the GPS data perfectly, but the rest of EXIF data are deleted.

If I remove the code mLoadOption.Flags := GFL_LOAD_COMMENT;, the files that do not contain data EXIF originally are stored the information correctly, but files containing EXIF data originally are stored incorrectly. In this case:

Latitude: 28/1º 26/1' 59.50"

This does not happen if the original file contains GPS data. In this case, the information is recorded correctly.

If image resolution data are recorded , the same:

Code: Select all

....
//Resolution
    gflBitmapSetEXIFValueRational2(mEXIFData2, GFL_EXIF_MAIN_IFD, 282, 200, 1);     // For 200 dpi
    gflBitmapSetEXIFValueRational2(mEXIFData2, GFL_EXIF_MAIN_IFD, 283, 200, 1);     // For 200 dpi
....
xResolution: -56/1
yResolution: -56/1


What is the problem?

Miguel Angel
User avatar
dominique
Posts: 72
Joined: Thu Nov 08, 2007 9:22 am

Re: Problems recording GPS data

Post by dominique »

You should becarful of the IFD in the EXIF functions. In the previous version 2.90, the IFD_0 and MAIN_IDF were REVERSED.
You should use IFD_0 for resolution.
See this link to choose the right IFD and the right type of value : http://www.sno.phy.queensu.ca/~phil/exi ... /EXIF.html
I think you should keep metadata if you use gflBitmapGetEXIF2, complete with your own metadata, gflBitmapRemoveMetaData and gflBitmapSetEXIF2.
Dom
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Re: Problems recording GPS data

Post by madiazg »

Hi,
I changed the constants in the file libgfl.pas:

Code: Select all

  GFL_EXIF_IFD_0 = $0001; 
  GFL_EXIF_MAIN_IFD = $0002;

The correct code to save the resolution is:

Code: Select all

  gflBitmapSetEXIFValueRational2(mEXIFData2, GFL_EXIF_IFD_0, 282, 200, 1);     // For 200 dpi
  gflBitmapSetEXIFValueRational2(mEXIFData2, GFL_EXIF_IFD_0, 283, 200, 1);     // For 200 dpi
I've been doing some tests. If I use mLoadOption.Flags := GFL_LOAD_COMMENT erases all EXIF data from the file final:

Code: Select all

var
  mLoadOption: TGFL_LOAD_PARAMS;
  mSaveOption: TGFL_SAVE_PARAMS;
  mOriBitmap: PGFL_BITMAP;
  mError : GFL_ERROR ;
...
begin
...
    gflLibraryInit();
    gflGetDefaultLoadParams(mLoadOption);
    mLoadOption.Flags := GFL_LOAD_READ_ALL_COMMENT;
    mLoadOption.Flags := GFL_LOAD_METADATA;
    mLoadOption.Flags := GFL_LOAD_COMMENT;
    mError := gflLoadBitmap(Pchar(FileName1),mOriBitmap, mLoadOption, lInformation); // Carga una imagen en Memoria

    gflGetDefaultSaveParams(mSaveOption);
    mSaveOption.Flags := GFL_SAVE_REPLACE_EXTENSION;
    mSaveOption.Flags := GFL_SAVE_ICC_PROFILE;
    mSaveOption.FormatIndex := 0;
    mSaveOption.Quality := 50;
    gflSaveBitmap(PChar('prueba.jpg'),mOriBitmap,mSaveOption);
...
end;
If I delete mLoadOption.Flags := GFL_LOAD_COMMENT, EXIF data is preserved in the final file.

The problem with the GPS data is with cameras NIKON. I have a Nikon D70s.
You can download an image from a D90 on the following link:
http://a.img-dpreview.com/gallery/nikon ... c_1948.jpg

I've tried other brands of cameras (Canon, Sony) and I do not have these problems.

With Nikon, if I use mLoadOption.Flags := GFL_LOAD_COMMENT erases original EXIF data but records the GPS data that I put in code. If not using mLoadOption.Flags := GFL_LOAD_COMMENT, keep the original EXIF data but record erroneous of GPS data that I enter manually (gflBitmapSetEXIFValueRationalArray2 and gflBitmapSetEXIFValueRational2)

I also found a error. In this case, the value of GPS Version ID. Originally, the value of this data is 2.2.0.0. When I save the EXIF data, the value changes to 2.0.0.0. I have not found a way to change this value.

Miguel Angel
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Re: Problems recording GPS data

Post by madiazg »

Hi,
Have you been able to examine the EXIF data of a photograph obtained with a Nikon camera and check the error that occurs when recording the GPS data?

Miguel Angel
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Re: Problems recording GPS data

Post by madiazg »

Hi,
you have been able to find out what is wrong?

Miguel Angel
User avatar
xnview
Author of XnView
Posts: 43442
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Problems recording GPS data

Post by xnview »

madiazg wrote:Hi,
you have been able to find out what is wrong?
Could you send me the jpeg file used?
Pierre.
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Re: Problems recording GPS data

Post by madiazg »

Hello Pierre,
I have sent you the file at: <-- removed* -->

The code used is as follows (Delphi):

Code: Select all

var
  Lat_pq,Long_pq : array[0..5] of integer;
  PosicionXgpsRef,PosicionYgpsRef : string;
  ppp : integer;
....
begin
....
//GPS
    PosicionYgpsRef := 'N';
    PosicionXgpsRef := 'W';
    Lat_pq[0] := 28;
    Lat_pq[1] := 1;
    Lat_pq[2] := 16;
    Lat_pq[3] := 1;
    Lat_pq[4] := 2095;
    Lat_pq[5] := 100;
    Long_pq[0] := 16;
    Long_pq[1] := 1;
    Long_pq[2] := 38;
    Long_pq[3] := 1;
    Long_pq[4] := 3325;
    Long_pq[5] := 100;
    gflBitmapSetEXIFValueString2(EXIF2, GFL_EXIF_GPS_IFD, 1,PChar(PosicionYgpsRef));
    gflBitmapSetEXIFValueRationalArray2(EXIF2,GFL_EXIF_GPS_IFD,2,@Lat_pq,3);
    gflBitmapSetEXIFValueString2(EXIF2, GFL_EXIF_GPS_IFD, 3,PChar(PosicionXgpsRef));
    gflBitmapSetEXIFValueRationalArray2(EXIF2,GFL_EXIF_GPS_IFD,4,@Long_pq,3);
//Resolutión
    ppp := 200;
    gflBitmapSetEXIFValueRational2(EXIF2, GFL_EXIF_IFD_0, $011a, ppp, 1);
    gflBitmapSetEXIFValueRational2(EXIF2, GFL_EXIF_IFD_0, $011b, ppp, 1);
//Guarda los datos EXIF2
    gflBitmapSetEXIF2(gfl_bmpS,EXIF2);
....
end;
This error occurs with Nikon cameras.

Miguel Angel
User avatar
xnview
Author of XnView
Posts: 43442
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Problems recording GPS data

Post by xnview »

Ok, 2 bugs, i've sent to you a fixed version
Pierre.
User avatar
madiazg
Posts: 82
Joined: Wed Jul 18, 2007 8:00 pm
Location: Tenerife - Islas Canarias
Contact:

Re: Problems recording GPS data

Post by madiazg »

Thank you very much!
Miguel Angel
Post Reply