Browse Source

removed ExifIdCode from ExifConstants and ExifProfile, using ExifMarker defined in Jpeg ProfileResolver

af/merge-core
popow 8 years ago
parent
commit
a7208dee7d
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs
  2. 9
      src/ImageSharp/MetaData/Profiles/Exif/ExifConstants.cs
  3. 15
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  4. 20
      src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs

@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
public static readonly byte[] AdobeMarker = Encoding.UTF8.GetBytes("Adobe");
/// <summary>
/// Returns a value indicating whether the passed bytes are a match to the profile identifer
/// Returns a value indicating whether the passed bytes are a match to the profile identifier
/// </summary>
/// <param name="bytesToCheck">The bytes to check</param>
/// <param name="profileIdentifier">The profile identifier</param>

9
src/ImageSharp/MetaData/Profiles/Exif/ExifConstants.cs

@ -5,15 +5,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
{
internal static class ExifConstants
{
public static readonly byte[] ExifIdCode = {
(byte)'E',
(byte)'x',
(byte)'i',
(byte)'f',
0x00,
0x00
};
public static readonly byte[] LittleEndianByteOrderMarker = {
(byte)'I',
(byte)'I',

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

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
@ -15,11 +16,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// </summary>
public sealed class ExifProfile
{
/// <summary>
/// The EXIF ID code: ASCII "Exif" followed by two zeros.
/// </summary>
private static readonly byte[] ExifCode = { 69, 120, 105, 102, 0, 0 };
/// <summary>
/// The byte array to read the EXIF profile from.
/// </summary>
@ -239,7 +235,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// Converts this instance to a byte array.
/// </summary>
/// <param name="includeExifIdCode">Indicates, if the Exif ID code should be included.
/// This Exif ID code should not be included in case of PNG's. Defaults to true.</param>
/// The Exif Id Code is part of the JPEG APP1 segment. This Exif ID code should not be included in case of PNG's.
/// Defaults to true.</param>
/// <returns>The <see cref="T:byte[]"/></returns>
public byte[] ToByteArray(bool includeExifIdCode = true)
{
@ -275,10 +272,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
return false;
}
int exifLength = ExifCode.Length;
for (int i = 0; i < ExifCode.Length; i++)
int exifLength = ProfileResolver.ExifMarker.Length;
for (int i = 0; i < ProfileResolver.ExifMarker.Length; i++)
{
if (exifBytes[i] != ExifCode[i])
if (exifBytes[i] != ProfileResolver.ExifMarker[i])
{
return false;
}

20
src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs

@ -5,6 +5,7 @@ using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Text;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
@ -42,13 +43,14 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// Returns the EXIF data.
/// </summary>
/// <param name="includeExifIdCode">Indicates, if the Exif ID code should be included.
/// This Exif ID code should not be included in case of PNG's. Defaults to true.</param>
/// The Exif Id Code is part of the JPEG APP1 segment. This Exif ID code should not be included in case of PNG's.
/// Defaults to true.</param>
/// <returns>
/// The <see cref="T:byte[]"/>.
/// </returns>
public byte[] GetData(bool includeExifIdCode = true)
{
uint startIndex = 6;
uint startIndex = (uint)ProfileResolver.ExifMarker.Length;
uint length;
int exifIndex = -1;
int gpsIndex = -1;
@ -86,19 +88,19 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
if (includeExifIdCode)
{
// Exif Code (6 bytes) + byte order marker (4 bytes)
length += 10;
// Exif Id Code "Exif00" (6 bytes)
length += (uint)ProfileResolver.ExifMarker.Length;
}
else
{
// special case for PNG eXIf Chunk:
// two bytes for the byte Order marker 'II', followed by the number 42 (0x2A) and a 0, making 4 bytes total
length += 4;
// if the Exif Code ("Exif00") is not included, the start index is 0 instead of 6
startIndex = 0;
}
// two bytes for the byte Order marker 'II', followed by the number 42 (0x2A) and a 0, making 4 bytes total
length += (uint)ExifConstants.LittleEndianByteOrderMarker.Length;
length += 4 + 2;
byte[] result = new byte[length];
@ -106,8 +108,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
int i = 0;
if (includeExifIdCode)
{
ExifConstants.ExifIdCode.AsSpan().CopyTo(result); // 0-5
i += ExifConstants.ExifIdCode.Length;
ProfileResolver.ExifMarker.AsSpan().CopyTo(result); // 0-5
i += ProfileResolver.ExifMarker.Length;
}
// the byte order marker for little-endian, followed by the number 42 and a 0

Loading…
Cancel
Save