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
This commit is contained in:
wp_xxyyzz 2024-03-15 16:14:43 +00:00
parent 2f5e3d2cc2
commit d77952de79

View File

@ -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<kind> and GPS<kind>Ref 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;