Browse Source

StyleStalin

pull/126/head
Anton Firszov 9 years ago
parent
commit
19251fe4fe
  1. 59
      src/ImageSharp/Colors/Color.BulkOperations.cs
  2. 2
      src/ImageSharp/Common/Helpers/DebugGuard.cs
  3. 9
      src/ImageSharp/Common/Memory/BufferPointer.cs
  4. 2
      src/ImageSharp/Common/Memory/BufferPointer{T}.cs
  5. 10
      src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs

59
src/ImageSharp/Colors/Color.BulkOperations.cs

@ -1,3 +1,8 @@
// <copyright file="Color.BulkOperations.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
@ -5,6 +10,9 @@ namespace ImageSharp
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
/// <content>
/// Conains the definition of <see cref="BulkOperations"/>
/// </content>
public partial struct Color
{
/// <summary>
@ -13,27 +21,7 @@ namespace ImageSharp
internal class BulkOperations : BulkPixelOperations<Color>
{
/// <summary>
/// Value type to store <see cref="Color"/>-s unpacked into multiple <see cref="uint"/>-s.
/// </summary>
private struct UnpackedRGBA
{
private uint r;
private uint g;
private uint b;
private uint a;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Load(uint p)
{
this.r = p;
this.g = p >> Color.GreenShift;
this.b = p >> Color.BlueShift;
this.a = p >> Color.AlphaShift;
}
}
/// <summary>
/// SIMD optimized bulk implementation of <see cref="IPixel.PackFromVector4(Vector4)"/>
/// SIMD optimized bulk implementation of <see cref="IPixel.PackFromVector4(Vector4)"/>
/// that works only with `count` divisible by <see cref="Vector{UInt32}.Count"/>.
/// </summary>
/// <param name="sourceColors">The <see cref="BufferPointer{T}"/> to the source colors.</param>
@ -55,8 +43,7 @@ namespace ImageSharp
DebugGuard.IsTrue(
count % vecSize == 0,
nameof(count),
"Argument 'count' should divisible by Vector<uint>.Count!"
);
"Argument 'count' should divisible by Vector<uint>.Count!");
Vector<float> bVec = new Vector<float>(256.0f / 255.0f);
Vector<float> magicFloat = new Vector<float>(32768.0f);
@ -64,7 +51,7 @@ namespace ImageSharp
Vector<uint> mask = new Vector<uint>(255);
int unpackedRawCount = count * 4;
uint* src = (uint*)sourceColors.PointerAtOffset;
uint* srcEnd = src + count;
@ -92,7 +79,7 @@ namespace ImageSharp
vf.CopyTo(fTemp, i);
}
BufferPointer.Copy<uint>(tempBuf, (BufferPointer<byte>) destVectors, unpackedRawCount);
BufferPointer.Copy<uint>(tempBuf, (BufferPointer<byte>)destVectors, unpackedRawCount);
}
}
@ -120,7 +107,7 @@ namespace ImageSharp
internal override unsafe void PackFromXyzBytes(BufferPointer<byte> sourceBytes, BufferPointer<Color> destColors, int count)
{
byte* source = (byte*)sourceBytes;
byte* destination = (byte*)destColors;
byte* destination = (byte*)destColors;
for (int x = 0; x < count; x++)
{
@ -224,6 +211,26 @@ namespace ImageSharp
destination += 4;
}
}
/// <summary>
/// Value type to store <see cref="Color"/>-s unpacked into multiple <see cref="uint"/>-s.
/// </summary>
private struct UnpackedRGBA
{
private uint r;
private uint g;
private uint b;
private uint a;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Load(uint p)
{
this.r = p;
this.g = p >> Color.GreenShift;
this.b = p >> Color.BlueShift;
this.a = p >> Color.AlphaShift;
}
}
}
}
}

2
src/ImageSharp/Common/Helpers/DebugGuard.cs

