diff --git a/src/ImageSharp/Common/Helpers/UnitConverter.cs b/src/ImageSharp/Common/Helpers/UnitConverter.cs index 04ecb5afd0..983d86a711 100644 --- a/src/ImageSharp/Common/Helpers/UnitConverter.cs +++ b/src/ImageSharp/Common/Helpers/UnitConverter.cs @@ -91,7 +91,7 @@ internal static class UnitConverter [MethodImpl(InliningOptions.ShortMethod)] public static PixelResolutionUnit ExifProfileToResolutionUnit(ExifProfile profile) { - IExifValue resolution = profile.GetValue(ExifTag.ResolutionUnit); + IExifValue? resolution = profile.GetValue(ExifTag.ResolutionUnit); // EXIF is 1, 2, 3 so we minus "1" off the result. return resolution is null ? DefaultResolutionUnit : (PixelResolutionUnit)(byte)(resolution.Value - 1); diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifEncodedStringHelpers.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifEncodedStringHelpers.cs index 8d6723c28c..bfe991f833 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifEncodedStringHelpers.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifEncodedStringHelpers.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers.Binary; using System.Text; @@ -27,7 +26,8 @@ internal static class ExifEncodedStringHelpers // 20932 EUC-JP Japanese (JIS 0208-1990 and 0212-1990) // https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-6.0 - private static Encoding JIS0208Encoding => CodePagesEncodingProvider.Instance.GetEncoding(20932); + private static Encoding JIS0208Encoding => CodePagesEncodingProvider.Instance.GetEncoding(20932) ?? + throw new InvalidOperationException(); public static bool IsEncodedString(ExifTagValue tag) => tag switch { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs index dbe19d8b6e..9a41fb6a4e 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs @@ -1,7 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Metadata.Profiles.Exif; @@ -14,12 +15,12 @@ public sealed class ExifProfile : IDeepCloneable /// /// The byte array to read the EXIF profile from. /// - private readonly byte[] data; + private readonly byte[]? data; /// /// The collection of EXIF values /// - private List values; + private List? values; /// /// The thumbnail offset position in the byte stream @@ -35,7 +36,7 @@ public sealed class ExifProfile : IDeepCloneable /// Initializes a new instance of the class. /// public ExifProfile() - : this((byte[])null) + : this((byte[]?)null) { } @@ -43,7 +44,7 @@ public sealed class ExifProfile : IDeepCloneable /// Initializes a new instance of the class. /// /// The byte array to read the EXIF profile from. - public ExifProfile(byte[] data) + public ExifProfile(byte[]? data) { this.Parts = ExifParts.All; this.data = data; @@ -110,6 +111,7 @@ public sealed class ExifProfile : IDeepCloneable /// /// Gets the values of this EXIF profile. /// + [MemberNotNull(nameof(values))] public IReadOnlyList Values { get @@ -125,7 +127,7 @@ public sealed class ExifProfile : IDeepCloneable /// /// The . /// - public Image CreateThumbnail() => this.CreateThumbnail(); + public Image? CreateThumbnail() => this.CreateThumbnail(); /// /// Returns the thumbnail in the EXIF profile when available. @@ -134,7 +136,7 @@ public sealed class ExifProfile : IDeepCloneable /// /// The . /// - public Image CreateThumbnail() + public Image? CreateThumbnail() where TPixel : unmanaged, IPixel { this.InitializeValues(); @@ -161,9 +163,9 @@ public sealed class ExifProfile : IDeepCloneable /// The tag of the exif value. /// The value with the specified tag. /// The data type of the tag. - public IExifValue GetValue(ExifTag tag) + public IExifValue? GetValue(ExifTag tag) { - IExifValue value = this.GetValueInternal(tag); + IExifValue? value = this.GetValueInternal(tag); return value is null ? null : (IExifValue)value; } @@ -203,7 +205,7 @@ public sealed class ExifProfile : IDeepCloneable /// Converts this instance to a byte array. /// /// The - public byte[] ToByteArray() + public byte[]? ToByteArray() { if (this.values is null) { @@ -227,7 +229,7 @@ public sealed class ExifProfile : IDeepCloneable /// /// The tag of the exif value. /// The value with the specified tag. - internal IExifValue GetValueInternal(ExifTag tag) + internal IExifValue? GetValueInternal(ExifTag tag) { foreach (IExifValue exifValue in this.Values) { @@ -245,7 +247,7 @@ public sealed class ExifProfile : IDeepCloneable /// /// The tag of the exif value. /// The value. - internal void SetValueInternal(ExifTag tag, object value) + internal void SetValueInternal(ExifTag tag, object? value) { foreach (IExifValue exifValue in this.Values) { @@ -256,7 +258,7 @@ public sealed class ExifProfile : IDeepCloneable } } - ExifValue newExifValue = ExifValues.Create(tag); + ExifValue? newExifValue = ExifValues.Create(tag); if (newExifValue is null) { throw new NotSupportedException(); @@ -278,7 +280,7 @@ public sealed class ExifProfile : IDeepCloneable private void SyncResolution(ExifTag tag, double resolution) { - IExifValue value = this.GetValue(tag); + IExifValue? value = this.GetValue(tag); if (value is null) { @@ -294,6 +296,7 @@ public sealed class ExifProfile : IDeepCloneable this.SetValue(tag, newResolution); } + [MemberNotNull(nameof(values))] private void InitializeValues() { if (this.values != null) diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs index a93973a8dc..7b989c8d8a 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers; using System.Buffers.Binary; @@ -20,7 +19,7 @@ internal class ExifReader : BaseExifReader { } - public ExifReader(byte[] exifData, MemoryAllocator allocator) + public ExifReader(byte[] exifData, MemoryAllocator? allocator) : base(new MemoryStream(exifData ?? throw new ArgumentNullException(nameof(exifData))), allocator) { } @@ -90,13 +89,13 @@ internal abstract class BaseExifReader private readonly byte[] buf4 = new byte[4]; private readonly byte[] buf2 = new byte[2]; - private readonly MemoryAllocator allocator; + private readonly MemoryAllocator? allocator; private readonly Stream data; - private List invalidTags; + private List? invalidTags; - private List subIfds; + private List? subIfds; - protected BaseExifReader(Stream stream, MemoryAllocator allocator) + protected BaseExifReader(Stream stream, MemoryAllocator? allocator) { this.data = stream ?? throw new ArgumentNullException(nameof(stream)); this.allocator = allocator; @@ -219,7 +218,7 @@ internal abstract class BaseExifReader this.Seek(tag.Offset); if (this.TryReadSpan(buffer)) { - object value = this.ConvertValue(tag.DataType, buffer, tag.NumberOfComponents > 1 || tag.Exif.IsArray); + object? value = this.ConvertValue(tag.DataType, buffer, tag.NumberOfComponents > 1 || tag.Exif.IsArray); this.Add(values, tag.Exif, value); } } @@ -255,7 +254,7 @@ internal abstract class BaseExifReader private static byte ConvertToByte(ReadOnlySpan buffer) => buffer[0]; - private object ConvertValue(ExifDataType dataType, ReadOnlySpan buffer, bool isArray) + private object? ConvertValue(ExifDataType dataType, ReadOnlySpan buffer, bool isArray) { if (buffer.Length == 0) { @@ -390,7 +389,7 @@ internal abstract class BaseExifReader numberOfComponents = 4 / ExifDataTypes.GetSize(dataType); } - ExifValue exifValue = ExifValues.Create(tag) ?? ExifValues.Create(tag, dataType, numberOfComponents); + ExifValue? exifValue = ExifValues.Create(tag) ?? ExifValues.Create(tag, dataType, numberOfComponents); if (exifValue is null) { @@ -414,7 +413,7 @@ internal abstract class BaseExifReader } else { - object value = this.ConvertValue(dataType, offsetBuffer[..(int)size], numberOfComponents > 1 || exifValue.IsArray); + object? value = this.ConvertValue(dataType, offsetBuffer[..(int)size], numberOfComponents > 1 || exifValue.IsArray); this.Add(values, exifValue, value); } } @@ -443,7 +442,7 @@ internal abstract class BaseExifReader numberOfComponents = 8 / ExifDataTypes.GetSize(dataType); } - ExifValue exifValue = tag switch + ExifValue? exifValue = tag switch { ExifTagValue.StripOffsets => new ExifLong8Array(ExifTagValue.StripOffsets), ExifTagValue.StripByteCounts => new ExifLong8Array(ExifTagValue.StripByteCounts), @@ -471,12 +470,12 @@ internal abstract class BaseExifReader } else { - object value = this.ConvertValue(dataType, offsetBuffer[..(int)size], numberOfComponents > 1 || exifValue.IsArray); + object? value = this.ConvertValue(dataType, offsetBuffer[..(int)size], numberOfComponents > 1 || exifValue.IsArray); this.Add(values, exifValue, value); } } - private void Add(IList values, IExifValue exif, object value) + private void Add(IList values, IExifValue exif, object? value) { if (!exif.TrySetValue(value)) { @@ -510,7 +509,7 @@ internal abstract class BaseExifReader private void AddInvalidTag(ExifTag tag) => (this.invalidTags ??= new List()).Add(tag); - private void AddSubIfd(object val) + private void AddSubIfd(object? val) => (this.subIfds ??= new List()).Add(Convert.ToUInt64(val, CultureInfo.InvariantCulture)); private void Seek(ulong pos) diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs index b9e74e246d..da5214087f 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifTagDescriptionAttribute.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Reflection; @@ -29,10 +28,10 @@ internal sealed class ExifTagDescriptionAttribute : Attribute /// /// The . /// - public static string GetDescription(ExifTag tag, object value) + public static string? GetDescription(ExifTag tag, object? value) { var tagValue = (ExifTagValue)(ushort)tag; - FieldInfo field = typeof(ExifTagValue).GetField(tagValue.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); + FieldInfo? field = typeof(ExifTagValue).GetField(tagValue.ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (field is null) { @@ -41,11 +40,11 @@ internal sealed class ExifTagDescriptionAttribute : Attribute foreach (CustomAttributeData customAttribute in field.CustomAttributes) { - object attributeValue = customAttribute.ConstructorArguments[0].Value; + object? attributeValue = customAttribute.ConstructorArguments[0].Value; if (Equals(attributeValue, value)) { - return (string)customAttribute.ConstructorArguments[1].Value; + return (string?)customAttribute.ConstructorArguments[1].Value; } } diff --git a/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs index d156cbee36..26442b2c41 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Buffers.Binary; @@ -16,7 +15,7 @@ internal sealed class ExifWriter /// private readonly ExifParts allowedParts; private readonly IList values; - private List dataOffsets; + private List? dataOffsets; private readonly List ifdValues; private readonly List exifValues; private readonly List gpsValues; @@ -45,8 +44,8 @@ internal sealed class ExifWriter { const uint startIndex = 0; - IExifValue exifOffset = GetOffsetValue(this.ifdValues, this.exifValues, ExifTag.SubIFDOffset); - IExifValue gpsOffset = GetOffsetValue(this.ifdValues, this.gpsValues, ExifTag.GPSIFDOffset); + IExifValue? exifOffset = GetOffsetValue(this.ifdValues, this.exifValues, ExifTag.SubIFDOffset); + IExifValue? gpsOffset = GetOffsetValue(this.ifdValues, this.gpsValues, ExifTag.GPSIFDOffset); uint ifdLength = GetLength(this.ifdValues); uint exifLength = GetLength(this.exifValues); @@ -160,7 +159,7 @@ internal sealed class ExifWriter return offset + 4; } - private static IExifValue GetOffsetValue(List ifdValues, List values, ExifTag offset) + private static IExifValue? GetOffsetValue(List ifdValues, List values, ExifTag offset) { int index = -1; @@ -179,7 +178,9 @@ internal sealed class ExifWriter return ifdValues[index]; } - ExifValue result = ExifValues.Create(offset); + ExifValue? result = ExifValues.Create(offset); + Guard.NotNull(result); + ifdValues.Add(result); return result; @@ -219,7 +220,7 @@ internal sealed class ExifWriter private static bool HasValue(IExifValue exifValue) { - object value = exifValue.GetValue(); + object? value = exifValue.GetValue(); if (value is null) { return false; @@ -270,11 +271,11 @@ internal sealed class ExifWriter internal static uint GetNumberOfComponents(IExifValue exifValue) { - object value = exifValue.GetValue(); + object? value = exifValue.GetValue(); if (ExifUcs2StringHelpers.IsUcs2Tag((ExifTagValue)(ushort)exifValue.Tag)) { - return (uint)ExifUcs2StringHelpers.Ucs2Encoding.GetByteCount((string)value); + return (uint)ExifUcs2StringHelpers.Ucs2Encoding.GetByteCount((string?)value!); } if (value is EncodedString encodedString) @@ -284,7 +285,7 @@ internal sealed class ExifWriter if (exifValue.DataType == ExifDataType.Ascii) { - return (uint)ExifConstants.DefaultEncoding.GetByteCount((string)value) + 1; + return (uint)ExifConstants.DefaultEncoding.GetByteCount((string?)value!) + 1; } if (value is Array arrayValue) @@ -298,7 +299,7 @@ internal sealed class ExifWriter private static int WriteArray(IExifValue value, Span destination, int offset) { int newOffset = offset; - foreach (object obj in (Array)value.GetValue()) + foreach (object obj in (Array)value.GetValue()!) { newOffset = WriteValue(value.DataType, obj, destination, newOffset); } @@ -308,7 +309,7 @@ internal sealed class ExifWriter private int WriteData(uint startIndex, List values, Span destination, int offset) { - if (this.dataOffsets.Count == 0) + if (this.dataOffsets is null || this.dataOffsets.Count == 0) { return offset; } @@ -428,7 +429,8 @@ internal sealed class ExifWriter internal static int WriteValue(IExifValue exifValue, Span destination, int offset) { - object value = exifValue.GetValue(); + object? value = exifValue.GetValue(); + Guard.NotNull(value); if (ExifUcs2StringHelpers.IsUcs2Tag((ExifTagValue)(ushort)exifValue.Tag)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs index 97f795c0fd..64b8d23137 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifArrayValue{TValueType}.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Metadata.Profiles.Exif; @@ -23,11 +22,11 @@ internal abstract class ExifArrayValue : ExifValue, IExifValue true; - public TValueType[] Value { get; set; } + public TValueType[]? Value { get; set; } - public override object GetValue() => this.Value; + public override object? GetValue() => this.Value; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (value is null) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs index 910da27da0..eb69c43897 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByte.cs @@ -20,7 +20,7 @@ internal sealed class ExifByte : ExifValue protected override string StringValue => this.Value.ToString("X2", CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs index 532d69395c..4320cb5e82 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifByteArray.cs @@ -16,7 +16,7 @@ internal sealed class ExifByteArray : ExifArrayValue public override ExifDataType DataType { get; } - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs index e8a2699d82..1d24a7dfb7 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifDouble.cs @@ -26,7 +26,7 @@ internal sealed class ExifDouble : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs index 317f8d7716..cce7cf3e89 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs @@ -24,7 +24,7 @@ internal sealed class ExifEncodedString : ExifValue protected override string StringValue => this.Value.Text; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs index 904a9ee02c..bfe5871e8a 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifFloat.cs @@ -21,7 +21,7 @@ internal sealed class ExifFloat : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs index 4fb5e8092b..8f185ea363 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong.cs @@ -26,7 +26,7 @@ internal sealed class ExifLong : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs index 9f25031446..13feb6ad6e 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs @@ -26,7 +26,7 @@ internal sealed class ExifLong8 : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs index ff48fc7741..b7756e62bd 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs @@ -34,7 +34,7 @@ internal sealed class ExifLong8Array : ExifArrayValue } } - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs index 780f389ab4..a78107317c 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumber.cs @@ -32,7 +32,7 @@ internal sealed class ExifNumber : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs index 6b5aafbad5..1162c25ea9 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifNumberArray.cs @@ -34,7 +34,7 @@ internal sealed class ExifNumberArray : ExifArrayValue } } - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs index 958c6f8342..c25f0f5dc1 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRational.cs @@ -26,7 +26,7 @@ internal sealed class ExifRational : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs index 0114a7fbda..ac6453edc7 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifRationalArray.cs @@ -22,7 +22,7 @@ internal sealed class ExifRationalArray : ExifArrayValue public override ExifDataType DataType => ExifDataType.Rational; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs index 68932b3b87..d35b21422b 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShort.cs @@ -26,7 +26,7 @@ internal sealed class ExifShort : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs index 42c919bb7d..a205e77dee 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifShortArray.cs @@ -22,7 +22,7 @@ internal sealed class ExifShortArray : ExifArrayValue public override ExifDataType DataType => ExifDataType.Short; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs index c9bf7a820f..95a239b70d 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedByte.cs @@ -21,7 +21,7 @@ internal sealed class ExifSignedByte : ExifValue protected override string StringValue => this.Value.ToString("X2", CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs index 72fd0b65a1..6726febef0 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShort.cs @@ -21,7 +21,7 @@ internal sealed class ExifSignedShort : ExifValue protected override string StringValue => this.Value.ToString(CultureInfo.InvariantCulture); - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs index 464105b3be..8023fb8bca 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifSignedShortArray.cs @@ -17,7 +17,7 @@ internal sealed class ExifSignedShortArray : ExifArrayValue public override ExifDataType DataType => ExifDataType.SignedShort; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs index 1eb712bcac..562583daee 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifString.cs @@ -24,9 +24,9 @@ internal sealed class ExifString : ExifValue public override ExifDataType DataType => ExifDataType.Ascii; - protected override string StringValue => this.Value; + protected override string? StringValue => this.Value; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifUcs2String.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifUcs2String.cs index 9e7c96dac9..88c3e816ec 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifUcs2String.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifUcs2String.cs @@ -22,11 +22,11 @@ internal sealed class ExifUcs2String : ExifValue public override ExifDataType DataType => ExifDataType.Byte; - protected override string StringValue => this.Value; + protected override string? StringValue => this.Value; - public override object GetValue() => this.Value; + public override object? GetValue() => this.Value; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (base.TrySetValue(value)) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs index b28e404dfc..eacb41cfb3 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable using System.Runtime.CompilerServices; @@ -28,7 +27,7 @@ internal abstract class ExifValue : IExifValue, IEquatable else { // All array types are value types so Clone() is sufficient here. - var array = (Array)other.GetValue(); + Array? array = (Array?)other.GetValue(); this.TrySetValue(array?.Clone()); } } @@ -43,7 +42,7 @@ internal abstract class ExifValue : IExifValue, IEquatable public static bool operator !=(ExifValue left, ExifTag right) => !Equals(left, right); - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is null) { @@ -69,14 +68,14 @@ internal abstract class ExifValue : IExifValue, IEquatable } [MethodImpl(InliningOptions.ShortMethod)] - public bool Equals(ExifTag other) => this.Tag.Equals(other); + public bool Equals(ExifTag? other) => this.Tag.Equals(other); [MethodImpl(InliningOptions.ShortMethod)] public override int GetHashCode() => HashCode.Combine(this.Tag, this.GetValue()); - public abstract object GetValue(); + public abstract object? GetValue(); - public abstract bool TrySetValue(object value); + public abstract bool TrySetValue(object? value); public abstract IExifValue DeepClone(); } diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs index 783da40253..8aa54c3a40 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValues.cs @@ -1,18 +1,17 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Metadata.Profiles.Exif; internal static partial class ExifValues { - public static ExifValue Create(ExifTagValue tag) => (ExifValue)CreateValue(tag); + public static ExifValue? Create(ExifTagValue tag) => (ExifValue?)CreateValue(tag); - public static ExifValue Create(ExifTag tag) => (ExifValue)CreateValue((ExifTagValue)(ushort)tag); + public static ExifValue? Create(ExifTag tag) => (ExifValue?)CreateValue((ExifTagValue)(ushort)tag); - public static ExifValue Create(ExifTagValue tag, ExifDataType dataType, ulong numberOfComponents) => Create(tag, dataType, numberOfComponents != 1); + public static ExifValue? Create(ExifTagValue tag, ExifDataType dataType, ulong numberOfComponents) => Create(tag, dataType, numberOfComponents != 1); - public static ExifValue Create(ExifTagValue tag, ExifDataType dataType, bool isArray) + public static ExifValue? Create(ExifTagValue tag, ExifDataType dataType, bool isArray) { switch (dataType) { @@ -49,7 +48,7 @@ internal static partial class ExifValues } } - private static object CreateValue(ExifTagValue tag) + private static object? CreateValue(ExifTagValue tag) { switch (tag) { diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs index 0face8401f..6442f26846 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/ExifValue{TValueType}.cs @@ -1,6 +1,5 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -#nullable disable namespace SixLabors.ImageSharp.Metadata.Profiles.Exif; @@ -21,16 +20,16 @@ internal abstract class ExifValue : ExifValue, IExifValue /// Gets the value of the current instance as a string. /// - protected abstract string StringValue { get; } + protected abstract string? StringValue { get; } - public override object GetValue() => this.Value; + public override object? GetValue() => this.Value; - public override bool TrySetValue(object value) + public override bool TrySetValue(object? value) { if (value is null) { @@ -49,14 +48,9 @@ internal abstract class ExifValue : ExifValue, IExifValue /// Gets the value of this exif value. /// /// The value of this exif value. - object GetValue(); + object? GetValue(); /// /// Sets the value of this exif value. /// /// The value of this exif value. /// A value indicating whether the value could be set. - bool TrySetValue(object value); + bool TrySetValue(object? value); } diff --git a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs index d49e80ea00..ec84b78f71 100644 --- a/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs +++ b/src/ImageSharp/Metadata/Profiles/Exif/Values/IExifValue{TValueType}.cs @@ -12,5 +12,5 @@ public interface IExifValue : IExifValue /// /// Gets or sets the value. /// - TValueType Value { get; set; } + TValueType? Value { get; set; } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Linear/AutoOrientProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Linear/AutoOrientProcessor{TPixel}.cs index 6952e561fb..6d70bd3797 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Linear/AutoOrientProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Linear/AutoOrientProcessor{TPixel}.cs @@ -88,7 +88,7 @@ internal class AutoOrientProcessor : ImageProcessor return ExifOrientationMode.Unknown; } - IExifValue value = source.Metadata.ExifProfile.GetValue(ExifTag.Orientation); + IExifValue? value = source.Metadata.ExifProfile.GetValue(ExifTag.Orientation); if (value is null) { return ExifOrientationMode.Unknown;