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"); public static readonly byte[] AdobeMarker = Encoding.UTF8.GetBytes("Adobe");
/// <summary> /// <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> /// </summary>
/// <param name="bytesToCheck">The bytes to check</param> /// <param name="bytesToCheck">The bytes to check</param>
/// <param name="profileIdentifier">The profile identifier</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 internal static class ExifConstants
{ {
public static readonly byte[] ExifIdCode = {
(byte)'E',
(byte)'x',
(byte)'i',
(byte)'f',
0x00,
0x00
};
public static readonly byte[] LittleEndianByteOrderMarker = { public static readonly byte[] LittleEndianByteOrderMarker = {
(byte)'I', (byte)'I',
(byte)'I', (byte)'I',

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

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
@ -15,11 +16,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// </summary> /// </summary>
public sealed class ExifProfile 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> /// <summary>
/// The byte array to read the EXIF profile from. /// The byte array to read the EXIF profile from.
/// </summary> /// </summary>
@ -239,7 +235,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// Converts this instance to a byte array. /// Converts this instance to a byte array.
/// </summary> /// </summary>
/// <param name="includeExifIdCode">Indicates, if the Exif ID code should be included. /// <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> /// <returns>The <see cref="T:byte[]"/></returns>
public byte[] ToByteArray(bool includeExifIdCode = true) public byte[] ToByteArray(bool includeExifIdCode = true)
{ {
@ -275,10 +272,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
return false; return false;
} }
int exifLength = ExifCode.Length; int exifLength = ProfileResolver.ExifMarker.Length;
for (int i = 0; i < ExifCode.Length; i++) for (int i = 0; i < ProfileResolver.ExifMarker.Length; i++)
{ {
if (exifBytes[i] != ExifCode[i]) if (exifBytes[i] != ProfileResolver.ExifMarker[i])
{ {
return false; return false;
} }

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

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

Loading…
Cancel
Save