Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions MetadataExtractor/Formats/Exif/ExifDescriptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public override string GetDescription(int tagType)
return GetOrientationDescription();
case ExifDirectoryBase.TagResolutionUnit:
return GetResolutionDescription();
case ExifDirectoryBase.TagPageNumber:
return GetPageNumberDescription();
case ExifDirectoryBase.TagYCbCrPositioning:
return GetYCbCrPositioningDescription();
case ExifDirectoryBase.TagXResolution:
Expand Down Expand Up @@ -271,6 +273,25 @@ public string GetResolutionDescription()
"cm");
}

[CanBeNull]
public string GetPageNumberDescription()
{
var values = Directory.GetInt32Array(ExifDirectoryBase.TagPageNumber);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the specs I have seen describe this as a short array. Exiftool has it typed as ushort. When feasible, I typically try to keep the same data types in .NET as the spec. Not every array type is implemented, so can fall back on the 'as' operator:

var values = Directory.GetObject(ExifDirectoryBase.TagPageNumber) as ushort[];

Obviously, the parsed datatype isn't always to spec so you would have to test whether this works all the time. Doing this in Java isn't always possible, so int32 isn't so bad if you're trying to match code.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. We don't have a GetInt16Array extension method for Directory and I wasn't feeling up to making one, partly because of the inconsistent mess that permitting type coercion within directories has left us with. We could call GetObject and cast, but GetInt32Array will convert the value if it's non-standard, which does tend to increase coverage.


if (values?.Length != 2)
return null;

if (values[1] == 0)
return (values[0] + 1).ToString();

// The first number is the zero-based page index. However, support for this tag seems quite variable in the wild.
// If the page number seems within range, increment it to the more human friendly one-based index.
if (values[0] < values[1])
values[0]++;

return $"{values[0]} of {values[1]}";
}

/// <summary>The Windows specific tags uses plain Unicode.</summary>
[CanBeNull]
private string GetUnicodeDescription(int tag)
Expand Down