Browse Source

fix for duplicates skipping

pull/2869/head
Ildar Khayrutdinov 1 year ago
parent
commit
8de08ba72a
  1. 5
      src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs
  2. 11
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

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

@ -490,8 +490,9 @@ internal abstract class BaseExifReader
foreach (IExifValue val in values)
{
// Sometimes duplicates appear, can compare val.Tag == exif.Tag
if (val == exif)
// to skip duplicates must be used Equals method,
// == operator not defined for ExifValue and IExifValue
if (exif.Equals(val))
{
Debug.WriteLine($"Duplicate Exif tag: tag={exif.Tag}, dataType={exif.DataType}");
return;

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

@ -10,7 +10,6 @@ using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities;
using static SixLabors.ImageSharp.Metadata.Profiles.Exif.EncodedString;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg;
@ -496,17 +495,15 @@ public partial class JpegDecoderTests
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);
Assert.Equal(
new EncodedString(CharacterCode.ASCII, "StockSubmitter|Miscellaneous||Miscellaneous$|00|0000330000000110000000000000000|22$@NA_1005010.460@145$$@Miscellaneous.Miscellaneous$$@$@26$$@$@$@$@205$@$@$@$@$@$@$@$@$@43$@$@$@$$@Miscellaneous.Miscellaneous$$@90$$@22$@$@$@$@$@$@$|||"),
new EncodedString(EncodedString.CharacterCode.ASCII, "StockSubmitter|Miscellaneous||Miscellaneous$|00|0000330000000110000000000000000|22$@NA_1005010.460@145$$@Miscellaneous.Miscellaneous$$@$@26$$@$@$@$@205$@$@$@$@$@$@$@$@$@43$@$@$@$$@Miscellaneous.Miscellaneous$$@90$$@22$@$@$@$@$@$@$|||"),
exifProfile.GetValue(ExifTag.UserComment).Value);
// the profile contains 4 duplicated UserComment
Assert.Equal(1, exifProfile.Values.Count(t => t.Tag == ExifTag.UserComment));
image.Mutate(x => x.Crop(new(0, 0, 100, 100)));
image.Save(ms, new JpegEncoder());
foreach (IExifValue val in image.Metadata.ExifProfile.Values)
{
this.Output.WriteLine($"{val.Tag}={val.GetValue()}");
}
}
private static void VerifyEncodedStrings(ExifProfile exif)

Loading…
Cancel
Save