Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert OrientationMode into something usable. #1976

Merged
merged 6 commits into from
Feb 6, 2022

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

I noticed while working on SixLabors/ImageSharp.Web#215 that our OrientationMode enum was internal. I'm assuming because explicitly casting to a ushort each time was not a great developer experience. By converting it to a static class with constants we're able to expose the type in a much more useful form.

}
else
{
orientation = (OrientationMode)Convert.ToUInt16(value.Value);
orientation = Convert.ToUInt16(value.Value);
source.Metadata.ExifProfile.RemoveValue(ExifTag.Orientation);

Choose a reason for hiding this comment

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

This line should be removed, because the value is always set below:

Suggested change
source.Metadata.ExifProfile.RemoveValue(ExifTag.Orientation);

Copy link
Member Author

Choose a reason for hiding this comment

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

We remove to ensure that any invalid values are gone. We've seen in the wild some odd implementations of this property. SetValue actually calls TrySetValue on the value which can return false.

source.Metadata.ExifProfile.RemoveValue(ExifTag.Orientation);
}

source.Metadata.ExifProfile.SetValue(ExifTag.Orientation, (ushort)OrientationMode.TopLeft);
source.Metadata.ExifProfile.SetValue(ExifTag.Orientation, ExifOrientationMode.TopLeft);

Choose a reason for hiding this comment

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

Would you be open to make it possible to opt-in to removing the value, instead of resetting it to ExifOrientationMode.TopLeft? This would require a single bool RemoveExifValue { get; } property and the following code:

if (this.RemoveExifValue)
{
    source.Metadata.ExifProfile.RemoveValue(ExifTag.Orientation);
}
else
{
    source.Metadata.ExifProfile.SetValue(ExifTag.Orientation, ExifOrientationMode.TopLeft);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we'll keep it since the value was explicitly set by the previous encoder.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

I wish there was a good way to consume enums in ExifTag.SetValue(), but I don't see how would it be possible, so LGTM.

@JimBobSquarePants JimBobSquarePants merged commit e5c40dc into master Feb 6, 2022
@JimBobSquarePants JimBobSquarePants deleted the js/expose-orientation branch February 6, 2022 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants