Skip to content

Commit 2ebe20d

Browse files
committed
Renamed ExifParts to ExifIfds and renamed ExifProfile.Parts to ExifProfile.AllowedIfds and mark the old names as obsolete.
1 parent 1325e35 commit 2ebe20d

7 files changed

Lines changed: 71 additions & 20 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
6+
namespace ImageMagick;
7+
8+
/// <summary>
9+
/// Specifies the different IFDs that can be found in an Exif profile.
10+
/// </summary>
11+
[Flags]
12+
public enum ExifIfds
13+
{
14+
/// <summary>
15+
/// None.
16+
/// </summary>
17+
None = 0,
18+
19+
/// <summary>
20+
/// Primary IFD.
21+
/// </summary>
22+
Ifd0 = 1,
23+
24+
/// <summary>
25+
/// Thumbnail IFD.
26+
/// </summary>
27+
Exif = 4,
28+
29+
/// <summary>
30+
/// GPS IFD.
31+
/// </summary>
32+
Gps = 8,
33+
34+
/// <summary>
35+
/// All.
36+
/// </summary>
37+
All = Ifd0 | Exif | Gps,
38+
}

src/Magick.NET.Core/Profiles/Exif/ExifParts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ImageMagick;
99
/// Specifies which parts will be written when the profile is added to an image.
1010
/// </summary>
1111
[Flags]
12+
[Obsolete($"This enum will be removed in the next major release, use {nameof(ExifIfds)} instead.")]
1213
public enum ExifParts
1314
{
1415
/// <summary>

src/Magick.NET.Core/Profiles/Exif/ExifProfile.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ public ExifProfile(Stream stream)
5151
{
5252
}
5353

54+
/// <summary>
55+
/// Gets or sets which ifds will be written when the profile is added to an image.
56+
/// </summary>
57+
public ExifIfds AllowedIfds { get; set; } = ExifIfds.All;
58+
5459
/// <summary>
5560
/// Gets or sets which parts will be written when the profile is added to an image.
5661
/// </summary>
62+
[Obsolete($"This property will be removed in the next major release, use {nameof(AllowedIfds)} instead.")]
5763
public ExifParts Parts { get; set; } = ExifParts.All;
5864

5965
/// <summary>
@@ -209,7 +215,7 @@ protected override void UpdateData()
209215
return;
210216
}
211217

212-
var writer = new ExifWriter(Parts);
218+
var writer = new ExifWriter(AllowedIfds);
213219
SetData(writer.Write(_data.Values));
214220
}
215221

src/Magick.NET.Core/Profiles/Exif/ExifTags.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ImageMagick;
55

66
internal static class ExifTags
77
{
8-
public static ExifParts GetPart(ExifTag tag)
8+
public static ExifIfds GetIfd(ExifTag tag)
99
=> (ExifTagValue)(ushort)tag switch
1010
{
1111
ExifTagValue.SubfileType or
@@ -133,7 +133,7 @@ ExifTagValue.XPAuthor or
133133
ExifTagValue.XPKeywords or
134134
ExifTagValue.XPSubject or
135135
ExifTagValue.GDALMetadata or
136-
ExifTagValue.GDALNoData => ExifParts.IfdTags,
136+
ExifTagValue.GDALNoData => ExifIfds.Ifd0,
137137

138138
ExifTagValue.ExposureTime or
139139
ExifTagValue.FNumber or
@@ -226,7 +226,7 @@ ExifTagValue.SerialNumber or
226226
ExifTagValue.LensInfo or
227227
ExifTagValue.LensMake or
228228
ExifTagValue.LensModel or
229-
ExifTagValue.LensSerialNumber => ExifParts.ExifTags,
229+
ExifTagValue.LensSerialNumber => ExifIfds.Exif,
230230

231231
ExifTagValue.GPSVersionID or
232232
ExifTagValue.GPSLatitudeRef or
@@ -258,8 +258,8 @@ ExifTagValue.GPSDestDistance or
258258
ExifTagValue.GPSProcessingMethod or
259259
ExifTagValue.GPSAreaInformation or
260260
ExifTagValue.GPSDateStamp or
261-
ExifTagValue.GPSDifferential => ExifParts.GpsTags,
261+
ExifTagValue.GPSDifferential => ExifIfds.Gps,
262262

263-
_ => ExifParts.None,
263+
_ => ExifIfds.None,
264264
};
265265
}

