Skip to content

Commit

Permalink
Changed ExifProfile property to methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 24, 2024
1 parent 3dea21a commit d371cb0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 63 deletions.
68 changes: 35 additions & 33 deletions src/Magick.NET.Core/Profiles/8Bim/EightBimProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,52 +87,31 @@ public IReadOnlyCollection<IClipPath> ClipPaths
}

/// <summary>
/// Gets or sets the exif profile inside the 8bim profile.
/// Gets the values of this 8bim profile.
/// </summary>
public IExifProfile? ExifProfile
public IReadOnlyCollection<IEightBimValue> Values
{
get
{
Initialize();

var value = FindValue(ExifProfileId);
if (value is null)
return null;

return new ExifProfile(value.ToByteArray());
}

set
{
Initialize();

var currentValue = FindValue(ExifProfileId);

if (currentValue is not null)
_values.Remove(currentValue);

SetData(null);

if (value is null)
return;

var data = value.ToByteArray();
if (data is not null)
_values.Add(new EightBimValue(ExifProfileId, null, data));
return _values;
}
}

/// <summary>
/// Gets the values of this 8bim profile.
/// Gets the exif profile inside the 8bim profile.
/// </summary>
public IReadOnlyCollection<IEightBimValue> Values
/// <returns>The exif profile.</returns>
public IExifProfile? GetExifProfile()
{
get
{
Initialize();
Initialize();

return _values;
}
var value = FindValue(ExifProfileId);
if (value is null)
return null;

return new ExifProfile(value.ToByteArray());
}

/// <summary>
Expand Down Expand Up @@ -165,6 +144,29 @@ public IReadOnlyCollection<IEightBimValue> Values
return new XmpProfile(value.ToByteArray());
}

/// <summary>
/// Sets the exif profile inside the 8bim profile.
/// </summary>
/// <param name="profile">The exif profile.</param>
public void SetExifProfile(IExifProfile? profile)
{
Initialize();

var currentValue = FindValue(ExifProfileId);

if (currentValue is not null)
_values.Remove(currentValue);

SetData(null);

if (profile is null)
return;

var data = profile.ToByteArray();
if (data is not null)
_values.Add(new EightBimValue(ExifProfileId, null, data));
}

/// <summary>
/// Sets the iptc profile inside the 8bim profile.
/// </summary>
Expand Down
15 changes: 11 additions & 4 deletions src/Magick.NET.Core/Profiles/8Bim/IEightBimProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ public interface IEightBimProfile : IImageProfile
IReadOnlyCollection<IClipPath> ClipPaths { get; }

/// <summary>
/// Gets or sets the exif profile inside the 8bim profile.
/// Gets the values of this 8bim profile.
/// </summary>
IExifProfile? ExifProfile { get; set; }
IReadOnlyCollection<IEightBimValue> Values { get; }

/// <summary>
/// Gets the values of this 8bim profile.
/// Gets the exif profile inside the 8bim profile.
/// </summary>
IReadOnlyCollection<IEightBimValue> Values { get; }
/// <returns>The exif profile.</returns>
IExifProfile? GetExifProfile();

/// <summary>
/// Gets the iptc profile inside the 8bim profile.
Expand All @@ -37,6 +38,12 @@ public interface IEightBimProfile : IImageProfile
/// <returns>The xmp profile.</returns>
IXmpProfile? GetXmpProfile();

/// <summary>
/// Sets the exif profile inside the 8bim profile.
/// </summary>
/// <param name="profile">The exif profile.</param>
void SetExifProfile(IExifProfile? profile);

/// <summary>
/// Sets the iptc profile inside the 8bim profile.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using ImageMagick;
using Xunit;

namespace Magick.NET.Tests;

public partial class EightBimProfileTests
{
public class TheGetExifProfileMethod
{
[Fact]
public void ShouldReturnNullWhenProfileHasNoIptcProfile()
{
using var image = new MagickImage(Files.EightBimTIF);

var profile = image.Get8BimProfile()!;

Assert.Null(profile.GetExifProfile());
}

[Fact]
public void ShouldReturnValueWhenProfileHasIptcProfile()
{
using var image = new MagickImage(Files.EightBimJPG);

var profile = image.Get8BimProfile();
var exifProfile = profile.GetExifProfile();

Assert.NotNull(exifProfile);
Assert.Equal(446, exifProfile.GetData().Length);
Assert.Empty(exifProfile.Values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,8 @@ namespace Magick.NET.Tests;

public partial class EightBimProfileTests
{
public class TheExifProfileProperty
public class TheSetExifProfileMethod
{
[Fact]
public void ShouldReturnNullWhenProfileHasNoIptcProfile()
{
using var image = new MagickImage(Files.EightBimTIF);

var profile = image.Get8BimProfile()!;

Assert.Null(profile.ExifProfile);
}

[Fact]
public void ShouldReturnValueWhenProfileHasIptcProfile()
{
using var image = new MagickImage(Files.EightBimJPG);

var profile = image.Get8BimProfile();

Assert.NotNull(profile.ExifProfile);
Assert.Equal(446, profile.ExifProfile.GetData().Length);
Assert.Empty(profile.ExifProfile.Values);
}

[Fact]
public void ShouldRemoveProfileWhenSetToNull()
{
Expand All @@ -42,7 +20,7 @@ public void ShouldRemoveProfileWhenSetToNull()
image.RemoveProfile(exifProfile);

var profile = image.Get8BimProfile();
profile.ExifProfile = null;
profile.SetExifProfile(null);

image.SetProfile(profile);

Expand All @@ -65,7 +43,7 @@ public void ShouldAddTheProfile()

IExifProfile exifProfile = new ExifProfile();
exifProfile.SetValue(ExifTag.Copyright, "Magick.NET");
profile.ExifProfile = exifProfile;
profile.SetExifProfile(exifProfile);

image.SetProfile(profile);

Expand All @@ -78,7 +56,7 @@ public void ShouldAddTheProfile()
profile = image.Get8BimProfile();
exifProfile = image.GetExifProfile();

Assert.NotNull(profile.ExifProfile);
Assert.NotNull(profile.GetExifProfile());
Assert.NotNull(exifProfile);
Assert.Single(exifProfile.Values);
}
Expand Down

0 comments on commit d371cb0

Please sign in to comment.