Skip to content

Commit 83d46b4

Browse files
author
github-actions
committed
Merge branch 'release/3.2.0'
2 parents b79b5df + 0368ffc commit 83d46b4

20 files changed

+1322
-1082
lines changed

.github/workflows/foss-compliance-scan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v1
1919
with:
20-
dotnet-version: 3.1.x
20+
dotnet-version: 8.0.x
2121
- name: Setup MSBuild
2222
uses: microsoft/[email protected]
2323
with:

src/PiWeb.Volume.Tests/VolumeTestHelper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public static byte[] CreateLowNoiseBlock( int u, int v, int w )
5858
for( var y = 0; y < BlockVolume.N; y++ )
5959
for( var x = 0; x < BlockVolume.N; x++ )
6060
{
61-
var value = DiscreteCosineTransform.U[ u * BlockVolume.N + x ] *
62-
DiscreteCosineTransform.U[ v * BlockVolume.N + y ] *
63-
DiscreteCosineTransform.U[ w * BlockVolume.N + z ];
61+
var value = DiscreteCosineTransform.U[ u ][ x ] *
62+
DiscreteCosineTransform.U[ v ][ y ] *
63+
DiscreteCosineTransform.U[ w ][ z ];
6464

6565
min = Math.Min( min, value );
6666
max = Math.Max( max, value );

src/PiWeb.Volume/Block/BlockIndex.cs

+19-20
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,29 @@
88

99
#endregion
1010

11-
namespace Zeiss.PiWeb.Volume.Block
11+
namespace Zeiss.PiWeb.Volume.Block;
12+
13+
/// <summary>
14+
/// Stores the index of a data block.
15+
/// </summary>
16+
internal readonly record struct BlockIndex
1217
{
13-
/// <summary>
14-
/// Stores the index of a data block.
15-
/// </summary>
16-
internal readonly record struct BlockIndex
17-
{
18-
#region constructors
18+
#region constructors
1919

20-
internal BlockIndex( ushort x, ushort y, ushort z )
21-
{
22-
X = x;
23-
Y = y;
24-
Z = z;
25-
}
20+
internal BlockIndex( ushort x, ushort y, ushort z )
21+
{
22+
X = x;
23+
Y = y;
24+
Z = z;
25+
}
2626

27-
#endregion
27+
#endregion
2828

29-
#region properties
29+
#region properties
3030

31-
public readonly ushort X;
32-
public readonly ushort Y;
33-
public readonly ushort Z;
31+
public readonly ushort X;
32+
public readonly ushort Y;
33+
public readonly ushort Z;
3434

35-
#endregion
36-
}
35+
#endregion
3736
}

src/PiWeb.Volume/Block/BlockInfo.cs

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#region copyright
2+
3+
/* * * * * * * * * * * * * * * * * * * * * * * * * */
4+
/* Carl Zeiss Industrielle Messtechnik GmbH */
5+
/* Softwaresystem PiWeb */
6+
/* (c) Carl Zeiss 2024 */
7+
/* * * * * * * * * * * * * * * * * * * * * * * * * */
8+
9+
#endregion
10+
11+
namespace Zeiss.PiWeb.Volume.Block;
12+
13+
#region usings
14+
15+
using System;
16+
using System.IO;
17+
18+
#endregion
19+
20+
/// <summary>
21+
/// Holds information about a block of encoded values.
22+
/// </summary>
23+
internal readonly record struct BlockInfo( ushort ValueCount, bool IsFirstValueShort, bool AreOtherValuesShort )
24+
{
25+
#region constants
26+
27+
private const ushort ValueCountMask = 0b0000111111111111;
28+
private const ushort IsFirstValueShortMask = 0b0001000000000000;
29+
private const int IsFirstValueShortOffset = 12;
30+
private const ushort AreOtherValuesShortMask = 0b0010000000000000;
31+
private const int AreOtherValuesShortOffset = 13;
32+
33+
#endregion
34+
35+
#region properties
36+
37+
/// <summary>
38+
/// The length of the block in bytes.
39+
/// </summary>
40+
public ushort Length =>
41+
ValueCount switch
42+
{
43+
0 => 0,
44+
1 => FirstValueSize,
45+
_ => (ushort)( FirstValueSize + ( ValueCount - 1 ) * ( AreOtherValuesShort ? 2 : 1 ) )
46+
};
47+
48+
/// <summary>
49+
/// The size of the first value in bytes.
50+
/// </summary>
51+
public byte FirstValueSize => (byte)( IsFirstValueShort ? 2 : 1 );
52+
53+
#endregion
54+
55+
#region methods
56+
57+
/// <summary>
58+
/// Reads the <see cref="BlockInfo"/> from the specified <paramref name="reader"/>.
59+
/// </summary>
60+
public static BlockInfo Read( BinaryReader reader )
61+
{
62+
var resultLength = reader.ReadUInt16();
63+
var valueCount = resultLength & ValueCountMask;
64+
var isFirstValueShort = ( resultLength & IsFirstValueShortMask ) >> IsFirstValueShortOffset;
65+
var areOtherValuesShort = ( resultLength & AreOtherValuesShortMask ) >> AreOtherValuesShortOffset;
66+
67+
return new BlockInfo( (ushort)valueCount, isFirstValueShort > 0, areOtherValuesShort > 0 );
68+
}
69+
70+
/// <summary>
71+
/// Writes the <see cref="BlockInfo"/> to the specified <paramref name="writer"/>.
72+
/// </summary>
73+
public void Write( BinaryWriter writer )
74+
{
75+
var result = ValueCount & ValueCountMask;
76+
if( IsFirstValueShort )
77+
result |= ( 1 << IsFirstValueShortOffset );
78+
if( AreOtherValuesShort )
79+
result |= ( 1 << AreOtherValuesShortOffset );
80+
81+
writer.Write( (ushort)result );
82+
}
83+
84+
/// <summary>
85+
/// Creates a <see cref="BlockInfo"/> for the specified <paramref name="resultBlock"/>.
86+
/// </summary>
87+
public static BlockInfo Create( ReadOnlySpan<short> resultBlock )
88+
{
89+
var count = 0;
90+
var isFirstValueShort = resultBlock[ 0 ] is > sbyte.MaxValue or < sbyte.MinValue;
91+
var areOtherValuesShort = false;
92+
93+
for( var i = 0; i < BlockVolume.N3; i++ )
94+
{
95+
var value = resultBlock[ i ];
96+
if( value != 0 )
97+
count = i + 1;
98+
99+
if( i > 0 && ( value is > sbyte.MaxValue or < sbyte.MinValue ) )
100+
areOtherValuesShort = true;
101+
}
102+
103+
return new BlockInfo( (ushort)count, isFirstValueShort, areOtherValuesShort );
104+
}
105+
106+
#endregion
107+
}

0 commit comments

Comments
 (0)