src/Magick.NET.Core/Profiles/Exif/ExifWriter.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ internal sealed class ExifWriter
1212
{
1313
private const int HeaderSize = 2 + 2 + 4 + 4;
1414

15-
private readonly ExifParts _allowedParts;
15+
private readonly ExifIfds _allowedIfds;
1616

17-
public ExifWriter(ExifParts allowedParts)
18-
=> _allowedParts = allowedParts;
17+
public ExifWriter(ExifIfds allowedIfds)
18+
=> _allowedIfds = allowedIfds;
1919

2020
public byte[]? Write(Collection<IExifValue> values)
2121
{
22-
var ifdValues = GetPartValues(values, ExifParts.IfdTags);
23-
var exifValues = GetPartValues(values, ExifParts.ExifTags);
24-
var gpsValues = GetPartValues(values, ExifParts.GpsTags);
22+
var ifdValues = GetPartValues(values, ExifIfds.Ifd0);
23+
var exifValues = GetPartValues(values, ExifIfds.Exif);
24+
var gpsValues = GetPartValues(values, ExifIfds.Gps);
2525

2626
RemoveOffsetValues(ifdValues, ExifTag.SubIFDOffset, ExifTag.GPSIFDOffset);
2727

@@ -297,19 +297,19 @@ private static void WriteSignedRational(MemoryStream stream, SignedRational valu
297297
stream.WriteBytes(BitConverter.GetBytes(value.Denominator));
298298
}
299299

300-
private Collection<IExifValue> GetPartValues(Collection<IExifValue> values, ExifParts part)
300+
private Collection<IExifValue> GetPartValues(Collection<IExifValue> values, ExifIfds ifd)
301301
{
302302
var result = new Collection<IExifValue>();
303303

304-
if (!EnumHelper.HasFlag(_allowedParts, part))
304+
if (!EnumHelper.HasFlag(_allowedIfds, ifd))
305305
return result;
306306

307307
foreach (var value in values)
308308
{
309309
if (!HasValue(value))
310310
continue;
311311

312-
if (ExifTags.GetPart(value.Tag) == part)
312+
if (ExifTags.GetIfd(value.Tag) == ifd)
313313
result.Add(value);
314314
}
315315

src/Magick.NET.Core/Profiles/Exif/IExifProfile.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using System.Collections.Generic;
56

67
namespace ImageMagick;
@@ -10,9 +11,15 @@ namespace ImageMagick;
1011
/// </summary>
1112
public interface IExifProfile : IImageProfile
1213
{
14+
/// <summary>
15+
/// Gets or sets which ifds will be written when the profile is added to an image.
16+
/// </summary>
17+
ExifIfds AllowedIfds { get; set; }
18+
1319
/// <summary>
1420
/// Gets or sets which parts will be written when the profile is added to an image.
1521
/// </summary>
22+
[Obsolete($"This property will be removed in the next major release, use {nameof(AllowedIfds)} instead.")]
1623
ExifParts Parts { get; set; }
1724

1825
/// <summary>

tests/Magick.NET.Tests/Profiles/Exif/ExifProfileTests/ThePartsProperty.cs renamed to tests/Magick.NET.Tests/Profiles/Exif/ExifProfileTests/TheAllowedIfdsProperty.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.IO;
5-
using System.Linq;
65
using ImageMagick;
76
using Xunit;
87

98
namespace Magick.NET.Tests;
109

1110
public partial class ExifProfileTests
1211
{
13-
public class ThePartsProperty
12+
public class TheAllowedIfdsProperty
1413
{
1514
[Fact]
1615
public void ShouldFilterTheTagsWhenWritten()
@@ -21,9 +20,9 @@ public void ShouldFilterTheTagsWhenWritten()
2120

2221
Assert.NotNull(profile);
2322

24-
Assert.Equal(44, profile.Values.Count());
23+
Assert.Equal(44, profile.Values.Count);
2524

26-
profile.Parts = ExifParts.ExifTags;
25+
profile.AllowedIfds = ExifIfds.Exif;
2726
input.SetProfile(profile);
2827
input.Write(memStream);
2928

@@ -32,7 +31,7 @@ public void ShouldFilterTheTagsWhenWritten()
3231
profile = output.GetExifProfile();
3332

3433
Assert.NotNull(profile);
35-
Assert.Equal(24, profile.Values.Count());
34+
Assert.Equal(24, profile.Values.Count);
3635
}
3736
}
3837
}

0 commit comments

Comments
 (0)