Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETFRAMEWORK || NETSTANDARD1_3
#if NETSTANDARD2_0

namespace System.Diagnostics.CodeAnalysis
{
Expand Down
5 changes: 2 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

<!-- https://aka.ms/vs-build-acceleration -->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

<ModernDotNetTargetFrameworkAlias>net8.0</ModernDotNetTargetFrameworkAlias>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />

<!-- Avoid needing to have targeting packs installed for .NET Framework. -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

<!-- Analyzers -->
Expand Down
13 changes: 1 addition & 12 deletions MetadataExtractor.Benchmarks/MetadataExtractor.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>$(ModernDotNetTargetFrameworkAlias)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -13,15 +13,4 @@
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Windows" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="System.Xaml" />
<Reference Include="System.Drawing" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
9 changes: 7 additions & 2 deletions MetadataExtractor.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System.Drawing;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using MetadataExtractor.Formats.Exif;
using MetadataExtractor.Formats.Jpeg;

#if !NET
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Media.Imaging;
#endif

namespace MetadataExtractor.Benchmarks
{
Expand Down Expand Up @@ -108,6 +111,7 @@ public DateTime ImageMetadataReaderBenchmark()
return subIfdDirectory.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);
}

#if !NET
private readonly Regex _dateTimeRegex = new Regex(":");

[Benchmark]
Expand Down Expand Up @@ -145,5 +149,6 @@ public DateTime WpfJpegBitmapDecoderBenchmark()
var dateTakenStr = (string)metadata.GetQuery("/app1/ifd/exif/subifd:{uint=36867}");
return DateTime.Parse(_dateTimeRegex.Replace(dateTakenStr, "-", count: 2));
}
#endif
}
}
2 changes: 1 addition & 1 deletion MetadataExtractor.Tests/MetadataExtractor.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<TargetFrameworks>$(ModernDotNetTargetFrameworkAlias);net472</TargetFrameworks>

<RootNamespace>MetadataExtractor</RootNamespace>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#if NETFRAMEWORK

#pragma warning disable IDE0130 // Namespace does not match folder structure

namespace System.Collections.Generic;

