mirror of https://github.com/SixLabors/ImageSharp
216 changed files with 3449 additions and 5271 deletions
@ -0,0 +1,67 @@ |
|||
param( |
|||
[string]$targetFramework, |
|||
[string]$is32Bit = "False" |
|||
) |
|||
|
|||
if (!$targetFramework){ |
|||
Write-Host "run-tests.ps1 ERROR: targetFramework is undefined!" |
|||
exit 1 |
|||
} |
|||
|
|||
function VerifyPath($path, $errorMessage) { |
|||
if (!(Test-Path -Path $path)) { |
|||
Write-Host "run-tests.ps1 $errorMessage `n $xunitRunnerPath" |
|||
exit 1 |
|||
} |
|||
} |
|||
|
|||
if ( ($targetFramework -eq "netcoreapp2.0") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) { |
|||
# We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.0 + 64bit ) |
|||
$testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd" |
|||
} |
|||
elseif ($targetFramework -eq "mono") { |
|||
$testDllPath = "$PSScriptRoot\tests\ImageSharp.Tests\bin\Release\net462\SixLabors.ImageSharp.Tests.dll" |
|||
VerifyPath($testDllPath, "test dll missing:") |
|||
|
|||
$xunitRunnerPath = "${env:HOMEPATH}\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\" |
|||
|
|||
VerifyPath($xunitRunnerPath, "xunit console runner is missing on path:") |
|||
|
|||
cd "$xunitRunnerPath" |
|||
|
|||
if ($is32Bit -ne "True") { |
|||
$monoPath = "${env:PROGRAMFILES}\Mono\bin\mono.exe" |
|||
} |
|||
else { |
|||
$monoPath = "${env:ProgramFiles(x86)}\Mono\bin\mono.exe" |
|||
} |
|||
|
|||
VerifyPath($monoPath, "mono runtime missing:") |
|||
|
|||
$testRunnerCmd = "& `"${monoPath}`" .\xunit.console.exe `"${testDllPath}`"" |
|||
} |
|||
else { |
|||
cd .\tests\ImageSharp.Tests |
|||
$xunitArgs = "-nobuild -c Release -framework $targetFramework" |
|||
|
|||
if ($targetFramework -eq "netcoreapp2.0") { |
|||
# There were issues matching the correct installed runtime if we do not specify it explicitly: |
|||
$xunitArgs += " --fx-version 2.0.0" |
|||
} |
|||
|
|||
if ($is32Bit -eq "True") { |
|||
$xunitArgs += " -x86" |
|||
} |
|||
|
|||
$testRunnerCmd = "dotnet xunit $xunitArgs" |
|||
} |
|||
|
|||
Write-Host "running:" |
|||
Write-Host $testRunnerCmd |
|||
Write-Host "..." |
|||
|
|||
Invoke-Expression $testRunnerCmd |
|||
|
|||
cd $PSScriptRoot |
|||
|
|||
exit $LASTEXITCODE |
|||
@ -1,84 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Implementation of EndianBitConverter which converts to/from big-endian byte arrays.
|
|||
/// </summary>
|
|||
internal sealed class BigEndianBitConverter : EndianBitConverter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Endianness Endianness |
|||
{ |
|||
get { return Endianness.BigEndian; } |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool IsLittleEndian |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(short value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 2); |
|||
|
|||
buffer[index] = (byte)(value >> 8); |
|||
buffer[index + 1] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(int value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 4); |
|||
|
|||
buffer[index] = (byte)(value >> 24); |
|||
buffer[index + 1] = (byte)(value >> 16); |
|||
buffer[index + 2] = (byte)(value >> 8); |
|||
buffer[index + 3] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(long value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 8); |
|||
|
|||
buffer[index] = (byte)(value >> 56); |
|||
buffer[index + 1] = (byte)(value >> 48); |
|||
buffer[index + 2] = (byte)(value >> 40); |
|||
buffer[index + 3] = (byte)(value >> 32); |
|||
buffer[index + 4] = (byte)(value >> 24); |
|||
buffer[index + 5] = (byte)(value >> 16); |
|||
buffer[index + 6] = (byte)(value >> 8); |
|||
buffer[index + 7] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override short ToInt16(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 2); |
|||
|
|||
return (short)((value[startIndex] << 8) | value[startIndex + 1]); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int ToInt32(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 4); |
|||
|
|||
return (value[startIndex] << 24) | (value[startIndex + 1] << 16) | (value[startIndex + 2] << 8) | value[startIndex + 3]; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override long ToInt64(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 8); |
|||
|
|||
long p1 = (value[startIndex] << 24) | (value[startIndex + 1] << 16) | (value[startIndex + 2] << 8) | value[startIndex + 3]; |
|||
long p2 = (value[startIndex + 4] << 24) | (value[startIndex + 5] << 16) | (value[startIndex + 6] << 8) | value[startIndex + 7]; |
|||
return (p2 & 0xFFFFFFFF) | (p1 << 32); |
|||
} |
|||
} |
|||
} |
|||
@ -1,61 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Equivalent of <see cref="BitConverter"/>, but with either endianness.
|
|||
/// </summary>
|
|||
internal abstract partial class EndianBitConverter |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the specified double-precision floating point number to a
|
|||
/// 64-bit signed integer. Note: the endianness of this converter does not
|
|||
/// affect the returned value.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert. </param>
|
|||
/// <returns>A 64-bit signed integer whose value is equivalent to value.</returns>
|
|||
public unsafe long DoubleToInt64Bits(double value) |
|||
{ |
|||
return *((long*)&value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts the specified 64-bit signed integer to a double-precision
|
|||
/// floating point number. Note: the endianness of this converter does not
|
|||
/// affect the returned value.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert. </param>
|
|||
/// <returns>A double-precision floating point number whose value is equivalent to value.</returns>
|
|||
public unsafe double Int64BitsToDouble(long value) |
|||
{ |
|||
return *((double*)&value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts the specified single-precision floating point number to a
|
|||
/// 32-bit signed integer. Note: the endianness of this converter does not
|
|||
/// affect the returned value.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert. </param>
|
|||
/// <returns>A 32-bit signed integer whose value is equivalent to value.</returns>
|
|||
public unsafe int SingleToInt32Bits(float value) |
|||
{ |
|||
return *((int*)&value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts the specified 32-bit signed integer to a single-precision floating point
|
|||
/// number. Note: the endianness of this converter does not
|
|||
/// affect the returned value.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert. </param>
|
|||
/// <returns>A single-precision floating point number whose value is equivalent to value.</returns>
|
|||
public unsafe float Int32BitsToSingle(int value) |
|||
{ |
|||
return *((float*)&value); |
|||
} |
|||
} |
|||
} |
|||
@ -1,143 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Equivalent of <see cref="BitConverter"/>, but with either endianness.
|
|||
/// </summary>
|
|||
internal abstract partial class EndianBitConverter |
|||
{ |
|||
/// <summary>
|
|||
/// Copies the specified 16-bit signed integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public abstract void CopyBytes(short value, byte[] buffer, int index); |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified 32-bit signed integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public abstract void CopyBytes(int value, byte[] buffer, int index); |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified 64-bit signed integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public abstract void CopyBytes(long value, byte[] buffer, int index); |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified 16-bit unsigned integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public void CopyBytes(ushort value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(unchecked((short)value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified 32-bit unsigned integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public void CopyBytes(uint value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(unchecked((int)value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified 64-bit unsigned integer value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public void CopyBytes(ulong value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(unchecked((long)value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified Boolean value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">A Boolean value.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public void CopyBytes(bool value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 1); |
|||
buffer[index] = value ? (byte)1 : (byte)0; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified Unicode character value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">A character to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public void CopyBytes(char value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(unchecked((short)value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified double-precision floating point value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public unsafe void CopyBytes(double value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(*((long*)&value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified single-precision floating point value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public unsafe void CopyBytes(float value, byte[] buffer, int index) |
|||
{ |
|||
this.CopyBytes(*((int*)&value), buffer, index); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the specified decimal value into the specified byte array,
|
|||
/// beginning at the specified index.
|
|||
/// </summary>
|
|||
/// <param name="value">A character to convert.</param>
|
|||
/// <param name="buffer">The byte array to copy the bytes into</param>
|
|||
/// <param name="index">The first index into the array to copy the bytes into</param>
|
|||
public unsafe void CopyBytes(decimal value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 16); |
|||
|
|||
int* pvalue = (int*)&value; |
|||
this.CopyBytes(pvalue[0], buffer, index); |
|||
this.CopyBytes(pvalue[1], buffer, index + 4); |
|||
this.CopyBytes(pvalue[2], buffer, index + 8); |
|||
this.CopyBytes(pvalue[3], buffer, index + 12); |
|||
} |
|||
} |
|||
} |
|||
@ -1,137 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Equivalent of <see cref="BitConverter"/>, but with either endianness.
|
|||
/// </summary>
|
|||
internal abstract partial class EndianBitConverter |
|||
{ |
|||
/// <summary>
|
|||
/// Returns the specified 16-bit signed integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 2.</returns>
|
|||
public byte[] GetBytes(short value) |
|||
{ |
|||
byte[] result = new byte[2]; |
|||
this.CopyBytes(value, result, 0); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified 32-bit signed integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 4.</returns>
|
|||
public byte[] GetBytes(int value) |
|||
{ |
|||
byte[] result = new byte[4]; |
|||
this.CopyBytes(value, result, 0); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified 64-bit signed integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 8.</returns>
|
|||
public byte[] GetBytes(long value) |
|||
{ |
|||
byte[] result = new byte[8]; |
|||
this.CopyBytes(value, result, 0); |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified 16-bit unsigned integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 2.</returns>
|
|||
public byte[] GetBytes(ushort value) |
|||
{ |
|||
return this.GetBytes(unchecked((short)value)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified 32-bit unsigned integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 4.</returns>
|
|||
public byte[] GetBytes(uint value) |
|||
{ |
|||
return this.GetBytes(unchecked((int)value)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified 64-bit unsigned integer value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 8.</returns>
|
|||
public byte[] GetBytes(ulong value) |
|||
{ |
|||
return this.GetBytes(unchecked((long)value)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified Boolean value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">A Boolean value.</param>
|
|||
/// <returns>An array of bytes with length 1.</returns>
|
|||
/// <returns>
|
|||
/// The <see cref="T:byte[]"/>.
|
|||
/// </returns>
|
|||
public byte[] GetBytes(bool value) |
|||
{ |
|||
return new byte[1] { value ? (byte)1 : (byte)0 }; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified Unicode character value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">A character to convert.</param>
|
|||
/// <returns>An array of bytes with length 2.</returns>
|
|||
/// <returns>
|
|||
/// The <see cref="T:byte[]"/>.
|
|||
/// </returns>
|
|||
public byte[] GetBytes(char value) |
|||
{ |
|||
return this.GetBytes((short)value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified double-precision floating point value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 8.</returns>
|
|||
public unsafe byte[] GetBytes(double value) |
|||
{ |
|||
return this.GetBytes(*((long*)&value)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified single-precision floating point value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 4.</returns>
|
|||
public unsafe byte[] GetBytes(float value) |
|||
{ |
|||
return this.GetBytes(*((int*)&value)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the specified decimal value as an array of bytes.
|
|||
/// </summary>
|
|||
/// <param name="value">The number to convert.</param>
|
|||
/// <returns>An array of bytes with length 16.</returns>
|
|||
public byte[] GetBytes(decimal value) |
|||
{ |
|||
byte[] result = new byte[16]; |
|||
this.CopyBytes(value, result, 0); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -1,139 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Equivalent of <see cref="BitConverter"/>, but with either endianness.
|
|||
/// </summary>
|
|||
internal abstract partial class EndianBitConverter |
|||
{ |
|||
/// <summary>
|
|||
/// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 16-bit signed integer formed by two bytes beginning at startIndex.</returns>
|
|||
public abstract short ToInt16(byte[] value, int startIndex); |
|||
|
|||
/// <summary>
|
|||
/// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 32-bit signed integer formed by four bytes beginning at startIndex.</returns>
|
|||
public abstract int ToInt32(byte[] value, int startIndex); |
|||
|
|||
/// <summary>
|
|||
/// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 64-bit signed integer formed by eight bytes beginning at startIndex.</returns>
|
|||
public abstract long ToInt64(byte[] value, int startIndex); |
|||
|
|||
/// <summary>
|
|||
/// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 16-bit unsigned integer formed by two bytes beginning at startIndex.</returns>
|
|||
public ushort ToUInt16(byte[] value, int startIndex) |
|||
{ |
|||
return unchecked((ushort)this.ToInt16(value, startIndex)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 32-bit unsigned integer formed by four bytes beginning at startIndex.</returns>
|
|||
public uint ToUInt32(byte[] value, int startIndex) |
|||
{ |
|||
return unchecked((uint)this.ToInt32(value, startIndex)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A 64-bit unsigned integer formed by eight bytes beginning at startIndex.</returns>
|
|||
public ulong ToUInt64(byte[] value, int startIndex) |
|||
{ |
|||
return unchecked((ulong)this.ToInt64(value, startIndex)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a Boolean value converted from one byte at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>true if the byte at startIndex in value is nonzero; otherwise, false.</returns>
|
|||
public bool ToBoolean(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 1); |
|||
return value[startIndex] != 0; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a Unicode character converted from two bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A character formed by two bytes beginning at startIndex.</returns>
|
|||
public char ToChar(byte[] value, int startIndex) |
|||
{ |
|||
return unchecked((char)this.ToInt16(value, startIndex)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a double-precision floating point number converted from eight bytes
|
|||
/// at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A double precision floating point number formed by eight bytes beginning at startIndex.</returns>
|
|||
public unsafe double ToDouble(byte[] value, int startIndex) |
|||
{ |
|||
long intValue = this.ToInt64(value, startIndex); |
|||
return *((double*)&intValue); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a single-precision floating point number converted from four bytes
|
|||
/// at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A single precision floating point number formed by four bytes beginning at startIndex.</returns>
|
|||
public unsafe float ToSingle(byte[] value, int startIndex) |
|||
{ |
|||
int intValue = this.ToInt32(value, startIndex); |
|||
return *((float*)&intValue); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a decimal value converted from sixteen bytes
|
|||
/// at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <returns>A decimal formed by sixteen bytes beginning at startIndex.</returns>
|
|||
public unsafe decimal ToDecimal(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 16); |
|||
|
|||
decimal result = 0m; |
|||
int* presult = (int*)&result; |
|||
presult[0] = this.ToInt32(value, startIndex); |
|||
presult[1] = this.ToInt32(value, startIndex + 4); |
|||
presult[2] = this.ToInt32(value, startIndex + 8); |
|||
presult[3] = this.ToInt32(value, startIndex + 12); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -1,127 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Equivalent of <see cref="BitConverter"/>, but with either endianness.
|
|||
/// </summary>
|
|||
internal abstract partial class EndianBitConverter |
|||
{ |
|||
/// <summary>
|
|||
/// The little-endian bit converter.
|
|||
/// </summary>
|
|||
public static readonly LittleEndianBitConverter LittleEndianConverter = new LittleEndianBitConverter(); |
|||
|
|||
/// <summary>
|
|||
/// The big-endian bit converter.
|
|||
/// </summary>
|
|||
public static readonly BigEndianBitConverter BigEndianConverter = new BigEndianBitConverter(); |
|||
|
|||
/// <summary>
|
|||
/// Gets the byte order ("endianness") in which data is converted using this class.
|
|||
/// </summary>
|
|||
public abstract Endianness Endianness { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether the byte order ("endianness") in which data is converted is little endian.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Different computer architectures store data using different byte orders. "Big-endian"
|
|||
/// means the most significant byte is on the left end of a word. "Little-endian" means the
|
|||
/// most significant byte is on the right end of a word.
|
|||
/// </remarks>
|
|||
public abstract bool IsLittleEndian { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the converter.
|
|||
/// </summary>
|
|||
/// <param name="endianness">The endianness.</param>
|
|||
/// <returns>an <see cref="EndianBitConverter"/></returns>
|
|||
/// <exception cref="ArgumentException">Not a valid form of Endianness - endianness</exception>
|
|||
public static EndianBitConverter GetConverter(Endianness endianness) |
|||
{ |
|||
switch (endianness) |
|||
{ |
|||
case Endianness.LittleEndian: |
|||
return LittleEndianConverter; |
|||
case Endianness.BigEndian: |
|||
return BigEndianConverter; |
|||
default: |
|||
throw new ArgumentException("Not a valid form of Endianness", nameof(endianness)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a String converted from the elements of a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <remarks>All the elements of value are converted.</remarks>
|
|||
/// <returns>
|
|||
/// A String of hexadecimal pairs separated by hyphens, where each pair
|
|||
/// represents the corresponding element in value; for example, "7F-2C-4A".
|
|||
/// </returns>
|
|||
public static string ToString(byte[] value) |
|||
{ |
|||
return BitConverter.ToString(value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a String converted from the elements of a byte array starting at a specified array position.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <remarks>The elements from array position startIndex to the end of the array are converted.</remarks>
|
|||
/// <returns>
|
|||
/// A String of hexadecimal pairs separated by hyphens, where each pair
|
|||
/// represents the corresponding element in value; for example, "7F-2C-4A".
|
|||
/// </returns>
|
|||
public static string ToString(byte[] value, int startIndex) |
|||
{ |
|||
return BitConverter.ToString(value, startIndex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a String converted from a specified number of bytes at a specified position in a byte array.
|
|||
/// </summary>
|
|||
/// <param name="value">An array of bytes.</param>
|
|||
/// <param name="startIndex">The starting position within value.</param>
|
|||
/// <param name="length">The number of bytes to convert.</param>
|
|||
/// <remarks>The length elements from array position startIndex are converted.</remarks>
|
|||
/// <returns>
|
|||
/// A String of hexadecimal pairs separated by hyphens, where each pair
|
|||
/// represents the corresponding element in value; for example, "7F-2C-4A".
|
|||
/// </returns>
|
|||
public static string ToString(byte[] value, int startIndex, int length) |
|||
{ |
|||
return BitConverter.ToString(value, startIndex, length); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Checks the given argument for validity.
|
|||
/// </summary>
|
|||
/// <param name="value">The byte array passed in</param>
|
|||
/// <param name="startIndex">The start index passed in</param>
|
|||
/// <param name="bytesRequired">The number of bytes required</param>
|
|||
/// <exception cref="ArgumentNullException">value is a null reference</exception>
|
|||
/// <exception cref="ArgumentOutOfRangeException">
|
|||
/// startIndex is less than zero or greater than the length of value minus bytesRequired.
|
|||
/// </exception>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
protected static void CheckByteArgument(byte[] value, int startIndex, int bytesRequired) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(value)); |
|||
} |
|||
|
|||
if (startIndex < 0 || startIndex > value.Length - bytesRequired) |
|||
{ |
|||
throw new ArgumentOutOfRangeException(nameof(startIndex)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,81 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.IO |
|||
{ |
|||
/// <summary>
|
|||
/// Implementation of EndianBitConverter which converts to/from little-endian byte arrays.
|
|||
/// </summary>
|
|||
internal sealed class LittleEndianBitConverter : EndianBitConverter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Endianness Endianness |
|||
{ |
|||
get { return Endianness.LittleEndian; } |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool IsLittleEndian |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(short value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 2); |
|||
|
|||
buffer[index + 1] = (byte)(value >> 8); |
|||
buffer[index] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(int value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 4); |
|||
|
|||
buffer[index + 3] = (byte)(value >> 24); |
|||
buffer[index + 2] = (byte)(value >> 16); |
|||
buffer[index + 1] = (byte)(value >> 8); |
|||
buffer[index] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void CopyBytes(long value, byte[] buffer, int index) |
|||
{ |
|||
CheckByteArgument(buffer, index, 8); |
|||
|
|||
buffer[index + 7] = (byte)(value >> 56); |
|||
buffer[index + 6] = (byte)(value >> 48); |
|||
buffer[index + 5] = (byte)(value >> 40); |
|||
buffer[index + 4] = (byte)(value >> 32); |
|||
buffer[index + 3] = (byte)(value >> 24); |
|||
buffer[index + 2] = (byte)(value >> 16); |
|||
buffer[index + 1] = (byte)(value >> 8); |
|||
buffer[index] = (byte)value; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public unsafe override short ToInt16(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 2); |
|||
return (short)((value[startIndex + 1] << 8) | value[startIndex]); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public unsafe override int ToInt32(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 4); |
|||
return (value[startIndex + 3] << 24) | (value[startIndex + 2] << 16) | (value[startIndex + 1] << 8) | value[startIndex]; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public unsafe override long ToInt64(byte[] value, int startIndex) |
|||
{ |
|||
CheckByteArgument(value, startIndex, 8); |
|||
long p1 = (value[startIndex + 7] << 24) | (value[startIndex + 6] << 16) | (value[startIndex + 5] << 8) | value[startIndex + 4]; |
|||
long p2 = (value[startIndex + 3] << 24) | (value[startIndex + 2] << 16) | (value[startIndex + 1] << 8) | value[startIndex]; |
|||
return (p2 & 0xFFFFFFFF) | (p1 << 32); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,281 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using static SixLabors.ImageSharp.MetaData.Profiles.Exif.ExifTag; |
|||
|
|||
namespace SixLabors.ImageSharp.MetaData.Profiles.Exif |
|||
{ |
|||
internal static class ExifTags |
|||
{ |
|||
/// <summary>
|
|||
/// The collection if Image File Directory tags
|
|||
/// </summary>
|
|||
public static readonly ExifTag[] Ifd = |
|||
{ |
|||
SubfileType, |
|||
OldSubfileType, |
|||
ImageWidth, |
|||
ImageLength, |
|||
BitsPerSample, |
|||
Compression, |
|||
PhotometricInterpretation, |
|||
Thresholding, |
|||
CellWidth, |
|||
CellLength, |
|||
FillOrder, |
|||
DocumentName, |
|||
ImageDescription, |
|||
Make, |
|||
Model, |
|||
StripOffsets, |
|||
Orientation, |
|||
SamplesPerPixel, |
|||
RowsPerStrip, |
|||
StripByteCounts, |
|||
MinSampleValue, |
|||
MaxSampleValue, |
|||
XResolution, |
|||
YResolution, |
|||
PlanarConfiguration, |
|||
PageName, |
|||
XPosition, |
|||
YPosition, |
|||
FreeOffsets, |
|||
FreeByteCounts, |
|||
GrayResponseUnit, |
|||
GrayResponseCurve, |
|||
T4Options, |
|||
T6Options, |
|||
ResolutionUnit, |
|||
PageNumber, |
|||
ColorResponseUnit, |
|||
TransferFunction, |
|||
Software, |
|||
DateTime, |
|||
Artist, |
|||
HostComputer, |
|||
Predictor, |
|||
WhitePoint, |
|||
PrimaryChromaticities, |
|||
ColorMap, |
|||
HalftoneHints, |
|||
TileWidth, |
|||
TileLength, |
|||
TileOffsets, |
|||
TileByteCounts, |
|||
BadFaxLines, |
|||
CleanFaxData, |
|||
ConsecutiveBadFaxLines, |
|||
InkSet, |
|||
InkNames, |
|||
NumberOfInks, |
|||
DotRange, |
|||
TargetPrinter, |
|||
ExtraSamples, |
|||
SampleFormat, |
|||
SMinSampleValue, |
|||
SMaxSampleValue, |
|||
TransferRange, |
|||
ClipPath, |
|||
XClipPathUnits, |
|||
YClipPathUnits, |
|||
Indexed, |
|||
JPEGTables, |
|||
OPIProxy, |
|||
ProfileType, |
|||
FaxProfile, |
|||
CodingMethods, |
|||
VersionYear, |
|||
ModeNumber, |
|||
Decode, |
|||
DefaultImageColor, |
|||
T82ptions, |
|||
JPEGProc, |
|||
JPEGInterchangeFormat, |
|||
JPEGInterchangeFormatLength, |
|||
JPEGRestartInterval, |
|||
JPEGLosslessPredictors, |
|||
JPEGPointTransforms, |
|||
JPEGQTables, |
|||
JPEGDCTables, |
|||
JPEGACTables, |
|||
YCbCrCoefficients, |
|||
YCbCrSubsampling, |
|||
YCbCrSubsampling, |
|||
YCbCrPositioning, |
|||
ReferenceBlackWhite, |
|||
StripRowCounts, |
|||
XMP, |
|||
Rating, |
|||
RatingPercent, |
|||
ImageID, |
|||
CFARepeatPatternDim, |
|||
CFAPattern2, |
|||
BatteryLevel, |
|||
Copyright, |
|||
MDFileTag, |
|||
MDScalePixel, |
|||
MDLabName, |
|||
MDSampleInfo, |
|||
MDPrepDate, |
|||
MDPrepTime, |
|||
MDFileUnits, |
|||
PixelScale, |
|||
IntergraphPacketData, |
|||
IntergraphRegisters, |
|||
IntergraphMatrix, |
|||
ModelTiePoint, |
|||
SEMInfo, |
|||
ModelTransform, |
|||
ImageLayer, |
|||
FaxRecvParams, |
|||
FaxSubaddress, |
|||
FaxRecvTime, |
|||
ImageSourceData, |
|||
XPTitle, |
|||
XPComment, |
|||
XPAuthor, |
|||
XPKeywords, |
|||
XPSubject, |
|||
GDALMetadata, |
|||
GDALNoData |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// The collection of Exif tags
|
|||
/// </summary>
|
|||
public static readonly ExifTag[] Exif = |
|||
{ |
|||
ExposureTime, |
|||
FNumber, |
|||
ExposureProgram, |
|||
SpectralSensitivity, |
|||
ISOSpeedRatings, |
|||
OECF, |
|||
Interlace, |
|||
TimeZoneOffset, |
|||
SelfTimerMode, |
|||
SensitivityType, |
|||
StandardOutputSensitivity, |
|||
RecommendedExposureIndex, |
|||
ISOSpeed, |
|||
ISOSpeedLatitudeyyy, |
|||
ISOSpeedLatitudezzz, |
|||
ExifVersion, |
|||
DateTimeOriginal, |
|||
DateTimeDigitized, |
|||
OffsetTime, |
|||
OffsetTimeOriginal, |
|||
OffsetTimeDigitized, |
|||
ComponentsConfiguration, |
|||
CompressedBitsPerPixel, |
|||
ShutterSpeedValue, |
|||
ApertureValue, |
|||
BrightnessValue, |
|||
ExposureBiasValue, |
|||
MaxApertureValue, |
|||
SubjectDistance, |
|||
MeteringMode, |
|||
LightSource, |
|||
Flash, |
|||
FocalLength, |
|||
FlashEnergy2, |
|||
SpatialFrequencyResponse2, |
|||
Noise, |
|||
FocalPlaneXResolution2, |
|||
FocalPlaneYResolution2, |
|||
FocalPlaneResolutionUnit2, |
|||
ImageNumber, |
|||
SecurityClassification, |
|||
ImageHistory, |
|||
SubjectArea, |
|||
ExposureIndex2, |
|||
TIFFEPStandardID, |
|||
SensingMethod2, |
|||
MakerNote, |
|||
UserComment, |
|||
SubsecTime, |
|||
SubsecTimeOriginal, |
|||
SubsecTimeDigitized, |
|||
AmbientTemperature, |
|||
Humidity, |
|||
Pressure, |
|||
WaterDepth, |
|||
Acceleration, |
|||
CameraElevationAngle, |
|||
FlashpixVersion, |
|||
ColorSpace, |
|||
PixelXDimension, |
|||
PixelYDimension, |
|||
RelatedSoundFile, |
|||
FlashEnergy, |
|||
SpatialFrequencyResponse, |
|||
FocalPlaneXResolution, |
|||
FocalPlaneYResolution, |
|||
FocalPlaneResolutionUnit, |
|||
SubjectLocation, |
|||
ExposureIndex, |
|||
SensingMethod, |
|||
FileSource, |
|||
SceneType, |
|||
CFAPattern, |
|||
CustomRendered, |
|||
ExposureMode, |
|||
WhiteBalance, |
|||
DigitalZoomRatio, |
|||
FocalLengthIn35mmFilm, |
|||
SceneCaptureType, |
|||
GainControl, |
|||
Contrast, |
|||
Saturation, |
|||
Sharpness, |
|||
DeviceSettingDescription, |
|||
SubjectDistanceRange, |
|||
ImageUniqueID, |
|||
OwnerName, |
|||
SerialNumber, |
|||
LensInfo, |
|||
LensMake, |
|||
LensModel, |
|||
LensSerialNumber |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// The collection of GPS tags
|
|||
/// </summary>
|
|||
public static readonly ExifTag[] Gps = |
|||
{ |
|||
GPSVersionID, |
|||
GPSLatitudeRef, |
|||
GPSLatitude, |
|||
GPSLongitudeRef, |
|||
GPSLongitude, |
|||
GPSAltitudeRef, |
|||
GPSAltitude, |
|||
GPSTimestamp, |
|||
GPSSatellites, |
|||
GPSStatus, |
|||
GPSMeasureMode, |
|||
GPSDOP, |
|||
GPSSpeedRef, |
|||
GPSSpeed, |
|||
GPSTrackRef, |
|||
GPSTrack, |
|||
GPSImgDirectionRef, |
|||
GPSImgDirection, |
|||
GPSMapDatum, |
|||
GPSDestLatitudeRef, |
|||
GPSDestLatitude, |
|||
GPSDestLongitudeRef, |
|||
GPSDestLongitude, |
|||
GPSDestBearingRef, |
|||
GPSDestBearing, |
|||
GPSDestDistanceRef, |
|||
GPSDestDistance, |
|||
GPSProcessingMethod, |
|||
GPSAreaInformation, |
|||
GPSDateStamp, |
|||
GPSDifferential |
|||
}; |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue