From e0d533ac91e635f359a0dadcd823e34f2db189fc Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 7 Dec 2017 11:35:50 +0000 Subject: [PATCH] fpexif: Provide option to read exif without maker notes (not standardized and poorly documented feature). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6091 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/metadata_viewer/mdvmain.lfm | 67 ++++++++++--------- .../examples/metadata_viewer/mdvmain.pas | 6 +- components/fpexif/fpeexifreadwrite.pas | 1 + components/fpexif/fpeglobal.pas | 7 +- components/fpexif/fpemetadata.pas | 4 +- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/components/fpexif/examples/metadata_viewer/mdvmain.lfm b/components/fpexif/examples/metadata_viewer/mdvmain.lfm index 36665a33c..4860f3c71 100644 --- a/components/fpexif/examples/metadata_viewer/mdvmain.lfm +++ b/components/fpexif/examples/metadata_viewer/mdvmain.lfm @@ -115,18 +115,18 @@ object MainForm: TMainForm Height = 573 Top = 23 Width = 647 - ActivePage = PgImage + ActivePage = PgMetadata Align = alClient - TabIndex = 1 + TabIndex = 0 TabOrder = 1 OnChange = PageControl1Change object PgMetadata: TTabSheet Caption = 'Meta data' - ClientHeight = 640 + ClientHeight = 545 ClientWidth = 639 object TagListView: TListView Left = 0 - Height = 640 + Height = 525 Top = 0 Width = 639 Align = alClient @@ -155,6 +155,31 @@ object MainForm: TMainForm OnCompare = TagListViewCompare OnSelectItem = TagListViewSelectItem end + object Panel1: TPanel + Left = 0 + Height = 20 + Top = 525 + Width = 639 + Align = alBottom + AutoSize = True + BevelOuter = bvNone + ClientHeight = 20 + ClientWidth = 639 + TabOrder = 1 + object CbDecodeMakerNotes: TCheckBox + AnchorSideLeft.Control = Panel1 + AnchorSideTop.Control = Panel1 + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 19 + Top = 1 + Width = 127 + Caption = 'Decode MakerNotes' + Checked = True + State = cbChecked + TabOrder = 0 + end + end end object PgImage: TTabSheet Caption = 'Image' @@ -162,7 +187,7 @@ object MainForm: TMainForm ClientWidth = 639 object Image: TImage Left = 0 - Height = 517 + Height = 545 Top = 0 Width = 639 Align = alClient @@ -171,40 +196,16 @@ object MainForm: TMainForm Stretch = True StretchOutEnabled = False end - object Panel1: TPanel - Left = 0 - Height = 28 - Top = 517 - Width = 639 - Align = alBottom - AutoSize = True - BevelOuter = bvNone - ClientHeight = 28 - ClientWidth = 639 - TabOrder = 0 - Visible = False - object CheckBox1: TCheckBox - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = Panel1 - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 19 - Top = 5 - Width = 127 - BorderSpacing.Top = 4 - BorderSpacing.Bottom = 4 - Caption = 'Decode MakerNotes' - TabOrder = 0 - end - end end end object Messages: TMemo - Left = 0 + Left = 4 Height = 90 Top = 596 - Width = 647 + Width = 639 Align = alBottom + BorderSpacing.Left = 4 + BorderSpacing.Right = 4 TabOrder = 2 end object Splitter3: TSplitter diff --git a/components/fpexif/examples/metadata_viewer/mdvmain.pas b/components/fpexif/examples/metadata_viewer/mdvmain.pas index 948843f4d..3c8d6dd9e 100644 --- a/components/fpexif/examples/metadata_viewer/mdvmain.pas +++ b/components/fpexif/examples/metadata_viewer/mdvmain.pas @@ -14,7 +14,7 @@ type { TMainForm } TMainForm = class(TForm) - CheckBox1: TCheckBox; + CbDecodeMakerNotes: TCheckBox; FilenameInfo: TLabel; Image: TImage; Messages: TMemo; @@ -114,6 +114,10 @@ begin FImgInfo := TImgInfo.Create; try try + if CbDecodeMakerNotes.Checked then + FImgInfo.MetadataKinds := FImgInfo.MetadataKinds + [mdkExif] - [mdkExifNoMakerNotes] + else + FImgInfo.MetadataKinds := FImgInfo.MetadataKinds - [mdkExif] + [mdkExifNoMakerNotes]; FImgInfo.LoadFromFile(AFileName); Messages.Hide; except diff --git a/components/fpexif/fpeexifreadwrite.pas b/components/fpexif/fpeexifreadwrite.pas index b75163b49..64d33bf80 100644 --- a/components/fpexif/fpeexifreadwrite.pas +++ b/components/fpexif/fpeexifreadwrite.pas @@ -411,6 +411,7 @@ begin Move(AData[0], FExifVersion[1], Length(FExifVersion)); end; FULLTAG_MAKERNOTE: + if FImgInfo.MetadataKinds * [mdkExif, mdkExifNoMakerNotes] = [mdkExif] then begin // The stream is at the end of the makernote data area --> rewind it to start AStream.Position := AStream.Position - Length(AData); diff --git a/components/fpexif/fpeglobal.pas b/components/fpexif/fpeglobal.pas index a14ead2c9..3545323ff 100644 --- a/components/fpexif/fpeglobal.pas +++ b/components/fpexif/fpeglobal.pas @@ -12,7 +12,12 @@ uses Classes, SysUtils; type - TMetaDataKind = (mdkExif, mdkIPTC, mdkComment); + TMetaDataKind = ( + mdkExif, // Complete Exif (incl MakerNotes) + mdkExifNoMakerNotes, // Exif without MakerNotes (instead of mdkExif) + mdkIPTC, // IPTC + mdkComment // Comment segment + ); TMetaDataKinds = set of TMetaDataKind; const diff --git a/components/fpexif/fpemetadata.pas b/components/fpexif/fpemetadata.pas index 085413e54..37d8dc9c0 100644 --- a/components/fpexif/fpemetadata.pas +++ b/components/fpexif/fpemetadata.pas @@ -459,7 +459,7 @@ begin p := AStream.Position; case marker of M_EXIF: - if (mdkEXIF in FMetadataKinds) then begin + if FMetaDataKinds * [mdkExif, mdkExifNoMakerNotes] <> [] then begin reader := TExifReader.Create(self); try if not TExifReader(reader).ReadExifHeader(AStream) then @@ -647,7 +647,7 @@ begin AStream.WriteBuffer(SOI_MARKER, SizeOf(SOI_MARKER)); // No Exif --> write an APP0 segment - if not HasExif or not (mdkExif in FMetadataKinds) then begin + if not HasExif or (FMetadataKinds * [mdkExif, mdkExifNoMakerNotes] = []) then begin if Length(FHeaderSegment) = 0 then begin Move(JFIF[1], {%H-}JFIFSegment.Identifier[0], Length(JFIF)); JFIFSegment.JFIFVersion[0] := 1;