Skip to content

Commit

Permalink
Merge pull request #2541 from Cheesebaron/bugfix/2437-timezoneoffset-…
Browse files Browse the repository at this point in the history
…exif-type

Change ExifTag TimeZoneOffset to Signed Short
  • Loading branch information
JimBobSquarePants authored Oct 4, 2023
2 parents e905b0a + ee02262 commit d378306
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public abstract partial class ExifTag
/// </summary>
public static ExifTag<uint[]> IntergraphRegisters { get; } = new ExifTag<uint[]>(ExifTagValue.IntergraphRegisters);

/// <summary>
/// Gets the TimeZoneOffset exif tag.
/// </summary>
public static ExifTag<uint[]> TimeZoneOffset { get; } = new ExifTag<uint[]>(ExifTagValue.TimeZoneOffset);

/// <summary>
/// Gets the offset to child IFDs exif tag.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.ImageSharp.Metadata.Profiles.Exif;

/// <content/>
public abstract partial class ExifTag
{
/// <summary>
/// Gets the TimeZoneOffset exif tag.
/// </summary>
public static ExifTag<short[]> TimeZoneOffset { get; } = new ExifTag<short[]>(ExifTagValue.TimeZoneOffset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif;

internal sealed class ExifSignedShortArray : ExifArrayValue<short>
{
public ExifSignedShortArray(ExifTag<short[]> tag)
: base(tag)
{
}

public ExifSignedShortArray(ExifTagValue tag)
: base(tag)
{
Expand Down
5 changes: 3 additions & 2 deletions src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ internal static partial class ExifValues
return new ExifLongArray(ExifTag.StripRowCounts);
case ExifTagValue.IntergraphRegisters:
return new ExifLongArray(ExifTag.IntergraphRegisters);
case ExifTagValue.TimeZoneOffset:
return new ExifLongArray(ExifTag.TimeZoneOffset);
case ExifTagValue.SubIFDs:
return new ExifLongArray(ExifTag.SubIFDs);

Expand Down Expand Up @@ -417,6 +415,9 @@ internal static partial class ExifValues
case ExifTagValue.Decode:
return new ExifSignedRationalArray(ExifTag.Decode);

case ExifTagValue.TimeZoneOffset:
return new ExifSignedShortArray(ExifTag.TimeZoneOffset);

case ExifTagValue.ImageDescription:
return new ExifString(ExifTag.ImageDescription);
case ExifTagValue.Make:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public class ExifValuesTests
{ ExifTag.JPEGDCTables },
{ ExifTag.JPEGACTables },
{ ExifTag.StripRowCounts },
{ ExifTag.IntergraphRegisters },
{ ExifTag.TimeZoneOffset }
{ ExifTag.IntergraphRegisters }
};

public static TheoryData<ExifTag> NumberTags => new TheoryData<ExifTag>
Expand Down Expand Up @@ -235,6 +234,11 @@ public class ExifValuesTests
{ ExifTag.Decode }
};

public static TheoryData<ExifTag> SignedShortArrayTags => new TheoryData<ExifTag>
{
{ ExifTag.TimeZoneOffset }
};

public static TheoryData<ExifTag> StringTags => new TheoryData<ExifTag>
{
{ ExifTag.ImageDescription },
Expand Down Expand Up @@ -559,6 +563,21 @@ public void ExifSignedRationalArrayTests(ExifTag tag)
Assert.Equal(expected, typed.Value);
}


[Theory]
[MemberData(nameof(SignedShortArrayTags))]
public void ExifSignedShortArrayTests(ExifTag tag)
{
short[] expected = new short[] { 21, 42 };
ExifValue value = ExifValues.Create(tag);

Assert.False(value.TrySetValue(expected.ToString()));
Assert.True(value.TrySetValue(expected));

var typed = (ExifSignedShortArray)value;
Assert.Equal(expected, typed.Value);
}

[Theory]
[MemberData(nameof(StringTags))]
public void ExifStringTests(ExifTag tag)
Expand Down

0 comments on commit d378306

Please sign in to comment.