Browse Source

StyleStalin

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

55
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 namespace ImageSharp
{ {
using System; using System;
@ -5,6 +10,9 @@ namespace ImageSharp
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
/// <content>
/// Conains the definition of <see cref="BulkOperations"/>
/// </content>
public partial struct Color public partial struct Color
{ {
/// <summary> /// <summary>
@ -12,26 +20,6 @@ namespace ImageSharp
/// </summary> /// </summary>
internal class BulkOperations : BulkPixelOperations<Color> 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> /// <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"/>. /// that works only with `count` divisible by <see cref="Vector{UInt32}.Count"/>.
@ -55,8 +43,7 @@ namespace ImageSharp
DebugGuard.IsTrue( DebugGuard.IsTrue(
count % vecSize == 0, count % vecSize == 0,
nameof(count), 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> bVec = new Vector<float>(256.0f / 255.0f);
Vector<float> magicFloat = new Vector<float>(32768.0f); Vector<float> magicFloat = new Vector<float>(32768.0f);
@ -92,7 +79,7 @@ namespace ImageSharp
vf.CopyTo(fTemp, i); 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) internal override unsafe void PackFromXyzBytes(BufferPointer<byte> sourceBytes, BufferPointer<Color> destColors, int count)
{ {
byte* source = (byte*)sourceBytes; byte* source = (byte*)sourceBytes;
byte* destination = (byte*)destColors; byte* destination = (byte*)destColors;
for (int x = 0; x < count; x++) for (int x = 0; x < count; x++)
{ {
@ -224,6 +211,26 @@ namespace ImageSharp
destination += 4; 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> /// <summary>
/// Verifies that the specified value is less than a maximum value /// Verifies that the specified value is less than a maximum value
/// and throws an exception if it is not. /// and throws an exception if it is not.
@ -117,7 +116,6 @@ namespace ImageSharp
} }
} }
/// <summary> /// <summary>
/// Verifies, that the method parameter with specified target value is true /// Verifies, that the method parameter with specified target value is true
/// and throws an exception if it is found to be so. /// and throws an exception if it is found to be so.

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

@ -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, // 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 // 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. // delegates and other patterns.
if (typeof(TSource) == typeof(long)) if (typeof(TSource) == typeof(long))
{ {
long[] srcArray = Unsafe.As<long[]>(source.Array); long[] srcArray = Unsafe.As<long[]>(source.Array);

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

@ -107,9 +107,8 @@ namespace ImageSharp
} }
/// <summary> /// <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> /// </summary>
/// <typeparam name="T">The element type</typeparam>
/// <returns>The <see cref="BufferPointer{T}"/></returns> /// <returns>The <see cref="BufferPointer{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferPointer<T> Slice() public unsafe BufferPointer<T> Slice()
@ -118,9 +117,9 @@ namespace ImageSharp
} }
/// <summary> /// <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> /// </summary>
/// <typeparam name="T">The element type</typeparam> /// <param name="offset">The offset</param>
/// <returns>The <see cref="BufferPointer{T}"/></returns> /// <returns>The <see cref="BufferPointer{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferPointer<T> Slice(int offset) public unsafe BufferPointer<T> Slice(int offset)
@ -128,7 +127,6 @@ namespace ImageSharp
return new BufferPointer<T>(this.Array, (void*)this.Pointer, offset); return new BufferPointer<T>(this.Array, (void*)this.Pointer, offset);
} }
/// <summary> /// <summary>
/// Disposes the <see cref="PinnedBuffer{T}"/> instance by unpinning the array, and returning the pooled buffer when necessary. /// Disposes the <see cref="PinnedBuffer{T}"/> instance by unpinning the array, and returning the pooled buffer when necessary.
/// </summary> /// </summary>

Loading…
Cancel
Save