Browse Source

added some comments to Block8x8F stuff

pull/97/head
Anton Firszov 9 years ago
parent
commit
ddcd9cd906
  1. 19
      src/ImageSharp.Formats.Jpeg/Components/Block8x8F.cs
  2. 18
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs

19
src/ImageSharp.Formats.Jpeg/Components/Block8x8F.cs

@ -377,23 +377,6 @@ namespace ImageSharp.Formats.Jpg
}
}
/// <summary>
/// Performs division and rounding of a rational number represented by a dividend and a divisior into an integer.
/// </summary>
/// <param name="dividend">The dividend</param>
/// <param name="divisor">The divisor</param>
/// <returns>The result integer</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int DivideRound(int dividend, int divisor)
{
if (dividend >= 0)
{
return (dividend + (divisor >> 1)) / divisor;
}
return -((-dividend + (divisor >> 1)) / divisor);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b)
{
@ -418,9 +401,11 @@ namespace ImageSharp.Formats.Jpg
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor)
{
// sign(v) = max(min(v, 1), -1)
Vector4 sign = Vector4.Min(dividend, Vector4.One);
sign = Vector4.Max(sign, new Vector4(-1));
// AlmostRound(dividend/divisor) = dividend/divisior + 0.5*sign(dividend)
return (dividend / divisor) + (sign * new Vector4(0.5f));
}
}

18
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs

@ -21,7 +21,7 @@ namespace ImageSharp.Tests
internal static class ReferenceImplementations
{
/// <summary>
/// Transpose 8x8 block stored linearly in a span (inplace)
/// Transpose 8x8 block stored linearly in a <see cref="MutableSpan{T}"/> (inplace)
/// </summary>
/// <param name="data"></param>
internal static void Transpose8x8(MutableSpan<float> data)
@ -39,7 +39,7 @@ namespace ImageSharp.Tests
}
/// <summary>
/// Transpose 8x8 block stored linearly in a span
/// Transpose 8x8 block stored linearly in a <see cref="MutableSpan{T}"/>
/// </summary>
internal static void Transpose8x8(MutableSpan<float> src, MutableSpan<float> dest)
{
@ -876,6 +876,14 @@ namespace ImageSharp.Tests
}
}
/// <summary>
/// Reference implementation to test <see cref="Block8x8F.UnzigDivRound"/>.
/// Rounding is done used an integer-based algorithm defined in <see cref="RationalRound"/>.
/// </summary>
/// <param name="src">The input block</param>
/// <param name="dest">The destination block of integers</param>
/// <param name="qt">The quantization table</param>
/// <param name="unzigPtr">Pointer to <see cref="UnzigData.Data"/> </param>
public static unsafe void UnZigDivRoundRational(Block8x8F* src, int* dest, Block8x8F* qt, int* unzigPtr)
{
float* s = (float*)src;
@ -891,6 +899,12 @@ namespace ImageSharp.Tests
}
}
/// <summary>
/// Rounds a rational number defined as dividend/divisor into an integer
/// </summary>
/// <param name="dividend">The dividend</param>
/// <param name="divisor">The divisior</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int RationalRound(int dividend, int divisor)
{

Loading…
Cancel
Save