diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
index 6a4042ba0..f2cd24411 100644
--- a/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -68,6 +69,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
///
private bool isExif;
+ ///
+ /// Contains exif data
+ ///
+ private byte[] exifData;
+
///
/// Whether the image has an Adobe marker.
/// It's faster to check this than to use the equality operator on the struct
@@ -413,6 +419,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
}
}
+ this.InitExifProfile();
this.InitDerivedMetaDataProperties();
}
@@ -425,6 +432,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
&& mcuCounter < this.TotalMCUCount;
}
+ ///
+ /// Initializes the exif profile.
+ ///
+ private void InitExifProfile()
+ {
+ if (this.isExif)
+ {
+ this.MetaData.ExifProfile = new ExifProfile(this.exifData);
+ }
+ }
+
///
/// Assigns derived metadata properties to , eg. horizontal and vertical resolution if it has a JFIF header.
///
@@ -500,19 +518,31 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker))
{
this.isExif = true;
- if (this.MetaData.ExifProfile == null)
+ if (this.exifData == null)
{
// the first 6 bytes (Exif00) will be skipped, because this is Jpeg specific
- this.MetaData.ExifProfile = new ExifProfile(profile.Skip(6).ToArray());
+ this.exifData = profile.Skip(6).ToArray();
}
else
{
- // if the exif information exceeds 64K, it will be split over multiple APP1 marker
- this.MetaData.ExifProfile.Extend(profile.Skip(6).ToArray());
+ // if the exif information exceeds 64K, it will be split over multiple APP1 markers
+ this.ExtendExif(profile.Skip(6).ToArray());
}
}
}
+ ///
+ /// Extends the exif profile with additional data.
+ ///
+ /// The array containing addition profile data.
+ private void ExtendExif(byte[] bytes)
+ {
+ int currentLength = this.exifData.Length;
+
+ Array.Resize(ref this.exifData, currentLength + bytes.Length);
+ Buffer.BlockCopy(bytes, 0, this.exifData, currentLength, bytes.Length);
+ }
+
///
/// Processes the App2 marker retrieving any stored ICC profile information
///
diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
index d539cf37c..c143812c6 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
@@ -74,6 +74,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
///
private bool isExif;
+ ///
+ /// Contains exif data
+ ///
+ private byte[] exifData;
+
///
/// Contains information about the JFIF marker
///
@@ -202,6 +207,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
where TPixel : struct, IPixel
{
this.ParseStream(stream);
+ this.InitExifProfile();
this.InitDerivedMetaDataProperties();
return this.PostProcessIntoImage();
}
@@ -213,6 +219,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
public IImageInfo Identify(Stream stream)
{
this.ParseStream(stream, true);
+ this.InitExifProfile();
this.InitDerivedMetaDataProperties();
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData);
}
@@ -404,6 +411,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");
}
+ ///
+ /// Initializes the exif profile.
+ ///
+ private void InitExifProfile()
+ {
+ if (this.isExif)
+ {
+ this.MetaData.ExifProfile = new ExifProfile(this.exifData);
+ }
+ }
+
///
/// Assigns derived metadata properties to , eg. horizontal and vertical resolution if it has a JFIF header.
///
@@ -481,19 +499,31 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker))
{
this.isExif = true;
- if (this.MetaData.ExifProfile == null)
+ if (this.exifData == null)
{
// the first 6 bytes (Exif00) will be skipped, because this is Jpeg specific
- this.MetaData.ExifProfile = new ExifProfile(profile.Skip(6).ToArray());
+ this.exifData = profile.Skip(6).ToArray();
}
else
{
- // if the exif information exceeds 64K, it will be split over multiple APP1 marker
- this.MetaData.ExifProfile.Extend(profile.Skip(6).ToArray());
+ // if the exif information exceeds 64K, it will be split over multiple APP1 markers
+ this.ExtendExif(profile.Skip(6).ToArray());
}
}
}
+ ///
+ /// Extends the exif profile with additional data.
+ ///
+ /// The array containing addition profile data.
+ private void ExtendExif(byte[] bytes)
+ {
+ int currentLength = this.exifData.Length;
+
+ Array.Resize(ref this.exifData, currentLength + bytes.Length);
+ Buffer.BlockCopy(bytes, 0, this.exifData, currentLength, bytes.Length);
+ }
+
///
/// Processes the App2 marker retrieving any stored ICC profile information
///
diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
index 5ab6c59ac..6f5af8ffc 100644
--- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
+++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
@@ -229,18 +229,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
this.values.Add(newExifValue);
}
- ///
- /// Extends the profile with additional data.
- ///
- /// The array containing addition profile data.
- public void Extend(byte[] bytes)
- {
- int currentLength = this.data.Length;
-
- Array.Resize(ref this.data, currentLength + bytes.Length);
- Buffer.BlockCopy(bytes, 0, this.data, currentLength, bytes.Length);
- }
-
///
/// Converts this instance to a byte array.
///