Browse Source

Apply EXIF part selection when encoding WebP

pull/3187/head
James Jackson-South 4 weeks ago
parent
commit
84613d4839
  1. 2
      src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
  2. 27
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

2
src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs

@ -143,6 +143,8 @@ internal abstract class BitWriterBase
{ {
if (exifProfile != null) if (exifProfile != null)
{ {
// Materialize lazy values so Parts is applied during serialization.
_ = exifProfile.Values;
RiffHelper.WriteChunk(stream, (uint)WebpChunkType.Exif, exifProfile.ToByteArray()); RiffHelper.WriteChunk(stream, (uint)WebpChunkType.Exif, exifProfile.ToByteArray());
} }

27
tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

@ -4,9 +4,11 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Processing.Processors.Quantization;
@ -22,6 +24,31 @@ public class WebpEncoderTests
{ {
private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.NoFilter06); private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.NoFilter06);
[Fact]
public void Encode_LazyExifProfile_AppliesSelectedParts()
{
using Image<Rgba32> input = new(8, 8);
ExifProfile exif = new();
exif.SetValue(ExifTag.Make, "ImageSharp");
exif.SetValue(ExifTag.GPSLatitudeRef, "N");
input.Metadata.ExifProfile = exif;
using MemoryStream jpegStream = new();
input.Save(jpegStream, new JpegEncoder());
jpegStream.Position = 0;
using Image source = Image.Load(jpegStream);
source.Metadata.ExifProfile!.Parts = ExifParts.IfdTags | ExifParts.ExifTags;
using MemoryStream webpStream = new();
source.Save(webpStream, new WebpEncoder());
webpStream.Position = 0;
using Image result = Image.Load(webpStream);
Assert.True(result.Metadata.ExifProfile!.TryGetValue(ExifTag.Make, out _));
Assert.False(result.Metadata.ExifProfile.TryGetValue(ExifTag.GPSLatitudeRef, out _));
}
[Theory] [Theory]
[WithFile(Lossless.Animated, PixelTypes.Rgba32)] [WithFile(Lossless.Animated, PixelTypes.Rgba32)]
public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider) public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider)

Loading…
Cancel
Save