Browse Source

moved extending the ExifProfile to the jpeg decoder

pull/616/head
popow 8 years ago
parent
commit
efd0288f1d
  1. 38
      src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs
  2. 38
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  3. 12
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs

38
src/ImageSharp/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -68,6 +69,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
/// </summary> /// </summary>
private bool isExif; private bool isExif;
/// <summary>
/// Contains exif data
/// </summary>
private byte[] exifData;
/// <summary> /// <summary>
/// Whether the image has an Adobe marker. /// Whether the image has an Adobe marker.
/// It's faster to check this than to use the equality operator on the struct /// 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(); this.InitDerivedMetaDataProperties();
} }
@ -425,6 +432,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
&& mcuCounter < this.TotalMCUCount; && mcuCounter < this.TotalMCUCount;
} }
/// <summary>
/// Initializes the exif profile.
/// </summary>
private void InitExifProfile()
{
if (this.isExif)
{
this.MetaData.ExifProfile = new ExifProfile(this.exifData);
}
}
/// <summary> /// <summary>
/// Assigns derived metadata properties to <see cref="MetaData"/>, eg. horizontal and vertical resolution if it has a JFIF header. /// Assigns derived metadata properties to <see cref="MetaData"/>, eg. horizontal and vertical resolution if it has a JFIF header.
/// </summary> /// </summary>
@ -500,19 +518,31 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker))
{ {
this.isExif = true; 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 // 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 else
{ {
// if the exif information exceeds 64K, it will be split over multiple APP1 marker // if the exif information exceeds 64K, it will be split over multiple APP1 markers
this.MetaData.ExifProfile.Extend(profile.Skip(6).ToArray()); this.ExtendExif(profile.Skip(6).ToArray());
} }
} }
} }
/// <summary>
/// Extends the exif profile with additional data.
/// </summary>
/// <param name="bytes">The array containing addition profile data.</param>
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);
}
/// <summary> /// <summary>
/// Processes the App2 marker retrieving any stored ICC profile information /// Processes the App2 marker retrieving any stored ICC profile information
/// </summary> /// </summary>

38
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -74,6 +74,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// </summary> /// </summary>
private bool isExif; private bool isExif;
/// <summary>
/// Contains exif data
/// </summary>
private byte[] exifData;
/// <summary> /// <summary>
/// Contains information about the JFIF marker /// Contains information about the JFIF marker
/// </summary> /// </summary>
@ -202,6 +207,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
this.ParseStream(stream); this.ParseStream(stream);
this.InitExifProfile();
this.InitDerivedMetaDataProperties(); this.InitDerivedMetaDataProperties();
return this.PostProcessIntoImage<TPixel>(); return this.PostProcessIntoImage<TPixel>();
} }
@ -213,6 +219,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
public IImageInfo Identify(Stream stream) public IImageInfo Identify(Stream stream)
{ {
this.ParseStream(stream, true); this.ParseStream(stream, true);
this.InitExifProfile();
this.InitDerivedMetaDataProperties(); this.InitDerivedMetaDataProperties();
return new ImageInfo(new PixelTypeInfo(this.BitsPerPixel), this.ImageWidth, this.ImageHeight, this.MetaData); 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}"); throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");
} }
/// <summary>
/// Initializes the exif profile.
/// </summary>
private void InitExifProfile()
{
if (this.isExif)
{
this.MetaData.ExifProfile = new ExifProfile(this.exifData);
}
}
/// <summary> /// <summary>
/// Assigns derived metadata properties to <see cref="MetaData"/>, eg. horizontal and vertical resolution if it has a JFIF header. /// Assigns derived metadata properties to <see cref="MetaData"/>, eg. horizontal and vertical resolution if it has a JFIF header.
/// </summary> /// </summary>
@ -481,19 +499,31 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker))
{ {
this.isExif = true; 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 // 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 else
{ {
// if the exif information exceeds 64K, it will be split over multiple APP1 marker // if the exif information exceeds 64K, it will be split over multiple APP1 markers
this.MetaData.ExifProfile.Extend(profile.Skip(6).ToArray()); this.ExtendExif(profile.Skip(6).ToArray());
} }
} }
} }
/// <summary>
/// Extends the exif profile with additional data.
/// </summary>
/// <param name="bytes">The array containing addition profile data.</param>
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);
}
/// <summary> /// <summary>
/// Processes the App2 marker retrieving any stored ICC profile information /// Processes the App2 marker retrieving any stored ICC profile information
/// </summary> /// </summary>

12
src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs

@ -229,18 +229,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
this.values.Add(newExifValue); this.values.Add(newExifValue);
} }
/// <summary>
/// Extends the profile with additional data.
/// </summary>
/// <param name="bytes">The array containing addition profile data.</param>
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);
}
/// <summary> /// <summary>
/// Converts this instance to a byte array. /// Converts this instance to a byte array.
/// </summary> /// </summary>

Loading…
Cancel
Save