Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use InlineArray and change CodingParameters to record struct #33

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CodingParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CharLS.Managed;

internal sealed record CodingParameters
internal record struct CodingParameters
{
public int NearLossless { get; init; }
public int RestartInterval { get; init; }
Expand Down
22 changes: 19 additions & 3 deletions src/ScanCodec.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Team CharLS.
// SPDX-License-Identifier: BSD-3-Clause

using System.Runtime.CompilerServices;

namespace CharLS.Managed;

/// <summary>
Expand All @@ -10,14 +12,28 @@ namespace CharLS.Managed;
internal class ScanCodec
{
protected int RunIndex;
protected RunModeContext[] RunModeContexts = new RunModeContext[2];
protected RegularModeContext[] RegularModeContext = new RegularModeContext[365];

protected RunModeContextArray RunModeContexts;

protected RegularModeContextArray RegularModeContext;

// Used to determine how large runs should be encoded at a time.
// Defined by the JPEG-LS standard, A.2.1., Initialization step 3.
protected static readonly int[] J =
[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15];

[InlineArray(2)]
protected struct RunModeContextArray
{
private RunModeContext _element;
}

[InlineArray(365)]
protected struct RegularModeContextArray
{
private RegularModeContext _element;
}

protected ScanCodec(FrameInfo frameInfo, JpegLSPresetCodingParameters presetCodingParameters, CodingParameters codingParameters)
{
FrameInfo = frameInfo;
Expand All @@ -34,7 +50,7 @@ protected ScanCodec(FrameInfo frameInfo, JpegLSPresetCodingParameters presetCodi
protected void InitializeParameters(int range)
{
var regularModeContext = new RegularModeContext(range);
for (int i = 0; i < RegularModeContext.Length; i++)
for (int i = 0; i < 365; i++)
{
RegularModeContext[i] = regularModeContext;
}
Expand Down