diff --git a/CONTRIB.md b/CONTRIB.md index 1d75624..1592c75 100644 --- a/CONTRIB.md +++ b/CONTRIB.md @@ -1,6 +1,6 @@ # Contributors to ExifLibrary -* Ozgur Ozcitak -* Devedse +* [oozcitak](https://github.com/oozcitak) +* [Devedse](https://github.com/devedse) - Conversion to .Net Standard - - Automatic builds \ No newline at end of file + - Automatic builds diff --git a/ExifLibrary/ExifExtendedProperty.cs b/ExifLibrary/ExifExtendedProperty.cs index 4e96b8d..f10a57d 100644 --- a/ExifLibrary/ExifExtendedProperty.cs +++ b/ExifLibrary/ExifExtendedProperty.cs @@ -148,7 +148,7 @@ public override ExifInterOperability Interoperability /// /// Represents the exif version as a 4 byte ASCII string. (EXIF Specification: UNDEFINED) - /// Used for the ExifVersion, FlashpixVersion, InteroperabilityVersion and GPSVersionID fields. + /// Used for the ExifVersion, FlashpixVersion and InteroperabilityVersion fields. /// public class ExifVersion : ExifProperty { @@ -189,6 +189,28 @@ public override ExifInterOperability Interoperability } } + /// + /// Represents a version as a 4 byte byte array. (Specification: int8u[4]) + /// Used for the GPSVersionID field. + /// + public class VersionID : ExifByteArray + { + public VersionID(ExifTag tag, byte [] value) + : base(tag, value) + { + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + foreach (var b in Value) + { + sb.Append(b).Append('.'); + } + return sb.ToString().TrimEnd('.'); + } + } + /// /// Represents the location and area of the subject (EXIF Specification: 2xSHORT) /// The coordinate values, width, and height are expressed in relation to the diff --git a/ExifLibrary/ExifPropertyFactory.cs b/ExifLibrary/ExifPropertyFactory.cs index 31130f1..d5c1e08 100644 --- a/ExifLibrary/ExifPropertyFactory.cs +++ b/ExifLibrary/ExifPropertyFactory.cs @@ -134,7 +134,7 @@ public static ExifProperty Get(ushort tag, ushort type, uint count, byte[] value else if (ifd == IFD.GPS) { if (tag == 0) // GPSVersionID - return new ExifVersion(ExifTag.GPSVersionID, ExifBitConverter.ToString(value)); + return new VersionID(ExifTag.GPSVersionID, value); else if (tag == 1) // GPSLatitudeRef return new ExifEnumProperty(ExifTag.GPSLatitudeRef, (GPSLatitudeRef)value[0]); else if (tag == 2) // GPSLatitude diff --git a/ExifLibrary/JPEGFile.cs b/ExifLibrary/JPEGFile.cs index ed3f425..84e9b28 100644 --- a/ExifLibrary/JPEGFile.cs +++ b/ExifLibrary/JPEGFile.cs @@ -161,23 +161,7 @@ protected internal JPEGFile(Stream stream, Encoding encoding) /// public override void Crush() { - // Keep JFIF Tags - List jfifProperties = new List(); - foreach (ExifProperty prop in Properties) - { - if (prop.IFD == IFD.JFIF) - { - if (prop.Tag == ExifTag.JFIFXThumbnail) - prop.Value = 0; - if (prop.Tag == ExifTag.JFIFYThumbnail) - prop.Value = 0; - if (prop.Tag == ExifTag.JFIFThumbnail) - prop.Value = new JFIFThumbnail(JFIFThumbnail.ImageFormat.JPEG, new byte[0]); - } - } Properties.Clear(); - foreach (ExifProperty prop in jfifProperties) - Properties.Add(prop); // Remove metadata sections. // Keep the sections in this whitelist only: @@ -187,14 +171,11 @@ public override void Crush() // RST0 - RST7 // SOI, EOI // DQT - // DNL - // DRI - // DHP - // EXP - Sections.RemoveAll((section) => - { - return (section.Marker < JPEGMarker.SOF0 || section.Marker > JPEGMarker.EXP); - }); + // DNL + // DRI + // DHP + // EXP + Sections.RemoveAll(section => section.Marker < JPEGMarker.SOF0 || section.Marker > JPEGMarker.EXP); } /// @@ -653,27 +634,26 @@ private bool WriteExifApp1(bool preserveMakerNote) thumbSizeLocation = 0; thumbSizeValue = 0; // Write thumbnail tags if they are missing, remove otherwise - int indexf = -1; - int indexl = -1; - for (int i = 0; i < Properties.Count; i++) + ExifProperty thumbnailFormatProperty = null; + ExifProperty thumbnailLengthProperty = null; + foreach (var prop in Properties) { - ExifProperty prop = Properties[i]; - if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormat) indexf = i; - if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormatLength) indexl = i; - if (indexf != -1 && indexl != -1) break; + if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormat) thumbnailFormatProperty = prop; + if (prop.Tag == ExifTag.ThumbnailJPEGInterchangeFormatLength) thumbnailLengthProperty = prop; + if (thumbnailFormatProperty != null && thumbnailLengthProperty != null) break; } if (Thumbnail == null) { - if (indexf != -1) - Properties.RemoveAt(indexf); - if (indexl != -1) - Properties.RemoveAt(indexl); + if (thumbnailFormatProperty != null) + Properties.Remove(thumbnailFormatProperty); + if (thumbnailLengthProperty != null) + Properties.Remove(thumbnailLengthProperty); } else { - if (indexf == -1) + if (thumbnailFormatProperty == null) Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormat, 0)); - if (indexl == -1) + if (thumbnailLengthProperty == null) Properties.Add(new ExifUInt(ExifTag.ThumbnailJPEGInterchangeFormatLength, 0)); } @@ -725,7 +705,8 @@ private bool WriteExifApp1(bool preserveMakerNote) if (ifdzeroth.Count == 0 && ifdgps.Count == 0 && ifdinterop.Count == 0 && ifdfirst.Count == 0 && Thumbnail == null) { - // Nothing to write + // Nothing to write to App1 section + exifApp1.Header = new byte[0]; return false; }