internal static class DeconstructionExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
<TargetFrameworks>$(ModernDotNetTargetFrameworkAlias);net48</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PropertyGroup Condition="'$(TargetFramework)' == '$(ModernDotNetTargetFrameworkAlias)'">
<PublishTrimmed>true</PublishTrimmed>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>$(ModernDotNetTargetFrameworkAlias)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
6 changes: 1 addition & 5 deletions MetadataExtractor/Formats/Exif/ExifTiffHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,7 @@ private bool ProcessMakernote(in TiffReaderContext context, int makernoteOffset)
PushDirectory(new OlympusMakernoteDirectory());
TiffReader.ProcessIfd(this, context, ifdOffset: makernoteOffset);
}
#if NETSTANDARD1_3 || NET462
else if (cameraMake is not null && cameraMake.TrimStart().StartsWith("NIKON", StringComparison.OrdinalIgnoreCase))
#else
else if (cameraMake is not null && cameraMake.AsSpan().TrimStart().StartsWith("NIKON", StringComparison.OrdinalIgnoreCase))
#endif
else if (cameraMake is not null && cameraMake.AsSpan().TrimStart().StartsWith("NIKON".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
if (headerBytes.StartsWith("Nikon"u8))
{
Expand Down
8 changes: 4 additions & 4 deletions MetadataExtractor/Formats/Icc/IccDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ private enum IccTagType
{
case IccTagType.Text:
{
#if !NETSTANDARD1_3
Span<byte> textBytes = bytes.AsSpan(start: 8, length: bytes.Length - 8 - 1);

try
{
return Encoding.ASCII.GetString(bytes, 8, bytes.Length - 8 - 1);
return Encoding.ASCII.GetString(textBytes);
}
catch
#endif
{
return Encoding.UTF8.GetString(bytes, 8, bytes.Length - 8 - 1);
return Encoding.UTF8.GetString(textBytes);
}
}

Expand Down
6 changes: 1 addition & 5 deletions MetadataExtractor/Formats/Iptc/Iso2022Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public static class Iso2022Converter

if (ascii)
{
#if NETSTANDARD1_3
return Encoding.UTF8;
#else
return Encoding.ASCII;
#endif
}

var utf8 = false;
Expand Down Expand Up @@ -97,7 +93,7 @@ public static class Iso2022Converter
{
int charCount = encoding.GetChars(bytes, 0, bytes.Length, charBuffer, 0);

if (charBuffer.AsSpan(0, charCount).IndexOf((char)65533) != -1)
if (charBuffer.AsSpan(0, charCount).IndexOf((char)0xFFFD) != -1)
continue;
return encoding;
}
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/Formats/Jpeg/JpegComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MetadataExtractor.Formats.Jpeg
/// quantization table number.
/// </summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public sealed class JpegComponent
Expand Down
6 changes: 3 additions & 3 deletions MetadataExtractor/Formats/Jpeg/JpegProcessingException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace MetadataExtractor.Formats.Jpeg
{
/// <summary>An exception class thrown upon unexpected and fatal conditions while processing a JPEG file.</summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class JpegProcessingException : ImageProcessingException
Expand All @@ -28,7 +28,7 @@ public JpegProcessingException(Exception? innerException)
{
}

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
protected JpegProcessingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/Formats/Png/PngColorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MetadataExtractor.Formats.Png
{
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public sealed class PngColorType
Expand Down
6 changes: 3 additions & 3 deletions MetadataExtractor/Formats/Png/PngProcessingException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace MetadataExtractor.Formats.Png
{
/// <summary>An exception class thrown upon unexpected and fatal conditions while processing a JPEG file.</summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class PngProcessingException : ImageProcessingException
Expand All @@ -28,7 +28,7 @@ public PngProcessingException(Exception? innerException)
{
}

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
protected PngProcessingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
13 changes: 1 addition & 12 deletions MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ namespace MetadataExtractor.Formats.QuickTime
/// </summary>
public static class QuickTimeReaderExtensions
{
#if NET462 || NETSTANDARD1_3
public static unsafe string Get4ccString(this SequentialReader reader)
#else
public static string Get4ccString(this SequentialReader reader)
#endif
{
// https://en.wikipedia.org/wiki/FourCC

Expand All @@ -28,14 +24,7 @@ public static string Get4ccString(this SequentialReader reader)
(char)bytes[3]
];

#if NET462 || NETSTANDARD1_3
fixed (char* pChars = chars)
{
return new string(pChars, startIndex: 0, length: 4);
}
#else
return new string(chars);
#endif
return chars.ToString();
}

public static decimal Get16BitFixedPoint(this SequentialReader reader)
Expand Down
6 changes: 3 additions & 3 deletions MetadataExtractor/Formats/Riff/RiffProcessingException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace MetadataExtractor.Formats.Riff
{
/// <summary>An exception class thrown upon unexpected and fatal conditions while processing a RIFF file.</summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class RiffProcessingException : ImageProcessingException
Expand All @@ -28,7 +28,7 @@ public RiffProcessingException(Exception? innerException)
{
}

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
protected RiffProcessingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
6 changes: 3 additions & 3 deletions MetadataExtractor/Formats/Tiff/TiffProcessingException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

Expand All @@ -9,7 +9,7 @@ namespace MetadataExtractor.Formats.Tiff
/// <summary>An exception class thrown upon unexpected and fatal conditions while processing a TIFF file.</summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
/// <author>Darren Salomons</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class TiffProcessingException : ImageProcessingException
Expand All @@ -29,7 +29,7 @@ public TiffProcessingException(Exception? innerException)
{
}

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
protected TiffProcessingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
6 changes: 3 additions & 3 deletions MetadataExtractor/IO/BufferBoundsException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

Expand All @@ -10,7 +10,7 @@ namespace MetadataExtractor.IO
/// Thrown when the index provided to an <see cref="IndexedReader"/> is invalid.
/// </summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class BufferBoundsException : IOException
Expand Down Expand Up @@ -43,7 +43,7 @@ private static string GetMessage(int index, int bytesRequested, long bufferLengt
return $"Attempt to read from beyond end of underlying data source (requested index: {index}, requested count: {bytesRequested}, max index: {bufferLength - 1})";
}

#if !NETSTANDARD1_3 && !NET8_0_OR_GREATER
#if !NET8_0_OR_GREATER
protected BufferBoundsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
4 changes: 2 additions & 2 deletions MetadataExtractor/IO/BufferReader.Indexed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public readonly long GetInt64(int index)
/// <exception cref="IOException"/>
public readonly float GetFloat32(int index)
{
#if NET462 || NETSTANDARD1_3
#if NETSTANDARD2_0
return BitConverter.ToSingle(BitConverter.GetBytes(GetInt32(index)), 0);
#else
Span<byte> bytes = stackalloc byte[4];
Expand All @@ -153,7 +153,7 @@ public readonly float GetFloat32(int index)

public readonly double GetDouble64(int index)
{
#if NET462 || NETSTANDARD1_3
#if NETSTANDARD2_0
return BitConverter.Int64BitsToDouble(GetInt64(index));
#else
Span<byte> bytes = stackalloc byte[8];
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/IO/IndexedCapturingReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void Dispose()

private void GetPosition(int index, out int chunkIndex, out int innerIndex)
{
#if NET462 || NETSTANDARD2_1
#if NETSTANDARD2_1
chunkIndex = Math.DivRem(index, _chunkLength, out innerIndex);
#elif NET6_0_OR_GREATER
(chunkIndex, innerIndex) = Math.DivRem(index, _chunkLength);
Expand Down
4 changes: 2 additions & 2 deletions MetadataExtractor/IO/IndexedReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public float GetS15Fixed16(int index)
/// <exception cref="IOException"/>
public float GetFloat32(int index)
{
#if NET462 || NETSTANDARD1_3
#if NETSTANDARD2_0
return BitConverter.ToSingle(BitConverter.GetBytes(GetInt32(index)), 0);
#else
Span<byte> bytes = stackalloc byte[4];
Expand All @@ -299,7 +299,7 @@ public float GetFloat32(int index)
/// <exception cref="IOException"/>
public double GetDouble64(int index)
{
#if NET462 || NETSTANDARD1_3
#if NETSTANDARD2_0
return BitConverter.Int64BitsToDouble(GetInt64(index));
#else
Span<byte> bytes = stackalloc byte[8];
Expand Down
Loading