Skip to content

Commit

Permalink
Merge pull request #14 from Yellow-Dog-Man/prime/feat/clear-exif
Browse files Browse the repository at this point in the history
feat(exif): Enable EXIF Writing using FIMD_EXIF_RAW
  • Loading branch information
ProbablePrime authored May 9, 2024
2 parents 7e664a3 + 91ef4e6 commit 0717e93
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
19 changes: 12 additions & 7 deletions Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ public class ImageMetadata : IEnumerable, IComparable, IComparable<ImageMetadata
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public ImageMetadata(FIBITMAP dib) : this(dib, false) { }

/// <summary>
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
/// showing or hiding empry models.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
/// <summary>
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
/// showing or hiding empry models.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
/// will be hidden until a tag to this model is added.</param>
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
/// <param name="includeRaw">When <b>true</b>, include raw byte access to EXIF, <see cref="MDM_EXIF_RAW"/>.
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels, bool includeRaw = false)
{
if (dib.IsNull) throw new ArgumentNullException("dib");
data = new List<MetadataModel>(FreeImage.FREE_IMAGE_MDMODELS.Length);
Expand All @@ -86,6 +87,10 @@ public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
data.Add(new MDM_IPTC(dib));
data.Add(new MDM_NODATA(dib));
data.Add(new MDM_XMP(dib));

// This is based on: https://sourceforge.net/p/freeimage/discussion/36111/thread/2d087f91/
if (includeRaw)
data.Add(new MDM_EXIF_RAW(dib));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public bool RemoveTag(string key)
/// which will remove all tags of this model from the bitmap.
/// </summary>
/// <returns>Returns true on success, false on failure.</returns>
public bool DestoryModel()
public bool DestroyModel()
{
return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero);
}
Expand Down
28 changes: 28 additions & 0 deletions Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,34 @@ public override FREE_IMAGE_MDMODEL Model
}
}

/// <summary>
/// Represents a collection of all tags contained in the metadata model
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_RAW"/>.
/// </summary>
/// <remarks>
/// FreeImage keeps two separate copies of Exif Metadata in memory.
/// One is used/found in <see cref="MDM_EXIF_MAIN"/> and its extensions(e.g. <see cref="MDM_EXIF_GPS"/>).
/// Another one is used when files are actually written that support the EXIF Format. In some cases you want to access, the raw data.
/// A good example of this is when using <see cref="MetadataModel.DestroyModel"/> to wipe EXIF data on an image,
/// that you want persisted if that file is exported again from FreeImage.
/// </remarks>
public class MDM_EXIF_RAW : MetadataModel
{
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
public MDM_EXIF_RAW(FIBITMAP dib) : base(dib) { }

/// <summary>
/// Retrieves the datamodel that this instance represents.
/// </summary>
public override FREE_IMAGE_MDMODEL Model
{
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_RAW; }
}
}

/// <summary>
/// Represents a collection of all tags contained in the metadata model
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public enum FREE_IMAGE_MDMODEL
/// <summary>
/// Used to attach other metadata types to a dib
/// </summary>
FIMD_CUSTOM = 10
FIMD_CUSTOM = 10,

/// <summary>
/// Raw access to EXIF.
/// </summary>
/// <remarks>This is based on: https://sourceforge.net/p/freeimage/discussion/36111/thread/2d087f91/</remarks>
FIMD_EXIF_RAW = 11
}
}

0 comments on commit 0717e93

Please sign in to comment.