Browse Source

Fixing documentation warnings. Moving MutableSpanExtensions into ints own file.

pull/49/head
Olivia 9 years ago
parent
commit
229954a641
  1. 2
      src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs
  2. 52
      src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs
  3. 9
      src/ImageSharp/Formats/Jpg/Components/Bytes.cs
  4. 9
      src/ImageSharp/Formats/Jpg/Components/Huffman.cs
  5. 75
      src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs
  6. 81
      src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs
  7. 3
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

2
src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs

@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Processors
int offsetY = y - polyStartY;
Vector2 currentPoint = default(Vector2);
Vector2 currentPointOffset = default(Vector2);
for (int x = minX; x < maxX; x++)
{
int offsetX = x - startX;

52
src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs

@ -15,9 +15,17 @@ namespace ImageSharp.Formats
/// </summary>
internal partial struct Block8x8F
{
/// <summary>
/// Vector count
/// </summary>
public const int VectorCount = 16;
/// <summary>
/// Scalar count
/// </summary>
public const int ScalarCount = VectorCount * 4;
#pragma warning disable SA1600 // ElementsMustBeDocumented
public Vector4 V0L;
public Vector4 V0R;
@ -41,6 +49,7 @@ namespace ImageSharp.Formats
public Vector4 V7L;
public Vector4 V7R;
#pragma warning restore SA1600 // ElementsMustBeDocumented
#pragma warning disable SA1310 // FieldNamesMustNotContainUnderscore
private static readonly Vector4 C_1_175876 = new Vector4(1.175876f);
@ -59,6 +68,11 @@ namespace ImageSharp.Formats
private static readonly Vector4 C_0_125 = new Vector4(0.1250f);
#pragma warning restore SA1310 // FieldNamesMustNotContainUnderscore
/// <summary>
/// Index into the block
/// </summary>
/// <param name="idx">The index</param>
/// <returns>The float value at the specified index</returns>
public unsafe float this[int idx]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -143,25 +157,29 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Multiply in place
/// </summary>
/// <param name="scalar">Scalar to multiply by</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void MultiplyAllInplace(Vector4 s)
public void MultiplyAllInplace(Vector4 scalar)
{
this.V0L *= s;
this.V0R *= s;
this.V1L *= s;
this.V1R *= s;
this.V2L *= s;
this.V2R *= s;
this.V3L *= s;
this.V3R *= s;
this.V4L *= s;
this.V4R *= s;
this.V5L *= s;
this.V5R *= s;
this.V6L *= s;
this.V6R *= s;
this.V7L *= s;
this.V7R *= s;
this.V0L *= scalar;
this.V0R *= scalar;
this.V1L *= scalar;
this.V1R *= scalar;
this.V2L *= scalar;
this.V2R *= scalar;
this.V3L *= scalar;
this.V3R *= scalar;
this.V4L *= scalar;
this.V4R *= scalar;
this.V5L *= scalar;
this.V5R *= scalar;
this.V6L *= scalar;
this.V6R *= scalar;
this.V7L *= scalar;
this.V7R *= scalar;
}
/// <summary>

9
src/ImageSharp/Formats/Jpg/Components/Bytes.cs

@ -23,8 +23,14 @@ namespace ImageSharp.Formats
/// </summary>
public byte[] Buffer;
/// <summary>
/// Start of bytes read
/// </summary>
public int I;
/// <summary>
/// End of bytes read
/// </summary>
public int J;
/// <summary>
@ -44,6 +50,9 @@ namespace ImageSharp.Formats
return new Bytes { Buffer = ArrayPool.Rent(4096) };
}
/// <summary>
/// Disposes of the underlying buffer
/// </summary>
public void Dispose()
{
if (this.Buffer != null)

9
src/ImageSharp/Formats/Jpg/Components/Huffman.cs

@ -53,6 +53,12 @@ namespace ImageSharp.Formats
private static readonly ArrayPool<int> IntBuffer = ArrayPool<int>.Create(JpegDecoderCore.MaxCodeLength, 50);
/// <summary>
/// Initializes the Huffman tree
/// </summary>
/// <param name="lutSize">Lut size</param>
/// <param name="maxNCodes">Max N codes</param>
/// <param name="maxCodeLength">Max code length</param>
public void Init(int lutSize, int maxNCodes, int maxCodeLength)
{
this.Lut = UshortBuffer.Rent(1 << lutSize);
@ -62,6 +68,9 @@ namespace ImageSharp.Formats
this.Indices = IntBuffer.Rent(maxCodeLength);
}
/// <summary>
/// Disposes the underlying buffers
/// </summary>
public void Dispose()
{
UshortBuffer.Return(this.Lut, true);

75
src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs

@ -5,7 +5,6 @@
namespace ImageSharp.Formats
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
@ -18,24 +17,48 @@ namespace ImageSharp.Formats
/// <typeparam name="T"></typeparam>
internal struct MutableSpan<T>
{
/// <summary>
/// Data
/// </summary>
public T[] Data;
/// <summary>
/// Offset
/// </summary>
public int Offset;
/// <summary>
/// Initializes a new instance of the <see cref="MutableSpan{T}"/> struct.
/// </summary>
/// <param name="size">The size of the span</param>
/// <param name="offset">The offset (defaults to 0)</param>
public MutableSpan(int size, int offset = 0)
{
this.Data = new T[size];
this.Offset = offset;
}
/// <summary>
/// Initializes a new instance of the <see cref="MutableSpan{T}"/> struct.
/// </summary>
/// <param name="data">The data</param>
/// <param name="offset">The offset (defaults to 0)</param>
public MutableSpan(T[] data, int offset = 0)
{
this.Data = data;
this.Offset = offset;
}
/// <summary>
/// Gets the total count of data
/// </summary>
public int TotalCount => this.Data.Length - this.Offset;
/// <summary>
/// Index into the data
/// </summary>
/// <param name="idx">The data</param>
/// <returns>The value at the specified index</returns>
public T this[int idx]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -53,57 +76,25 @@ namespace ImageSharp.Formats
public static implicit operator MutableSpan<T>(T[] data) => new MutableSpan<T>(data, 0);
/// <summary>
/// Slice the data
/// </summary>
/// <param name="offset">The offset</param>
/// <returns>The new <see cref="MutableSpan{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MutableSpan<T> Slice(int offset)
{
return new MutableSpan<T>(this.Data, this.Offset + offset);
}
/// <summary>
/// Add to the offset
/// </summary>
/// <param name="offset">The additional offset</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddOffset(int offset)
{
this.Offset += offset;
}
}
internal static class MutableSpanExtensions
{
public static MutableSpan<T> Slice<T>(this T[] array, int offset) => new MutableSpan<T>(array, offset);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SaveTo(this MutableSpan<float> data, ref Vector4 v)
{
v.X = data[0];
v.Y = data[1];
v.Z = data[2];
v.W = data[3];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SaveTo(this MutableSpan<int> data, ref Vector4 v)
{
v.X = data[0];
v.Y = data[1];
v.Z = data[2];
v.W = data[3];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LoadFrom(this MutableSpan<float> data, ref Vector4 v)
{
data[0] = v.X;
data[1] = v.Y;
data[2] = v.Z;
data[3] = v.W;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LoadFrom(this MutableSpan<int> data, ref Vector4 v)
{
data[0] = (int)v.X;
data[1] = (int)v.Y;
data[2] = (int)v.Z;
data[3] = (int)v.W;
}
}
}

81
src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs

@ -0,0 +1,81 @@
// <copyright file="MutableSpanExtensions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpg.Components
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// MutableSpan Extensions
/// </summary>
internal static class MutableSpanExtensions
{
/// <summary>
/// Slice <see cref="MutableSpan{T}"/>
/// </summary>
/// <typeparam name="T">The type of the data in the span</typeparam>
/// <param name="array">The data array</param>
/// <param name="offset">The offset</param>
/// <returns>The new <see cref="MutableSpan{T}"/></returns>
public static MutableSpan<T> Slice<T>(this T[] array, int offset) => new MutableSpan<T>(array, offset);
/// <summary>
/// Save to a Vector4
/// </summary>
/// <param name="data">The data</param>
/// <param name="v">The vector to save to</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SaveTo(this MutableSpan<float> data, ref Vector4 v)
{
v.X = data[0];
v.Y = data[1];
v.Z = data[2];
v.W = data[3];
}
/// <summary>
/// Save to a Vector4
/// </summary>
/// <param name="data">The data</param>
/// <param name="v">The vector to save to</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SaveTo(this MutableSpan<int> data, ref Vector4 v)
{
v.X = data[0];
v.Y = data[1];
v.Z = data[2];
v.W = data[3];
}
/// <summary>
/// Load from Vector4
/// </summary>
/// <param name="data">The data</param>
/// <param name="v">The vector to load from</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LoadFrom(this MutableSpan<float> data, ref Vector4 v)
{
data[0] = v.X;
data[1] = v.Y;
data[2] = v.Z;
data[3] = v.W;
}
/// <summary>
/// Load from Vector4
/// </summary>
/// <param name="data">The data</param>
/// <param name="v">The vector to load from</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LoadFrom(this MutableSpan<int> data, ref Vector4 v)
{
data[0] = (int)v.X;
data[1] = (int)v.Y;
data[2] = (int)v.Z;
data[3] = (int)v.W;
}
}
}

3
src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

@ -449,6 +449,9 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
for (int i = 0; i < this.huffmanTrees.Length; i++)

Loading…
Cancel
Save