From d77952de791b3142d25957ff0ed8f5f9679c7494 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 15 Mar 2024 16:14:43 +0000 Subject: [PATCH] fpexif: New EXIF convenience property GPSDateTime (read/write) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9281 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpexif/fpeexifdata.pas | 56 ++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/components/fpexif/fpeexifdata.pas b/components/fpexif/fpeexifdata.pas index 1f3045a5d..38703d095 100644 --- a/components/fpexif/fpeexifdata.pas +++ b/components/fpexif/fpeexifdata.pas @@ -63,15 +63,17 @@ type FExportOptions: TExportOptions; FOnBeginReading: TExifBeginReadingEvent; FOnEndReading: TExifEndReadingEvent; + function GetGPSDateTime: TDateTime; + function GetGPSPosition(AKind: Integer): double; function GetImgHeight: Integer; function GetImgWidth: Integer; function GetOrientation: TExifOrientation; - function GetGPSPosition(AKind: Integer): double; function GetTagByID(ATagID: TTagID): TTag; function GetTagByIndex(AIndex: Integer): TTag; function GetTagByName(AFullTagName: String): TTag; function GetTagCount: Integer; procedure SetExportOptions(const AValue: TExportOptions); + procedure SetGPSDateTime(AValue: TDateTime); procedure SetGPSPosition(AKind: Integer; AValue: Double); procedure SetOrientation(AValue: TExifOrientation); procedure SetTagByID(ATagID: TTagID; ATag: TTag); @@ -151,6 +153,7 @@ type property GPSAltitude: Double index 2 read GetGPSPosition write SetGPSPosition; property GPSLatitude: Double index 1 read GetGPSPosition write SetGPSPosition; property GPSLongitude: Double index 0 read GetGPSPosition write SetGPSPosition; + property GPSDateTime: TDateTime read GetGPSDateTime write SetGPSDateTime; property OnBeginReading: TExifBeginReadingEvent read FOnBeginReading write FOnBeginReading; @@ -953,6 +956,32 @@ begin Result := TExifOrientation(tag.AsInteger); end; +{ Combines the GPSDateStamp and GPSTimeStamp tags to a Pascal DateTime value. } +function TExifData.GetGPSDateTime: TDateTime; +var + tag: TTag; + hr, mn, sc: Word; + d: TDate = 0; + t: TTime = 0.0; +begin + Result := 0; + + tag := TagByName['GPSTimeStamp']; + if (tag <> nil) and (Length(tag.AsIntegerArray) = 3) then + begin + hr := tag.AsIntegerArray[0]; + mn := tag.AsIntegerArray[1]; + sc := tag.AsIntegerArray[2]; + TryEncodeTime(hr, mn, sc, 0, t); + end; + + tag := TagByName['GPSDateStamp']; + if tag <> nil then + d := ScanDateTime('yyyy":"mm":"dd', tag.AsString); + + Result := d + t; +end; + { Combines the GPS and GPSRef tags for Longitude (AKind = 0), Latitude (AKind = 1), Aligutude (AKind = 2) to a floating point value } @@ -1194,6 +1223,31 @@ begin end; end; +procedure TExifData.SetGPSDateTime(AValue: TDateTime); +var + tag: TTag; + hr, mn, sc, ms: Word; + arr: array[0..2] of TEXIFRational; + b: TBytes; +begin + tag := TagByName['GPSDateStamp']; + if tag = nil then + tag := AddTagByName('GPSDateStamp'); + tag.AsString := FormatDateTime('yyyy":"mm":"dd', AValue); + + tag := TagByName['GPSTimeStamp']; + if tag = nil then + tag := AddTagByName('GPSTimeStamp'); + DecodeTime(AValue, hr, mn, sc, ms); + arr[0].Numerator := hr; arr[0].Denominator := 1; + arr[1].Numerator := mn; arr[1].Denominator := 1; + arr[2].Numerator := sc; arr[2].Denominator := 1; + SetLength(b, SizeOf(arr)); + Move(arr, b[0], SizeOf(arr)); + tag.RawData := b; +end; + + procedure TExifData.SetGPSPosition(AKind: Integer; AValue: Double); var tag: TTag;