|
7 | 7 | using SixLabors.ImageSharp.Formats.Tiff.Constants;
|
8 | 8 | using SixLabors.ImageSharp.Metadata;
|
9 | 9 | using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
| 10 | +using SixLabors.ImageSharp.Metadata.Profiles.Icc; |
10 | 11 | using SixLabors.ImageSharp.Metadata.Profiles.Iptc;
|
11 | 12 | using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
|
12 | 13 | using SixLabors.ImageSharp.PixelFormats;
|
@@ -318,4 +319,94 @@ public void Encode_PreservesMetadata<TPixel>(TestImageProvider<TPixel> provider)
|
318 | 319 | Assert.Equal((ushort)TiffPlanarConfiguration.Chunky, encodedImageExifProfile.GetValue(ExifTag.PlanarConfiguration)?.Value);
|
319 | 320 | Assert.Equal(exifProfileInput.Values.Count, encodedImageExifProfile.Values.Count);
|
320 | 321 | }
|
| 322 | + |
| 323 | + [Theory] |
| 324 | + [WithFile(SampleMetadata, PixelTypes.Rgba32)] |
| 325 | + public void Encode_PreservesMetadata_IptcAndIcc<TPixel>(TestImageProvider<TPixel> provider) |
| 326 | + where TPixel : unmanaged, IPixel<TPixel> |
| 327 | + { |
| 328 | + // Load Tiff image |
| 329 | + DecoderOptions options = new() { SkipMetadata = false }; |
| 330 | + using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance, options); |
| 331 | + |
| 332 | + ImageMetadata inputMetaData = image.Metadata; |
| 333 | + ImageFrame<TPixel> rootFrameInput = image.Frames.RootFrame; |
| 334 | + |
| 335 | + IptcProfile iptcProfile = new(); |
| 336 | + iptcProfile.SetValue(IptcTag.Name, "Test name"); |
| 337 | + rootFrameInput.Metadata.IptcProfile = iptcProfile; |
| 338 | + |
| 339 | + IccProfileHeader iccProfileHeader = new() { Class = IccProfileClass.ColorSpace }; |
| 340 | + IccProfile iccProfile = new(); |
| 341 | + rootFrameInput.Metadata.IccProfile = iccProfile; |
| 342 | + |
| 343 | + TiffFrameMetadata frameMetaInput = rootFrameInput.Metadata.GetTiffMetadata(); |
| 344 | + XmpProfile xmpProfileInput = rootFrameInput.Metadata.XmpProfile; |
| 345 | + ExifProfile exifProfileInput = rootFrameInput.Metadata.ExifProfile; |
| 346 | + IptcProfile iptcProfileInput = rootFrameInput.Metadata.IptcProfile; |
| 347 | + IccProfile iccProfileInput = rootFrameInput.Metadata.IccProfile; |
| 348 | + |
| 349 | + Assert.Equal(TiffCompression.Lzw, frameMetaInput.Compression); |
| 350 | + Assert.Equal(TiffBitsPerPixel.Bit4, frameMetaInput.BitsPerPixel); |
| 351 | + |
| 352 | + // Save to Tiff |
| 353 | + TiffEncoder tiffEncoder = new() { PhotometricInterpretation = TiffPhotometricInterpretation.Rgb }; |
| 354 | + using MemoryStream ms = new(); |
| 355 | + image.Save(ms, tiffEncoder); |
| 356 | + |
| 357 | + // Assert |
| 358 | + ms.Position = 0; |
| 359 | + using Image<Rgba32> encodedImage = Image.Load<Rgba32>(ms); |
| 360 | + |
| 361 | + ImageMetadata encodedImageMetaData = encodedImage.Metadata; |
| 362 | + ImageFrame<Rgba32> rootFrameEncodedImage = encodedImage.Frames.RootFrame; |
| 363 | + TiffFrameMetadata tiffMetaDataEncodedRootFrame = rootFrameEncodedImage.Metadata.GetTiffMetadata(); |
| 364 | + ExifProfile encodedImageExifProfile = rootFrameEncodedImage.Metadata.ExifProfile; |
| 365 | + XmpProfile encodedImageXmpProfile = rootFrameEncodedImage.Metadata.XmpProfile; |
| 366 | + IptcProfile encodedImageIptcProfile = rootFrameEncodedImage.Metadata.IptcProfile; |
| 367 | + IccProfile encodedImageIccProfile = rootFrameEncodedImage.Metadata.IccProfile; |
| 368 | + |
| 369 | + Assert.Equal(TiffBitsPerPixel.Bit4, tiffMetaDataEncodedRootFrame.BitsPerPixel); |
| 370 | + Assert.Equal(TiffCompression.Lzw, tiffMetaDataEncodedRootFrame.Compression); |
| 371 | + |
| 372 | + Assert.Equal(inputMetaData.HorizontalResolution, encodedImageMetaData.HorizontalResolution); |
| 373 | + Assert.Equal(inputMetaData.VerticalResolution, encodedImageMetaData.VerticalResolution); |
| 374 | + Assert.Equal(inputMetaData.ResolutionUnits, encodedImageMetaData.ResolutionUnits); |
| 375 | + |
| 376 | + Assert.Equal(rootFrameInput.Width, rootFrameEncodedImage.Width); |
| 377 | + Assert.Equal(rootFrameInput.Height, rootFrameEncodedImage.Height); |
| 378 | + |
| 379 | + PixelResolutionUnit resolutionUnitInput = UnitConverter.ExifProfileToResolutionUnit(exifProfileInput); |
| 380 | + PixelResolutionUnit resolutionUnitEncoded = UnitConverter.ExifProfileToResolutionUnit(encodedImageExifProfile); |
| 381 | + Assert.Equal(resolutionUnitInput, resolutionUnitEncoded); |
| 382 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.XResolution).Value.ToDouble(), encodedImageExifProfile.GetValue(ExifTag.XResolution).Value.ToDouble()); |
| 383 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.YResolution).Value.ToDouble(), encodedImageExifProfile.GetValue(ExifTag.YResolution).Value.ToDouble()); |
| 384 | + |
| 385 | + Assert.NotNull(xmpProfileInput); |
| 386 | + Assert.NotNull(encodedImageXmpProfile); |
| 387 | + Assert.Equal(xmpProfileInput.Data, encodedImageXmpProfile.Data); |
| 388 | + |
| 389 | + Assert.NotNull(iptcProfileInput); |
| 390 | + Assert.NotNull(encodedImageIptcProfile); |
| 391 | + Assert.Equal(iptcProfileInput.Data, encodedImageIptcProfile.Data); |
| 392 | + Assert.Equal(iptcProfileInput.GetValues(IptcTag.Name)[0].Value, encodedImageIptcProfile.GetValues(IptcTag.Name)[0].Value); |
| 393 | + |
| 394 | + Assert.NotNull(iccProfileInput); |
| 395 | + Assert.NotNull(encodedImageIccProfile); |
| 396 | + Assert.Equal(iccProfileInput.Entries.Length, encodedImageIccProfile.Entries.Length); |
| 397 | + Assert.Equal(iccProfileInput.Header.Class, encodedImageIccProfile.Header.Class); |
| 398 | + |
| 399 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Software).Value, encodedImageExifProfile.GetValue(ExifTag.Software).Value); |
| 400 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.ImageDescription).Value, encodedImageExifProfile.GetValue(ExifTag.ImageDescription).Value); |
| 401 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Make).Value, encodedImageExifProfile.GetValue(ExifTag.Make).Value); |
| 402 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Copyright).Value, encodedImageExifProfile.GetValue(ExifTag.Copyright).Value); |
| 403 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Artist).Value, encodedImageExifProfile.GetValue(ExifTag.Artist).Value); |
| 404 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Orientation).Value, encodedImageExifProfile.GetValue(ExifTag.Orientation).Value); |
| 405 | + Assert.Equal(exifProfileInput.GetValue(ExifTag.Model).Value, encodedImageExifProfile.GetValue(ExifTag.Model).Value); |
| 406 | + |
| 407 | + Assert.Equal((ushort)TiffPlanarConfiguration.Chunky, encodedImageExifProfile.GetValue(ExifTag.PlanarConfiguration)?.Value); |
| 408 | + |
| 409 | + // Adding the IPTC and ICC profiles dynamically increments the number of values in the original EXIF profile by 2 |
| 410 | + Assert.Equal(exifProfileInput.Values.Count + 2, encodedImageExifProfile.Values.Count); |
| 411 | + } |
321 | 412 | }
|
0 commit comments