Skip to content

Commit 8de08ba

Browse files
fix for duplicates skipping
1 parent d48a6dd commit 8de08ba

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ private void Add(IList<IExifValue> values, ExifValue exif, object? value)
490490

491491
foreach (IExifValue val in values)
492492
{
493-
// Sometimes duplicates appear, can compare val.Tag == exif.Tag
494-
if (val == exif)
493+
// to skip duplicates must be used Equals method,
494+
// == operator not defined for ExifValue and IExifValue
495+
if (exif.Equals(val))
495496
{
496497
Debug.WriteLine($"Duplicate Exif tag: tag={exif.Tag}, dataType={exif.DataType}");
497498
return;

tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using SixLabors.ImageSharp.PixelFormats;
1111
using SixLabors.ImageSharp.Processing;
1212
using SixLabors.ImageSharp.Tests.TestUtilities;
13-
using static SixLabors.ImageSharp.Metadata.Profiles.Exif.EncodedString;
1413

1514
// ReSharper disable InconsistentNaming
1615
namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
@@ -496,17 +495,15 @@ public void Issue2857_SubSubIfds<TPixel>(TestImageProvider<TPixel> provider)
496495
Assert.Equal("Carers; seniors; caregiver; senior care; retirement home; hands; old; elderly; elderly caregiver; elder care; elderly care; geriatric care; nursing home; age; old age care; outpatient; needy; health care; home nurse; home care; sick; retirement; medical; mobile; the elderly; nursing department; nursing treatment; nursing; care services; nursing services; nursing care; nursing allowance; nursing homes; home nursing; care category; nursing class; care; nursing shortage; nursing patient care staff\0", exifProfile.GetValue(ExifTag.XPKeywords).Value);
497496

498497
Assert.Equal(
499-
new EncodedString(CharacterCode.ASCII, "StockSubmitter|Miscellaneous||Miscellaneous$|00|0000330000000110000000000000000|22$@NA_1005010.460@[email protected]$$@$@26$$@$@$@$@205$@$@$@$@$@$@$@$@$@43$@$@$@[email protected]$$@90$$@22$@$@$@$@$@$@$|||"),
498+
new EncodedString(EncodedString.CharacterCode.ASCII, "StockSubmitter|Miscellaneous||Miscellaneous$|00|0000330000000110000000000000000|22$@NA_1005010.460@[email protected]$$@$@26$$@$@$@$@205$@$@$@$@$@$@$@$@$@43$@$@$@[email protected]$$@90$$@22$@$@$@$@$@$@$|||"),
500499
exifProfile.GetValue(ExifTag.UserComment).Value);
501500

501+
// the profile contains 4 duplicated UserComment
502+
Assert.Equal(1, exifProfile.Values.Count(t => t.Tag == ExifTag.UserComment));
503+
502504
image.Mutate(x => x.Crop(new(0, 0, 100, 100)));
503505

504506
image.Save(ms, new JpegEncoder());
505-
506-
foreach (IExifValue val in image.Metadata.ExifProfile.Values)
507-
{
508-
this.Output.WriteLine($"{val.Tag}={val.GetValue()}");
509-
}
510507
}
511508

512509
private static void VerifyEncodedStrings(ExifProfile exif)

0 commit comments

Comments
 (0)