mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 71 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
internal static class JxlNoiseHelper |
||||
|
{ |
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public static JxlNoiseIndexAndFraction IndexAndFraction(float x) |
||||
|
{ |
||||
|
const int scaleNumerator = JxlNoiseParameters.NoisePoints - 2; |
||||
|
const float scale = scaleNumerator / 1.0f; |
||||
|
|
||||
|
float scaledX = MathF.Max(0f, x * scale); |
||||
|
float floorX = MathF.Floor(scaledX); |
||||
|
float fractionalX = scaledX - floorX; |
||||
|
|
||||
|
if (scaledX >= scaleNumerator + 1) |
||||
|
{ |
||||
|
floorX = scaleNumerator; |
||||
|
fractionalX = 1f; |
||||
|
} |
||||
|
|
||||
|
return new((int)floorX, fractionalX); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct JxlNoiseIndexAndFraction(int index, float fraction) |
||||
|
{ |
||||
|
public int Index = index; |
||||
|
|
||||
|
public float Fraction = fraction; |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential)] |
||||
|
internal struct JxlNoiseLevel(float noiseLevel, float intensity) |
||||
|
{ |
||||
|
public float NoiseLevel = noiseLevel; |
||||
|
|
||||
|
public float Intensity = intensity; |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jxl.Processing; |
||||
|
|
||||
|
internal sealed class JxlNoiseParameters |
||||
|
{ |
||||
|
public const int NoisePoints = 8; |
||||
|
|
||||
|
public float[] Lookup { get; set; } = new float[NoisePoints]; |
||||
|
|
||||
|
public bool ContainsAny => this.Lookup.Any(x => MathF.Abs(x) > 1e-3f); |
||||
|
|
||||
|
public void Clear() => Array.Fill(this.Lookup, 0f); |
||||
|
} |
||||
Loading…
Reference in new issue