Browse Source

Remove prefix in Block8x8F and cleanup

pull/571/head
James Jackson-South 8 years ago
parent
commit
fc66a446c3
  1. 60
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

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

@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
get get
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Components.Block8x8F, float>(ref this); ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
return Unsafe.Add(ref selfRef, idx); return Unsafe.Add(ref selfRef, idx);
} }
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
set set
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Components.Block8x8F, float>(ref this); ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
Unsafe.Add(ref selfRef, idx) = value; Unsafe.Add(ref selfRef, idx) = value;
} }
} }
@ -80,9 +80,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
set => this[(y * 8) + x] = value; set => this[(y * 8) + x] = value;
} }
public static Components.Block8x8F operator *(Components.Block8x8F block, float value) public static Block8x8F operator *(Block8x8F block, float value)
{ {
Components.Block8x8F result = block; Block8x8F result = block;
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)
{ {
float val = result[i]; float val = result[i];
@ -93,55 +93,55 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
return result; return result;
} }
public static Components.Block8x8F operator /(Components.Block8x8F block, float value) public static Block8x8F operator /(Block8x8F block, float value)
{ {
Components.Block8x8F result = block; Block8x8F result = block;
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)
{ {
float val = result[i]; float val = result[i];
val /= value; val /= value;
result[i] = (float)val; result[i] = val;
} }
return result; return result;
} }
public static Components.Block8x8F operator +(Components.Block8x8F block, float value) public static Block8x8F operator +(Block8x8F block, float value)
{ {
Components.Block8x8F result = block; Block8x8F result = block;
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)
{ {
float val = result[i]; float val = result[i];
val += value; val += value;
result[i] = (float)val; result[i] = val;
} }
return result; return result;
} }
public static Components.Block8x8F operator -(Components.Block8x8F block, float value) public static Block8x8F operator -(Block8x8F block, float value)
{ {
Components.Block8x8F result = block; Block8x8F result = block;
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)
{ {
float val = result[i]; float val = result[i];
val -= value; val -= value;
result[i] = (float)val; result[i] = val;
} }
return result; return result;
} }
public static Components.Block8x8F Load(Span<float> data) public static Block8x8F Load(Span<float> data)
{ {
var result = default(Components.Block8x8F); var result = default(Block8x8F);
result.LoadFrom(data); result.LoadFrom(data);
return result; return result;
} }
public static Components.Block8x8F Load(Span<int> data) public static Block8x8F Load(Span<int> data)
{ {
var result = default(Components.Block8x8F); var result = default(Block8x8F);
result.LoadFrom(data); result.LoadFrom(data);
return result; return result;
} }
@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void Clear() public void Clear()
{ {
// The cheapest way to do this in C#: // The cheapest way to do this in C#:
this = default(Components.Block8x8F); this = default;
} }
/// <summary> /// <summary>
@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void LoadFrom(Span<float> source) public void LoadFrom(Span<float> source)
{ {
ref byte s = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(source)); ref byte s = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(source));
ref byte d = ref Unsafe.As<Components.Block8x8F, byte>(ref this); ref byte d = ref Unsafe.As<Block8x8F, byte>(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float)); Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));
} }
@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="blockPtr">Block pointer</param> /// <param name="blockPtr">Block pointer</param>
/// <param name="source">Source</param> /// <param name="source">Source</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void LoadFrom(Components.Block8x8F* blockPtr, Span<float> source) public static unsafe void LoadFrom(Block8x8F* blockPtr, Span<float> source)
{ {
blockPtr->LoadFrom(source); blockPtr->LoadFrom(source);
} }
@ -204,7 +204,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void CopyTo(Span<float> dest) public void CopyTo(Span<float> dest)
{ {
ref byte d = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(dest)); ref byte d = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(dest));
ref byte s = ref Unsafe.As<Components.Block8x8F, byte>(ref this); ref byte s = ref Unsafe.As<Block8x8F, byte>(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float)); Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));
} }
@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="blockPtr">Pointer to block</param> /// <param name="blockPtr">Pointer to block</param>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void CopyTo(Components.Block8x8F* blockPtr, Span<byte> dest) public static unsafe void CopyTo(Block8x8F* blockPtr, Span<byte> dest)
{ {
float* fPtr = (float*)blockPtr; float* fPtr = (float*)blockPtr;
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)
@ -231,7 +231,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="blockPtr">Block pointer</param> /// <param name="blockPtr">Block pointer</param>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void CopyTo(Components.Block8x8F* blockPtr, Span<float> dest) public static unsafe void CopyTo(Block8x8F* blockPtr, Span<float> dest)
{ {
blockPtr->CopyTo(dest); blockPtr->CopyTo(dest);
} }
@ -301,7 +301,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Multiply all elements of the block by the corresponding elements of 'other' /// Multiply all elements of the block by the corresponding elements of 'other'
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void MultiplyInplace(ref Components.Block8x8F other) public void MultiplyInplace(ref Block8x8F other)
{ {
this.V0L *= other.V0L; this.V0L *= other.V0L;
this.V0R *= other.V0R; this.V0R *= other.V0R;
@ -353,7 +353,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="qtPtr">Qt pointer</param> /// <param name="qtPtr">Qt pointer</param>
/// <param name="unzigPtr">Unzig pointer</param> /// <param name="unzigPtr">Unzig pointer</param>
// [MethodImpl(MethodImplOptions.AggressiveInlining)] // [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DequantizeBlock(Components.Block8x8F* blockPtr, Components.Block8x8F* qtPtr, byte* unzigPtr) public static unsafe void DequantizeBlock(Block8x8F* blockPtr, Block8x8F* qtPtr, byte* unzigPtr)
{ {
float* b = (float*)blockPtr; float* b = (float*)blockPtr;
float* qtp = (float*)qtPtr; float* qtp = (float*)qtPtr;
@ -378,9 +378,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="qt">The quantization table</param> /// <param name="qt">The quantization table</param>
/// <param name="unzigPtr">Pointer to elements of <see cref="ZigZag"/></param> /// <param name="unzigPtr">Pointer to elements of <see cref="ZigZag"/></param>
public static unsafe void Quantize( public static unsafe void Quantize(
Components.Block8x8F* block, Block8x8F* block,
Components.Block8x8F* dest, Block8x8F* dest,
Components.Block8x8F* qt, Block8x8F* qt,
byte* unzigPtr) byte* unzigPtr)
{ {
float* s = (float*)block; float* s = (float*)block;
@ -399,7 +399,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// </summary> /// </summary>
/// <param name="destination">The destination block.</param> /// <param name="destination">The destination block.</param>
/// <param name="source">The source block.</param> /// <param name="source">The source block.</param>
public static unsafe void Scale16X16To8X8(Components.Block8x8F* destination, Components.Block8x8F* source) public static unsafe void Scale16X16To8X8(Block8x8F* destination, Block8x8F* source)
{ {
float* d = (float*)destination; float* d = (float*)destination;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -421,7 +421,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DivideRoundAll(ref Components.Block8x8F a, ref Components.Block8x8F b) private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b)
{ {
a.V0L = DivideRound(a.V0L, b.V0L); a.V0L = DivideRound(a.V0L, b.V0L);
a.V0R = DivideRound(a.V0R, b.V0R); a.V0R = DivideRound(a.V0R, b.V0R);

Loading…
Cancel
Save