mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.9 KiB
136 lines
3.9 KiB
<#
|
|
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.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" #>
|
|
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System.Numerics;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
// <auto-generated />
|
|
<#
|
|
char[] coordz = {'X', 'Y', 'Z', 'W'};
|
|
#>
|
|
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
|
|
{
|
|
internal partial struct Block8x8F
|
|
{
|
|
private static readonly Vector4 CMin4 = new Vector4(0F);
|
|
private static readonly Vector4 CMax4 = new Vector4(255F);
|
|
private static readonly Vector4 COff4 = new Vector4(128F);
|
|
|
|
/// <summary>
|
|
/// Transpose the block into the destination block.
|
|
/// </summary>
|
|
/// <param name="d">The destination block</param>
|
|
[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++)
|
|
{
|
|
if(i > 0 && j == 0){
|
|
WriteLine("");
|
|
}
|
|
|
|
char srcCoord = coordz[j % 4];
|
|
char srcSide = (j / 4) % 2 == 0 ? 'L' : 'R';
|
|
|
|
string expression = $"d.V{j}{destSide}.{destCoord} = V{i}{srcSide}.{srcCoord};\r\n";
|
|
Write(expression);
|
|
}
|
|
}
|
|
PopIndent();
|
|
#>
|
|
}
|
|
|
|
/// <summary>
|
|
/// Level shift by +128, clip to [0, 255]
|
|
/// </summary>
|
|
public void NormalizeColorsInplace()
|
|
{
|
|
<#
|
|
|
|
PushIndent(" ");
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
char side = j == 0 ? 'L' : 'R';
|
|
Write($"this.V{i}{side} = Vector4.Clamp(this.V{i}{side} + COff4, CMin4, CMax4);\r\n");
|
|
}
|
|
}
|
|
PopIndent();
|
|
#>
|
|
}
|
|
|
|
/// <summary>
|
|
/// AVX2-only variant for executing <see cref="NormalizeColorsInplace"/> and <see cref="RoundInplace"/> in one step.
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void NormalizeColorsAndRoundInplaceAvx2()
|
|
{
|
|
Vector<float> off = new Vector<float>(128f);
|
|
Vector<float> max = new Vector<float>(255F);
|
|
<#
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
#>
|
|
|
|
ref Vector<float> row<#=i#> = ref Unsafe.As<Vector4, Vector<float>>(ref this.V<#=i#>L);
|
|
row<#=i#> = NormalizeAndRound(row<#=i#>, off, max);
|
|
<#
|
|
}
|
|
#>
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fill the block from 'source' doing short -> float conversion.
|
|
/// </summary>
|
|
public void LoadFrom(ref Block8x8 source)
|
|
{
|
|
ref short selfRef = ref Unsafe.As<Block8x8, short>(ref source);
|
|
|
|
<#
|
|
PushIndent(" ");
|
|
for (int j = 0; j < 8; j++)
|
|
{
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
char destCoord = coordz[i % 4];
|
|
char destSide = (i / 4) % 2 == 0 ? 'L' : 'R';
|
|
|
|
if(j > 0 && i == 0){
|
|
WriteLine("");
|
|
}
|
|
|
|
char srcCoord = coordz[j % 4];
|
|
char srcSide = (j / 4) % 2 == 0 ? 'L' : 'R';
|
|
|
|
string expression = $"this.V{j}{destSide}.{destCoord} = Unsafe.Add(ref selfRef, {j*8+i});\r\n";
|
|
Write(expression);
|
|
|
|
}
|
|
}
|
|
PopIndent();
|
|
#>
|
|
}
|
|
}
|
|
}
|
|
|