// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // // ReSharper disable InconsistentNaming <#@ 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" #> // #pragma warning disable using System; using System.Numerics; using System.Runtime.CompilerServices; <# char[] coordz = {'X', 'Y', 'Z', 'W'}; #> namespace ImageSharp.Formats.Jpg { internal partial struct Block8x8F { private static readonly Vector4 CMin4 = new Vector4(-128f); private static readonly Vector4 CMax4 = new Vector4(127f); private static readonly Vector4 COff4 = new Vector4(128f); /// /// Transpose the block into d /// /// Destination [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}; "; Write(expression); } WriteLine(""); } PopIndent(); #> } /// /// Level shift by +128, clip to [0, 255] /// /// Destination [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void TransformByteConvetibleColorValuesInto(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(); #> } } }