Skip to content

Commit

Permalink
Merge commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
oozcitak committed Oct 17, 2018
2 parents 8e8e2d6 + 9351f3d commit 3092164
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
6 changes: 3 additions & 3 deletions CONTRIB.md
Original file line number Diff line number Diff line change
@@ -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
- Automatic builds
24 changes: 23 additions & 1 deletion ExifLibrary/ExifExtendedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override ExifInterOperability Interoperability

/// <summary>
/// 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.
/// </summary>
public class ExifVersion : ExifProperty
{
Expand Down Expand Up @@ -189,6 +189,28 @@ public override ExifInterOperability Interoperability
}
}

/// <summary>
/// Represents a version as a 4 byte byte array. (Specification: int8u[4])
/// Used for the GPSVersionID field.
/// </summary>
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('.');
}
}

/// <summary>
/// Represents the location and area of the subject (EXIF Specification: 2xSHORT)
/// The coordinate values, width, and height are expressed in relation to the
Expand Down
2 changes: 1 addition & 1 deletion ExifLibrary/ExifPropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GPSLatitudeRef>(ExifTag.GPSLatitudeRef, (GPSLatitudeRef)value[0]);
else if (tag == 2) // GPSLatitude
Expand Down
57 changes: 19 additions & 38 deletions ExifLibrary/JPEGFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,7 @@ protected internal JPEGFile(Stream stream, Encoding encoding)
/// </summary>
public override void Crush()
{
// Keep JFIF Tags
List<ExifProperty> jfifProperties = new List<ExifProperty>();
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:
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3092164

Please sign in to comment.