Skip to content

Commit

Permalink
Upgrade libczicompressc to version 0.5.2 (#22)
Browse files Browse the repository at this point in the history
* Upgrade libczicompressc to 0.5.2

* Adapt tests

* Use LFS for CZIs
  • Loading branch information
m-ringler authored Nov 13, 2023
1 parent 40a2ba8 commit c77db3b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.nupkg filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.czi filter=lfs diff=lfs merge=lfs -text
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@ FodyWeavers.xsd

##################################
### END VisualStudio.gitignore ###
##################################
##################################

# Be able to commit local nupkg
!czishrink/packages_local/*.nupkg
4 changes: 2 additions & 2 deletions czishrink/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- Version -->
<VersionPrefix>1.0.1<!--fix/version-stuff--></VersionPrefix>
<VersionPrefix>1.0.2<!--feature/upgrade-libczicompressc-0_5_2--></VersionPrefix>
</PropertyGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions czishrink/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageVersion Include="DynamicData" Version="8.1.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Fody" Version="6.8.0" />
<PackageVersion Include="libczicompressc" Version="0.5.1-alpha.0" />
<PackageVersion Include="libczicompressc" Version="0.5.2" />
<PackageVersion Include="MessageBox.Avalonia" Version="3.1.5.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
Expand All @@ -37,4 +37,4 @@
<PackageVersion Include="xunit" Version="2.6.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions czishrink/libczicompressc/libczicompressc.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>libczicompressc</id>
<version>0.5.1-alpha.0</version>
<version>0.5.2</version>
<title>Native runtimes for CZI ZStd compression</title>
<authors>Carl Zeiss Microscopy</authors>
<owners>Carl Zeiss Microscopy</owners>
Expand All @@ -11,6 +11,6 @@
<license type="expression">MIT</license>
<projectUrl>https://github.com/zeissmicroscopy/czicompress/</projectUrl>
<copyright>© Carl Zeiss Microscopy GmbH and others. All rights reserved.</copyright>
<repository type="git" url="https://github.com/ZEISS/czicompress" branch="main" commit="029973e80f064bce28b22122213e327037eef782" />
<repository type="git" url="https://github.com/ZEISS/czicompress" branch="main" commit="40a2ba8489544626c2481ca95177b3235b5c0de7" />
</metadata>
</package>
65 changes: 59 additions & 6 deletions czishrink/netczicompressTests/Models/PInvokeFileProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace netczicompressTests.Models;

using System.Reactive.Disposables;
using System.Text;
using System.Xml.Linq;
using System.Xml.XPath;

/// <summary>
/// Tests for <see cref="PInvokeFileProcessor"/>.
Expand All @@ -23,7 +26,7 @@ public void Ctr_WhenCalledWithNoOp_Throws()
[InlineData(CompressionMode.CompressUncompressed)]
[InlineData(CompressionMode.CompressAll)]
[InlineData(CompressionMode.CompressUncompressedAndZstd)]
public void CompressAndDecompressOneFile_FilesHaveCorrectSize(
public void CompressAndDecompressOneFile_FilesHaveCorrectSizeAndMetadata(
CompressionMode mode)
{
// ARRANGE
Expand All @@ -43,13 +46,17 @@ public void CompressAndDecompressOneFile_FilesHaveCorrectSize(
decompressor.ProcessFile(compressed, uncompressed, _ => { }, CancellationToken.None);

var compressedSize = GetLength(compressed);

var decompressedSize = GetLength(uncompressed);
var originalSize = GetLength(testFile);

// ASSERT
compressedSize.Should().Be(58432L);
compressedSize.Should().Be(58528L);
decompressedSize.Should().BeCloseTo(originalSize, 2048);
decompressedSize.Should().Be(99552L);
decompressedSize.Should().Be(99648L);

Metadata.FromFile(compressed).CurrentCompressionParameters.Should().Be("Lossless: True");
Metadata.FromFile(uncompressed).CurrentCompressionParameters.Should().BeEmpty();
}

[Theory]
Expand Down Expand Up @@ -114,9 +121,9 @@ public void GetLibFullName_WhenCalled_ReturnsExpected()
}

[Theory]
[InlineData(0, 99552L, 57760L)]
[InlineData(2, 99552L, 57920L)]
[InlineData(4, 99552L, 57472L)]
[InlineData(0, 99648L, 57856L)]
[InlineData(2, 99648L, 58016L)]
[InlineData(4, 99648L, 57568L)]
public void CompressWithLevel_FilesHaveCorrectSize(
int compressionLevel, long expectedUncompressedSize, long expectedCompressedSize)
{
Expand Down Expand Up @@ -160,4 +167,50 @@ private static string GetTestFilePath()
var testFile = Path.Combine(dirname ?? ".", "mandelbrot.czi");
return testFile;
}

private class Metadata
{
public required XDocument Xml { get; init; }

public string? CurrentCompressionParameters => this.Xml
.XPathSelectElement(
"ImageDocument/Metadata/Information/Image/CurrentCompressionParameters")
?.Value;

public static Metadata FromFile(string path) => new() { Xml = ParseMetadataXml(path) };

private static XDocument ParseMetadataXml(string filePath)
{
return XDocument.Parse(ReadMetadataXml(filePath));
}

private static string ReadMetadataXml(string filePath)
{
// These numbers are from the ZISRAW file specification.
const int SegmentHeaderSize = 16 + 8 + 8;
const int MetadataPositionInFileHeader = 60;
const int MetadataHeaderSize = 256;

using var stream = File.OpenRead(filePath);

// BinaryReader uses little-endian as required.
using var reader = new BinaryReader(stream);

// Read metadataPosition from ZISRAW file header
stream.Position = SegmentHeaderSize + MetadataPositionInFileHeader;
long metadataHeaderPosition = reader.ReadInt64() + SegmentHeaderSize;

// Read size of XML from ZISRAWMETADATA header
stream.Position = metadataHeaderPosition;
int metadataSize = reader.ReadInt32();

// Read XML bytes from ZISRAWMETADATA segment
stream.Position = metadataHeaderPosition + MetadataHeaderSize;
var xmlBytes = reader.ReadBytes(metadataSize);

// Decode (always UTF-8 according to the spec)
var result = Encoding.UTF8.GetString(xmlBytes);
return result;
}
}
}
Binary file modified czishrink/netczicompressTests/mandelbrot.czi
Binary file not shown.
3 changes: 0 additions & 3 deletions czishrink/packages_local/libczicompressc.0.5.1-alpha.0.nupkg

This file was deleted.

3 changes: 3 additions & 0 deletions czishrink/packages_local/libczicompressc.0.5.2.nupkg
Git LFS file not shown

0 comments on commit c77db3b

Please sign in to comment.