@ -30,7 +30,6 @@ namespace ImageSharp
}
}
/// <summary>
/// Verifies that the specified value is less than a maximum value
/// and throws an exception if it is not.
@ -117,7 +116,6 @@ namespace ImageSharp
}
}
/// <summary>
/// Verifies, that the method parameter with specified target value is true
/// and throws an exception if it is found to be so.

9
src/ImageSharp/Common/Memory/BufferPointer.cs

@ -63,7 +63,7 @@ namespace ImageSharp
return;
}
}
Unsafe.CopyBlock((void*)destination.PointerAtOffset, (void*)source.PointerAtOffset, byteCount);
}
@ -110,13 +110,13 @@ namespace ImageSharp
public static uint USizeOf<T>(int count)
where T : struct
=> (uint)SizeOf<T>(count);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryMarshalCopy<TSource, TDest>(BufferPointer<TSource> source, BufferPointer<TDest> destination, int count)
where TSource : struct
where TSource : struct
where TDest : struct
{
// Pattern Based On:
// Pattern Based On:
// https://github.com/dotnet/corefx/blob/master/src/System.Numerics.Vectors/src/System/Numerics/Vector.cs#L12
//
// Note: The following patterns are used throughout the code here and are described here
@ -128,7 +128,6 @@ namespace ImageSharp
// At runtime, each instantiation of BufferPointer<T> will be type-specific, and each of these typeof blocks will be eliminated,
// as typeof(T) is a (JIT) compile-time constant for each instantiation. This design was chosen to eliminate any overhead from
// delegates and other patterns.
if (typeof(TSource) == typeof(long))
{
long[] srcArray = Unsafe.As<long[]>(source.Array);

2
src/ImageSharp/Common/Memory/BufferPointer{T}.cs

@ -89,7 +89,7 @@ namespace ImageSharp
}
/// <summary>
/// Converts <see cref="BufferPointer{T}"/> instance to <see cref="BufferPointer{Byte}"/>
/// Converts <see cref="BufferPointer{T}"/> instance to <see cref="BufferPointer{Byte}"/>
/// setting it's <see cref="Offset"/> and <see cref="PointerAtOffset"/> to correct values.
/// </summary>
/// <param name="source">The <see cref="BufferPointer{T}"/> to convert</param>

10
src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs

@ -95,7 +95,7 @@ namespace ImageSharp
/// Gets a pointer to the pinned <see cref="Array"/>.
/// </summary>
public IntPtr Pointer { get; private set; }
/// <summary>
/// Converts <see cref="PinnedBuffer{T}"/> to an <see cref="BufferPointer{T}"/>.
/// </summary>
@ -107,9 +107,8 @@ namespace ImageSharp
}
/// <summary>
/// Gets a <see cref="BufferPointer{T}"/> to the beginning of the raw data in 'buffer'.
/// Gets a <see cref="BufferPointer{T}"/> to the beginning of the raw data of the buffer.
/// </summary>
/// <typeparam name="T">The element type</typeparam>
/// <returns>The <see cref="BufferPointer{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferPointer<T> Slice()
@ -118,9 +117,9 @@ namespace ImageSharp
}
/// <summary>
/// Gets a <see cref="BufferPointer{T}"/> to the beginning of the raw data in 'buffer'.
/// Gets a <see cref="BufferPointer{T}"/> to an offseted position inside the buffer.
/// </summary>
/// <typeparam name="T">The element type</typeparam>
/// <param name="offset">The offset</param>
/// <returns>The <see cref="BufferPointer{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferPointer<T> Slice(int offset)
@ -128,7 +127,6 @@ namespace ImageSharp
return new BufferPointer<T>(this.Array, (void*)this.Pointer, offset);
}
/// <summary>
/// Disposes the <see cref="PinnedBuffer{T}"/> instance by unpinning the array, and returning the pooled buffer when necessary.
/// </summary>

Loading…
Cancel
Save