From 026f0d857a802f843f2e8a7e349bb0ea0359d0a6 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 6 Dec 2016 00:23:02 +0100 Subject: [PATCH] . --- .../Jpg/Components/Block8x8F.Generated.cs | 55 -- .../Jpg/Components/Block8x8F.Generated.tt | 93 ---- .../Formats/Jpg/Components/Block8x8F.cs | 509 ------------------ .../Formats/Jpg/Components/MutableSpan.cs | 95 ---- 4 files changed, 752 deletions(-) delete mode 100644 src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.cs delete mode 100644 src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.tt delete mode 100644 src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs delete mode 100644 src/ImageSharp46/Formats/Jpg/Components/MutableSpan.cs diff --git a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.cs b/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.cs deleted file mode 100644 index 2fec402d62..0000000000 --- a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.cs +++ /dev/null @@ -1,55 +0,0 @@ - -using System; -using System.Numerics; -using System.Runtime.CompilerServices; - - -namespace ImageSharp.Formats -{ - internal partial struct Block8x8F - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void TransposeInto(ref Block8x8F d) - { - d.V0L.X = V0L.X; d.V1L.X = V0L.Y; d.V2L.X = V0L.Z; d.V3L.X = V0L.W; d.V4L.X = V0R.X; d.V5L.X = V0R.Y; d.V6L.X = V0R.Z; d.V7L.X = V0R.W; - d.V0L.Y = V1L.X; d.V1L.Y = V1L.Y; d.V2L.Y = V1L.Z; d.V3L.Y = V1L.W; d.V4L.Y = V1R.X; d.V5L.Y = V1R.Y; d.V6L.Y = V1R.Z; d.V7L.Y = V1R.W; - d.V0L.Z = V2L.X; d.V1L.Z = V2L.Y; d.V2L.Z = V2L.Z; d.V3L.Z = V2L.W; d.V4L.Z = V2R.X; d.V5L.Z = V2R.Y; d.V6L.Z = V2R.Z; d.V7L.Z = V2R.W; - d.V0L.W = V3L.X; d.V1L.W = V3L.Y; d.V2L.W = V3L.Z; d.V3L.W = V3L.W; d.V4L.W = V3R.X; d.V5L.W = V3R.Y; d.V6L.W = V3R.Z; d.V7L.W = V3R.W; - d.V0R.X = V4L.X; d.V1R.X = V4L.Y; d.V2R.X = V4L.Z; d.V3R.X = V4L.W; d.V4R.X = V4R.X; d.V5R.X = V4R.Y; d.V6R.X = V4R.Z; d.V7R.X = V4R.W; - d.V0R.Y = V5L.X; d.V1R.Y = V5L.Y; d.V2R.Y = V5L.Z; d.V3R.Y = V5L.W; d.V4R.Y = V5R.X; d.V5R.Y = V5R.Y; d.V6R.Y = V5R.Z; d.V7R.Y = V5R.W; - d.V0R.Z = V6L.X; d.V1R.Z = V6L.Y; d.V2R.Z = V6L.Z; d.V3R.Z = V6L.W; d.V4R.Z = V6R.X; d.V5R.Z = V6R.Y; d.V6R.Z = V6R.Z; d.V7R.Z = V6R.W; - d.V0R.W = V7L.X; d.V1R.W = V7L.Y; d.V2R.W = V7L.Z; d.V3R.W = V7L.W; d.V4R.W = V7R.X; d.V5R.W = V7R.Y; d.V6R.W = V7R.Z; d.V7R.W = V7R.W; - } - - - public void CropInto(float min, float max, ref Block8x8F d) - { - Vector4 minVec = new Vector4(min); - Vector4 maxVec = new Vector4(max); - - d.V0L = Vector4.Max(Vector4.Min(V0L, maxVec), minVec);d.V0R = Vector4.Max(Vector4.Min(V0R, maxVec), minVec); - d.V1L = Vector4.Max(Vector4.Min(V1L, maxVec), minVec);d.V1R = Vector4.Max(Vector4.Min(V1R, maxVec), minVec); - d.V2L = Vector4.Max(Vector4.Min(V2L, maxVec), minVec);d.V2R = Vector4.Max(Vector4.Min(V2R, maxVec), minVec); - d.V3L = Vector4.Max(Vector4.Min(V3L, maxVec), minVec);d.V3R = Vector4.Max(Vector4.Min(V3R, maxVec), minVec); - d.V4L = Vector4.Max(Vector4.Min(V4L, maxVec), minVec);d.V4R = Vector4.Max(Vector4.Min(V4R, maxVec), minVec); - d.V5L = Vector4.Max(Vector4.Min(V5L, maxVec), minVec);d.V5R = Vector4.Max(Vector4.Min(V5R, maxVec), minVec); - d.V6L = Vector4.Max(Vector4.Min(V6L, maxVec), minVec);d.V6R = Vector4.Max(Vector4.Min(V6R, maxVec), minVec); - d.V7L = Vector4.Max(Vector4.Min(V7L, maxVec), minVec);d.V7R = Vector4.Max(Vector4.Min(V7R, maxVec), minVec); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void ColorifyInto(ref Block8x8F d) - { - d.V0L = Vector4.Max(Vector4.Min(V0L, CMax4), CMin4) + COff4;d.V0R = Vector4.Max(Vector4.Min(V0R, CMax4), CMin4) + COff4; - d.V1L = Vector4.Max(Vector4.Min(V1L, CMax4), CMin4) + COff4;d.V1R = Vector4.Max(Vector4.Min(V1R, CMax4), CMin4) + COff4; - d.V2L = Vector4.Max(Vector4.Min(V2L, CMax4), CMin4) + COff4;d.V2R = Vector4.Max(Vector4.Min(V2R, CMax4), CMin4) + COff4; - d.V3L = Vector4.Max(Vector4.Min(V3L, CMax4), CMin4) + COff4;d.V3R = Vector4.Max(Vector4.Min(V3R, CMax4), CMin4) + COff4; - d.V4L = Vector4.Max(Vector4.Min(V4L, CMax4), CMin4) + COff4;d.V4R = Vector4.Max(Vector4.Min(V4R, CMax4), CMin4) + COff4; - d.V5L = Vector4.Max(Vector4.Min(V5L, CMax4), CMin4) + COff4;d.V5R = Vector4.Max(Vector4.Min(V5R, CMax4), CMin4) + COff4; - d.V6L = Vector4.Max(Vector4.Min(V6L, CMax4), CMin4) + COff4;d.V6R = Vector4.Max(Vector4.Min(V6R, CMax4), CMin4) + COff4; - d.V7L = Vector4.Max(Vector4.Min(V7L, CMax4), CMin4) + COff4;d.V7R = Vector4.Max(Vector4.Min(V7R, CMax4), CMin4) + COff4; - } - - - } -} diff --git a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.tt b/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.tt deleted file mode 100644 index 810c4e9047..0000000000 --- a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.Generated.tt +++ /dev/null @@ -1,93 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ output extension=".cs" #> - -using System; -using System.Numerics; -using System.Runtime.CompilerServices; - -<# -char[] coordz = new[] {'X', 'Y', 'Z', 'W'}; -#> - -namespace ImageSharp.Formats -{ - internal partial struct Block8x8F - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void TransposeInto(ref Block8x8F d) - { - <# - PushIndent(" "); - - for (int i = 0; i < 8; i++) - { - char destCoord = coordz[i % 4]; - char destSide = (i / 4) % 2 == 0 ? 'L' : 'R'; - - for (int j = 0; j < 8; j++) - { - char srcCoord = coordz[j % 4]; - char srcSide = (j / 4) % 2 == 0 ? 'L' : 'R'; - - string expression = $"d.V{j}{destSide}.{destCoord} = V{i}{srcSide}.{srcCoord}; "; - //bld.Append(expression); - Write(expression); - } - //bld.AppendLine(); - WriteLine(""); - } - PopIndent(); - //Write(bld.ToString()); - #> - } - - - public void CropInto(float min, float max, ref Block8x8F d) - { - Vector4 minVec = new Vector4(min); - Vector4 maxVec = new Vector4(max); - - <# - - PushIndent(" "); - - for (int i = 0; i < 8; i++) - { - for (int j = 0; j < 2; j++) - { - char side = j == 0 ? 'L' : 'R'; - Write($"d.V{i}{side} = Vector4.Max(Vector4.Min(V{i}{side}, maxVec), minVec);"); - } - WriteLine(""); - } - PopIndent(); - #> - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void ColorifyInto(ref Block8x8F d) - { - <# - - PushIndent(" "); - - for (int i = 0; i < 8; i++) - { - for (int j = 0; j < 2; j++) - { - char side = j == 0 ? 'L' : 'R'; - Write($"d.V{i}{side} = Vector4.Max(Vector4.Min(V{i}{side}, CMax4), CMin4) + COff4;"); - } - WriteLine(""); - } - PopIndent(); - #> - } - - - } -} diff --git a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs deleted file mode 100644 index 4b9830aa73..0000000000 --- a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs +++ /dev/null @@ -1,509 +0,0 @@ -using System; -using System.Buffers; -using System.Numerics; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// ReSharper disable InconsistentNaming - -namespace ImageSharp.Formats -{ - /// - /// DCT code Ported from https://github.com/norishigefukushima/dct_simd - /// - internal partial struct Block8x8F - { - public Vector4 V0L; - public Vector4 V0R; - - public Vector4 V1L; - public Vector4 V1R; - - public Vector4 V2L; - public Vector4 V2R; - - public Vector4 V3L; - public Vector4 V3R; - - public Vector4 V4L; - public Vector4 V4R; - - public Vector4 V5L; - public Vector4 V5R; - - public Vector4 V6L; - public Vector4 V6R; - - public Vector4 V7L; - public Vector4 V7R; - - - public const int VectorCount = 16; - public const int ScalarCount = VectorCount*4; - - private static readonly ArrayPool ScalarArrayPool = ArrayPool.Create(ScalarCount, 50); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe void LoadFrom(MutableSpan source) - { - fixed (Vector4* ptr = &V0L) - { - Marshal.Copy(source.Data, source.Offset, (IntPtr) ptr, ScalarCount); - //float* fp = (float*)ptr; - //for (int i = 0; i < ScalarCount; i++) - //{ - // fp[i] = source[i]; - //} - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe void CopyTo(MutableSpan dest) - { - fixed (Vector4* ptr = &V0L) - { - Marshal.Copy((IntPtr) ptr, dest.Data, dest.Offset, ScalarCount); - } - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe void CopyTo(float[] dest) - { - fixed (Vector4* ptr = &V0L) - { - Marshal.Copy((IntPtr) ptr, dest, 0, ScalarCount); - } - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void LoadFrom(Block8x8F* blockPtr, MutableSpan source) - { - Marshal.Copy(source.Data, source.Offset, (IntPtr) blockPtr, ScalarCount); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void CopyTo(Block8x8F* blockPtr, MutableSpan dest) - { - Marshal.Copy((IntPtr) blockPtr, dest.Data, dest.Offset, ScalarCount); - } - - - internal unsafe void LoadFrom(MutableSpan source) - { - fixed (Vector4* ptr = &V0L) - { - float* fp = (float*) ptr; - for (int i = 0; i < ScalarCount; i++) - { - fp[i] = source[i]; - } - } - } - - internal unsafe void CopyTo(MutableSpan dest) - { - fixed (Vector4* ptr = &V0L) - { - float* fp = (float*) ptr; - for (int i = 0; i < ScalarCount; i++) - { - dest[i] = (int) fp[i]; - } - } - } - - public unsafe void TransposeInplace() - { - fixed (Vector4* ptr = &V0L) - { - float* data = (float*) ptr; - - for (int i = 1; i < 8; i++) - { - int i8 = i*8; - for (int j = 0; j < i; j++) - { - float tmp = data[i8 + j]; - data[i8 + j] = data[j*8 + i]; - data[j*8 + i] = tmp; - } - } - } - - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void MultiplyAllInplace(Vector4 s) - { - V0L *= s; - V0R *= s; - V1L *= s; - V1R *= s; - V2L *= s; - V2R *= s; - V3L *= s; - V3R *= s; - V4L *= s; - V4R *= s; - V5L *= s; - V5R *= s; - V6L *= s; - V6R *= s; - V7L *= s; - V7R *= s; - } - - // ReSharper disable once InconsistentNaming - public void IDCTInto(ref Block8x8F dest, ref Block8x8F temp) - { - TransposeInto(ref temp); - temp.iDCT2D8x4_LeftPart(ref dest); - temp.iDCT2D8x4_RightPart(ref dest); - - dest.TransposeInto(ref temp); - - temp.iDCT2D8x4_LeftPart(ref dest); - temp.iDCT2D8x4_RightPart(ref dest); - - dest.MultiplyAllInplace(_0_125); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void IDCTInplace() - { - Block8x8F result = new Block8x8F(); - Block8x8F temp = new Block8x8F(); - IDCTInto(ref result, ref temp); - this = result; - } - - private static readonly Vector4 _1_175876 = new Vector4(1.175876f); - private static readonly Vector4 _1_961571 = new Vector4(-1.961571f); - private static readonly Vector4 _0_390181 = new Vector4(-0.390181f); - private static readonly Vector4 _0_899976 = new Vector4(-0.899976f); - private static readonly Vector4 _2_562915 = new Vector4(-2.562915f); - private static readonly Vector4 _0_298631 = new Vector4(0.298631f); - private static readonly Vector4 _2_053120 = new Vector4(2.053120f); - private static readonly Vector4 _3_072711 = new Vector4(3.072711f); - private static readonly Vector4 _1_501321 = new Vector4(1.501321f); - private static readonly Vector4 _0_541196 = new Vector4(0.541196f); - private static readonly Vector4 _1_847759 = new Vector4(-1.847759f); - private static readonly Vector4 _0_765367 = new Vector4(0.765367f); - private static readonly Vector4 _0_125 = new Vector4(0.1250f); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void iDCT2D8x4_LeftPart(ref Block8x8F d) - { - /* - float a0,a1,a2,a3,b0,b1,b2,b3; float z0,z1,z2,z3,z4; float r[8]; int i; - for(i = 0;i < 8;i++){ r[i] = (float)(cos((double)i / 16.0 * M_PI) * M_SQRT2); } - */ - /* - 0: 1.414214 - 1: 1.387040 - 2: 1.306563 - 3: - 4: 1.000000 - 5: 0.785695 - 6: - 7: 0.275899 - */ - - Vector4 my1 = V1L; - Vector4 my7 = V7L; - Vector4 mz0 = my1 + my7; - - Vector4 my3 = V3L; - Vector4 mz2 = my3 + my7; - Vector4 my5 = V5L; - Vector4 mz1 = my3 + my5; - Vector4 mz3 = my1 + my5; - - Vector4 mz4 = ((mz0 + mz1)*_1_175876); - //z0 = y[1] + y[7]; z1 = y[3] + y[5]; z2 = y[3] + y[7]; z3 = y[1] + y[5]; - //z4 = (z0 + z1) * r[3]; - - mz2 = mz2*_1_961571 + mz4; - mz3 = mz3*_0_390181 + mz4; - mz0 = mz0*_0_899976; - mz1 = mz1*_2_562915; - - /* - -0.899976 - -2.562915 - -1.961571 - -0.390181 - z0 = z0 * (-r[3] + r[7]); - z1 = z1 * (-r[3] - r[1]); - z2 = z2 * (-r[3] - r[5]) + z4; - z3 = z3 * (-r[3] + r[5]) + z4;*/ - - - Vector4 mb3 = my7*_0_298631 + mz0 + mz2; - Vector4 mb2 = my5*_2_053120 + mz1 + mz3; - Vector4 mb1 = my3*_3_072711 + mz1 + mz2; - Vector4 mb0 = my1*_1_501321 + mz0 + mz3; - - /* - 0.298631 - 2.053120 - 3.072711 - 1.501321 - b3 = y[7] * (-r[1] + r[3] + r[5] - r[7]) + z0 + z2; - b2 = y[5] * ( r[1] + r[3] - r[5] + r[7]) + z1 + z3; - b1 = y[3] * ( r[1] + r[3] + r[5] - r[7]) + z1 + z2; - b0 = y[1] * ( r[1] + r[3] - r[5] - r[7]) + z0 + z3; - */ - - Vector4 my2 = V2L; - Vector4 my6 = V6L; - mz4 = (my2 + my6)*_0_541196; - Vector4 my0 = V0L; - Vector4 my4 = V4L; - mz0 = my0 + my4; - mz1 = my0 - my4; - - mz2 = mz4 + my6*_1_847759; - mz3 = mz4 + my2*_0_765367; - - my0 = mz0 + mz3; - my3 = mz0 - mz3; - my1 = mz1 + mz2; - my2 = mz1 - mz2; - /* - 1.847759 - 0.765367 - z4 = (y[2] + y[6]) * r[6]; - z0 = y[0] + y[4]; z1 = y[0] - y[4]; - z2 = z4 - y[6] * (r[2] + r[6]); - z3 = z4 + y[2] * (r[2] - r[6]); - a0 = z0 + z3; a3 = z0 - z3; - a1 = z1 + z2; a2 = z1 - z2; - */ - - d.V0L = my0 + mb0; - d.V7L = my0 - mb0; - d.V1L = my1 + mb1; - d.V6L = my1 - mb1; - d.V2L = my2 + mb2; - d.V5L = my2 - mb2; - d.V3L = my3 + mb3; - d.V4L = my3 - mb3; - /* - x[0] = a0 + b0; x[7] = a0 - b0; - x[1] = a1 + b1; x[6] = a1 - b1; - x[2] = a2 + b2; x[5] = a2 - b2; - x[3] = a3 + b3; x[4] = a3 - b3; - for(i = 0;i < 8;i++){ x[i] *= 0.353554f; } - */ - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void iDCT2D8x4_RightPart(ref Block8x8F d) - { - /* - float a0,a1,a2,a3,b0,b1,b2,b3; float z0,z1,z2,z3,z4; float r[8]; int i; - for(i = 0;i < 8;i++){ r[i] = (float)(cos((double)i / 16.0 * M_PI) * M_SQRT2); } - */ - /* - 0: 1.414214 - 1: 1.387040 - 2: 1.306563 - 3: - 4: 1.000000 - 5: 0.785695 - 6: - 7: 0.275899 - */ - - Vector4 my1 = V1R; - Vector4 my7 = V7R; - Vector4 mz0 = my1 + my7; - - Vector4 my3 = V3R; - Vector4 mz2 = my3 + my7; - Vector4 my5 = V5R; - Vector4 mz1 = my3 + my5; - Vector4 mz3 = my1 + my5; - - Vector4 mz4 = ((mz0 + mz1)*_1_175876); - //z0 = y[1] + y[7]; z1 = y[3] + y[5]; z2 = y[3] + y[7]; z3 = y[1] + y[5]; - //z4 = (z0 + z1) * r[3]; - - mz2 = mz2*_1_961571 + mz4; - mz3 = mz3*_0_390181 + mz4; - mz0 = mz0*_0_899976; - mz1 = mz1*_2_562915; - - /* - -0.899976 - -2.562915 - -1.961571 - -0.390181 - z0 = z0 * (-r[3] + r[7]); - z1 = z1 * (-r[3] - r[1]); - z2 = z2 * (-r[3] - r[5]) + z4; - z3 = z3 * (-r[3] + r[5]) + z4;*/ - - - Vector4 mb3 = my7*_0_298631 + mz0 + mz2; - Vector4 mb2 = my5*_2_053120 + mz1 + mz3; - Vector4 mb1 = my3*_3_072711 + mz1 + mz2; - Vector4 mb0 = my1*_1_501321 + mz0 + mz3; - - /* - 0.298631 - 2.053120 - 3.072711 - 1.501321 - b3 = y[7] * (-r[1] + r[3] + r[5] - r[7]) + z0 + z2; - b2 = y[5] * ( r[1] + r[3] - r[5] + r[7]) + z1 + z3; - b1 = y[3] * ( r[1] + r[3] + r[5] - r[7]) + z1 + z2; - b0 = y[1] * ( r[1] + r[3] - r[5] - r[7]) + z0 + z3; - */ - - Vector4 my2 = V2R; - Vector4 my6 = V6R; - mz4 = (my2 + my6)*_0_541196; - Vector4 my0 = V0R; - Vector4 my4 = V4R; - mz0 = my0 + my4; - mz1 = my0 - my4; - - mz2 = mz4 + my6*_1_847759; - mz3 = mz4 + my2*_0_765367; - - my0 = mz0 + mz3; - my3 = mz0 - mz3; - my1 = mz1 + mz2; - my2 = mz1 - mz2; - /* - 1.847759 - 0.765367 - z4 = (y[2] + y[6]) * r[6]; - z0 = y[0] + y[4]; z1 = y[0] - y[4]; - z2 = z4 - y[6] * (r[2] + r[6]); - z3 = z4 + y[2] * (r[2] - r[6]); - a0 = z0 + z3; a3 = z0 - z3; - a1 = z1 + z2; a2 = z1 - z2; - */ - - d.V0R = my0 + mb0; - d.V7R = my0 - mb0; - d.V1R = my1 + mb1; - d.V6R = my1 - mb1; - d.V2R = my2 + mb2; - d.V5R = my2 - mb2; - d.V3R = my3 + mb3; - d.V4R = my3 - mb3; - /* - x[0] = a0 + b0; x[7] = a0 - b0; - x[1] = a1 + b1; x[6] = a1 - b1; - x[2] = a2 + b2; x[5] = a2 - b2; - x[3] = a3 + b3; x[4] = a3 - b3; - for(i = 0;i < 8;i++){ x[i] *= 0.353554f; } - */ - } - - - public unsafe float this[int idx] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - fixed (Block8x8F* p = &this) - { - float* fp = (float*) p; - return fp[idx]; - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - fixed (Block8x8F* p = &this) - { - float* fp = (float*) p; - fp[idx] = value; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe float GetScalarAt(Block8x8F* blockPtr, int idx) - { - float* fp = (float*) blockPtr; - return fp[idx]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void SetScalarAt(Block8x8F* blockPtr, int idx, float value) - { - float* fp = (float*) blockPtr; - fp[idx] = value; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal void Clear() - { - this = new Block8x8F(); // LOL C# Plz! - } - - internal void LoadFrom(ref BlockF legacyBlock) - { - LoadFrom(legacyBlock.Data); - } - - internal void CopyTo(ref BlockF legacyBlock) - { - CopyTo(legacyBlock.Data); - } - - private static readonly Vector4 CMin4 = new Vector4(-128f); - private static readonly Vector4 CMax4 = new Vector4(127f); - private static readonly Vector4 COff4 = new Vector4(128f); - - /// - /// Level shift by +128, clip to [0, 255], and write to buffer. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal unsafe void CopyColorsTo( - MutableSpan buffer, - int stride, - Block8x8F* temp) - { - ColorifyInto(ref *temp); - - float* src = (float*) temp; - for (int i = 0; i < 8; i++) - { - buffer[0] = (byte) src[0]; - buffer[1] = (byte) src[1]; - buffer[2] = (byte) src[2]; - buffer[3] = (byte) src[3]; - buffer[4] = (byte) src[4]; - buffer[5] = (byte) src[5]; - buffer[6] = (byte) src[6]; - buffer[7] = (byte) src[7]; - buffer.AddOffset(stride); - src += 8; - } - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static unsafe void UnZig(Block8x8F* block, Block8x8F* qt, int* unzigPtr) - { - float* b = (float*)block; - float* qtp = (float*)qt; - for (int zig = 0; zig < BlockF.BlockSize; zig++) - { - float* unzigPos = b + unzigPtr[zig]; - float val = *unzigPos; - val *= qtp[zig]; - *unzigPos = val; - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp46/Formats/Jpg/Components/MutableSpan.cs b/src/ImageSharp46/Formats/Jpg/Components/MutableSpan.cs deleted file mode 100644 index 0cb11690b0..0000000000 --- a/src/ImageSharp46/Formats/Jpg/Components/MutableSpan.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System.Buffers; -using System.Numerics; -using System.Runtime.CompilerServices; - -namespace ImageSharp.Formats -{ - /// - /// Like corefxlab Span, but with an AddOffset() method for efficiency. - /// TODO: When Span will be official, consider replacing this class! - /// - /// - /// - internal struct MutableSpan - { - public T[] Data; - public int Offset; - - public int TotalCount => Data.Length - Offset; - - public MutableSpan(int size, int offset = 0) - { - Data = new T[size]; - Offset = offset; - } - - public MutableSpan(T[] data, int offset = 0) - { - Data = data; - Offset = offset; - } - - public T this[int idx] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Data[idx + Offset]; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Data[idx + Offset] = value; } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public MutableSpan Slice(int offset) - { - return new MutableSpan(Data, Offset + offset); - } - - public static implicit operator MutableSpan(T[] data) => new MutableSpan(data, 0); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddOffset(int offset) - { - Offset += offset; - } - } - - internal static class MutableSpanExtensions - { - public static MutableSpan Slice(this T[] array, int offset) => new MutableSpan(array, offset); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SaveTo(this MutableSpan 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 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 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 data, ref Vector4 v) - { - data[0] = (int)v.X; - data[1] = (int)v.Y; - data[2] = (int)v.Z; - data[3] = (int)v.W; - } - - - } -} \ No newline at end of file