Browse Source

Use Unsafe.As<>

pull/639/head
Jason Nelson 8 years ago
parent
commit
5554aa3198
  1. 9
      src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs
  2. 9
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs

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

@ -6,6 +6,7 @@ using System.Buffers.Binary;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using SixLabors.ImageSharp.IO;
@ -462,7 +463,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
}
}
private unsafe double ConvertToDouble(ReadOnlySpan<byte> buffer)
private double ConvertToDouble(ReadOnlySpan<byte> buffer)
{
if (buffer.Length < 8)
{
@ -473,7 +474,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
? BinaryPrimitives.ReadInt64BigEndian(buffer)
: BinaryPrimitives.ReadInt64LittleEndian(buffer);
return *((double*)&intValue);
return Unsafe.As<long, double>(ref intValue);
}
private uint ConvertToUInt32(ReadOnlySpan<byte> buffer)
@ -501,7 +502,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
: BinaryPrimitives.ReadUInt16LittleEndian(buffer);
}
private unsafe float ConvertToSingle(ReadOnlySpan<byte> buffer)
private float ConvertToSingle(ReadOnlySpan<byte> buffer)
{
if (buffer.Length < 4)
{
@ -512,7 +513,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
? BinaryPrimitives.ReadInt32BigEndian(buffer)
: BinaryPrimitives.ReadInt32LittleEndian(buffer);
return *((float*)&intValue);
return Unsafe.As<int, float>(ref intValue);
}
private Rational ToRational(ReadOnlySpan<byte> buffer)

9
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs

@ -3,6 +3,7 @@
using System;
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
using System.Text;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
@ -70,22 +71,22 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// Reads a float.
/// </summary>
/// <returns>the value</returns>
public unsafe float ReadSingle()
public float ReadSingle()
{
int intValue = this.ReadInt32();
return *((float*)&intValue);
return Unsafe.As<int, float>(ref intValue);
}
/// <summary>
/// Reads a double
/// </summary>
/// <returns>the value</returns>
public unsafe double ReadDouble()
public double ReadDouble()
{
long intValue = this.ReadInt64();
return *((double*)&intValue);
return Unsafe.As<long, double>(ref intValue);
}
/// <summary>

Loading…
Cancel
Save